Skip to content

[codex] Add local agent context server#17

Merged
qyinm merged 4 commits into
mainfrom
codex-agent-server-context-jobs
May 5, 2026
Merged

[codex] Add local agent context server#17
qyinm merged 4 commits into
mainfrom
codex-agent-server-context-jobs

Conversation

@qyinm
Copy link
Copy Markdown
Owner

@qyinm qyinm commented May 5, 2026

Summary

Adds a local MirrorNoteAgentServer daemon and routes source context generation through it so meeting context jobs can live outside the desktop UI process.

Why

Agent context should be generated automatically as part of the meeting lifecycle, and longer-running agent work needs a local service boundary that can later survive desktop window restarts without introducing cloud-server assumptions.

Changes

  • Added native/agent-server-rust with localhost JSON-line IPC, daemon lifecycle commands, generateContext, jobStatus, and persisted job status under context/agent-jobs/.
  • Updated Electron main to call MirrorNoteAgentServer for source context generation and automatically enqueue context generation after recording completion.
  • Added restart/status recovery from the persisted agent job file when metadata is stale.
  • Wired MirrorNoteAgentServer into native build, release staging, macOS binary signing metadata, and helper boundary docs.
  • Extended source context schema source types for upcoming agent/session and work-system sources.

Validation:

  • node --check apps/desktop/main.cjs
  • npm run native:build
  • npm run desktop:test:main
  • npm run renderer:test
  • CARGO_TARGET_DIR=target cargo test --test context_packet_contract in native/native-host-rust
  • CARGO_TARGET_DIR=target cargo test in native/agent-server-rust
  • Manual localhost IPC smoke for capabilities, shutdown, and failed generateContext job persistence

Summary by CodeRabbit

  • New Features

    • Source context generation now runs via a local agent server with improved job lifecycle handling and broader support for more source record types (calendar, GitHub, Jira, Confluence, agent sessions).
    • Automatic source-context scheduling after capture completes.
  • Tests

    • Added tests for persisted agent job status and failed-job handling.
  • Documentation

    • Updated docs to reflect the new agent-server helper and helper boundaries.
  • Chores

    • Build/release scripts and macOS packaging updated; added .gitignore entry for native agent build output.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 31ab59be-5d71-41ba-b4f8-94e7b5018aa1

📥 Commits

Reviewing files that changed from the base of the PR and between 3cc1bae and 2a0e663.

📒 Files selected for processing (3)
  • apps/desktop/main.cjs
  • package.json
  • scripts/build_native.sh
✅ Files skipped from review due to trivial changes (1)
  • apps/desktop/main.cjs

📝 Walkthrough

Walkthrough

Adds a new Rust daemon, MirrorNoteAgentServer, that accepts newline-delimited JSON over localhost TCP to run and persist asynchronous source-context generation jobs. Electron is updated to call the agent, derive job status from persisted files, auto-schedule generation after capture stops, and build/release scripts include the new binary.

Changes

Agent Server & Electron Integration

Layer / File(s) Summary
Request/Response Contracts
native/agent-server-rust/src/main.rs
Defines AgentRequest/AgentResponse JSON schemas, AgentCommand variants, and JobStatus/JobState model with camelCase serde config.
Agent Server Core
native/agent-server-rust/src/main.rs
TCP listener bound to 127.0.0.1:<port> (env MIRROR_NOTE_AGENT_SERVER_PORT, default 49731), per-connection thread handling, dispatches capabilities, generateContext, jobStatus, and shutdown.
Job Execution & Persistence
native/agent-server-rust/src/main.rs
generate_context_job() validates request, persists agent-jobs/generate-context.json, transitions states (QueuedRunningSucceeded/Failed), invokes generate_source_context, and writes final status; helpers read/write pretty JSON and create directories.
Electron TCP Bridge
apps/desktop/main.cjs
Adds AgentServerBridge that spawns/detaches the agent server, polls capabilities for readiness, and sends newline-delimited JSON requests with retry/restart on connection errors. Defines agentServerRequest.
Job Status Derivation & Scheduling
apps/desktop/main.cjs
Adds sourceContextStatusFromAgentJob() to map persisted job JSON to UI status; sourceContextStatusFromMetadata() falls back to agent job when metadata is insufficient; adds scheduleAutomaticSourceContextGeneration() to run generation after capture stops.
Runtime Resolution & Helpers
apps/desktop/main.cjs
Adds DEFAULT_AGENT_SERVER_PORT, rustAgentServerPath(), resolveAgentServerLaunch(), and agentServerPort() for executable/port resolution.
Test Hooks & Tests
apps/desktop/main.cjs, apps/desktop/main/native-launch.node-test.cjs, scripts/smoke_notes_store.cjs
Expose __testHooks.agentServerRequest for test injection; new test fixture for a failed agent job and updates to smoke tests to stub agentServerRequest.
Crate Definition & Tests
native/agent-server-rust/Cargo.toml, native/agent-server-rust/src/main.rs
Adds MirrorNoteAgentServer binary crate with deps (serde, serde_json, chrono, native-host-rust), release profile, and unit tests for job-status persistence.
Build & Release Integration
package.json, scripts/build_native.sh, scripts/build_and_run.sh, scripts/prepare_macos_release.sh
Adds scripts/build_native.sh to build three Rust helpers and stage binaries; package.json uses new script; build/verify/release scripts add MirrorNoteAgentServer to staging and verification.
Source Record Allowlist & Documentation
native/native-host-rust/src/context_packet.rs, docs/native-helper-boundaries.md, docs/distribution.md, .gitignore
Extends SOURCE_RECORD_TYPES to include agent_session and other types; documents new agent-server responsibilities and Electron env vars; .gitignore ignores native/agent-server-rust/target/.

Sequence Diagram

sequenceDiagram
    participant Electron as Electron (apps/desktop/main.cjs)
    participant Agent as AgentServer (Rust)
    participant Native as NativeHost (native-host-rust)
    participant FS as Filesystem (context/)
    participant Provider as External Provider (e.g., OpenAI)

    Electron->>Electron: capture stops → scheduleAutomaticSourceContextGeneration()
    Electron->>Agent: TCP connect & send generateContext (newline JSON)
    Agent->>FS: create/read agent-jobs/generate-context.json (Queued)
    Agent->>Agent: set JobState → Running, persist
    Agent->>Native: call generate_source_context()
    Native->>Provider: request embeddings/summaries
    Provider-->>Native: response
    Native->>FS: write packets/metrics
    Native-->>Agent: return result
    Agent->>FS: persist Succeeded/Failed job JSON
    Agent-->>Electron: send AgentResponse (ok/payload)
    Electron->>FS: read job status for UI derivation
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A tiny agent scurries on localhost threads,
Queues context work while the recorder tucks beds,
Rust writes the status, Electron asks and reads,
Jobs bloom and retry like springtime seeds,
Hops of JSON, packets, and softly persisted threads.


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.

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cc1baeb4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/main.cjs Outdated
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 a new Rust-based helper, MirrorNoteAgentServer, to handle local agent jobs such as source context generation. This offloads long-lived tasks from the native host and provides persistent job status tracking within meeting bundles. The Electron main process now includes an AgentServerBridge to manage communication with this daemon via a local TCP socket. Additionally, the context packet module was updated with new record types, and build scripts were adjusted to include the new binary. Feedback suggests simplifying numeric parsing in the job status logic and refactoring the increasingly complex build script in package.json into a separate file for better maintainability.

Comment thread apps/desktop/main.cjs Outdated
Comment thread package.json Outdated
@qyinm qyinm merged commit ad47803 into main May 5, 2026
2 checks passed
@qyinm qyinm deleted the codex-agent-server-context-jobs branch May 5, 2026 14:41
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