// WHERE the dock is standing — the scoping rule, and the only rule the dock// has.//// The page-and-pill spec (2026-08-17, §"The dock") states it://// > the pill captures INTO the place you're standing on. Today → plain// > capture; person page → "Keep something about {name}" (person note).//// AMENDED by chain 1 of the projects-first program (spec 2026-08-29 §D4): the// places that pre-attach something are the PROJECT page and the person page.// A tag page pre-attached nothing after chain 1 — `#` means a project — and// chain 4 removed the member outright with the tag surface itself (schema// v16, §D5), so the quoted line's "tag page → capture pre-tagged" names a// place that no longer exists.//// Pure so every branch is decidable in a unit test — the dock renders what// these functions say, and a new place mounts the same component without it// learning anything new. No SwiftUI import, deliberately: a scoping rule that// needs a view to be exercised is a scoping rule nobody exercises.importCottonKitimportFoundation/// The three places a dock can stand on.////// The TypeScript exports a `PAGE_PLACE` constant because a discriminated union/// there is a fresh object every time it is written. Swift's case IS that/// constant — `DockPlace.page` is one value with one identity — so the port/// drops the name rather than declaring a second way to say it.publicenumDockPlace: Sendable, Equatable {/// The page (Today) — the dock's home.case pagecase person(id: String, name: String)case project(id: String, name: String)}/// The destination a place makes certain, as `placePlan` builds it.////// This is a SLICE of the phone's `RoutePlan`, not the whole of it: the full/// `RouteTarget` union is ten shapes wide and belongs to the routing port, and/// a place can only ever make ONE of them certain. Declaring the other nine/// here as empty cases would be a second declaration to keep in step with the/// first, and the day they drift the compiler says nothing.publicenumDockRouteTarget: Sendable, Equatable {case personNote(personId: String, body: String)}/// One record a plan proposes to create from a capture, with its own/// confidence — the model may be sure about one record and unsure about/// another, so the number rides each record rather than the plan.publicstructDockPlannedRecord: Sendable, Equatable {publiclet target: DockRouteTargetpubliclet confidence: Doublepublicinit(target: DockRouteTarget, confidence: Double) {self.target = targetself.confidence = confidence }}/// The full filing proposal for one capture: records that land together or not/// at all.publicstructDockRoutePlan: Sendable, Equatable {publiclet records: [DockPlannedRecord]publicinit(records: [DockPlannedRecord]) {self.records = records }}/// The pill's invitation, in the voice of the place it is standing on.publicfunc dockPlaceholder(_ place: DockPlace) -> String {switch place {case .person(_, let name):returnShellLines.line("capture", "dock.place_person", ["name": name])case .project(_, let name):returnShellLines.line("capture", "dock.place_project", ["name": name])case .page:returnShellLines.line("capture", "dock.place_page") }}/// The project the PLACE itself puts on the capture.////// A project page's dock arrives with its own project already attached —/// visible as a chip and removable, because a capture made on a project page/// that the writer decides is not about the project is still a capture./// Standing somewhere is a deliberate act, so this lands `applied_by: 'user'`/// exactly as a typed `#` does.////// This replaced `placeTagIds`: since chain 1 the `#` grammar means a project,/// and since chain 4 there is no tag page to stand on at all.publicfunc placeProjectIds(_ place: DockPlace) -> [String] {ifcase .project(let id, _) = place { return [id] }return []}/// The person the PLACE puts on the capture. A person page's dock already/// produces a `person_note` through ``placePlan(_:text:attachedPersonIds:)``,/// and this is the OTHER half of that: the `@` chip, so the same capture on the/// same screen carries the same person whichever road it takes.publicfunc placePersonIds(_ place: DockPlace) -> [String] {ifcase .person(let id, _) = place { return [id] }return []}/// The name the PLACE itself can put on a chip it pre-attached.////// The dock resolves a chip's name from the vocabulary it was handed, but a/// host may hand it none — R8 of this chain: `CaptureDock` stays usable by a/// host that passes only `place` and `onCapture`. The place already knows what/// it is called, so the chip is never a blank pill, and never invisible while/// the vocabulary query is still in flight.publicfunc placeChipName(_ place: DockPlace, sigil: Sigil, id: String) -> String? {if sigil == .hash, case .project(let projectId, let name) = place, projectId == id {return name }if sigil == .at, case .person(let personId, let name) = place, personId == id {return name }returnnil}/// A place's identity, for the dock's "standing somewhere NEW re-arms the/// chips" adjustment.////// A function rather than a ternary at the call site, and exhaustive over the/// union: the ternary this replaced named `tag` and `person` only, so two/// project pages would have shared one key and the chip would never re-arm.////// Not a sentence anybody reads, so it does not go through `CottonStrings` —/// it is an identity the dock compares against itself.publicfunc placeKeyOf(_ place: DockPlace) -> String {switch place {case .person(let id, _):return"person:\(id)"case .project(let id, _):return"project:\(id)"case .page:return"page" }}/// The destination the place makes CERTAIN — a plan the router never sees.////// On a person's page there is nothing to classify: the words are about them,/// so they become a person note and the model is not asked a question whose/// answer is already on the screen. Everywhere else this is nil and the/// capture takes its usual road (the live plan if the classifier produced one/// for these words, the background router otherwise).////// THE CHIP IS THE SCOPE. The person's pre-attached `@` chip is what this/// reads: take it off and the capture reverts to ordinary classification,/// exactly as taking off `#project` on a project page removes the link. A plan/// that outlived its chip would make the chip decoration — gone from the/// screen, still deciding what the capture becomes.publicfunc placePlan( _ place: DockPlace, text: String, attachedPersonIds: [String]) -> DockRoutePlan? {guardcase .person(let personId, _) = place else { returnnil }guard attachedPersonIds.contains(personId) else { returnnil }let body = text.trimmingCharacters(in: .whitespacesAndNewlines)if body.isEmpty { returnnil }returnDockRoutePlan( records: [DockPlannedRecord( target: .personNote(personId: personId, body: body),// A human standing on the person's page decided this; there is// no model judgement to be uncertain about. confidence: 1 ) ] )}