Build the semantic commit-message engine
CommitMessageEngine replaces the interim composer as the wired default: a pure total function from two snapshots + changed paths to a message. Full vocabulary — Add / Delete / Move / Rename / Edit / Restyle / Resize / Reorder over cards, lanes, board; Attach / Remove; Repair for the duplicate remint (detected as a heal-classed rename-paired arrival whose id the previous snapshot never held — the loader withholds duplicates, so the shape is a bare arrival); the trash triple by diff shape alone (into .trash = Delete, out = Restore, leaving the tree = Permanently delete); Relabel / Assign / Set due date plus the named generic for custom keys. Plural folding with shared destinations, implied events as body bullets never subjects, ~40-char subject truncation, "(untitled)". Bookkeeping (sequence-preserving renumbers, stamps, backfilled kind) composes nothing. Non-snapshot paths compose path-shaped events — CLAUDE.md reads "Update agent guide (vN)" via the marker line (the m10 card's deferred bullet lands here), everything else "Update '<path>'". The comment verb family per 01's ruling (comments shipped, so 06 gains the verbs): Comment on / Edit comment on / Delete comment on / Draft comment on / Permanently delete comment on '<card>', grouped one event per comment folder, classified ahead of the model-silence rules, card title resolved from either snapshot. GIT_DELTA_ADDED is surfaced as GitChangedPath.isArrival — post vs edit is unanswerable from snapshots that exclude comments by ruling. A card moving with its thread swallows the comment events (implied-events one level down). The previous snapshot is HEAD's tree, materialized per flush into a temp dir (index.md blobs in full, other blobs zero-byte — the model reads attachment names, never bytes) and re-parsed through the one BoardLoader; never a value carried forward. changedPaths is a hard filter per split commit, which also earns the stage-around and kills phantom events. Launch catch-up and foreign windows compose through the same engine. 48 new tests (35 pure + comment family + engine-level); 2293 tests / 394 suites green; InertGitTests untouched. Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
@@ -25,13 +25,18 @@ public enum CommitAuthorship: Sendable, Equatable {
|
||||
/// Everything the message engine is handed for one commit.
|
||||
///
|
||||
/// **A struct rather than an argument list**, because the point of this seam is that the semantic
|
||||
/// composer — the next card — plugs into it without reshaping the engine: it can start reading
|
||||
/// `snapshot` and HEAD's tree the day it lands, and any input it turns out to need joins this type
|
||||
/// rather than every call site.
|
||||
/// composer plugs into it without reshaping the engine: any input it turns out to need joins this
|
||||
/// type rather than every call site. It did need two — `previousSnapshot` and `agentGuideText`, both
|
||||
/// below — and that is exactly what this shape was for.
|
||||
///
|
||||
/// **Everything here is a value, and that is the design.** The composer (`CommitMessageEngine`) reads
|
||||
/// no file and opens no repository: the flush resolves the environment once — the board as HEAD has
|
||||
/// it, the board as the app has it, the guide's bytes — and the message is then a pure function of
|
||||
/// this struct. Resolving once per *flush* rather than once per planned commit also means a
|
||||
/// three-way-split window materializes HEAD's tree once, not three times.
|
||||
public struct CommitMessageRequest: Sendable {
|
||||
|
||||
/// The board this is a commit in — and, for the composer card, where HEAD's tree is read from
|
||||
/// for the last-committed half of its diff.
|
||||
/// The board this is a commit in.
|
||||
public let boardRoot: URL
|
||||
|
||||
/// **The changed-path list** (06 ▸ Commit messages ▸ Non-snapshot files commit too: "beside the
|
||||
@@ -46,23 +51,46 @@ public struct CommitMessageRequest: Sendable {
|
||||
/// ("Initial board state", 06 ▸ Rules ▸ Abnormal repo states).
|
||||
public let isRootCommit: Bool
|
||||
|
||||
/// The board as the app last read it, or `nil` where no store is attached (a storeless
|
||||
/// committer, a test). The current half of the composer's "last-committed vs. current" diff; the
|
||||
/// other half is HEAD's tree, which the composer reads for itself.
|
||||
/// **The current half** of the composer's "last-committed vs. current" diff — the board as the
|
||||
/// app last read it, or, where no store is attached, as the flush read it off disk itself.
|
||||
///
|
||||
/// `nil` only when neither could answer: a board whose working tree does not load at all, which
|
||||
/// is a commit that will have to be described by its paths.
|
||||
public let snapshot: BoardModel?
|
||||
|
||||
/// **The last-committed half**: the board as HEAD's tree has it (`GitHeadSnapshot`).
|
||||
///
|
||||
/// `nil` on an unborn HEAD — where `isRootCommit` already says everything — and on a HEAD whose
|
||||
/// tree does not load as a board. It is read from the repository rather than carried forward from
|
||||
/// the last commit the app made, because the app is not the only writer and because launch
|
||||
/// catch-up has no carried value to offer: see `GitHeadSnapshot` for the whole of that argument.
|
||||
public let previousSnapshot: BoardModel?
|
||||
|
||||
/// **The board-root `CLAUDE.md` as it now reads**, when this commit touches it — the one
|
||||
/// non-snapshot file with a subject of its own ("Update agent guide (vN)", 06 ▸ Commit messages).
|
||||
///
|
||||
/// The *text*, not the version: N is "a pure function of file content"
|
||||
/// (`AgentGuide.installedVersion`), and keeping the parse on the composer's side is what keeps
|
||||
/// that rule where the message vocabulary is. `nil` when the guide is not in this commit, cannot
|
||||
/// be read, or has been deleted.
|
||||
public let agentGuideText: String?
|
||||
|
||||
public init(
|
||||
boardRoot: URL,
|
||||
changedPaths: [GitChangedPath],
|
||||
authorship: CommitAuthorship,
|
||||
isRootCommit: Bool,
|
||||
snapshot: BoardModel?
|
||||
snapshot: BoardModel?,
|
||||
previousSnapshot: BoardModel? = nil,
|
||||
agentGuideText: String? = nil
|
||||
) {
|
||||
self.boardRoot = boardRoot
|
||||
self.changedPaths = changedPaths
|
||||
self.authorship = authorship
|
||||
self.isRootCommit = isRootCommit
|
||||
self.snapshot = snapshot
|
||||
self.previousSnapshot = previousSnapshot
|
||||
self.agentGuideText = agentGuideText
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,11 +98,11 @@ public struct CommitMessageRequest: Sendable {
|
||||
|
||||
/// **What a commit says** (06-history-undo.md ▸ Commit messages).
|
||||
///
|
||||
/// The real implementation is the next card's: "a pure, testable function" composing from a
|
||||
/// structural diff of two board snapshots, with the whole Add/Delete/Move/Rename/Edit vocabulary,
|
||||
/// plural folding, path-shaped events for non-snapshot files, and the trash pair. None of that
|
||||
/// exists yet; what exists is this protocol, so that arriving card is one type conforming here
|
||||
/// rather than a change to the engine that calls it.
|
||||
/// The implementation is `SemanticCommitMessage` below, over `CommitMessageEngine`: "a pure, testable
|
||||
/// function" composing from a structural diff of two board snapshots, with the whole
|
||||
/// Add/Delete/Move/Rename/Edit vocabulary, plural folding, path-shaped events for non-snapshot files,
|
||||
/// and the trash pair. The protocol survives its interim purpose because it is still what lets a test
|
||||
/// inject a fake and assert *when* a message was asked for without asserting what it said.
|
||||
///
|
||||
/// `Sendable` because composition runs off the main actor, inside the same detached task that stages
|
||||
/// and commits — the message has to be in hand before `git_commit_create` is called, and none of the
|
||||
@@ -83,22 +111,19 @@ public protocol CommitMessageComposing: Sendable {
|
||||
func message(for request: CommitMessageRequest) -> String
|
||||
}
|
||||
|
||||
// MARK: - The interim
|
||||
// MARK: - The wired composer
|
||||
|
||||
/// **The placeholder message**, deliberately the *fallback* 06 already names rather than an
|
||||
/// invention: "genuinely mixed windows fall back to 'Update board'".
|
||||
/// **The semantic composer**, and the committer's default (`GitAutoCommitter.composer`).
|
||||
///
|
||||
/// So the trail an interim build writes is a trail the composer card only ever makes *more*
|
||||
/// specific — no message written today becomes wrong tomorrow, and the root commit's subject is
|
||||
/// already the settled one.
|
||||
public struct InterimCommitMessage: CommitMessageComposing {
|
||||
|
||||
/// 06's own mixed-window fallback.
|
||||
public static let fallbackSubject = "Update board"
|
||||
/// A one-line conformance over `CommitMessageEngine`, deliberately: the vocabulary is worth a file of
|
||||
/// its own and nothing about it should have to know that a protocol exists. The type stays because
|
||||
/// the seam takes an existential, and because a *named* default is what makes "the engine's composer
|
||||
/// is the semantic one" assertable.
|
||||
public struct SemanticCommitMessage: CommitMessageComposing {
|
||||
|
||||
public init() {}
|
||||
|
||||
public func message(for request: CommitMessageRequest) -> String {
|
||||
request.isRootCommit ? GitRepository.initialCommitSubject : Self.fallbackSubject
|
||||
CommitMessageEngine.message(for: request)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user