feat(sessions): new post from session & drills (S2.7-8) (#30)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
A freeform Session births a Post. "New Post" in the Sessions pane opens an ask-before sheet prefilled with the session's last mentor reply (editable, G9); ONE confirm materializes the piece under projects/posts/ stamped origin: ai - immutable frontmatter, never stats-eligible - and opens it in Posts; a failed write keeps the sheet up with the reason inline and the draft intact. writeNew gains an origin parameter (additive default .writer, every existing caller compiles). "New Brainstorm" is a session started with an opener prompt - no new machinery (beginBrainstormSession over the normal new+prompt rails). The freeform composer (input, liveness, Stop) moved from MentorPaneView into the shared SessionTranscriptView: one conversation surface, two panes - the Sessions pane stops being a read-only transcript. Drill offers (S2.8) wire as one pass-persona section (v1.4): the seeded micro-drill doctrine owns the motivation moment, the two-minute bound, the single shelf, and the vanish - session flavor, no machinery beyond S2.3. Resume now speaks the real adapter wire. Live-probed against the engine: 0.21.5 answers session/load with the id at _meta.hermes.sessionProvenance.acpSessionId and NO top-level sessionId - resumeSession accepts both shapes; every prior real-engine resume misread as "engine does not know this session". The fake ACP server answers load in the real shape (a loadReplayLegacy knob pins the older contract), so the whole resume suite guards the live wire. New pins: draft-candidate extraction (last mentor row wins; thought/ card/research/raw lanes and refusal/connection rows never prefill), ai-stamp write + immutability through overwrite, brainstorm roster + labeled opener, legacy-shape resume. Finish-audit (three reviewers, parallel) converged on the confirm() dismissal that destroyed the edited draft on a failed write - fixed with sheet-local error state (stale-refusal re-show dies with the presentation) - and surfaced the missing brainstorm and legacy-shape pins; the resume fix was flip-verified (removing the provenance fallback fails the provenance pins). Full suite green (379 tests). Closes #30
This commit is contained in:
1 parent
b02d36bb5d
commit
ae234350ef
16 files changed
+521
-128
No files matched your search
@@ -407,6 +407,23 @@ final class MentorSessionModel {
|
||||
return await createSession(name: "\(kind.rawValue) · \(pieceTitle)", pieceTitle: pieceTitle)
|
||||
}
|
||||
|
||||
/// #30 (S2.7): the brainstorm flavor — a plain freeform session whose
|
||||
/// first turn is the brainstorm prompt (PRD S2.8: no new machinery).
|
||||
/// Nil when the session couldn't be created; the opener rides the
|
||||
/// normal prompt rail and streams like any turn.
|
||||
@discardableResult
|
||||
func beginBrainstormSession(pieceTitle: String?) async -> SessionEntry? {
|
||||
guard let entry = await newSession(name: "Brainstorm", pieceTitle: pieceTitle) else { return nil }
|
||||
_ = await sendPrompt(Self.brainstormPrompt, label: "Brainstorm")
|
||||
return entry
|
||||
}
|
||||
|
||||
/// #30 (S2.7): the brainstorm opener — questions over prose.
|
||||
nonisolated static let brainstormPrompt =
|
||||
"Let's brainstorm together. Ask me one question at a time to draw out ideas "
|
||||
+ "and angles for what I want to write — keep replies short and generative, "
|
||||
+ "and don't draft prose unless I ask."
|
||||
|
||||
/// The shared creation rail behind newSession/beginPassSession.
|
||||
private func createSession(name: String, pieceTitle: String?) async -> SessionEntry? {
|
||||
// Finish-audit backstop: fork guards !isStreaming; the views disable
|
||||
@@ -491,8 +508,20 @@ final class MentorSessionModel {
|
||||
timeout: Self.promptTimeout,
|
||||
)
|
||||
replayingSessionId = nil
|
||||
// null/absent (or empty) sessionId in the result = the engine does not know it.
|
||||
guard let sid = result?.objectValue?["sessionId"]?.stringValue, !sid.isEmpty else {
|
||||
// The real adapter (0.21.5, live-verified #30 dogfood) answers
|
||||
// session/load WITHOUT a top-level sessionId — the id rides
|
||||
// `_meta.hermes.sessionProvenance.acpSessionId`. The fake's
|
||||
// top-level shape stays accepted (the older contract).
|
||||
let resultObject = result?.objectValue
|
||||
let provenance = resultObject?["_meta"]?
|
||||
.objectValue?["hermes"]?
|
||||
.objectValue?["sessionProvenance"]?
|
||||
.objectValue
|
||||
let sid = resultObject?["sessionId"]?.stringValue
|
||||
?? provenance?["acpSessionId"]?.stringValue
|
||||
?? ""
|
||||
// null/absent everywhere = the engine does not know it.
|
||||
guard !sid.isEmpty else {
|
||||
// The refusal belongs to the ENTRY — attributed, and visible
|
||||
// on its next row click (the store is kept, not discarded).
|
||||
appendRow(
|
||||
@@ -821,6 +850,38 @@ extension MentorSessionModel {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: New Post from Session (#30, S2.7)
|
||||
|
||||
extension MentorSessionModel {
|
||||
/// The draft candidate for New Post from Session: the ACTIVE session's
|
||||
/// last mentor text row, "Mentor: " prefix stripped. Feeds the ask
|
||||
/// sheet's prefill.
|
||||
func draftCandidateText() -> String? {
|
||||
Self.draftCandidateText(in: rows)
|
||||
}
|
||||
|
||||
/// The pure extraction (test seam): scan backwards — the LAST mentor
|
||||
/// text row wins; user rows and thought/card/research/raw rows never
|
||||
/// prefill. Blank bodies are skipped so a whitespace leftover can't
|
||||
/// blank the prefill while an earlier real reply still exists.
|
||||
static func draftCandidateText(in rows: [SessionRow]) -> String? {
|
||||
for row in rows.reversed() {
|
||||
guard case let .text(text) = row.content, text.hasPrefix("Mentor: ") else { continue }
|
||||
// ponytail: refusal/connection rows share the display prefix —
|
||||
// excluded by their known shapes until SessionRow carries speaker
|
||||
// identity (an enum reshape is its own ticket).
|
||||
if text.hasPrefix("Mentor: (refused") || text.hasPrefix("Mentor: connection lost") {
|
||||
continue
|
||||
}
|
||||
let body = text.dropFirst("Mentor: ".count).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if !body.isEmpty {
|
||||
return String(body)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// Research-candidate batch parsing (#29): the submit_research_notes wire
|
||||
/// shape {piece_path, notes: [{title, url, quote?, note?}]} — one candidate
|
||||
/// PER note. Lenient: a missing piece_path, an empty/absent notes array, or
|
||||
|
||||
Reference in new issue
Block a user