Skip to content

Feat/ai compose rewrite#55

Draft
dr-data wants to merge 7 commits into
cloudflare:mainfrom
dr-data:feat/ai-compose-rewrite
Draft

Feat/ai compose rewrite#55
dr-data wants to merge 7 commits into
cloudflare:mainfrom
dr-data:feat/ai-compose-rewrite

Conversation

@dr-data

@dr-data dr-data commented Jul 22, 2026

Copy link
Copy Markdown

No description provided.

dr-data and others added 6 commits July 8, 2026 01:30
Adds an AI compose bar to the email compose panel with preset rewrite
actions (polish, formalize, friendly, shorten) and custom instructions.
Supports per-mailbox AI model selection via Workers AI or OpenRouter,
configurable in mailbox settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Turn mailbox memory into a provenance-aware corpus with chunked retrieval, optional semantic search, Google Drive imports, suggested facts, and a shared draft context pack. Keep source evidence visible to the operator while preventing citations and internal metadata from entering email bodies.

Constraint: Memory must remain mailbox-scoped and usable when semantic search is unavailable

Rejected: Separate Google Drive retrieval path | would bypass source normalization, deletion, and draft eligibility controls

Confidence: high

Scope-risk: broad

Reversibility: clean

Directive: Confirm suggested facts before making them draft-eligible; do not expose context-pack metadata in outgoing email

Tested: npm run typecheck; npm run build; git diff --check

Not-tested: Live Google Drive OAuth/service-account import and browser end-to-end flows
Suggested facts are useful only when their evidence can be reviewed and corrected. Add a mailbox-scoped review surface and API for editing, confirming, or rejecting extracted facts before they enter draft context.

Constraint: Extracted facts remain excluded from drafting until confirmed

Rejected: Automatic fact promotion | would turn model inference into unreviewed email content

Confidence: high

Scope-risk: narrow

Reversibility: clean

Directive: Preserve source provenance when facts are edited

Tested: npm run typecheck; npm run build; git diff --check

Not-tested: Browser interaction and live AI fact extraction
Add a Microsoft Graph app-only connector for explicitly selected OneDrive files and route those files through the existing normalization, chunking, provenance, and fact-review pipeline.

Constraint: The deployment uses a configured OneDrive owner and app-only Graph credentials

Rejected: Personal OneDrive delegated OAuth in this change | requires a separate consent, callback, token storage, and refresh lifecycle

Confidence: high

Scope-risk: moderate

Reversibility: clean

Directive: Keep Graph credentials server-side and retain explicit file-ID selection

Tested: npm run typecheck; npm run build; git diff --check

Not-tested: Live Microsoft Graph credentials and OneDrive download
Ship the remaining mailbox management, templates, rosters, safety, and MCP improvements together so the branch contains the complete application feature set alongside evidence-backed memory imports.

Constraint: Preserve the existing Cloudflare Workers, Durable Objects, R2, and Access deployment model

Rejected: Commit runtime orchestration state | generated .omx state is local session data, not application source

Confidence: medium

Scope-risk: broad

Reversibility: clean

Directive: Keep mailbox authorization aligned with the existing shared Cloudflare Access boundary

Tested: git diff --cached --check; prior npm run typecheck and npm run build

Not-tested: Full production Cloudflare deployment until this commit is pushed
The mailbox now exposes briefing, productivity, sync, and Outlook add-in flows so users can triage and act on email from the web app and Microsoft 365 surface.

Constraint: Preserve the existing Cloudflare Workers and Durable Object architecture

Rejected: Commit local .omx runtime state | generated session artifacts are not source changes

Confidence: high

Scope-risk: moderate

Directive: Keep Microsoft Graph token handling behind the existing worker service boundary

Tested: npm run typecheck; npm run build; git diff --cached --check

Not-tested: Live Microsoft Graph and deployed Cloudflare integration
Copilot AI review requested due to automatic review settings July 22, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR expands Agentic Inbox from a mail-only drafting tool into a broader “AI compose + evidence-backed memory + productivity” workspace. It adds durable-object backed memory storage (with keyword + optional semantic retrieval), per-mailbox AI provider selection (Workers AI vs OpenRouter), safety classifiers, and initial Microsoft Graph/Outlook integration (including an Outlook add-in shell and queued sync).

Changes:

  • Add evidence-backed Memory: upload/import (Google Drive/OneDrive), chunking/indexing, search + drafting context packs, and fact extraction/review flow.
  • Add AI compose improvements: rewrite actions, template insertion, memory sources panel, and undo/redo for AI edits.
  • Add productivity + Outlook connector foundations: Graph client, token crypto, DO tables/methods, briefing/productivity UI, add-in assets, and a sync queue consumer.

Reviewed changes

Copilot reviewed 80 out of 81 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
wrangler.jsonc Updates Worker vars and adds Queues configuration.
workers/types.ts Expands/changes runtime binding typing for Worker env.
workers/routes/reply-forward.ts Adds send-time sensitive-info warning response field.
workers/mcp/index.ts Exposes search_memory MCP tool.
workers/mcp/CLAUDE.md Adds claude-mem context file.
workers/lib/topic.ts Adds external-runner topic dispatch with HMAC signing.
workers/lib/tools.ts Adds memory tools and sensitive-info warning on send tools.
workers/lib/token-crypto.ts Adds AES-GCM token encryption/decryption helper.
workers/lib/text-metrics.ts Adds word/token estimation helpers.
workers/lib/productivity.ts Adds heuristic extraction + briefing ranking helpers.
workers/lib/onedrive.ts Adds OneDrive file import helper via Microsoft Graph.
workers/lib/microsoft-sync.ts Adds Microsoft inbox sync into DO email store.
workers/lib/microsoft-graph.ts Adds Microsoft Graph client + OAuth/token helpers.
workers/lib/memory-upload.ts Adds background memory file processing + chunking.
workers/lib/memory-summarize.ts Adds AI summary generation for memory files.
workers/lib/memory-search.ts Adds keyword + optional AI Search semantic retrieval.
workers/lib/memory-facts.ts Adds suggested fact extraction from memory content.
workers/lib/memory-context.ts Adds bounded drafting-context pack builder.
workers/lib/memory-chunks.ts Adds markdown chunking with offsets/tokens.
workers/lib/mailbox-settings.ts Adds per-mailbox safety settings loader from R2.
workers/lib/google-drive.ts Adds Google Drive service-account import helper.
workers/lib/CLAUDE.md Adds claude-mem context file.
workers/lib/ai-safety.ts Adds urgent/phishing/sensitive-info classifiers.
workers/lib/ai-rewrite.ts Adds mailbox-model-based rewrite endpoint helper.
workers/lib/ai-provider.ts Adds mailbox-scoped model/provider resolution.
workers/durableObject/migrations.ts Adds schema migrations for memory/templates/rosters/productivity/topics.
workers/durableObject/index.ts Implements memory/templates/rosters/productivity storage + Graph renewal alarm.
workers/durableObject/CLAUDE.md Adds claude-mem context file.
workers/db/schema.ts Adds Drizzle schema for memory/templates/rosters entities.
workers/db/CLAUDE.md Adds claude-mem context file.
workers/CLAUDE.md Adds claude-mem context file.
workers/app.ts Adds queue consumer and Access bypass for OAuth/webhooks/add-in.
workers/agent/index.ts Switches to mailbox model provider, adds memory tool/context, adds safety gating.
workers/agent/CLAUDE.md Adds claude-mem context file.
README.md Documents evidence-backed memory and drive imports.
public/add-in/taskpane.js Adds simple hosted Outlook taskpane JS (public assets).
public/add-in/taskpane.html Adds simple hosted Outlook taskpane HTML (public assets).
public/add-in/taskpane.css Adds simple hosted Outlook taskpane CSS (public assets).
package.json Adds OpenRouter provider dependency and metadata formatting.
package-lock.json Locks OpenRouter provider dependency.
docs/outlook-add-in.md Adds Outlook add-in + Graph connector deployment guide.
docs/memory-plan.md Adds memory design/plan documentation.
app/types/index.ts Adds client types for memory/templates/rosters/productivity/topics/settings.
app/types/CLAUDE.md Adds claude-mem context file.
app/services/CLAUDE.md Adds claude-mem context file.
app/services/api.ts Adds API methods for new features + FormData handling.
app/routes/templates.tsx Adds Templates CRUD UI route.
app/routes/settings.tsx Adds provider connections, AI provider, memory, and safety settings UI.
app/routes/roster.tsx Adds Roster upload/import UI route.
app/routes/productivity.tsx Adds Productivity snapshot UI route.
app/routes/memory.tsx Adds Memory UI route: upload/import/search/preview/facts.
app/routes/mailbox-index.tsx Changes default mailbox landing route to Briefing.
app/routes/home.tsx Adds Email Routing banner guidance during mailbox creation.
app/routes/email-list.tsx Adds bulk-select + bulk mark read/move actions.
app/routes/CLAUDE.md Adds claude-mem context file.
app/routes/briefing.tsx Adds Briefing UI route + queue sync trigger.
app/routes.ts Registers new app routes (briefing/productivity/memory/templates/roster).
app/queries/templates.ts Adds react-query hooks for templates CRUD.
app/queries/rosters.ts Adds react-query hooks for rosters/students CRUD.
app/queries/memory.ts Adds react-query hooks for memory CRUD/search/context/facts.
app/queries/keys.ts Adds query keys for new domains (memory/templates/rosters/productivity).
app/queries/emails.ts Adds mutations for bulk mark read and bulk move.
app/queries/CLAUDE.md Adds claude-mem context file.
app/lib/utils.ts Adds frontend textToHtml helper for consistent formatting.
app/lib/text-metrics.ts Adds compact count formatting helper.
app/lib/csv.ts Adds minimal CSV parser for roster uploads.
app/hooks/useComposeForm.ts Adds AI-edit history (undo/redo) and rewrite application plumbing.
app/hooks/CLAUDE.md Adds claude-mem context file.
app/components/Sidebar.tsx Adds navigation links for briefing/productivity/memory/templates/rosters.
app/components/MCPPanel.tsx Adds search_memory to tool list.
app/components/email-panel/CLAUDE.md Adds claude-mem context file.
app/components/ComposePanel.tsx Adds Compose AI bar and AI undo/redo controls.
app/components/ComposeAIBar.tsx Adds rewrite actions, template insertion, and memory sources popover.
app/components/CLAUDE.md Adds claude-mem context file.
app/CLAUDE.md Adds claude-mem context file.
add-in/taskpane.js Adds richer Outlook add-in taskpane JS (non-public path).
add-in/taskpane.html Adds richer Outlook add-in taskpane HTML.
add-in/taskpane.css Adds richer Outlook add-in taskpane CSS.
add-in/manifest.xml Adds Outlook add-in manifest for sideloading/distribution.
.dev.vars.example Expands example env vars for new integrations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread workers/types.ts
Comment on lines 5 to +9
export interface Env extends Cloudflare.Env {
POLICY_AUD: string;
TEAM_DOMAIN: string;
OPENROUTER_API_KEY?: string;
GOOGLE_SERVICE_ACCOUNT_EMAIL?: string;
GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY?: string;
MICROSOFT_TENANT_ID?: string;
Comment thread .dev.vars.example
Comment on lines +7 to +17
# Optional Microsoft Graph app-only OneDrive import.
MICROSOFT_TENANT_ID=your-tenant-id
MICROSOFT_CLIENT_ID=your-app-client-id
MICROSOFT_CLIENT_SECRET=your-app-client-secret
ONEDRIVE_USER_ID=person@example.com
# Microsoft OAuth (required for the Outlook connector)
MICROSOFT_TENANT_ID=common
MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
MICROSOFT_REDIRECT_URI=http://localhost:5173/auth/microsoft/callback
APP_ORIGIN=http://localhost:5173
Comment thread wrangler.jsonc
Comment on lines +14 to +19
"DOMAINS": "shor.lol",
"EMAIL_ADDRESSES": [],
"POLICY_AUD": "3b60a59232bccf2b6feb66e37b4c4363493fc4b5c6dd66fd7b3e86fac33c1ec4",
"TEAM_DOMAIN": "https://printact.cloudflareaccess.com",
// Empty string disables semantic search; memory search falls back to keyword-only.
"AI_SEARCH_INSTANCE_ID": ""
Comment on lines +114 to +118
const safetySettings = await getSafetySettings(c.env, mailboxId);
const sensitiveInfoWarning = safetySettings.sensitiveInfoWarning
? await containsSensitiveInfo(c.env.AI, html || text || "")
: false;

Comment on lines +207 to +211
const safetySettings = await getSafetySettings(c.env, mailboxId);
const sensitiveInfoWarning = safetySettings.sensitiveInfoWarning
? await containsSensitiveInfo(c.env.AI, html || text || "")
: false;

@dr-data
dr-data marked this pull request as draft July 22, 2026 12:12
The Premium HTTP bridge remains available, but the supported no-Premium workflow uses standard Outlook forwarding into Agentic Inbox. The README now distinguishes the deployed bridge from the pending email-relay work needed to recreate drafts in Outlook without Premium HTTP.

Constraint: Power Automate standard Outlook actions cannot call arbitrary external HTTP endpoints

Rejected: Treat Office 365 Users or Outlook Send an HTTP request as a generic bridge | those actions are Microsoft Graph-specific

Confidence: high

Scope-risk: moderate

Reversibility: clean

Directive: Keep the no-Premium workflow email-based unless the Outlook Draft result-email relay is implemented

Tested: npm run typecheck; npm run build; git diff --cached --check; deployed bridge smoke checks

Not-tested: End-to-end Power Automate run and Workers AI response with a live Outlook mailbox
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.

2 participants