The New Work form's site field accepts a bare hostname or an HTTP(S) URL with the scheme optional, stores the URL as the site's Work URL after the validator's on-host check, and every repository refusal reads as its own sentence instead of error N. Four commits plus the fixes this review applied.
HostnameNormalizer.siteOrURL is the one entry point for the field's two forms; bare and fromRawURL are unchanged and siteOrURL is now bare's only production caller.Site row (Q9).createWork refuses a URL whose URLComponents host disagrees with the derived one, naming both, before taking the lock; nothing is written (Q5, Q10).LibraryRepositoryError is LocalizedError, so every screen presenting localizedDescription shows the error's own sentence (Q6).:// before the first /, ? or # (Q12); missingHost mapped to the both-forms refusal (Q13); the iOS label behaviour recorded (Q14); requirement numbers, stale comments and the overview corrected.Ready to push
The implementation follows the smolspec, and the four review agents found no major issue. The review fixed the one real behavioural gap they raised — a scheme-less address embedding a URL was refused — plus a second refusal-wording gap, and moved the on-host guard onto the existing WorkURLPlanner.classifyWorkURL. The Core package's 3,144 tests pass with zero failures on this host, the pending-capture suites included, so the make test-core run the changelog said was owed has now happened. make test-quick was green on the App commit; the only app-target change since is a comment.
Pass rate: 100% (3094 of 3094)
New tests: 12
Diff coverage: 95% (251 of 265 added lines)
3f5ad399 T-2365: Accept a site or a URL when creating a work 6c86093b T-2365: changelog for the Core phase, spec In Progress d39d3a04 T-2365: Label the New Work field for a site or a URL 358a13b0 T-2365: changelog for the App phase, spec Done working-tree Fixes applied in this review The New Work form's second field only took a bare site name such as example.com. Pasting a page address was refused, and the refusal read "The operation couldn't be completed (AsterismCore.LibraryRepositoryError error 2)". Now the field takes a site name or a web address, with or without https://. From an address the app works out the site, creates the work there, and keeps the address as the work's Work URL. A bad input gets a sentence: "Enter a site such as example.com or an address such as example.com/story".
Pasting a link is the natural thing to do in that field. The readable-error half also fixes every other screen that showed "error N".
https:// at the front; the form assumes it when left off.IdentityNormalization.swift: HostnameNormalizer.siteOrURL(_:) returning (hostname, url?), a new unrecognizedSiteOrURL error case, and a shared urlSyntax character set used by bare and the new entry point.LibraryRepository.swift: createWork classifies through siteOrURL, checks an accepted URL with WorkURLPlanner.classifyWorkURL, and writes it to the new membership before the existing save.CrossProcessLibraryLock.swift: LibraryRepositoryError: LocalizedError.LibraryRepository+WorkMerge.swift: the confirmWorkURL label reads as words.NewWorkView.swift: title "Site or URL", examples in prompt:, urlKeyboard().Classification lives in Core beside the strictness it relaxes (Q3). siteOrURL trims, then: a :// before the first /?# is a scheme and the input is a URL as typed (Q12); any URL-syntax character means https:// is prefixed (Q4); otherwise a bare hostname. A URL's host goes through fromRawURL, the capture path's derivation, and then bare (Q9). The URL is stored as typed plus the assumed scheme (Q8) after classifyWorkURL confirms it is on the derived host, the same check the validator makes (Q5). malformedAuthority, unsupportedScheme and missingHost all become the both-forms sentence (Q13); an IPv6 literal is refused by the grammar (Q11).
https:// may store an address an HTTP-only site cannot open; an explicit http:// is kept and the detail view can replace it.LocalizedError on every case lets a log-shaped libraryUnavailable reach a screen verbatim; accepted as better than "error N".siteOrURL adds no third parser; the only new parsing is hasScheme, which rejects a :// preceded by /, ? or #. Without it, web.archive.org/web/2020/https://example.com/x had everything before the embedded :// read as the scheme by LexicalHTTPURL and was refused for input that is exactly the Req 3 form. The URL-syntax set is one Set<Character> shared by bare and siteOrURL; it is load-bearing because the doc comments promise URLSyntaxNotAllowed is unreachable from the form. The one derived host that can still contain a member is an IPv6 literal (the lexer strips the brackets), which is caught and rethrown as invalidHostname.
createWork classifies and checks before taking the exclusive lock, so a refusal writes nothing and locks nothing. Inside the lock, work.membership(for: hostname)?.workURLString = workURL targets the membership Work.create just inserted with work: work; SwiftData maintains the inverse before save and createWorkFromAURLStoresIt re-opens the store to prove the commit. The Req 5 sentence composes from description, which errorDescription returns, so the form shows it with no app-side mapping.
workURLString already existed.fromRawURL directly; no M4* performance arm touches this code.WorkAuthoredContent.isBare and the duplicate collapse's URL carry; nothing keys on it while urlIdentity is .none.user@example.com classifies as a URL with userinfo and stores https://user@example.com; follows from Q8, unlikely input.Form draws only the prompt; the title is the VoiceOver label (Q14). A drawn label would be a LabeledContent row no other field here has.WriteSiteRelationshipTests keeps an invariant form whose stored branch Q11 makes unreachable; retained so it still holds if the grammar ever admits literals.Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift
Why it matters. This is the rule that decides whether typed text is a site or an address and which host a permanent, synced Site row is minted from. Every accepted host must be the one capture would derive.
What to look at. IdentityNormalization.swift: HostnameNormalizer.urlSyntax, siteOrURL, hasScheme
Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift
Why it matters. A stored Work URL that fails the validator's on-host check would be a diagnosis on the next open. The guard runs before the exclusive lock so a refusal writes nothing.
What to look at. LibraryRepository.swift: createWork, the classifyWorkURL switch and the membership write
Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift
Why it matters. One line changes what every screen presenting localizedDescription shows: the error's own sentence instead of the NSError bridge's "error N".
What to look at. CrossProcessLibraryLock.swift: errorDescription
Asterism/Asterism/Views/NewWorkView.swift
Why it matters. The title is the accessibility label and the Mac's drawn label; the prompt is the placeholder. Moving the examples to prompt keeps VoiceOver's label short.
What to look at. NewWorkView.swift: the TextField
Packages/AsterismCore/Tests/AsterismCoreTests/WriteSiteRelationshipTests.swift
Why it matters. The refusal wording is the feature as the reader meets it; the off-host arm re-opens the store to prove no Work or Site was written.
What to look at. WriteSiteRelationshipTests.swift: the six createWork arms; IdentityNormalizationTests.swift: the siteOrURL vectors
createWork was bare's only production caller, so tolerance belongs where the strictness was. Renaming NewWorkDraft.hostname would touch about sixty fixture and test callers; the doc comment is the accepted trade.
Owner's pick. A bare hostname carries no scheme either, so demanding one on the longer form is inconsistent. Classification is by the URL-syntax characters bare already refuses.
The validator and the wrong-host heal classify a stored Work URL with the same derivation; a value written past it would be a diagnosis on the next open. Refusing is loud and shows the reader what to remove.
Owner's pick, matching the manual replacement on the work detail. Trackers are an identity-key concern and this feature computes no identity key.
fromRawURL enforces only a character class, so https://-foo-.com/x would mint a permanent, synced row from a typo. The grammar only refuses; every accepted host is the one capture would derive. An IPv6 literal falls out of this and is reported as the grammar refusal.
Review fix. The first draft read :// anywhere as a scheme, so a scheme-less Wayback or redirect address was refused with the both-forms sentence. Req 3 and the approach bullet are amended.
Review fix. Reached by an empty authority and by a host outside the lexical character class, for which "URL does not contain a host" was wrong twice. invalidCharacter keeps its precise wording.
TextField(_:text:prompt:) in an iOS Form draws only the prompt, as the field did before. The placeholder shows one example of each form; the title is the VoiceOver label and the Mac's drawn label.
| Severity | Area | Finding | Resolution |
|---|---|---|---|
| minor | IdentityNormalization.swift siteOrURL | Any :// counted as a scheme, so a scheme-less address embedding a URL (web.archive.org/web/2020/https://example.com/x) had everything before the embedded :// read as the scheme and was refused with the both-forms sentence. | hasScheme requires the :// before the first /, ? or #. Req 3 and the approach bullet amended; Q12 recorded; vector added to siteOrURLAssumesHTTPS. |
| minor | IdentityNormalization.swift siteOrURL | missingHost kept its parser wording, so https:///x and foo_bar.com/story told the reader "URL does not contain a host" while Req 6 says an unreadable authority gets the both-forms sentence. | missingHost rethrown as unrecognizedSiteOrURL; Q13 recorded; both inputs added to siteOrURLRefusals. |
| minor | LibraryRepository.swift createWork | The on-host guard hand-rolled a three-way split (isOnHost, then host(of:) again with a nil fallback) that WorkURLPlanner.classifyWorkURL already returns as .onHost / .offHost / .other. | Switched to classifyWorkURL; the composed refusal text is unchanged and the Req 5 test still passes. |
| minor | IdentityNormalization.swift | The URL-syntax character set ":/@?#[]" was written out twice, in bare and in siteOrURL, with a comment saying they must match. | One private static urlSyntax set used by both. |
| minor | specs/OVERVIEW.md | The per-spec section still said Planned with Q1–Q9 while the table row said Done. | Section reads Done, Q1–Q14, and names the test-core caveat; implementation.md added to the file list. |
| minor | Req 7 on iOS | An iOS Form draws only the prompt, so the visible text is the two examples and the title "Site or URL" is only the VoiceOver label; the changelog said the field "is labelled". | Recorded as Q14; changelog and spec bullet reworded. No UI change: the placeholder shows both forms, as the field did before. |
| minor | tasks.md, NewWorkView.swift, WorkURLMembershipTests.swift | Requirement numbers were off by one in five places (7 for LocalizedError should be 8, 6 for the field should be 7, 8 in task 3 should be 9). | Renumbered; tasks.md still parses under rune. |
| minor | LibraryRepository.swift Q5 comment | The comment named an IPv6 literal as a case the guard catches; under Q11 the grammar refuses it earlier and it never reaches the guard. | Comment names the trailing-dot host only. |
| nit | CHANGELOG.md, RepositoryWorksTests | The changelog said the two dropped refusals were covered as creations in WriteSiteRelationshipTests; that suite covers the forms, not those two inputs. | Both added as vectors in IdentityNormalizationTests; changelog sentence corrected. |
| nit | WriteSiteRelationshipTests | No test asserted the composed both-forms sentence through createWork; the IPv6 arm's comment described a guard that no longer decides the outcome. | One arm added pinning the reason and localizedDescription; the IPv6 comment says Q11 makes the refusal the branch taken. |
| nit | Doc comments | "nineteen app files" and "some sixty callers" are counts that will drift. | Reworded to "every app file" and a pointer to Q3; primaryMembership replaced by membership(for: hostname); one local operation label in createWork. |
| nit | siteOrURL | user@example.com classifies as a URL with userinfo and creates the work on example.com storing https://user@example.com. | Follows from Q8; unlikely input. Left for the owner to decide. |
| nit | CHANGELOG.md sections | The LocalizedError change is a fix under Keep a Changelog but sits inside the phase entries under Added. | Left; the entries are phase-level and mostly additions. |
Source: local run at 2026-09-23T08:40:00+10:00 · snapshot 358a13b0 (dirty working tree)
Baseline: none
Execution: passed · JUnit: 1 file · Coverage: 1 file · Baseline: absent
Coverage scope: every test in the repository
Totals: 3094 passed · 0 failed · 50 skipped · 0 errored · 0 flaky
Derived by declaration name, from the diff (no baseline run).
Aggregate diff coverage: 95% (251 of 265 measurable added lines).
Head 93.7% (104923 of 112018 lines)
9 of 17 changed files matched coverage data.
Asterism/Asterism/Views/NewWorkView.swift — no candidateAsterism/AsterismTests/MoveToAndNewWorkModelTests.swift — no candidateCHANGELOG.md — no candidatespecs/OVERVIEW.md — no candidatespecs/new-work-url-field/smolspec.md — no candidatespecs/new-work-url-field/decision_log.md — no candidatespecs/new-work-url-field/tasks.md — no candidatespecs/new-work-url-field/implementation.md — no candidateFiles that import a changed file on the left, changed files in the centre, files a changed file imports on the right. Snapshot working-tree against base ce131c87.
17 files: 11 code · 6 docs. Click to expand.
diff --git a/Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift b/Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swiftindex 8b271ffb..a497dfb7 100644--- a/Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift+++ b/Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift@@ -23,6 +23,12 @@ public enum HostnameNormalizationError: Error, Equatable, Sendable, CustomString case blankHostname case URLSyntaxNotAllowed case invalidHostname+ /// The input is neither of the two forms `siteOrURL` accepts: it is blank,+ /// its scheme is not HTTP(S), or its authority cannot be read+ /// (`new-work-url-field` Req 6). One case for all three, because the reader+ /// typed one thing into one field and the repair is the same sentence —+ /// which names both accepted forms rather than the one they missed.+ case unrecognizedSiteOrURL public var description: String { switch self {@@ -30,6 +36,8 @@ public enum HostnameNormalizationError: Error, Equatable, Sendable, CustomString case .blankHostname: "Hostname must not be blank" case .URLSyntaxNotAllowed: "Expected a bare hostname without URL syntax" case .invalidHostname: "Hostname does not follow the accepted grammar"+ case .unrecognizedSiteOrURL:+ "Enter a site such as example.com or an address such as example.com/story" } } }@@ -55,13 +63,30 @@ public enum HostnameNormalizer { } } + /// A bare hostname, as the reader typed it: trimmed, ASCII-lowercased, one+ /// terminal DNS dot removed, and held to the label grammar.+ ///+ /// **`siteOrURL` below is its only production caller** since+ /// `new-work-url-field`: the New Work form's field accepts a URL too, so the+ /// classification happens there and this function sees either a bare+ /// hostname or a host already derived from a URL. No input the reader types+ /// reaches `URLSyntaxNotAllowed` any more — anything carrying URL syntax is+ /// read as a URL instead, and the one derived host that raises it, an IPv6+ /// literal, is rethrown as `invalidHostname` (Q11).+ /// The characters that make an input a URL rather than a bare hostname —+ /// what `bare` refuses and what `siteOrURL` reads as the scheme-less form.+ /// One set, because the two have to agree: an input `bare` refused for+ /// carrying one of these that `siteOrURL` did not read as a URL would reach+ /// the reader as `URLSyntaxNotAllowed`, which Q4 promises they never see.+ private static let urlSyntax: Set<Character> = [":", "/", "@", "?", "#", "[", "]"]+ public static func bare(_ input: String) throws -> String { var hostname = input.trimmingCharacters(in: .whitespacesAndNewlines) guard !hostname.isEmpty else { throw HostnameNormalizationError.blankHostname } guard hostname.unicodeScalars.allSatisfy({ $0.isASCII }) else { throw HostnameNormalizationError.invalidHostname }- guard !hostname.contains(where: { ":/@?#[]".contains($0) }) else {+ guard !hostname.contains(where: { urlSyntax.contains($0) }) else { throw HostnameNormalizationError.URLSyntaxNotAllowed } hostname = hostname.asciiLowercased@@ -79,6 +104,69 @@ public enum HostnameNormalizer { } return hostname }++ /// The two forms the New Work form's one field accepts+ /// (`new-work-url-field` Reqs 1–3): a bare hostname, or an HTTP(S) URL with+ /// or without its scheme. Returns the hostname the work is created on and,+ /// where a URL was given, the URL to store as that membership's Work URL.+ ///+ /// The input is trimmed first, because `LexicalHTTPURL` refuses any+ /// character at or below a space. Then: a `://` before the first `/`, `?`+ /// or `#` is a scheme, and the input is a URL as typed; otherwise any of+ /// the characters `bare` refuses as URL syntax makes it a URL with+ /// `https://` prefixed (Q4, Q12); otherwise it is a bare hostname. A URL's+ /// host goes through `fromRawURL` **and then** `bare`, so+ /// a host that mints a permanent, synced `Site` row passes the same label+ /// grammar a typed hostname does (Q9) — `fromRawURL` enforces only a+ /// character class, which `https://-foo-.com/x` satisfies.+ public static func siteOrURL(_ input: String) throws -> (hostname: String, url: String?) {+ let trimmed = input.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !trimmed.isEmpty else { throw HostnameNormalizationError.unrecognizedSiteOrURL }+ let rawURL: String?+ if hasScheme(trimmed) {+ rawURL = trimmed+ } else if trimmed.contains(where: { urlSyntax.contains($0) }) {+ // The same characters `bare` refuses as URL syntax: anything it+ // would have refused for carrying them is read as a URL instead.+ rawURL = "https://" + trimmed+ } else {+ rawURL = nil+ }+ guard let rawURL else { return (try bare(trimmed), nil) }+ do {+ return (try bare(try fromRawURL(rawURL)), rawURL)+ } catch HostnameNormalizationError.URLSyntaxNotAllowed {+ // A derived host carrying URL syntax is an IPv6 literal, the one+ // input that reaches this case from the form (Q11). The reader+ // typed no bare hostname, so "expected a bare hostname without URL+ // syntax" would be an answer to a question they did not ask: a host+ // `bare` refuses is reported as the grammar refusal Req 6 names.+ throw HostnameNormalizationError.invalidHostname+ } catch HostnameNormalizationError.invalidURL(let reason) {+ switch reason {+ // Neither form: the reader gets the sentence naming both, rather+ // than a parser's account of the one they typed.+ // `missingHost` is an authority that cannot be read too: an empty+ // one (`https:///x`) or a host outside the lexical character class+ // (`foo_bar.com/story`), for which "URL does not contain a host"+ // would be wrong twice over (Q13).+ case .malformedAuthority, .unsupportedScheme, .missingHost:+ throw HostnameNormalizationError.unrecognizedSiteOrURL+ case .emptyInput, .invalidCharacter:+ throw HostnameNormalizationError.invalidURL(reason)+ }+ }+ }++ /// Whether the input carries its own scheme: a `://` before the first `/`,+ /// `?` or `#`. One that comes later is inside the path or query — a+ /// scheme-less Wayback or redirect address such as+ /// `web.archive.org/web/2020/https://example.com/x` — and would otherwise+ /// make `LexicalHTTPURL` read everything before it as the scheme (Q12).+ private static func hasScheme(_ input: String) -> Bool {+ guard let separator = input.range(of: "://") else { return false }+ return !input[..<separator.lowerBound].contains(where: { "/?#".contains($0) })+ } } private struct LexicalHTTPURL {
diff --git a/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift b/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swiftindex 41ace356..6d8c5b8c 100644--- a/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift+++ b/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift@@ -1136,9 +1136,40 @@ public actor LibraryRepository { guard !draft.displayTitle.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { throw LibraryRepositoryError.invalidInput(operation: "creating Work", reason: "display title is blank") }+ // The field holds either form (`new-work-url-field` Reqs 1–3): a bare+ // hostname, or an HTTP(S) URL with or without its scheme. The host a+ // URL reduces to is the one capture derives for the same URL, so a+ // later capture of a page on that site lands on this same `Site` row.+ let operation = "checking the site or URL" let hostname: String- do { hostname = try HostnameNormalizer.bare(draft.hostname) }- catch { throw LibraryRepositoryError.invalidInput(operation: "validating Work hostname", reason: String(describing: error)) }+ let workURL: String?+ do { (hostname, workURL) = try HostnameNormalizer.siteOrURL(draft.hostname) }+ catch {+ throw LibraryRepositoryError.invalidInput(+ operation: operation, reason: String(describing: error))+ }+ // Q5: the validator and the wrong-host heal classify a stored Work URL+ // through `classifyWorkURL`, and the lexical host derivation above can+ // disagree with the `URLComponents` one that classification reads — a+ // trailing-dot host does. A value written past this guard would be a+ // diagnosis on the next open, so the creation is refused naming both+ // hosts rather than dropping silently what the reader typed.+ if let workURL {+ switch WorkURLPlanner.classifyWorkURL(workURL, on: hostname) {+ case .onHost, .empty:+ break+ case .offHost(let destination):+ throw LibraryRepositoryError.invalidInput(+ operation: operation,+ reason: "That address is on \(destination), not \(hostname).")+ case .other:+ // Q10: the lexical parser accepted a URL `URLComponents` reads+ // no host from, so there is no host to name.+ throw LibraryRepositoryError.invalidInput(+ operation: operation,+ reason: "That address is on a host this library cannot read, not \(hostname).")+ }+ } return try await withLockedContext(mode: .exclusive, operation: "creating Work") { context in let site = try Self.siteForWrite(hostname: hostname, context: context)@@ -1157,6 +1188,14 @@ public actor LibraryRepository { // and none of them may mint a to-read work // ([2.2](../../../../specs/to-read/requirements.md#2.2)). work.readingStatus = draft.readingStatus+ // Req 4: a URL the reader typed into the form is reader-confirmed,+ // the standing a manual replacement on the work detail has, so it+ // is stored as this membership's Work URL as typed — query,+ // fragment, scheme case and userinfo kept (Q8) — with the assumed+ // `https://` where the scheme was omitted. Beside the reading+ // status and for its reason: `Work.create` is the one door every+ // other creation path goes through, and none of them carries a URL.+ if let workURL { work.membership(for: hostname)?.workURLString = workURL } do { try saveStrategy.save(context) } catch { throw LibraryRepositoryError.libraryUnavailable(
diff --git a/Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift b/Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swiftindex 46015fd8..b4446b71 100644--- a/Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift+++ b/Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift@@ -1,7 +1,7 @@ import Darwin import Foundation -public enum LibraryRepositoryError: Error, Equatable, Sendable, CustomStringConvertible {+public enum LibraryRepositoryError: Error, Equatable, Sendable, CustomStringConvertible, LocalizedError { case libraryBusy(operation: String) case libraryUnavailable(operation: String, reason: String) case invalidInput(operation: String, reason: String)@@ -37,6 +37,14 @@ public enum LibraryRepositoryError: Error, Equatable, Sendable, CustomStringConv case .captureSaveFailed(let reason): "Saving the capture failed: \(reason)" } }++ /// The message the error already carries, for every app file that+ /// presents a failure through `localizedDescription` (`new-work-url-field`+ /// Q6). Without the conformance `NSError` bridging turns every one of them+ /// into "The operation couldn't be completed (AsterismCore.+ /// LibraryRepositoryError error 2)", which is what T-2365 reported. The+ /// precedent is `PatternApplicationError` in `TitleParsing.swift`.+ public var errorDescription: String? { description } } public final class LockLease: @unchecked Sendable {
diff --git a/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository+WorkMerge.swift b/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository+WorkMerge.swiftindex cde5f3ae..9514a96f 100644--- a/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository+WorkMerge.swift+++ b/Packages/AsterismCore/Sources/AsterismCore/LibraryRepository+WorkMerge.swift@@ -14,7 +14,8 @@ extension LibraryRepository { /// so the candidate is derived from that site's rule and that site's Entries, /// and the commit writes that membership's `workURLString`. A Work holding no /// membership for the hostname is refused with- /// `invalidInput(operation: "confirmWorkURL")` before anything is projected.+ /// `invalidInput(operation: "confirming the Work URL")` before anything is+ /// projected. public func projectWorkURL( workID: UUID, hostname: String,@@ -100,7 +101,7 @@ extension LibraryRepository { if let resulting = contract.outcome.resultingURL, !WorkURLPlanner.isOnHost(resulting, hostname: hostname) { throw LibraryRepositoryError.invalidInput(- operation: "confirmWorkURL",+ operation: "confirming the Work URL", reason: "That Work URL is not on \(hostname).") } let urlTimestamp = self.clock.now()@@ -935,7 +936,7 @@ extension LibraryRepository { ?? group.rows.compactMap { $0.membership(for: hostname) }.first guard let membership else { throw LibraryRepositoryError.invalidInput(- operation: "confirmWorkURL",+ operation: "confirming the Work URL", reason: "This Work is not on \(hostname), so it has no Work URL there.") } return membership
diff --git a/Packages/AsterismCore/Sources/AsterismCore/RepositoryDrafts.swift b/Packages/AsterismCore/Sources/AsterismCore/RepositoryDrafts.swiftindex 4864fa08..725d05ce 100644--- a/Packages/AsterismCore/Sources/AsterismCore/RepositoryDrafts.swift+++ b/Packages/AsterismCore/Sources/AsterismCore/RepositoryDrafts.swift@@ -33,6 +33,11 @@ public enum CaptureSiteStatus: Equatable, Sendable { public struct NewWorkDraft: Equatable, Sendable { public let displayTitle: String+ /// **Either form the New Work form's field accepts**: a bare hostname, or+ /// an HTTP(S) URL with or without its scheme (`new-work-url-field` Q3).+ /// `createWork` classifies it through `HostnameNormalizer.siteOrURL`, and a+ /// URL is also stored as the created membership's Work URL. The name+ /// understates that and keeps it anyway, for the reasons Q3 records. public let hostname: String /// `to-read` Q18: the reading status the created work is born with, and /// **defaulted**, which is the opposite choice from `WorkMetadataDraft`'s
diff --git a/Asterism/Asterism/Views/NewWorkView.swift b/Asterism/Asterism/Views/NewWorkView.swiftindex 2ab4f9d1..439d530d 100644--- a/Asterism/Asterism/Views/NewWorkView.swift+++ b/Asterism/Asterism/Views/NewWorkView.swift@@ -2,7 +2,7 @@ import AsterismCore import ConstellationKit import SwiftUI -/// New Work form: title and hostname fields with explicit Create action.+/// New Work form: title and site-or-URL fields with explicit Create action. struct NewWorkView: View { @State private var model: NewWorkFormModel @Environment(\.dismiss) private var dismiss@@ -18,8 +18,16 @@ struct NewWorkView: View { TextField("Title", text: $model.draftTitle) .accessibilityIdentifier("new-work-title-field") - TextField("Hostname (e.g. example.com)", text: $model.draftHostname)- .noAutocapitalization()+ // Req 7: the field takes either form, so the title is the+ // short label VoiceOver reads and the two examples go in+ // the prompt, where they are placeholder text rather than+ // the accessibility label. The URL keyboard is the work+ // detail's Work URL field's, and the identifier does not+ // move.+ TextField(+ "Site or URL", text: $model.draftHostname,+ prompt: Text("example.com or example.com/story"))+ .urlKeyboard() .autocorrectionDisabled() .accessibilityIdentifier("new-work-hostname-field") } header: {
diff --git a/Packages/AsterismCore/Tests/AsterismCoreTests/IdentityNormalizationTests.swift b/Packages/AsterismCore/Tests/AsterismCoreTests/IdentityNormalizationTests.swiftindex 1e8a4a63..8f3d41a6 100644--- a/Packages/AsterismCore/Tests/AsterismCoreTests/IdentityNormalizationTests.swift+++ b/Packages/AsterismCore/Tests/AsterismCoreTests/IdentityNormalizationTests.swift@@ -69,6 +69,77 @@ struct IdentityNormalizationTests { } } + /// `new-work-url-field` Reqs 1–3: the New Work form's one field holds+ /// either form, and the host a URL yields is the one capture derives for+ /// the same URL — `www.` kept, port never part of it, one terminal dot+ /// removed — so a later capture lands on the same `Site` row.+ @Test("A URL in the site field yields capture's host and the URL to store")+ func siteOrURLReadsURLs() throws {+ let vectors = [+ (" https://example.com/story ", "example.com", "https://example.com/story"),+ ("HTTPS://Example.com/story", "example.com", "HTTPS://Example.com/story"),+ ("https://example.com:8080/x", "example.com", "https://example.com:8080/x"),+ ("https://user:pw@example.com/x", "example.com", "https://user:pw@example.com/x"),+ ("https://example.com/x?utm_source=n", "example.com", "https://example.com/x?utm_source=n"),+ ("https://example.com./story", "example.com", "https://example.com./story"),+ ("http://www.example.com/x", "www.example.com", "http://www.example.com/x"),+ // The two inputs `bare` used to refuse that Reqs 2–3 make creations.+ ("https://example.com", "example.com", "https://example.com"),+ ("example.com:443", "example.com", "https://example.com:443"),+ ]+ for (input, hostname, url) in vectors {+ let result = try HostnameNormalizer.siteOrURL(input)+ #expect(result.hostname == hostname)+ #expect(result.url == url)+ }+ }++ /// Q4: the scheme is optional, so anything carrying URL syntax but no+ /// `://` is read — and stored — as its `https://` form.+ @Test("A scheme-less address is read as https")+ func siteOrURLAssumesHTTPS() throws {+ #expect(try HostnameNormalizer.siteOrURL("example.com/story").url == "https://example.com/story")+ #expect(try HostnameNormalizer.siteOrURL("example.com/story").hostname == "example.com")+ #expect(try HostnameNormalizer.siteOrURL("example.com:8080/x").url == "https://example.com:8080/x")+ #expect(try HostnameNormalizer.siteOrURL("example.com:8080/x").hostname == "example.com")+ // Q12: a `://` inside the path or query is not a scheme, so a+ // scheme-less Wayback or redirect address is still the https form.+ let wayback = try HostnameNormalizer.siteOrURL("web.archive.org/web/2020/https://example.com/x")+ #expect(wayback.hostname == "web.archive.org")+ #expect(wayback.url == "https://web.archive.org/web/2020/https://example.com/x")+ }++ @Test("A bare hostname yields a hostname and no URL")+ func siteOrURLReadsBareHostnames() throws {+ let result = try HostnameNormalizer.siteOrURL(" WWW.Example.COM. ")+ #expect(result.hostname == "www.example.com")+ #expect(result.url == nil)+ }++ /// Req 6: blank input, an unreadable authority and a non-HTTP scheme are+ /// one refusal naming both accepted forms. A host that fails the label+ /// grammar keeps the grammar's own message (Q9) — `fromRawURL` would have+ /// minted a permanent, synced `Site` row from `-foo-.com`.+ @Test("Neither form is refused with the sentence naming both")+ func siteOrURLRefusals() {+ // Q13: an empty authority and a host outside the lexical character+ // class are unreadable authorities too, not "URL does not contain a host".+ for value in ["", " ", "https:/example.com/x", "ftp://example.com/x", "https:///x", "foo_bar.com/story"] {+ #expect(throws: HostnameNormalizationError.unrecognizedSiteOrURL) {+ try HostnameNormalizer.siteOrURL(value)+ }+ }+ #expect(throws: HostnameNormalizationError.invalidHostname) {+ try HostnameNormalizer.siteOrURL("https://-foo-.com/x")+ }+ // Q11: an IPv6 literal is the one input that reaches+ // `URLSyntaxNotAllowed` through a derived host, and the reader sees the+ // grammar refusal rather than a sentence about syntax they did not type.+ #expect(throws: HostnameNormalizationError.invalidHostname) {+ try HostnameNormalizer.siteOrURL("https://[2001:db8::1]/story")+ }+ }+ @Test("Seeded generated URLs preserve all non-tracker query bytes") func seededProperties() throws { var generator = SeededGenerator(seed: 0xA57E_2157)
diff --git a/Packages/AsterismCore/Tests/AsterismCoreTests/WriteSiteRelationshipTests.swift b/Packages/AsterismCore/Tests/AsterismCoreTests/WriteSiteRelationshipTests.swiftindex 274bcb9c..dc6e0554 100644--- a/Packages/AsterismCore/Tests/AsterismCoreTests/WriteSiteRelationshipTests.swift+++ b/Packages/AsterismCore/Tests/AsterismCoreTests/WriteSiteRelationshipTests.swift@@ -126,6 +126,148 @@ struct WriteSiteRelationshipTests { withExtendedLifetime(dir) {} } + // MARK: - create-Work from a URL (`new-work-url-field`)++ /// Reqs 2 and 4: a URL in the field creates the work on the host capture+ /// would derive for the same URL, and the URL itself is stored as that+ /// membership's Work URL — as typed, query and all (Q8) — so the returned+ /// snapshot already carries it.+ @Test("A URL in the site field creates the work on its host and stores the URL")+ func createWorkFromAURLStoresIt() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (cfg, repository) = try await openLibrary(dir)++ let snapshot = try await repository.createWork(+ NewWorkDraft(+ displayTitle: "A Work",+ hostname: " https://Work.example/series/foo?utm_source=n "))++ #expect(snapshot.memberships.map(\.hostname) == ["work.example"])+ #expect(+ snapshot.memberships.first?.workURLString+ == "https://Work.example/series/foo?utm_source=n")+ try withStore(cfg) { context in+ let work = try #require(try context.fetch(FetchDescriptor<Work>()).first)+ let site = try #require(try context.fetch(FetchDescriptor<Site>()).first)+ #expect(site.hostname == "work.example")+ #expect(+ work.primaryMembership?.workURLString+ == "https://Work.example/series/foo?utm_source=n")+ }+ withExtendedLifetime(dir) {}+ }++ /// Q4: the scheme is optional, and the assumed `https://` is part of what+ /// is stored — the value has to be an address the work detail can open.+ @Test("A scheme-less address is stored in its https form")+ func createWorkFromASchemelessAddressStoresHTTPS() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (_, repository) = try await openLibrary(dir)++ let snapshot = try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "scheme.example/story"))++ #expect(snapshot.memberships.map(\.hostname) == ["scheme.example"])+ #expect(snapshot.memberships.first?.workURLString == "https://scheme.example/story")+ withExtendedLifetime(dir) {}+ }++ /// Req 6: neither form is refused with the one sentence naming both, and+ /// the reader sees it composed under the operation label.+ @Test("Neither form is refused with the sentence the reader sees")+ func createWorkFromNeitherFormIsRefusedReadably() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (_, repository) = try await openLibrary(dir)++ await #expect(throws: LibraryRepositoryError.invalidInput(+ operation: "checking the site or URL",+ reason: "Enter a site such as example.com or an address such as example.com/story")+ ) {+ try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "ftp://example.com/x"))+ }+ do {+ _ = try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "ftp://example.com/x"))+ } catch {+ #expect(+ error.localizedDescription+ == "Invalid input while checking the site or URL: Enter a site such as example.com or an address such as example.com/story")+ }+ withExtendedLifetime(dir) {}+ }++ /// A bare hostname is the form that existed before, and it still stores no+ /// Work URL: the work has no address, only a site.+ @Test("A bare hostname stores no Work URL")+ func createWorkFromABareHostnameStoresNoURL() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (_, repository) = try await openLibrary(dir)++ let snapshot = try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "bare.example"))++ #expect(snapshot.memberships.first?.workURLString == nil)+ withExtendedLifetime(dir) {}+ }++ /// Q5: the lexical host derivation and the `URLComponents` one `isOnHost`+ /// reads disagree about a trailing dot, so this URL would be an off-host+ /// Work URL the validator reports on the next open. It is refused, naming+ /// both hosts, and nothing is written.+ @Test("A URL whose host disagrees with the derived one is refused, writing nothing")+ func createWorkFromADisagreeingHostIsRefused() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (cfg, repository) = try await openLibrary(dir)++ do {+ _ = try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "https://example.com./story"))+ Issue.record("expected a refusal for a URL whose host is not the derived one")+ } catch let error as LibraryRepositoryError {+ guard case .invalidInput(let operation, let reason) = error else {+ Issue.record("expected invalidInput, got \(error)")+ return+ }+ #expect(operation == "checking the site or URL")+ #expect(reason == "That address is on example.com., not example.com.")+ }+ try withStore(cfg) { context in+ let works = try context.fetch(FetchDescriptor<Work>())+ let sites = try context.fetch(FetchDescriptor<Site>())+ #expect(works.isEmpty)+ #expect(sites.isEmpty)+ }+ withExtendedLifetime(dir) {}+ }++ /// Pins the **invariant** rather than the outcome: either the creation is+ /// refused or what was stored is a value `isOnHost` accepts, and a stored+ /// Work URL that fails that check may never happen. Since Q11 the refusal+ /// is the branch taken — `bare` refuses the derived host before the guard+ /// is asked — and `IdentityNormalizationTests` pins that; this arm stays+ /// in the form the spec asked for so it holds if that ever moves.+ @Test("An IPv6 literal is refused or stored as a value isOnHost accepts")+ func createWorkFromAnIPv6LiteralHoldsTheInvariant() async throws {+ let dir = try TempDir("WriteSiteWorkURL")+ let (_, repository) = try await openLibrary(dir)++ do {+ let snapshot = try await repository.createWork(+ NewWorkDraft(displayTitle: "A Work", hostname: "https://[2001:db8::1]/story"))+ let membership = try #require(snapshot.memberships.first)+ let stored = try #require(membership.workURLString)+ #expect(WorkURLPlanner.isOnHost(stored, hostname: membership.hostname))+ } catch let error as LibraryRepositoryError {+ guard case .invalidInput(let operation, _) = error else {+ Issue.record("expected invalidInput, got \(error)")+ return+ }+ #expect(operation == "checking the site or URL")+ }+ withExtendedLifetime(dir) {}+ }+ // MARK: - The seven write sites task 18's details do not name (Q41) /// The teaching commit creates one Work per parsed title
diff --git a/Packages/AsterismCore/Tests/AsterismCoreTests/WorkURLMembershipTests.swift b/Packages/AsterismCore/Tests/AsterismCoreTests/WorkURLMembershipTests.swiftindex 4cee5d6c..c2bb9fc4 100644--- a/Packages/AsterismCore/Tests/AsterismCoreTests/WorkURLMembershipTests.swift+++ b/Packages/AsterismCore/Tests/AsterismCoreTests/WorkURLMembershipTests.swift@@ -92,6 +92,23 @@ struct WorkURLMembershipTests { == [nil, "https://second.example/serial"]) } + /// `new-work-url-field` Req 8 and Q6: every screen presents a failure+ /// through `localizedDescription`, so the error's own sentence has to be+ /// what that returns. Without the `LocalizedError` conformance the bridge+ /// hands the reader "The operation couldn't be completed (… error 2)" and+ /// the operation and reason this error carries never reach them.+ @Test("A repository error reads as its description on every screen")+ func errorsReadAsTheirDescription() {+ let cases: [LibraryRepositoryError] = [+ .invalidInput(operation: "confirming the Work URL", reason: "That Work URL is not on a.example."),+ .libraryBusy(operation: "creating Work"),+ .recordNotFound(type: "Work", id: Self.workID),+ ]+ for error in cases {+ #expect(error.localizedDescription == error.description)+ }+ }+ @Test("A hostname the Work holds no membership for is refused") func absentMembershipIsRefused() async throws { let fixture = try await twoSiteFixture()@@ -109,7 +126,7 @@ struct WorkURLMembershipTests { Issue.record("expected invalidInput, got \(error)") return }- #expect(operation == "confirmWorkURL")+ #expect(operation == "confirming the Work URL") } } @@ -133,7 +150,7 @@ struct WorkURLMembershipTests { Issue.record("expected invalidInput, got \(error)") return }- #expect(operation == "confirmWorkURL")+ #expect(operation == "confirming the Work URL") } // Nothing was written: the first membership keeps the address it had. #expect(
diff --git a/Packages/AsterismCore/Tests/AsterismCoreTests/RepositoryWorksTests.swift b/Packages/AsterismCore/Tests/AsterismCoreTests/RepositoryWorksTests.swiftindex f67f4cad..b8453864 100644--- a/Packages/AsterismCore/Tests/AsterismCoreTests/RepositoryWorksTests.swift+++ b/Packages/AsterismCore/Tests/AsterismCoreTests/RepositoryWorksTests.swift@@ -62,14 +62,20 @@ struct RepositoryWorksTests { #expect(byTitle["Unstated"]?.readingStatus == .reading) } - @Test("Work creation validates title and bare hostname grammar")+ /// `new-work-url-field` Reqs 1–3 and 6: the field holds a site **or** a+ /// URL, so `https://example.com` and `example.com:443` are accepted now —+ /// they are covered as creations in `WriteSiteRelationshipTests`. What is+ /// still refused is a blank title, neither form, and a host that fails the+ /// label grammar, typed or derived.+ @Test("Work creation validates the title and the site-or-URL grammar") func standaloneValidation() async throws { let fixture = try await WorksRepositoryFixture() for draft in [ NewWorkDraft(displayTitle: " ", hostname: "example.com"),- NewWorkDraft(displayTitle: "Work", hostname: "https://example.com"),- NewWorkDraft(displayTitle: "Work", hostname: "example.com:443"),+ NewWorkDraft(displayTitle: "Work", hostname: " "),+ NewWorkDraft(displayTitle: "Work", hostname: "ftp://example.com/x"), NewWorkDraft(displayTitle: "Work", hostname: "example..com"),+ NewWorkDraft(displayTitle: "Work", hostname: "https://-foo-.com/x"), ] { await #expect(throws: LibraryRepositoryError.self) { try await fixture.repository.createWork(draft) } }
diff --git a/Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift b/Asterism/AsterismTests/MoveToAndNewWorkModelTests.swiftindex e06eae39..1513b3d9 100644--- a/Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift+++ b/Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift@@ -250,6 +250,27 @@ struct NewWorkFormModelTests { #expect(model.errorMessage != nil) } + /// `new-work-url-field` Req 8, Q6: the form presents `localizedDescription`,+ /// and without `LocalizedError` the bridge turns a repository refusal into+ /// "error 2" — which is what T-2365 reported. The reader sees the sentence+ /// the error carries.+ @Test("A repository refusal reaches the reader as its own message")+ @MainActor func refusalShowsTheErrorsOwnMessage() async {+ let mock = MockLibraryProvider()+ let error = LibraryRepositoryError.invalidInput(+ operation: "checking the site or URL",+ reason: "Enter a site such as example.com or an address such as example.com/story")+ mock.createWorkResult = .failure(error)+ let model = NewWorkFormModel(library: mock, onMutation: {})+ model.draftTitle = "Refused Work"+ model.draftHostname = "ftp://example.com/x"++ await model.create()++ #expect(model.errorMessage == error.description)+ #expect(model.state == .error(message: error.description))+ }+ @Test("Duplicate create is suppressed") @MainActor func duplicateCreateSuppressed() async throws { let mock = MockLibraryProvider()
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 53ef364d..add46702 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -236,6 +236,57 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added +- **A site or a URL when creating a work, in the app (T-2365,+ `specs/new-work-url-field/`, task 4).** The New Work form's second field+ is titled "Site or URL", which the Mac draws and VoiceOver reads on+ iOS, its placeholder shows one example of each form in the `prompt:`+ argument and is the only text an iOS Form draws (Q14), and it uses the+ URL keyboard the work detail's Work URL+ field uses in place of the never-capitalise modifier, which that+ keyboard already carries. The identifier `new-work-hostname-field` and+ `autocorrectionDisabled()` do not move, and `NewWorkFormModel` is+ unchanged. One arm in `MoveToAndNewWorkModelTests` has the mock library+ throw a real `LibraryRepositoryError.invalidInput` and pins that the+ form's `errorMessage` is that error's own sentence rather than+ "error 2". No UI test addressed the field by its label or placeholder.+ `make test-quick` is green, including the Mac build. With this the+ smolspec is complete.++- **A site or a URL when creating a work, in Core (T-2365,+ `specs/new-work-url-field/`, tasks 1 to 3).** The New Work form's second+ field only reduced to a bare hostname, so a pasted URL was refused and+ the refusal reached the reader as "error 2". `HostnameNormalizer.siteOrURL`+ is the one entry point for the field's two forms: it trims, reads `://`+ as a URL as typed, any other URL syntax as a URL with `https://`+ prefixed (Q4), and anything else as a bare hostname. A URL's host goes+ through `fromRawURL` and then `bare`, so a host that mints a permanent,+ synced `Site` row passes the same label grammar a typed hostname does+ (Q9); `bare` and `fromRawURL` are unchanged and `siteOrURL` is now+ `bare`'s only production caller. `createWork` uses it under the label+ "checking the site or URL", refuses a URL that fails+ `WorkURLPlanner.isOnHost` against the derived host naming both (Q5),+ and stores an accepted URL as typed (Q8) as the Work URL of the+ membership `Work.create` mints, before the save the call already makes.+ `LibraryRepositoryError` conforms to `LocalizedError`, so every screen+ presenting `localizedDescription` shows the sentence the error carries+ (Q6), and the `confirmWorkURL` operation label reads as words. Two quick+ decisions record what the spec left open: a URL whose host+ `URLComponents` cannot read is refused by the same guard (Q10), and an+ IPv6 literal is refused by the grammar on the derived host and reported+ as `invalidHostname` (Q11). `RepositoryWorksTests.standaloneValidation`+ no longer pins `https://example.com` and `example.com:443` as refusals;+ both are creations now, pinned as such in `IdentityNormalizationTests`.+ A pre-push review then narrowed the scheme test to a `://` before the+ first `/`, `?` or `#`, so a scheme-less Wayback address is accepted+ (Q12), mapped `missingHost` to the both-forms refusal (Q13), and moved+ the on-host guard onto `WorkURLPlanner.classifyWorkURL`. Every+ suite touching the changed code is green; the three pending-capture+ suites fail on this host with the file-protection error+ `docs/agent-notes/testing.md` records, identically on the pristine+ parent commit, so a clean `make test-core` is owed on an unlocked host.+ The form itself still passes its text through unchanged; the field's+ label, placeholder and keyboard are the App phase.+ - **To read, the app and its journeys (T-2354, `specs/to-read/`, tasks 10 to 13).** The view models are pinned for the fifth status: choosing `To read` raises no finished-reading prompt, a work-status change
diff --git a/specs/OVERVIEW.md b/specs/OVERVIEW.mdindex eb9f8676..aba4a252 100644--- a/specs/OVERVIEW.md+++ b/specs/OVERVIEW.md@@ -52,7 +52,7 @@ | [Today Announcements](#today-announcements) | 2026-09-19 | Done — `make test-core` (3,002 checks, zero known issues), `make test-quick` and `make build-mac` green; the six failures across `make test`, `make test-ui` and `make test-ui-ipad` are measured to reproduce at `main`'s tip (`verification-run.md` §2) | Smolspec. A release note and a getting-started guide surface on Today as one row that looks like an entry row and opens a sheet showing a bundled Markdown document, rendered natively with images; both stay reachable from a new About section in Settings. The release-note row shows when the marketing version differs from a per-device last-seen version kept in `UserDefaults` and hides when its sheet closes; getting started replaces the settled empty-library message and goes with the first entry. No schema change; the marketing version becomes 0.7.0. | | [Remove Article Mode](#remove-article-mode) | 2026-09-21 | Done — `make test` carries UI failures `main` owns, so Req 7.1 is not met as written (Q34) | Full spec (T-2336). Removes articles mode: the one-way Site state, its UI and repository operations, `SiteMode.articles` with every arm over it, and the `article` default work type. Schema V16 drops `Site.junkSuffixRule`, the one column only the mode used, and the archive moves to 15/16; 14/15 backups stop importing. No conversion is built, because no articles Site exists (Decision 1, Q10). Three commits: remove the mode, schema V16, archive and documents. | | [To Read](#to-read) | 2026-09-21 | Done | Full spec (T-2354). A fifth reading status, `toRead`, which the New Work form gives every work it creates and the reader can set in edit mode. A capture or a Move To into a to-read work makes it `reading` in the same commit; nothing else promotes. To-read works stay off Today's plan. No schema, marker or archive generation change. The share-sheet path is deferred to T-2363. |-| [New Work URL Field](#new-work-url-field) | 2026-09-22 | Planned | Smolspec (T-2365). The New Work form's site field accepts a bare hostname or an HTTP(S) URL with the scheme optional; a URL reduces to the host capture derives and is stored as that site's Work URL after the validator's on-host check. The field is relabelled with the URL keyboard, and `LibraryRepositoryError` becomes `LocalizedError` so every form shows a readable message. No schema change. The confirm-same-story dedup prompt is T-2366. |+| [New Work URL Field](#new-work-url-field) | 2026-09-22 | Done | Smolspec (T-2365). The New Work form's site field accepts a bare hostname or an HTTP(S) URL with the scheme optional; a URL reduces to the host capture derives and is stored as that site's Work URL after the validator's on-host check. The field is relabelled with the URL keyboard, and `LibraryRepositoryError` becomes `LocalizedError` so every form shows a readable message. No schema change. The confirm-same-story dedup prompt is T-2366. | --- @@ -869,7 +869,7 @@ Full spec (T-2354). Adds `toRead` as a fifth `ReadingStatus` value, ordered firs ## New Work URL Field -**Created:** 2026-09-22 · **Status:** Planned — four tasks in two phases. Q1–Q9 in the log.+**Created:** 2026-09-22 · **Status:** Done — four tasks in two phases, all complete. Q1–Q14 in the log. `make test-quick` green; the pending-capture suites of `make test-core` failed on the implementing host with the file-protection error `docs/agent-notes/testing.md` records, identically on the parent commit, so a clean `make test-core` on an unlocked host is owed. Smolspec (T-2365). The New Work form's site field accepts a bare hostname or an HTTP(S) URL, with the scheme optional (Q4): `example.com/story` is read as `https://example.com/story`. A URL reduces to the host the capture path derives, which must also pass the bare-hostname grammar so a typo cannot mint a permanent `Site` row (Q9), and the URL is stored as the confirmed Work URL of the membership the work is born with, as typed (Q8), after the same on-host check the validator makes; disagreement refuses the creation naming both hosts (Q5). The field is labelled "Site or URL" with the URL keyboard. `LibraryRepositoryError` conforms to `LocalizedError`, so every form presenting `localizedDescription` shows the error's own message instead of "error N" (Q6). No schema, marker or archive change. The confirm-same-story prompt for a capture that lands beside a to-read work is T-2366 (Q7).
diff --git a/specs/new-work-url-field/smolspec.md b/specs/new-work-url-field/smolspec.mdindex bfa3cfe3..b8665067 100644--- a/specs/new-work-url-field/smolspec.md+++ b/specs/new-work-url-field/smolspec.md@@ -8,7 +8,7 @@ The New Work form's second field only accepts a bare hostname. Pasting a normal - The system MUST accept a bare hostname in the New Work form's site field and create the work on it exactly as today: trimmed, ASCII-lowercased, one trailing dot removed, label grammar enforced, no Work URL stored. - The system MUST accept an HTTP(S) URL in that field, with surrounding whitespace ignored, and create the work on the host the capture path derives for the same URL, so a later capture of a page on that site lands on the same `Site` row. `www.` is kept and the port is never part of the hostname, because that is what capture does. The derived host MUST also pass the label grammar a bare hostname passes, because a `Site` row is never deleted and syncs everywhere (decision log Q9).-- The scheme MUST be optional: input that is not a bare hostname and carries no `://` is read as `https://` followed by the input, so `example.com/series/foo` is the URL `https://example.com/series/foo` (Q4). An explicit `http://` is kept.+- The scheme MUST be optional: input that is not a bare hostname and carries no scheme — a `://` before its first `/`, `?` or `#` (Q12) — is read as `https://` followed by the input, so `example.com/series/foo` is the URL `https://example.com/series/foo` (Q4). An explicit `http://` is kept. - When a URL was given, the system MUST store it, trimmed and with the assumed `https://` prefixed where the scheme was omitted, otherwise as typed, as the confirmed Work URL of the site membership the work is born with, and the returned snapshot MUST carry it. Query, fragment, scheme case and userinfo are kept, as a manual replacement on the work detail keeps them (Q8). - The system MUST refuse to create the work, writing nothing, when the URL is not on the derived host by the check the library validator makes for a stored Work URL. The reader sees "Invalid input while checking the site or URL: That address is on {host the URL names}, not {derived host}." so a trailing-dot host shows its dot. - The system MUST refuse blank input, a non-HTTP scheme, and an address whose authority cannot be read with "Invalid input while checking the site or URL: Enter a site such as example.com or an address such as example.com/story". A hostname that fails the grammar, typed or derived, MUST be refused with the same prefix and the existing "Hostname does not follow the accepted grammar".@@ -18,12 +18,12 @@ The New Work form's second field only accepts a bare hostname. Pasting a normal ## Implementation Approach -- **One entry point for the field's two forms**, in `Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift` beside `HostnameNormalizer.bare` and `HostnameNormalizer.fromRawURL`. It trims the input first, because `LexicalHTTPURL` refuses any character at or below a space. Then it classifies the trimmed input: containing `://` anywhere, it is a URL as typed; otherwise containing any of the characters `bare` refuses as URL syntax (`:`, `/`, `@`, `?`, `#`, `[`, `]`), it is a URL with `https://` prefixed; otherwise it is a bare hostname. A URL goes through `fromRawURL` and the result through `bare`, so the grammar is the same on both paths and every host that is accepted is the one capture would derive (Q9); a bare hostname goes through `bare` alone. It returns the hostname and, for a URL, the URL it parsed. Both existing functions stay unchanged, and `bare`'s `URLSyntaxNotAllowed` is no longer reachable from this path; a doc comment on `bare` notes this entry point is now its only production caller. Blank input and `fromRawURL`'s `invalidURL(.malformedAuthority)` and `invalidURL(.unsupportedScheme)` are rethrown as one new `HostnameNormalizationError` case whose description is "Enter a site such as example.com or an address such as example.com/story". Every other failure keeps its existing case.+- **One entry point for the field's two forms**, in `Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift` beside `HostnameNormalizer.bare` and `HostnameNormalizer.fromRawURL`. It trims the input first, because `LexicalHTTPURL` refuses any character at or below a space. Then it classifies the trimmed input: carrying a scheme, a `://` before the first `/`, `?` or `#` (Q12), it is a URL as typed; otherwise containing any of the characters `bare` refuses as URL syntax (`:`, `/`, `@`, `?`, `#`, `[`, `]`), it is a URL with `https://` prefixed; otherwise it is a bare hostname. A URL goes through `fromRawURL` and the result through `bare`, so the grammar is the same on both paths and every host that is accepted is the one capture would derive (Q9); a bare hostname goes through `bare` alone. It returns the hostname and, for a URL, the URL it parsed. Both existing functions stay unchanged, and `bare`'s `URLSyntaxNotAllowed` is no longer reachable from this path; a doc comment on `bare` notes this entry point is now its only production caller. Blank input and `fromRawURL`'s `invalidURL(.malformedAuthority)`, `invalidURL(.unsupportedScheme)` and `invalidURL(.missingHost)` (Q13) are rethrown as one new `HostnameNormalizationError` case whose description is "Enter a site such as example.com or an address such as example.com/story". Every other failure keeps its existing case. - **`createWork`** in `Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift` (about line 1135) calls that entry point instead of `bare`, with the `operation:` label "checking the site or URL". When a URL came back it checks `WorkURLPlanner.isOnHost(url, hostname:)` from `WorkURLPlanner.swift`, the derivation `LibraryValidator` (about line 975) and the wrong-host heal use, and on disagreement throws `LibraryRepositoryError.invalidInput` naming both hosts, the URL's from `WorkURLPlanner.host(of:)` (Q5). Then it sets `workURLString` on the membership `Work.create` minted, before the one save the call already makes, the way the `to-read` change sets `readingStatus` there. `Work.create` itself is left alone; every other creation path goes through it and none of them carries a URL. - **`NewWorkDraft.hostname`** in `RepositoryDrafts.swift` keeps its name and gains a doc comment saying it holds either form (Q3). `NewWorkFormModel.create()` in `Asterism/Asterism/ViewModels/NewWorkFormModel.swift` passes the field's text as it does today.-- **The field** in `Asterism/Asterism/Views/NewWorkView.swift`: the `TextField` title becomes "Site or URL", the placeholder goes in the `prompt:` argument as "example.com or example.com/story", and `noAutocapitalization()` is replaced by `urlKeyboard()` from `Asterism/Asterism/Support/PlatformModifiers.swift`, which the work detail's URL field uses. `autocorrectionDisabled()` and the identifier stay.+- **The field** in `Asterism/Asterism/Views/NewWorkView.swift`: the `TextField` title becomes "Site or URL", the placeholder goes in the `prompt:` argument as "example.com or example.com/story" (on iOS the placeholder is the only text drawn, Q14), and `noAutocapitalization()` is replaced by `urlKeyboard()` from `Asterism/Asterism/Support/PlatformModifiers.swift`, which the work detail's URL field uses. `autocorrectionDisabled()` and the identifier stay. - **`LibraryRepositoryError`** in `Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift` adds `LocalizedError` with `errorDescription` returning `description`, as `PatternApplicationError` and `PhraseTeachingError` do in `TitleParsing.swift`. The `"confirmWorkURL"` operation literal in `LibraryRepository+WorkMerge.swift` (about line 103) becomes "confirming the Work URL", with the two assertions in `WorkURLMembershipTests.swift` that pin it updated. No other label moves.-- **Tests.** The entry point in `IdentityNormalizationTests.swift`: whitespace around a URL, an uppercase scheme, a non-default port, userinfo, a `utm_` query, a trailing-dot host yielding `example.com`, `example.com/story` and `example.com:8080/x` yielding their `https://` forms, `www.example.com` yielding a hostname and no URL, `https:/example.com/x` and `ftp://example.com/x` refused with the both-forms case, and `https://-foo-.com/x` refused by the grammar. `createWork` arms in `WriteSiteRelationshipTests.swift`, which already creates works through it and reads the membership: a URL stores on the membership, a scheme-less address stores its `https://` form, a bare hostname stores nothing, `https://example.com./story` refuses naming both hosts, and an IPv6 literal either refuses or stores a value `isOnHost` accepts, whichever way `URLComponents` falls on this Foundation, so the invariant is pinned rather than the outcome. The error conformance beside an existing `LibraryRepositoryError` test. One arm in `Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift` where `MockLibraryProvider` throws a real `LibraryRepositoryError.invalidInput` and the form's `errorMessage` equals its `description`.+- **Tests.** The entry point in `IdentityNormalizationTests.swift`: whitespace around a URL, an uppercase scheme, a non-default port, userinfo, a `utm_` query, a trailing-dot host yielding `example.com`, `example.com/story` and `example.com:8080/x` yielding their `https://` forms, `www.example.com` yielding a hostname and no URL, `https:/example.com/x` and `ftp://example.com/x` refused with the both-forms case, and `https://-foo-.com/x` refused by the grammar. `createWork` arms in `WriteSiteRelationshipTests.swift`, which already creates works through it and reads the membership: a URL stores on the membership, a scheme-less address stores its `https://` form, a bare hostname stores nothing, `https://example.com./story` refuses naming both hosts, and an IPv6 literal either refuses or stores a value `isOnHost` accepts, so the invariant is pinned rather than the outcome (since Q9 the grammar refuses it, Q11). The error conformance beside an existing `LibraryRepositoryError` test. One arm in `Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift` where `MockLibraryProvider` throws a real `LibraryRepositoryError.invalidInput` and the form's `errorMessage` equals its `description`. - **Dependencies.** `HostnameNormalizer.fromRawURL`, `HostnameNormalizer.bare`, `WorkURLPlanner.isOnHost`, `WorkURLPlanner.host(of:)`, `Work.create`, `WorkSnapshot`'s membership `workURLString`, `urlKeyboard()`. - **Out of scope.** Prompting the reader when a later capture lands beside a to-read work on the same site (T-2366). Storing a Work URL for a bare hostname. Stripping trackers, fragments or userinfo from the stored URL. Treating `www.example.com` and `example.com` as one site. Rewording any other error label. Any change to the Move To new-work path, the capture path, `Work.create`, the schema, the readiness marker or the archive.
diff --git a/specs/new-work-url-field/decision_log.md b/specs/new-work-url-field/decision_log.mdindex 6d5b230d..ae2919ac 100644--- a/specs/new-work-url-field/decision_log.md+++ b/specs/new-work-url-field/decision_log.md@@ -9,7 +9,12 @@ | Q3 | 2026-09-22 | The two forms are classified in Core, and `NewWorkDraft.hostname` keeps its name | `createWork` is the only production caller of `bare`, so tolerance belongs where the strictness was; the form stays a draft holder. The name now understates what the field holds; renaming it, or adding a second initialiser, would touch about sixty fixture and test callers for a type with one production caller. The doc comment is the accepted trade | | Q4 | 2026-09-23 | The scheme is optional: `example.com/series/foo` is read and stored as `https://example.com/series/foo`; an explicit `http://` is kept | Owner's pick, overturning a first draft that refused it. A bare hostname carries no scheme either, so demanding one on the longer form is inconsistent, and `https` is what every site a reader would paste uses. Classification is by the URL-syntax characters `bare` already refuses, so `URLSyntaxNotAllowed` and its "without URL syntax" wording are unreachable from the form; the remaining refusal message names both accepted forms | | Q5 | 2026-09-22 | A URL whose `URLComponents` host disagrees with the lexical host is refused, not stored host-only | The validator and the wrong-host heal classify a stored Work URL with `WorkURLPlanner.isOnHost`, so a value written past that check would be a diagnosis on the next open. Dropping the URL silently would hide what the reader typed; refusing is loud and the case is an edge |-| Q6 | 2026-09-22 | `LibraryRepositoryError` conforms to `LocalizedError` in this change | One line with a precedent in `TitleParsing.swift`; the unreadable "error 2" was half of what T-2365 reported, and nineteen app files present errors through `localizedDescription` |+| Q6 | 2026-09-22 | `LibraryRepositoryError` conforms to `LocalizedError` in this change | One line with a precedent in `TitleParsing.swift`; the unreadable "error 2" was half of what T-2365 reported, and every app file that presents an error does so through `localizedDescription` (nineteen at the time) | | Q7 | 2026-09-22 | The confirm-same-story prompt is T-2366, a full spec | The match rule is user-owned and where it runs is contested; it belongs with the identity problem T-2363 recorded, not with a form field | | Q8 | 2026-09-22 | The stored Work URL keeps query, fragment, scheme case and userinfo as typed | Owner's pick, confirmed 2026-09-23 for userinfo specifically, which reaches CloudKit, backups and Markdown export. The precedent is the manual replacement on the work detail, which `WorkURLPlanner.project` stores as typed after `isValidHTTPURL`; the derived candidate strips query and fragment, but that path reads captured entries and this one reads what the reader pasted. Trackers are an identity-key concern, and this feature never computes an identity key | | Q9 | 2026-09-23 | A host derived from a URL is run through `bare`'s label grammar before a `Site` row is minted from it | `fromRawURL` enforces only a character class, so `https://-foo-.com/x` or `https://foo..com/x` would mint a permanent, synced `Site` row from a typo. The grammar only refuses; every host it accepts is the one capture would derive, so a later capture still lands on the same row. Capture is not made stricter: a browser has already resolved what it hands over |+| Q10 | 2026-09-23 | A URL whose host `URLComponents` cannot read at all is refused by the same guard, naming "a host this library cannot read" | Implementation detail Q5 left open: `WorkURLPlanner.host(of:)` is optional, and a URL the lexical parser accepts can still be one `URLComponents` returns no host for. One refusal rather than two messages, because the reader's repair is the same — retype the address |+| Q11 | 2026-09-23 | An IPv6-literal URL is refused by `bare`'s grammar on the derived host, and reported as `invalidHostname` | It falls out of Q9 rather than being chosen: `bare` refuses `:`, so `https://[2001:db8::1]/story` is refused before `isOnHost` is ever asked, and it is the one form-reachable input that raises `URLSyntaxNotAllowed`. Q4 promised the reader would never see "Expected a bare hostname without URL syntax", so the entry point rethrows it as the grammar refusal Req 6 names. A `Site` row keyed on an IPv6 literal is not one the capture path would ever produce |+| Q12 | 2026-09-23 | Input has a scheme only when its `://` comes before the first `/`, `?` or `#`; a later one is part of the path or query | Pre-push review. The first draft read `://` anywhere as a scheme, so a scheme-less Wayback or redirect address such as `web.archive.org/web/2020/https://example.com/x` had everything before its `://` read as the scheme and was refused with the both-forms sentence, for input that is exactly the `example.com/story` form Req 3 accepts. Req 3 and the approach bullet are amended |+| Q13 | 2026-09-23 | `fromRawURL`'s `missingHost` is rethrown as the both-forms refusal too | Pre-push review. It is reached by an empty authority (`https:///x`), which Req 6 already covers, and by a host outside the lexical character class (`foo_bar.com/story`), for which "URL does not contain a host" is wrong twice: there is a host, and the same typo as a bare hostname gets the grammar message. `invalidCharacter` keeps its own case: an inner space or a non-ASCII character is named precisely by it |+| Q14 | 2026-09-23 | On iOS the field's visible text is the placeholder alone; the title "Site or URL" is the VoiceOver label and the Mac's drawn label | `TextField(_:text:prompt:)` in an iOS Form draws only the prompt, which is what the field did before with its one example. The placeholder shows one example of each form, so it says what the label would; a drawn label would need a `LabeledContent` row that no other field in this form has. Req 7's "label" is met visually on the Mac and through accessibility on iOS |
diff --git a/specs/new-work-url-field/tasks.md b/specs/new-work-url-field/tasks.mdindex 1acc5775..e4f11222 100644--- a/specs/new-work-url-field/tasks.md+++ b/specs/new-work-url-field/tasks.md@@ -7,20 +7,20 @@ references: ## Core -- [ ] 1. Repository errors read as their descriptions on every screen <!-- id:3o27wdf -->- - Spec: smolspec.md Requirement 7 and the LibraryRepositoryError bullet of the Implementation Approach; decision log Q6.+- [x] 1. Repository errors read as their descriptions on every screen <!-- id:3o27wdf -->+ - Spec: smolspec.md Requirement 8 and the LibraryRepositoryError bullet of the Implementation Approach; decision log Q6. - LibraryRepositoryError in Packages/AsterismCore/Sources/AsterismCore/CrossProcessLibraryLock.swift conforms to LocalizedError with errorDescription returning its description, as PatternApplicationError does in TitleParsing.swift. - The confirmWorkURL operation literal in LibraryRepository+WorkMerge.swift reads as words; the two WorkURLMembershipTests assertions that pin it are updated. - Verify: grep the three test targets for any assertion on the error N wording before changing; a Core test asserts localizedDescription equals description for a representative case; make test-core is green with no new warnings. -- [ ] 2. A site or URL typed into the form reduces to the host capture would derive <!-- id:3o27wdd -->+- [x] 2. A site or URL typed into the form reduces to the host capture would derive <!-- id:3o27wdd --> - Spec: smolspec.md Requirements 1 to 3 and 6, the first bullet of the Implementation Approach; decision log Q4 and Q9. - One HostnameNormalizer entry point in Packages/AsterismCore/Sources/AsterismCore/IdentityNormalization.swift returns the hostname and, for a URL, the URL: trimmed input containing :// is a URL as typed; input containing any URL-syntax character bare refuses is a URL with https:// prefixed; anything else is a bare hostname. - A URL's host goes through fromRawURL and then bare. Blank input, malformedAuthority and unsupportedScheme rethrow as one new HostnameNormalizationError case whose description names both accepted forms. bare and fromRawURL are unchanged; the doc comment on bare notes its one production caller. - Verify: IdentityNormalizationTests covers whitespace around a URL, an uppercase scheme, a non-default port, userinfo, a utm_ query, a trailing-dot host yielding example.com, example.com/story and example.com:8080/x yielding their https forms, www.example.com yielding a hostname and no URL, https:/example.com/x and ftp://example.com/x refused with the both-forms case, and https://-foo-.com/x refused by the grammar; make test-core is green. -- [ ] 3. Creating a work from a URL stores it as the site's Work URL <!-- id:3o27wde -->- - Spec: smolspec.md Requirements 4, 5 and 8, the createWork and NewWorkDraft bullets of the Implementation Approach; decision log Q2, Q5 and Q8.+- [x] 3. Creating a work from a URL stores it as the site's Work URL <!-- id:3o27wde -->+ - Spec: smolspec.md Requirements 4, 5 and 9, the createWork and NewWorkDraft bullets of the Implementation Approach; decision log Q2, Q5 and Q8. - createWork in Packages/AsterismCore/Sources/AsterismCore/LibraryRepository.swift uses the entry point with the operation label checking the site or URL. When a URL came back it must pass WorkURLPlanner.isOnHost against the derived host, or the call throws invalidInput naming both hosts and writes nothing. The URL is set on the membership Work.create minted, before the existing save. Work.create is not changed. - NewWorkDraft.hostname in RepositoryDrafts.swift gains a doc comment saying it holds either form. - Verify: WriteSiteRelationshipTests shows a URL stored on the returned snapshot's membership, a scheme-less address stored in its https form, a bare hostname storing nothing, https://example.com./story refused naming both hosts, and an IPv6 literal either refused or stored with a value isOnHost accepts; every existing createWork test still passes; make test-core is green.@@ -28,8 +28,8 @@ references: ## App -- [ ] 4. The New Work field is labelled for both forms and shows a readable refusal <!-- id:3o27wdg -->- - Spec: smolspec.md Requirement 6 and the field bullet of the Implementation Approach.+- [x] 4. The New Work field is labelled for both forms and shows a readable refusal <!-- id:3o27wdg -->+ - Spec: smolspec.md Requirement 7 and the field bullet of the Implementation Approach. - In Asterism/Asterism/Views/NewWorkView.swift the TextField title is Site or URL, the placeholder example.com or example.com/story goes in the prompt argument, and urlKeyboard from Asterism/Asterism/Support/PlatformModifiers.swift replaces noAutocapitalization. autocorrectionDisabled and the identifier new-work-hostname-field stay. NewWorkFormModel is unchanged. - Verify: one arm in Asterism/AsterismTests/MoveToAndNewWorkModelTests.swift has MockLibraryProvider throw a real LibraryRepositoryError.invalidInput and asserts the form's errorMessage equals its description; make test-quick is green, which includes the Mac build. - Blocked-by: 3o27wdf (Repository errors read as their descriptions on every screen), 3o27wde (Creating a work from a URL stores it as the site's Work URL)
(diff fragment 'diff-implementation.md.txt' missing)
user@example.com becomes a work on example.com with the Work URL https://user@example.com. Q8 keeps userinfo deliberately; decide whether that is fine for this input.
Q14 accepts that iPhone and iPad show only the placeholder. If a drawn "Site or URL" label is wanted there, it is a LabeledContent row.
The App target's only change since its green run is a comment in NewWorkView.swift; the review did not rerun the simulator bundle.