Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions .claude/skills/add-service/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ A service is data. **No Swift changes** unless it needs a case ENGINE_DESIGN doe

1. Cloudflare's pricing and limits pages for the product: each counted thing, its Free and
Paid allowance, its overage price, when it resets.
2. The GraphQL dataset and fields: introspect the schema with a read-only token
(`__type(name: "AccountTypes")`), then run one query over a day and compare with the
dashboard. Note the time filter (`date` or `datetime`) and the focus dimension.
3. Record what you found, with the date, in ENGINE §6 and `docs/services/<id>/design.md`.
2. The GraphQL dataset and fields: `scripts/introspect-datasets.sh '<pattern>'` lists the
matching datasets with their `sum` / `max` / `dimensions` fields, using the token in the
Keychain and printing names only. Then run one query over a day and compare with the
dashboard. Note the time filter (`date` or `datetime`), the focus dimension, and any
`where` the limit needs (ENGINE §2). **A dataset name nobody verified never ships**: one
wrong name fails the whole refresh query for everyone watching that service.
3. Record what you found, with the date and how (docs, introspection, a live read), in
ENGINE §6.

## 2. Check the cases

Expand All @@ -33,10 +37,12 @@ propose the new case in ENGINE_DESIGN and ask the user to confirm before code.
2. `Modules/Services/Resources/Services/<id>.json`.
3. Its allowances (and prices) in **every** plan file under `Modules/Plans/Resources/Plans/`.
A plan without an allowance for a limit doesn't show that limit.
4. A recorded GraphQL answer (account ID replaced) and an `AnswerReader` test that reads it.
4. A `ReadPlanTests` test on the query it writes, and on a recorded answer (account ID replaced).

## 4. Ship

- `docs/services/<id>/README.md`: what it watches, which token permission it needs.
- One README table row, one CHANGELOG line under `Added`.
- `watchedByDefault: false` in its file: a new service arrives off (model law 21).
- A row in `docs/features/service-tabs/README.md` for its tab, and its switch in
`docs/features/settings/README.md`.
- One README table row, one CHANGELOG line under `Added`, the slice in `docs/status.md`.
- A mockup in `design-concept/` if the service gets a tab with a new kind of breakdown.
11 changes: 11 additions & 0 deletions .claude/skills/fix-bug/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ that the code breaks. Find the law and its **one owner**, and fix it there, not
site. If the right fix changes a law or moves it, that is a design change: update the doc and
ask the user to confirm first. If no law covers it, propose the law first.

### Think the domain first

A bug is often a shape that let it happen: a rule a view could work out for itself, one
value meaning two states (`nil` or `""` for both *not read yet* and *none*), a `String`
where a type would have refused the bad value, a Swift branch where a definition field
belonged. Ask the five questions of the types the bug touches →
[domain-shape.md](../implement-feature/references/domain-shape.md). Fix the shape when it
is the cause, in the same change, test first; a new node or a moved owner is a design
change, confirmed first.

### Locate in the modules

The map is [implement-feature → Architecture](../implement-feature/SKILL.md#architecture).
Expand Down Expand Up @@ -76,6 +86,7 @@ Then run the full suite:
## Checklist

- [ ] Bug reproduced; the law it breaks and its owner found
- [ ] Domain thought through: is the bug a shape the [five questions](../implement-feature/references/domain-shape.md) would have refused? Fixed there if so
- [ ] Failing test written, FAILS before the fix
- [ ] Minimal fix at the owner; test PASSES
- [ ] All tests pass
Expand Down
15 changes: 15 additions & 0 deletions .claude/skills/implement-feature/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ Read in order ([ARCHITECTURE.md](../../../docs/architecture/ARCHITECTURE.md) map
| Is it a choice or a reading? | choices go to `settings.json`, readings stay in memory (CANONICAL §2) |
| Is a law missing, or owned twice? | add it to CANONICAL §5 with **one** owner |

### Think the domain first

Before components, ask how the domain should be: from the person's problem (the issue,
the journey) to the facts it must respect, to the concepts those force, then compare with
the code. Ask the five questions of every type the feature touches (would the person say
it, does the thing decide about itself, can you see every state, is it as small as it can
be, is what differs data) and draw now beside proposed →
[references/domain-shape.md](references/domain-shape.md). A new node, a moved law or a
changed owner goes into the docs change below.

Write the change into the docs first, then present it: an ASCII diagram in the module
words ([references/architecture-diagrams.md](references/architecture-diagrams.md)) and a
table (component · purpose · inputs · outputs · dependencies). Ask with AskUserQuestion,
Expand Down Expand Up @@ -65,6 +75,10 @@ public struct Limit: Sendable, Equatable {

Views read `Account` directly ([references/swift-observable.md](references/swift-observable.md)).

The patterns, on Overmind's own types (a type answers the person's questions, tell don't ask,
a case per state, values over classes, what differs is data) →
[references/domain-models.md](references/domain-models.md).

### Ports are `@Mockable`, at the module's root; implementations are `internal`

```swift
Expand Down Expand Up @@ -117,6 +131,7 @@ xcodebuild test -workspace Overmind.xcworkspace -scheme Overmind-Workspace \
## Checklist

- [ ] Read the five design docs; placed it: owner, law, module
- [ ] Thought the domain first: the five questions asked of touched types, now/proposed drawn ([domain-shape.md](references/domain-shape.md))
- [ ] Design change written into the docs; **user approval** before code
- [ ] Failing test first, asserting STATE; minimal code; refactor
- [ ] No Swift names a Cloudflare product, dataset or price
Expand Down
116 changes: 116 additions & 0 deletions .claude/skills/implement-feature/references/domain-models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Rich domain model patterns

The basic patterns, shown on Overmind's own types. Before any change, think how the domain should be: [domain-shape.md](domain-shape.md) (five questions for a domain easy to understand).

The aim of every pattern here is **less to hold in your head**. Someone reading `Limit` should be able to say what it is, what it answers and what it can be told, in the person's words, without opening another file.

## A type answers the person's questions

Each public member is a question the person asks, named the way they'd ask it, with time passed in:

```swift
/// One thing counted against the plan: a card in *Every limit today*.
public struct Limit: Sendable, Equatable, Identifiable {
public let definition: LimitDefinition
public let allowance: Allowance
public private(set) var usage: Usage?

// "How much have I used?" nil with no reading for this period
public func percent(at now: Date) -> Percent? { … }
// "Should I worry?" OK · WATCH · ACT NOW (law 2, law 3)
public func level(at now: Date) -> Level? { … }
// "Where will I end up?" nil in the period's first hour (law 6)
public func pace(at now: Date) -> Pace? { … }
}
```

- **The doc comment says what the screen prints**, in italics: `/// *OK · WATCH · ACT NOW*`. Reading the type is reading the screen.
- **Name the law it keeps** (`(law 7)`), so the owner is findable from CANONICAL §5 and back.
- **`at now: Date`, never `Date()`** inside a domain type. It keeps the type pure and the test one line.

## Tell, don't ask

The caller hands over a fact; the type decides what it means. No caller reads the state and decides for it:

```swift
// The refresh tells it what Cloudflare said; it keeps the reading only if it is newer
// and not from an earlier period (law 7).
public mutating func record(_ reading: Usage) {
guard usage.map({ $0.isSuperseded(by: reading) }) ?? true else { return }
usage = reading
}

// NOT at the caller:
// if reading.readAt > limit.usage?.readAt ?? .distantPast { limit.usage = reading }
```

A rule that needs data from several nodes lives on the node that holds them all: `Account.closest(at:)` compares limits, so neither the menu bar nor Today ever compares percents.

## Enums for states, each state a case

A finite set of states the person can meet is an enum, and the rule that picks the case lives on it:

```swift
/// *OK · WATCH · ACT NOW* (CANONICAL law 2).
public enum Level: Sendable, Equatable, Comparable {
case ok, watch, actNow

public init(_ percent: Percent) { … } // the thresholds live here, and only here
}

public enum Freshness { case live, stale, refused, never } // not a Date? each view reads
public enum Allowance { case perDay(Quantity), perMonth(Quantity), perInvocation(Quantity), total(Quantity) }
```

- **One value never means two things.** If `nil`, `""` or `0` could mean both *not read yet* and *nothing there*, it's two cases ([domain-shape §3](domain-shape.md#five-questions)).
- **`Comparable` when the person ranks them**: the worst level is `levels.max()`.
- **No colours, fonts or glyphs in the domain.** The view maps `Level` to coral or butter; the domain says *act now*.

## Values for data, one class for what changes

| Shape | When | Overmind |
|---|---|---|
| `struct` | data with rules, compared by value | `Limit`, `Usage`, `Pace`, `Focus`, `Percent`, `Money`, `Period` |
| `enum` | a closed set of states or kinds | `Level`, `Allowance`, `Price`, `Read`, `Freshness` |
| `@MainActor @Observable final class` | the one thing that changes over time and that views watch | `Account` |
| `protocol` (`@Mockable`) | the outside world only | `AnalyticsAPI`, `BillingAPI`, `Notifier`, `TokenVault`, `SettingsStore` |

A new class or protocol inside the domain needs a reason the table doesn't already give. No managers, no services-of-services, no ViewModel.

## What differs is data, not code

A Cloudflare product or plan is a definition read from JSON. A difference between products is a field, or a generic case every definition gains, never a `switch` on an id:

```swift
// A plan without an allowance for a limit doesn't show it: the plan answers nil.
guard let allowance = plan.allowance(for: definition.id) else { return nil }

// A per-invocation allowance doesn't run out; the Allowance case says so, not "is this CPU?"
public var runsOut: Bool {
if case .perInvocation = allowance { return false }
return true
}
```

## Kernel values carry their unit

`Quantity`, `Money`, `Percent` and `Period` come from `Measures`. A number that has a unit is never a `Double` or `Int`: `"5M rows"` parses into a `Quantity`, a reset is a `Period`, a price is `Money`. The compiler then refuses rows compared to milliseconds.

## Factories, one per module

Construction that reads a bundle or builds a port lives on the module's factory enum, so callers never see `Internal/`:

```swift
let services = try ServiceCatalog.builtIns() // every Resources/Services/*.json
let day = Period.day(containing: now) // 00:00 UTC to 00:00 UTC
let month = Period.month(containing: now, renewsOn: renewal)
```

## Checklist for a type you add or touch

- [ ] Its doc comment quotes what the screen prints
- [ ] Every public member answers a question the person asks, or is a command they'd give
- [ ] Each state is a case; no `nil` or `""` with two meanings
- [ ] Time comes in as `at:`; units are `Measures` values
- [ ] No product id, dataset or Cloudflare number in Swift
- [ ] No colour or wording choice that belongs to the view
74 changes: 74 additions & 0 deletions .claude/skills/implement-feature/references/domain-shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Think the domain first

Before any change, a fix too, ask how the domain should be, not only where the line fits. The aim is a domain that is **easy to understand**: someone new reads a type's public surface and can explain it in the person's words. We borrow from DDD only what serves that; no pattern is added for its own sake.

Adapted from ClaudeBar's reference of the same name. The tree, the words and each law's owner are in [CANONICAL_MODEL](../../../../docs/architecture/CANONICAL_MODEL.md); the cases a definition can use in [ENGINE_DESIGN](../../../../docs/architecture/ENGINE_DESIGN.md).

## Five questions

**1. Would the person say it?**
Names come from the screen and the person ([USER_JOURNEYS §4](../../../../docs/architecture/USER_JOURNEYS.md#4--the-words-the-screens-print), [CANONICAL §0.1](../../../../docs/architecture/CANONICAL_MODEL.md)), never from the mechanism. Start from their problem: if the facts need a concept the code doesn't have, it is hiding somewhere as optionals, a flag or an empty string. *`Allowance`, not quota: Cloudflare's pages say "limits" and "included", and quota is ClaudeBar's word for something else.*

**2. Does the thing decide about itself?**
A rule lives on the node that holds its data; callers tell it, they don't read its state and decide. *`Limit.record(_:)` decides whether a reading counts (law 7); `Account.closest(at:)` picks the headline, so the menu bar and the Today header never compare percents themselves.*

**3. Can you see every state?**
Each state the person can meet is a case, carrying its data; one value never means two things. *`Freshness` is `never · live · stale · refused`, not a `Date?` each view interprets.*

**4. Is it as small as it can be?**
A plain value when it is data with rules; a class only when it changes over time; a protocol only at the outside world (Cloudflare, the Keychain, settings, notifications), so tests can stub it. No type, layer or flag the change doesn't need. *`Focus` is a value (a dimension and a value, or `.everything`); no `FocusManager`.*

**5. Is what differs between services and plans data?**
A field in the service or plan file, or a generic case every definition gains ([ENGINE_DESIGN](../../../../docs/architecture/ENGINE_DESIGN.md)); never a `switch` on a service id or a Swift line naming a product, dataset or number Cloudflare can change. *A plan without an allowance for a limit doesn't show that limit: `plan.allowance(for:)` returns `nil`, and no code asks "is this Free?".*

## An example: the menu bar that can't say why it's blank

An issue asks to hide *CPU time 10%* from the menu bar. A fix at the view (a toggle in `MenuBarLabel`) would work, but asking the five questions of `MenuBarState` first finds a shape that would make that toggle a guess.

```swift
// NOW (Modules/Monitor/Sources/Account.swift)
/// *D1 18%* and its level; the account's name before the first read.
public func menuBar(at now: Date) -> MenuBarState {
guard let closest = closest(at: now), let percent = closest.percent(at: now)
else { return MenuBarState(text: "", level: .ok) } // "": not read yet, OR nothing on the plan runs out
…
}

// the view (Sources/App/MenuBarLabel.swift)
case (.connected, _): Text(state.text.isEmpty ? "☁" : "☁ \(state.text)") // which empty?
```

| Question | What it finds |
|---|---|
| 1. Would the person say it? | Yes: *D1 18%* is what USER_JOURNEYS journey 4 prints. Keep the words |
| 2. Does the thing decide about itself? | Mostly: `Account` picks the limit. But the view decides what `""` means |
| 3. Can you see every state? | No: `""` covers *not read yet* and *nothing runs out*, and the doc comment promises a third (the account's name) that the code never returns |
| 4. Is it as small as it can be? | A small enum is enough; no new type for the label, no flag on the view |
| 5. Is what differs data? | Yes already: `short` comes from the limit's definition |

```swift
// PROPOSED: the states the person meets, each one a case
public enum MenuBarState: Equatable {
case notReadYet
case nothingRunsOut
case closest(short: String, percent: Percent, level: Level)
}

// the view draws each state; the person's choice of *icon only* becomes one more input, not a guess
```

Since it changes what the menu bar says, it went into USER_JOURNEYS and CANONICAL (law 22) first. Built 2026-10-11 as `notReadYet · iconOnly(Level) · closest(short:percent:level:)`: *nothing runs out* and *the person chose icon only* draw the same, so they are one case.

## Keep it in scope

- Fix what these questions find **in the types the change touches**, test first. Leave the rest for its own change.
- A new node, a moved law or a changed owner is a design change: the docs first, confirmed before code ([AGENTS.md](../../../../AGENTS.md#design-docs-are-the-source-of-truth)).
- A new Cloudflare product is question 5 by default: a JSON file, or a new ENGINE case proposed first ([add-service](../../add-service/SKILL.md)).
- When it isn't obvious, draw now beside proposed as a few lines of ASCII:

```
NOW PROPOSED
Account Account
└─ limits ← every service ├─ watching: [Service.ID] a choice, in settings.json
└─ limits ← watched services only
```
9 changes: 9 additions & 0 deletions .claude/skills/improvement/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ that only makes the code match the docs needs no approval. One that changes a la
a word the screen prints, or adds a piece is a design change: write it into the docs and ask
the user to confirm before coding.

**Think the domain first.** Ask how the domain should be, from the person's problem rather
than the type at hand. Ask the five questions of the types the improvement touches (would
the person say it, does the thing decide about itself, can you see every state, is it as
small as it can be, is what differs data) and refine them in the same change →
[domain-shape.md](../implement-feature/references/domain-shape.md). An improvement is the
usual moment to fit a type to its shape; a new node or a moved owner is a design change,
confirmed first.

## Kinds of improvement

| Kind | Examples | Test approach |
Expand All @@ -51,6 +59,7 @@ tests green: `tuist test <Module>`, then the full `xcodebuild test`.
## Checklist

- [ ] Design checked; doc changed and confirmed if a law/word/piece changed
- [ ] Domain thought through: the touched types asked [the five questions](../implement-feature/references/domain-shape.md), refined in scope
- [ ] Test for the improved behavior written and FAILS first
- [ ] Improvement implemented; all tests pass
- [ ] Docs and a CHANGELOG line for a change the person notices
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ One module per bounded context ([MODULAR_DESIGN.md](docs/architecture/MODULAR_DE
The design leads; code follows it. Before any change, in this order:

1. **Read the design, in order** ([the map](docs/architecture/ARCHITECTURE.md)): [USER_JOURNEYS](docs/architecture/USER_JOURNEYS.md), [CANONICAL_MODEL](docs/architecture/CANONICAL_MODEL.md), [TARGET_ARCHITECTURE](docs/architecture/TARGET_ARCHITECTURE.md), [MODULAR_DESIGN](docs/architecture/MODULAR_DESIGN.md), [ENGINE_DESIGN](docs/architecture/ENGINE_DESIGN.md).
2. **Place the change in it.** Which node owns it? Which law (CANONICAL §5) does it keep?
2. **Place the change in it.** Which node owns it? Which law (CANONICAL §5) does it keep? Think how the domain should be, from the person's problem rather than the type you are editing, for every change, a fix too: names the person would say, each thing deciding about itself, every state visible, nothing bigger than it needs, what differs between services and plans as data → [domain-shape.md](.claude/skills/implement-feature/references/domain-shape.md).
3. **Write the design change first** when the docs don't say it or say otherwise. Code that disagrees with the docs is behind.
4. **Ask the person to confirm the design** before writing code.
5. **Implement to the doc.** SRP: a type changes for one reason. OCP: a new product, plan or case is data or a new case, never an edit to a neighbour.
Expand Down
Loading
Loading