Skip to content

Add post-session context generation#16

Merged
qyinm merged 4 commits into
mainfrom
post-session-agent-context
May 4, 2026
Merged

Add post-session context generation#16
qyinm merged 4 commits into
mainfrom
post-session-agent-context

Conversation

@qyinm
Copy link
Copy Markdown
Owner

@qyinm qyinm commented May 4, 2026

Summary

Adds a post-session source context pipeline that generates agent-ready context packets once a completed transcript is available.

Why

The STT/session flow now needs a post-session artifact layer so completed recordings can become source-backed agent context without exposing internal ledger/debug files in the UI.

Changes

  • Track sourceContextStatus from metadata and existing context/agent-brief.md / context/project-context.md files.
  • Auto-queue source context generation only for completed sessions with usable transcript segments.
  • Keep missing transcript, provider errors, and generation failures visible and retryable.
  • Add compact Note tab actions for Generating context, Ready, Failed, Retry, and Open agent brief.
  • Add renderer and main-process smoke coverage for eligibility, idempotency, provider-missing, and retryable failure states.

Validation:

  • npm run renderer:check
  • node --check apps/desktop/main.cjs
  • node --check apps/desktop/preload.cjs
  • npm run desktop:test:main

Summary by CodeRabbit

  • New Features

    • Added source-context generation for completed notes with visible status (generating, ready, failed).
    • Automatic background generation for eligible notes with retry support.
    • Open agent brief from a note via a new action.
    • New localized strings for source-context UI (en/ko).
  • Bug Fixes

    • Better handling of generation errors and retryable failure state.
  • Tests

    • Added unit and integration tests covering generation gating, retry logic, and failure paths.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 0958e4fb-6332-4069-9aad-338961c1ebb5

📥 Commits

Reviewing files that changed from the base of the PR and between b6c618e and 2eb3afa.

📒 Files selected for processing (5)
  • apps/desktop/main.cjs
  • apps/desktop/main/native-launch.node-test.cjs
  • apps/desktop/src/App.tsx
  • apps/desktop/src/types.ts
  • apps/desktop/src/utils/sourceContext.test.ts

📝 Walkthrough

Walkthrough

Adds end-to-end source-context generation: new normalized status shape, metadata persistence and file-path derivation, generation gating and native invocation in the main process, IPC/preload handlers, frontend auto-generation, UI/status rendering with retry/open-agent-brief actions, and tests covering success and failure paths.

Changes

Source Context Generation Feature

Layer / File(s) Summary
Data Shape
apps/desktop/src/types.ts
Added SourceContextState and SourceContextStatus; extended NoteSummary and MirrorNoteAPI with sourceContextStatus, generateSourceContext, and openAgentBrief.
Normalization / Read Helpers
apps/desktop/main.cjs
Added normalizeSourceContextStatus, withDerivedSourceContextPaths, and sourceContextStatusFromMetadata to compute status and derive on-disk packet paths (optionally verifying files).
Transcript Gate
apps/desktop/main.cjs
Added noteHasCompletedTranscriptForSourceContext to require completed session + non-preview transcript segment before generation.
Core Generation & Persistence
apps/desktop/main.cjs
Rewrote generateSourceContext(noteID) to persist state transitions: early-return when already ready, set failed/retryable when transcript missing, persist generating, invoke native capture, persist ready with packet ids/counts on success, or failed (retryable) on error; syncs SQLite cache from bundle files after updates.
Bundle & DB Read Paths
apps/desktop/main.cjs
Include sourceContextStatus when loading bundle snapshots and when building summaries from DB rows (with on-disk probing disabled for row path).
IPC / Preload Bridge
apps/desktop/main.cjs, apps/desktop/preload.cjs
Registered ipcMain.handle("source-context:generate", ...) and ipcMain.handle("source-context:open-agent-brief", ...); preload exposes mirrorNote.generateSourceContext(id) and mirrorNote.openAgentBrief(id).
Frontend Auto-Generation & Handlers
apps/desktop/src/App.tsx
Added state (generatingSourceContextId, sourceContextError), per-note auto-queue dedup (sourceContextAutoQueuedRef), generateSourceContext and openAgentBrief flows (saving pending transcript, invoking API, reload on success, record error and cleanup on failure), and auto-trigger effect using canAutoGenerateSourceContext.
UI Rendering & Props
apps/desktop/src/components/NoteTab.tsx
Extended NoteTabProps; compute and render note-source-context-status pill (idle/generating/ready/failed), show open-agent-brief and retry actions when applicable, and display source-context error/details separate from summary errors.
Client Helpers & Tests
apps/desktop/src/utils/sourceContext.ts, apps/desktop/src/utils/sourceContext.test.ts
Added canAutoGenerateSourceContext, canRetrySourceContext, and hasUsableTranscriptSegment with tests validating session-state gating, transcript requirements, and retry semantics.
Main Process Test Exports & Node Tests
apps/desktop/main.cjs, apps/desktop/main/native-launch.node-test.cjs
Exported normalization/gating helpers in test build; node test now asserts transcript gating, retryable propagation, and sourceContextStatusFromMetadata produces expected ready paths when on-disk packet files exist.
Smoke Tests
scripts/smoke_notes_store.cjs
Extended smoke tests to persist metadataPath.listenerSession, verify failure semantics when transcript missing and when native provider throws, and assert failed + retryable: true.
Styling & Localization
apps/desktop/src/styles.css, apps/desktop/src/i18n.tsx
Added CSS for .note-source-context-status pill and spin animation; added i18n keys/translations for status labels and actions (EN/KO).

Sequence Diagram

sequenceDiagram
    participant App as App.tsx
    participant Preload as preload.cjs
    participant Main as main.cjs
    participant Native as Native Layer
    participant FS as File System
    participant DB as SQLite DB

    App->>App: detect eligible note (canAutoGenerateSourceContext)
    App->>App: set generatingSourceContextId, save pending transcript (if manual)
    App->>Preload: mirrorNote.generateSourceContext(noteId)
    Preload->>Main: IPC "source-context:generate" {noteId}
    Main->>Main: normalize status, check noteHasCompletedTranscriptForSourceContext
    alt transcript incomplete
        Main->>FS: write metadata.sourceContext = {state: failed, retryable: true}
        Main->>DB: sync metadata from bundle
        Main-->>Preload: respond with error
    else transcript complete
        Main->>FS: write metadata.sourceContext = {state: generating}
        Main->>DB: sync metadata
        Main->>Native: nativeCaptureRequest("generateSourceContext", ...)
        alt native success
            Native->>FS: write context packet files (agentBrief etc.)
            Main->>FS: write metadata.sourceContext = {state: ready, paths, counts}
            Main->>DB: sync metadata
            Main-->>Preload: return updated status
        else native fails
            Main->>FS: write metadata.sourceContext = {state: failed, retryable: true, detail}
            Main->>DB: sync metadata
            Main-->>Preload: respond with error
        end
    end
    Preload-->>App: return result or error
    App->>NoteTab: update props (isGeneratingSourceContext, sourceContextError)
    NoteTab->>NoteTab: render status pill + actions (open agent brief / retry)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

I nibbled metadata in the night,
stitched paths and packets by moonlight.
Now notes can find their story’s thread —
a rabbit’s hop from idle to ready. 🐇✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Review rate limit: 1/3 review remaining, refill in 23 minutes and 53 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the "Source Context" feature, enabling the generation of agent briefs from note transcripts. It includes backend logic for state management and persistence, along with frontend updates to display status and handle auto-generation. Feedback highlights several improvement opportunities: including missing metadata fields (like packet IDs and counts) in normalization and type definitions, replacing synchronous file system checks in the note list path to avoid performance issues, and deriving paths dynamically instead of storing absolute paths to ensure data portability. It is also suggested to handle potential failures in prerequisite save operations before starting context generation.

Comment thread apps/desktop/main.cjs
Comment thread apps/desktop/main.cjs
Comment thread apps/desktop/main.cjs Outdated
Comment thread apps/desktop/src/App.tsx Outdated
Comment thread apps/desktop/src/types.ts
@qyinm qyinm merged commit 3ff7e5d into main May 4, 2026
1 of 2 checks passed
@qyinm qyinm changed the title [codex] Add post-session context generation Add post-session context generation May 4, 2026
@qyinm qyinm deleted the post-session-agent-context branch May 4, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant