You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Goal: evolve MPP's AI capability from a reviewable local rewrite assistant into two clear product lines.
Black-box growth optimization mode: for creators and operators. One click optimizes an article against platform audiences, brand voice, and publishing goals, improving fit for recommendation, clicks, views, watch/read completion, and interaction signals.
Vibe Drafting mode: for professional content teams. A context-aware drafting workspace similar in spirit to Claude Code, Gemini CLI, and Codex, where users drive drafts, platform variants, comments, versions, and pre-publish checks through natural language.
Boundaries:
Do not promise guaranteed increases in platform push rate or views. Product language should say "improve platform fit" and "improve potential growth performance".
Do not let AI bypass user confirmation and directly mutate official content. Keep the default safety model: generate a proposal, review the diff, then persist only after confirmation.
Do not move publishing execution, account authorization, or database transactions into the AI service. The Go backend remains the boundary for permissions, context, tool execution, and persistence.
Do not rewrite the existing source editor, platform draft compiler, publish queue, or collaboration system. New AI capabilities should reuse those foundations.
Do not build fully automated campaign learning in the first phase. Real performance data should start with manual import or incremental platform API integration when available.
2. Current Business Foundation
2.1 Implemented Capabilities
The AI editing foundation is already in place:
ai-service is an independent FastAPI service that owns prompt construction, OpenAI-compatible LLM calls, streaming responses, internal Bearer Token authentication, and usage/cost metrics.
Existing endpoints include /content/edit, /content/edit/stream, /prepublish/edit, /prepublish/edit/stream, and /calibrate.
backend/internal/services/ai/client.go provides the backend AI service client. Dashboard routes already proxy normal and streaming AI edit requests.
Backend AI requests already use stream leases across user, tenant, IP, and global dimensions.
The frontend AIEditAssistant supports instruction input, streaming generation, preview, diff, stop, accept, and reject.
Both the source editor and platform draft panel already use the AI proposal workflow.
The content and publishing foundation is also fairly complete:
Project is the main content object. It stores title, source content, workspace, collaborative document, template reference, and brand profile reference.
content-pipeline-service already compiles WeChat HTML, Zhihu Markdown, X short text, and Douyin text drafts in Rust, with versioned draft/media profiles.
BrandProfile stores brand voice, target audience, banned words, CTA, link strategy, and default tags.
ContentTemplate stores title templates, source templates, default platforms, platform config, and tags.
MediaAsset and MediaAssetUsage support project/workspace media ownership, object storage references, and asset usage tracking.
ProjectVersion, ProjectComment, ProjectActivity, share links, and collaborators already support review, version recovery, and team collaboration.
Current AI requests only include title, current content, user instruction, platform draft, and temporary conversation. They do not include project_id, workspace_id, brand profile, template, platform audience, publishing goal, or historical performance context.
There is no platform audience profile or growth optimization profile, such as Xiaohongshu-style title hooks, Zhihu long-form credibility, WeChat opening retention, Douyin image-text pacing, or X length and interaction CTA guidance.
There is no optimization task/result model, so the system cannot record what context was used, which candidates were generated, which checks passed, or which version the user adopted.
Dashboard stats still focus on project count, successful publications, failed publications, and member count. They do not capture content performance metrics such as impressions, recommendations, plays/views, clicks, completion, interactions, favorites, or conversions.
There is no product loop for "optimize, then automatically sync platform drafts".
There is no AI result quality score, brand consistency check, platform compliance check, or A/B version comparison.
Vibe Drafting gaps:
Current AI is a single-shot text rewrite control, not a persistent session. The conversation field exists in the contract, but the UI does not productize it as a long-lived drafting session.
There is no context assembly module. The AI service cannot proactively read projects, drafts, comments, versions, templates, brand profiles, media, publish status, or account constraints.
There is no tool-call boundary. AI cannot propose structured operations such as changing a title, replacing a body block, updating a platform draft, creating a comment, creating a version, syncing prepublish, or generating a pre-publish checklist.
There is no patch/operation-level proposal model. Current proposals are mostly full text replacements.
There is no workspace memory, project summary, long-context compaction, retrieval, or context snapshot.
There is no professional drafting panel, command history, checkpoint, tool event stream, or multi-artifact preview.
3. Product Mode Design
3.1 Mode One: Black-box Growth Optimization
Positioning: users should not need to understand prompts, platform rules, context selection, or multi-step reasoning. They choose platforms and goals, then click once to optimize.
Entry points:
Primary "AI Optimize" button at the top of the project editor.
"Optimize current platform draft" button inside the platform draft panel.
Batch entry from the project list can come later and should not be part of the MVP.
User-visible inputs:
Target platforms: default to the platforms already selected for the project.
Short result summary, such as "strengthened opening hook, added platform tags, compressed X copy, enhanced WeChat CTA".
Risk warnings, such as banned words, exaggerated claims, platform format risk, or brand drift.
Apply to source content and platform drafts in one step, or apply only to selected platforms.
Internal black-box pipeline:
flowchart LR
User["One-click Optimize"] --> BE["Backend AI Context Assembler"]
BE --> Snapshot["Context Snapshot"]
Snapshot --> AI["AI Growth Optimizer"]
AI --> Checks["Brand / Platform / Safety Checks"]
Checks --> Compiler["content-pipeline-service"]
Compiler --> Proposal["Optimization Proposal"]
Proposal --> Review["Frontend Review + Diff"]
Review --> Apply["Backend Apply + Version + Prepublish Sync"]
Loading
Internal steps:
The backend reads project, brand, template, platform drafts, comment summaries, version summaries, media, publish status, and workspace information under the user's permissions.
The backend creates an immutable AIContextSnapshot and sends it to the AI service.
The AI service generates an optimization strategy first, then generates source content and platform candidates.
The backend or AI service runs quality checks: brand consistency, platform format, banned words, length, CTA, and risk statements.
Platform candidates are passed through content-pipeline-service or reused prepublish compilation so the output still conforms to platform draft contracts.
The frontend displays proposals, diffs, and risks.
After the user accepts, the backend creates a project version, updates source content or platform drafts, and records the optimization run.
3.2 Mode Two: Vibe Drafting
Positioning: professional users complete content production through a context-aware AI drafting panel instead of asking AI to rewrite a single text block.
The design should reference agentic runtimes in Claude Code / Codex-style products, but adapt the idea to content operations. The model does not directly "write to the database". Instead, it reads context, proposes a plan, calls controlled tools, streams progress, generates proposals, and lets the user confirm writes.
Core experience:
The user opens a drafting panel on a project page.
The panel automatically brings in the current project, selected body block, platform drafts, brand profile, template, comments, versions, and publishing goals.
The user can issue natural-language tasks, for example:
"Turn this into a professional Zhihu long-form article, but keep the current argument."
"Add a stronger opening for WeChat, but do not touch the second half."
"Add an FAQ section based on the questions in the comments."
"Generate a shorter caption and 5 tags for Douyin image-text publishing."
"Check what risks remain before publishing."
AI returns structured proposals: source patches, platform draft patches, comment replies, checklists, title candidates, tag candidates, and similar artifacts.
The user accepts, rejects, or continues discussing each item.
Key interaction patterns:
Plan mode: for broad rewrite goals, AI first produces a plan and affected-object list instead of immediately generating large text or applying changes.
Tool timeline: the frontend shows which context the AI is reading, which artifacts it is generating, which checks are running, and which confirmations are pending.
Permission prompt: any tool that changes a project, platform draft, comment, version, schedule, or workspace memory must enter a confirmation flow.
Interrupt: when the user sends a new message or clicks stop, interruptible tools can be cancelled. Non-interruptible write tools must complete or roll back to a clear state.
Checkpoint: long tasks automatically create recoverable checkpoints before and after execution. Accepting a proposal creates a project version.
Compact boundary: when context compaction happens, the session receives a boundary message so the user knows earlier context has been summarized and retained.
Backend AI Gateway: owns user authentication, workspace admission, route-level rate limiting, stream leasing, and public API boundaries.
AI Harness Runtime: owns the multi-turn model/tool loop, event sequencing, permission requests, interruption, durable tool-call state, compaction coordination, and recovery.
AI Context Assembler: turns project-related objects into a stable, trimmable, auditable context package.
AI Tool Executor: executes only allowlisted tools and prevents AI from writing directly to the database.
AI Event Log: stores durable session events, model deltas, tool calls, tool results, permission decisions, compact boundaries, and proposal lifecycle events in replay order.
Tool Result Store: stores large raw tool results and exposes stable summaries or references to the model and frontend.
ai-service: owns model calls, prompt rendering, structured-output parsing, and quality-check prompts. It does not execute business tools.
content-pipeline-service: continues to own deterministic platform draft compilation and media adaptation.
PostgreSQL: stores AI sessions, context snapshots, optimization runs, proposals, tool calls, adopted results, and later performance metrics.
Key design principles:
The backend harness is the product runtime. The AI service should be treated as a model adapter unless a later phase introduces a strictly controlled tool bridge.
Context reading and turn orchestration happen in the backend harness; prompt rendering and model calls happen in the AI service.
AI output becomes a proposal first, not a database write.
Tool interfaces should be named after business actions rather than exposing table shapes.
Every applied AI proposal creates a ProjectVersion or another recoverable change record.
Black-box mode may hide process details from the user, but the system must still store context version, prompt version, model, and check results for audit and evaluation.
Model-visible messages, frontend timeline events, and audit records must be related but separate artifacts. A UI event is not automatically model context.
5. Core Models
New model direction:
5.1 PlatformAudienceProfile
Platform audience and content preference profile.
Field direction:
platform
profile_version
audience_summary
content_preferences
title_rules
opening_rules
structure_rules
tag_rules
cta_rules
risk_rules
metrics_focus
created_at
updated_at
Rules:
Start with static built-in profiles, then support workspace overrides later.
Profiles must be versioned so historical optimization results remain explainable.
This is separate from content-pipeline-service draft profiles: draft profiles guarantee deterministic format, while audience profiles provide growth strategy and expression guidance.
The snapshot stores only business context needed by AI. It must not store platform account secrets, cookies, raw credentials, or internal tokens.
Generation tasks and proposal application both reference the same snapshot.
Large fields should prefer references and summaries, such as body versions, platform drafts, comment threads, and media lists. Only the current working set should enter full context.
Long context should first use layered summaries and partial compaction. Vector retrieval can come later.
All stream events should share a durable envelope:
event_id
sequence
workspace_id
project_id
session_id or run_id
turn_id
parent_event_id
tool_use_id, when the event belongs to a tool call
context_snapshot_id
artifact_id or proposal_id, when the event creates or updates an artifact
created_at
model_visible: whether the event is included in later model context
6.3 Vibe Drafting Tool Runtime
The Vibe Drafting tool layer should follow the key design ideas of Claude Code-style products: tools are not a simple exposure of backend endpoints, but an auditable, cancellable, permissioned, streaming execution runtime.
The runtime should be implemented as a backend AIHarnessRuntime module, with the following internal modules:
AIDraftingRunner: owns the turn loop: assemble context, call the model, receive tool requests, execute tools, append tool results, and continue until the turn is complete or blocked.
permission_policy: allow, ask, deny, with overrides by workspace role, project role, platform account grants, and proposal type.
is_read_only: whether the tool can modify project state.
is_destructive: whether the tool can delete, overwrite, publish, schedule, or otherwise create hard-to-reverse changes.
requires_user_interaction: whether the tool must stop and ask the user for missing information.
concurrency: parallel_safe or exclusive. Reading context and generating candidates can run in parallel; writing a project, updating drafts, and creating versions must be exclusive.
interrupt_behavior: cancel or block. Generation tools can be cancelled; write tools cannot be interrupted freely after entering commit.
idempotency: whether the tool supports safe retries and which fields form the idempotency key.
base_version_policy: whether the tool requires a source version, publication version, proposal version, or checklist version before it can apply changes.
progress_events: tools can stream queued, running, waiting_permission, completed, failed.
max_result_size: maximum model-visible result size before the raw result is persisted and replaced with a preview.
result_mapper: converts implementation output into model-visible result, frontend artifact, and audit record.
compact_summary: when the tool result is large, it must provide a short summary and raw-result reference to avoid polluting later context.
turn_id, tool_use_id, request_id, and monotonically increasing event sequence.
Current user, workspace role, project role, and visible platform account scope.
Current selection, active platform, active proposal, and latest user intent.
Current source version, publication versions, proposal versions, and draft status locks.
Context budget, output budget, cost budget, and available model.
Permission mode: default, plan, accept_edits, dont_ask, bypass. MPP should initially expose only default and plan; the rest should remain internal or future advanced settings.
Abort signal, tool event writer, and audit logger.
Control multi-step work, clarification, permission blocking, and context compaction
Execution rules:
The model can request tools, but only the backend AIToolExecutor can execute them.
Read tools and proposal tools can run in parallel; write tools, version tools, and draft update tools must execute exclusively.
Tool results are written back to the session in model request order to avoid context-order confusion from parallel tools.
Tool progress may stream immediately, but final model-visible tool_result messages must preserve request order.
If an exclusive write tool fails, later write tools in the same turn stop. The frontend shows the failure reason and retry entry point.
On user interruption, cancellable tools are cancelled. Non-interruptible tools must return a clear completed, failed, or needs-manual-action state.
Write tools must bind user approval to the exact tool name, exact normalized input, target object version, and idempotency key.
Write tools must record AIToolCall and ProjectActivity, and create ProjectVersion when needed inside the same database transaction.
Applying a proposal must fail with a recoverable conflict if source content, platform draft, or proposal version changed after the proposal was generated.
Permission denial, schema validation failure, missing tool, timeout, and interruption must all be converted into structured tool results that the model and frontend can understand.
Permission rules come from workspace role, project role, platform account grants, current permission mode, and the tool's own risk level.
Hooks or future policy adapters may allow, deny, ask, rewrite input, or add context, but an allow decision must not bypass explicit deny/ask rules.
The harness must use a circuit breaker for repeated compaction or tool failures so one broken session does not loop indefinitely.
6.4 Long Context And Compaction Strategy
Vibe Drafting needs to keep "the draft currently being worked on" faithful while compacting "older chat and supporting material". It should not simply push all project history, comments, versions, and tool results into the model.
Context layers:
Layer
Content
Handling
Pinned context
System constraints, product rules, workspace permissions, brand profile, current project ID, active platform
Kept every turn, summarized only when needed
Working set
Current title, current source body or selection, active platform draft, active proposal under review
Preserve full text where possible
Recent turns
Latest user messages, assistant replies, tool calls, and tool results
Keep the latest N turns; partial compact when over budget
Session summary
Older conversation, completed decisions, user preferences, accepted/rejected proposals
Compact into AIDraftingSessionSummary
Cold refs
Original versions, long comment threads, media lists, large platform drafts, detailed performance history
Do not place directly in prompt; keep references and retrieval entry points
Compaction triggers:
When token estimation crosses the warning threshold of the model's effective context window, the frontend shows a "context is near the limit" warning.
When token estimation crosses the auto-compact threshold, the backend automatically creates a compact task.
When the API returns prompt-too-long or insufficient model context, reactive compact runs and retries once.
The user can also manually trigger "compact session context".
Compaction types:
Conversation compact: summarize older messages while preserving user goals, key decisions, adopted content, rejected directions, and unfinished tasks.
Tool result compact: persist raw tool results and only return a short summary, key fields, artifact ID, and next-step suggestion to the context.
Artifact compact: do not copy large source bodies, large drafts, or long comment threads into the summary; record references such as project_version_id, publication_id, and proposal_id.
Partial compact: keep the latest several turns as raw text and compact only the earlier prefix.
Memory compact: persist stable preferences into workspace or project memory, such as "this brand avoids clickbait" or "this account prefers a professional tone".
Emergency compact: when the compaction request itself is too long, drop the oldest, recoverable, low-value context by priority and preserve a truncation note.
Tool result storage rules:
Every tool has a per-result model-visible size limit.
Oversized text results are stored as raw records and replaced with a stable preview plus raw_result_ref.
Empty tool results are replaced with an explicit success marker so the next model turn does not receive an ambiguous blank result.
Large media, full drafts, and long comment threads should be referenced by artifact IDs instead of copied into later prompts.
Result replacement decisions must be stable for a session so retries and resumes do not create different model context.
Compaction output structure:
summary: summary that lets the session continue.
user_intent: latest user goal and constraints.
accepted_changes: accepted proposals and corresponding versions.
rejected_directions: writing styles, strategies, or platform directions the user explicitly rejected.
open_tasks: unfinished drafting subtasks.
active_artifacts: proposals, title candidates, and draft candidates still under review.
source_refs: references to original context.
next_step_hint: what the next turn should continue first.
Post-compaction recovery:
After compaction completes, write a CompactBoundary message so the frontend can show "earlier context has been compacted".
The backend reassembles pinned context, working set, latest turns, and session summary.
Restore the active proposal, unfinished tool call, latest user intent, and current selection.
If compaction fails repeatedly past a threshold, the session enters a blocking state and asks the user to narrow context or start a new session.
Implementation touchpoints:
Add AIContextBudgeter in the backend to estimate tokens, layer context, and decide whether to compact.
Add AIContextCompactor in the backend to generate and persist AIDraftingSessionSummary.
Add an internal /drafting/compact endpoint in the AI service. During compaction, business tools are disabled and only structured summary is returned.
Every tool implementation must provide compact_summary; otherwise large results keep only a reference and a short prefix by default.
The frontend drafting panel should show remaining context, compact progress, compact boundaries, and an entry point for the restored summary.
7. Phase Plan
Phase 0A: Product Boundary And Harness Ownership
Goal: make the backend harness the clear runtime owner before adding new product behavior.
Document that the Go backend owns model/tool loop execution, permissions, durable events, proposal application, and recovery.
Keep ai-service as model adapter, prompt renderer, structured-output parser, and quality-check caller.
Define the first AIHarnessRuntime package boundary in backend/internal/services/ai.
Define the event envelope shared by frontend stream events, audit events, and model-visible messages.
Define turn_id, tool_use_id, event_id, sequence, and model_visible semantics.
Acceptance:
A design review can identify a single module responsible for every session state transition.
A sample stream can be replayed in event order without relying on frontend state.
Phase 0B: Contracts And Data Model Skeleton
Goal: add durable contracts without yet building the full drafting experience.
Define AIContextSnapshot, AIProposal, AIGrowthOptimizationRun, AIDraftingSession, and AIDraftingSessionSummary.
Define AIToolDefinition, AIToolCall, AIToolEvent, AIPermissionRequest, AIPermissionDecision, and AIToolResultRef.
Add growth, drafting, proposal, tool-call, permission, event, compact-summary, and quality-check schemas to contracts/components/ai.yaml.
Add database models and migrations for sessions, messages, events, proposals, context snapshots, tool calls, permission decisions, and tool result refs.
Store audit fields for prompt version, model, usage, model provider, context snapshot version, and quality checks.
Acceptance:
Contract generation succeeds for backend and frontend clients.
New tables can store a session with one user message, one assistant event, one tool call, one permission decision, and one proposal.
Phase 0C: Context Snapshot And Budgeting
Goal: make project context stable, permission-scoped, and trimmable.
Build AIContextAssembler, initially aggregating Project, Publication, BrandProfile, ContentTemplate, Comments, Versions, and Media summary.
Build AIContextBudgeter, defining trimming order for pinned context, working set, recent turns, session summary, and cold refs.
Explicitly exclude sensitive fields from AI context: cookies, credentials, secrets, OAuth tokens, internal tokens, and raw account auth material.
Add context token estimation and context warning metadata.
Add snapshot tests for permissions and sensitive-field exclusion.
Acceptance:
The backend can generate a stable context summary for one project.
Tests assert that context snapshots do not include sensitive account material.
A large project produces references and summaries instead of unbounded raw context.
Phase 0D: Harness Skeleton And Event Replay
Goal: prove the harness loop before adding real write tools.
Implement AIDraftingRunner with a fake model adapter and no-op tool registry.
Implement AIEventLog append and replay.
Implement stream delivery from the event log to the frontend.
Add structured failure events for missing tool, schema error, denied permission, timeout, and user interruption.
Add a minimal read_project_context tool.
Acceptance:
A test can run one drafting turn that reads context and ends with a replayable event log.
Event replay reconstructs the same frontend timeline and model-visible message sequence.
Phase 1A: Black-box Growth Optimization Contracts
Goal: users can create a growth optimization run that produces reviewable proposals.
Tool result replay produces the same model-visible context after resume.
Phase 2C: Drafting Proposal Tools
Goal: support the first useful professional drafting workflows.
Support basic instructions: rewrite selected content, generate title candidates, generate platform variants, add content from comments, and create pre-publish checks.
Support patch-level proposals and per-item acceptance.
Black-box optimization can read workspace historical performance summaries.
The dashboard can show a basic relationship between optimization adoption and publish performance.
Phase 4A: Governance And Audit
Goal: make AI behavior explainable to workspace admins.
Add admin-visible AI audit logs.
Add prompt/eval regression sets covering four platforms and typical content types.
Add workspace settings for whether to allow automatic draft application, whether to use historical performance data, and whether to share AI sessions across the team.
Acceptance:
Workspace admins can see which content AI changed and who accepted each change.
Key prompt changes have regression evaluation instead of relying only on manual trial.
Phase 4B: Quotas And Commercialization
Goal: make AI capabilities measurable, governable, and billable SaaS product features.
Meter workspace-level AI usage, tokens, cost, optimization run count, drafting session count, tool-call count, and stored tool-result volume.
Limit black-box optimization, drafting sessions, context length, historical performance lookback, and tool-result retention by plan.
Add quota warnings and upgrade states to the frontend.
Add retention policy for context snapshots, event logs, and raw tool results.
Acceptance:
AI features have clear quota and usage reports.
Plan limits are enforced by the backend harness before model calls or expensive tools run.
8. Current Code Touchpoints
Priority change areas:
contracts/components/ai.yaml: add growth, drafting, proposal, and quality check schemas.
1. Goals And Boundaries
Goal: evolve MPP's AI capability from a reviewable local rewrite assistant into two clear product lines.
Boundaries:
2. Current Business Foundation
2.1 Implemented Capabilities
The AI editing foundation is already in place:
ai-serviceis an independent FastAPI service that owns prompt construction, OpenAI-compatible LLM calls, streaming responses, internal Bearer Token authentication, and usage/cost metrics./content/edit,/content/edit/stream,/prepublish/edit,/prepublish/edit/stream, and/calibrate.backend/internal/services/ai/client.goprovides the backend AI service client. Dashboard routes already proxy normal and streaming AI edit requests.AIEditAssistantsupports instruction input, streaming generation, preview, diff, stop, accept, and reject.The content and publishing foundation is also fairly complete:
Projectis the main content object. It stores title, source content, workspace, collaborative document, template reference, and brand profile reference.ProjectPlatformPublicationstores platform drafts, platform account, config, publish status, draft status, review status, and remote publish result.content-pipeline-servicealready compiles WeChat HTML, Zhihu Markdown, X short text, and Douyin text drafts in Rust, with versioned draft/media profiles.BrandProfilestores brand voice, target audience, banned words, CTA, link strategy, and default tags.ContentTemplatestores title templates, source templates, default platforms, platform config, and tags.MediaAssetandMediaAssetUsagesupport project/workspace media ownership, object storage references, and asset usage tracking.ProjectVersion,ProjectComment,ProjectActivity, share links, and collaborators already support review, version recovery, and team collaboration.Workspace, members, invites, activity, shared platform account grants, scheduled publication, publish attempts, and notifications already exist.2.2 Main Gaps
Black-box growth optimization gaps:
title, current content, user instruction, platform draft, and temporary conversation. They do not includeproject_id,workspace_id, brand profile, template, platform audience, publishing goal, or historical performance context.Vibe Drafting gaps:
conversationfield exists in the contract, but the UI does not productize it as a long-lived drafting session.3. Product Mode Design
3.1 Mode One: Black-box Growth Optimization
Positioning: users should not need to understand prompts, platform rules, context selection, or multi-step reasoning. They choose platforms and goals, then click once to optimize.
Entry points:
User-visible inputs:
User-visible outputs:
Internal black-box pipeline:
Internal steps:
AIContextSnapshotand sends it to the AI service.content-pipeline-serviceor reused prepublish compilation so the output still conforms to platform draft contracts.3.2 Mode Two: Vibe Drafting
Positioning: professional users complete content production through a context-aware AI drafting panel instead of asking AI to rewrite a single text block.
The design should reference agentic runtimes in Claude Code / Codex-style products, but adapt the idea to content operations. The model does not directly "write to the database". Instead, it reads context, proposes a plan, calls controlled tools, streams progress, generates proposals, and lets the user confirm writes.
Core experience:
Key interaction patterns:
Vibe Drafting vs black-box optimization:
4. Target Architecture
flowchart TB FE["Frontend AI Surfaces"] --> BE["Go Backend AI Gateway"] BE --> Harness["AI Harness Runtime"] Harness --> Context["AI Context Assembler"] Harness --> Tools["AI Tool Executor"] Harness --> Events["AI Event Log"] Harness --> Results["Tool Result Store"] BE --> DB[("PostgreSQL")] BE --> Redis[("Redis / Stream Gate")] BE --> Pipeline["content-pipeline-service"] Harness --> AI["ai-service"] AI --> Provider["LLM Provider"] Context --> Snapshot["AIContextSnapshot"] Snapshot --> AI AI --> ModelEvents["Model Streaming Events"] ModelEvents --> Harness Events --> FE FE --> Apply["Accept Proposal"] Apply --> Tools Tools --> DB Tools --> Pipeline Results --> DBModule responsibilities:
Key design principles:
ProjectVersionor another recoverable change record.5. Core Models
New model direction:
5.1 PlatformAudienceProfile
Platform audience and content preference profile.
Field direction:
platformprofile_versionaudience_summarycontent_preferencestitle_rulesopening_rulesstructure_rulestag_rulescta_rulesrisk_rulesmetrics_focuscreated_atupdated_atRules:
content-pipeline-servicedraft profiles: draft profiles guarantee deterministic format, while audience profiles provide growth strategy and expression guidance.5.2 AIContextSnapshot
An immutable context package used by one AI task.
Field direction:
workspace_idproject_idcreated_bycontext_kind:growth_optimization,draftingsource_version_idproject_summarysource_contentselected_rangeplatformspublicationsbrand_profilecontent_templatecomments_summaryversions_summarymedia_summaryperformance_summarytoken_estimatecontext_budgetcompaction_level:none,partial,session_summary,memory_summaryraw_context_refscreated_atRules:
5.3 AIGrowthOptimizationRun
Main record for a black-box optimization task.
Field direction:
workspace_idproject_idcontext_snapshot_idgoal:recommendation,views,ctr,completion,engagement,conversionintensity:conservative,balanced,aggressivetarget_platformsstatus:running,ready,applied,failed,cancelledmodelprompt_versionusagequality_summarycreated_bycreated_atupdated_at5.4 AIProposal
Unified model for reviewable changes generated by black-box optimization and Vibe Drafting.
Field direction:
workspace_idproject_idsession_idrun_idcontext_snapshot_idproposal_type:source_rewrite,title_candidates,prepublish_patch,comment_reply,checklist,tag_candidatestarget_platformstatus:proposed,accepted,rejected,supersededsummarypatchfull_contentquality_checkscreated_atdecided_atdecided_byRules:
full_contentonly for full rewrites.5.5 AIDraftingSession
Persistent Vibe Drafting session.
Field direction:
workspace_idproject_idcreated_bytitlestatus:active,archivedactive_context_snapshot_idlast_message_atcreated_atupdated_atSupporting models:
AIDraftingMessage: user messages, assistant messages, tool events, system summaries.AIToolCall: tool name, arguments, result, error, duration.AIArtifact: title candidates, body fragments, platform drafts, checklists, strategy notes, and other non-direct-write outputs.5.6 ContentPerformanceSnapshot
Performance data needed for the later growth learning loop.
Field direction:
workspace_idproject_idpublication_idplatformplatform_account_idcaptured_atimpressionsrecommendationsviewsreadswatch_secondscompletion_rateclickslikescommentssharesfavoritesconversionssource:platform_api,manual_import,browser_captureRules:
6. API And Tool Design
6.1 Backend User API
New user-facing API direction:
/api/user/dashboard/projects/{id}/ai/contextGET/api/user/dashboard/projects/{id}/ai/optimizePOST/api/user/dashboard/projects/{id}/ai/optimize/{runId}GET/api/user/dashboard/projects/{id}/ai/proposals/{proposalId}/acceptPOST/api/user/dashboard/projects/{id}/ai/proposals/{proposalId}/rejectPOST/api/user/dashboard/projects/{id}/ai/drafting/sessionsGET/POST/api/user/dashboard/projects/{id}/ai/drafting/sessions/{sessionId}/messagesGET/POST/api/user/dashboard/projects/{id}/ai/drafting/sessions/{sessionId}/streamPOST6.2 AI Service Internal API
New internal API direction:
/growth/optimizePOST/growth/optimize/streamPOST/drafting/respondPOST/drafting/respond/streamPOST/quality/checkPOSTStreaming responses should evolve from plain
text/markdownto NDJSON or SSE events:{"type":"status","message":"assembling context"} {"type":"assistant_delta","content":"..."} {"type":"proposal","proposal_type":"source_rewrite","summary":"..."} {"type":"tool_call","name":"compile_platform_drafts","status":"running"} {"type":"quality_check","status":"passed","warnings":[]}All stream events should share a durable envelope:
event_idsequenceworkspace_idproject_idsession_idorrun_idturn_idparent_event_idtool_use_id, when the event belongs to a tool callcontext_snapshot_idartifact_idorproposal_id, when the event creates or updates an artifactcreated_atmodel_visible: whether the event is included in later model context6.3 Vibe Drafting Tool Runtime
The Vibe Drafting tool layer should follow the key design ideas of Claude Code-style products: tools are not a simple exposure of backend endpoints, but an auditable, cancellable, permissioned, streaming execution runtime.
The runtime should be implemented as a backend
AIHarnessRuntimemodule, with the following internal modules:AIDraftingRunner: owns the turn loop: assemble context, call the model, receive tool requests, execute tools, append tool results, and continue until the turn is complete or blocked.AIToolRegistry: owns enabled tool definitions, schema versions, model-facing tool prompts, and role/plan availability.AIToolExecutor: validates input, runs tools, streams progress, applies concurrency rules, and emits normalized tool results.AIPermissionEngine: resolves permission decisions from workspace role, project role, account grants, tool risk level, permission mode, and user confirmation.AIEventLog: persists the ordered event stream so a session can be replayed, resumed, debugged, or audited.AIToolResultStore: persists large raw results, returns stable previews, and prevents oversized tool outputs from polluting the model context.AICompactionCoordinator: watches context pressure, starts compaction, writes compact boundaries, and restores pinned context and active artifacts.Turn loop:
Tool definition fields:
name: stable tool name, such asread_project_context.version: schema and behavior version, used for audit and replay.description: model-facing capability description, including use cases and limitations.model_prompt: concise tool-specific guidance injected when the tool is available to the model.input_schema: strict JSON schema, validated again by the backend before execution.output_schema: structured result that the frontend can render as an artifact, diff, status, or error.capability:read,propose,validate,write,workflow.risk_level:low,medium,high,critical.permission_policy:allow,ask,deny, with overrides by workspace role, project role, platform account grants, and proposal type.is_read_only: whether the tool can modify project state.is_destructive: whether the tool can delete, overwrite, publish, schedule, or otherwise create hard-to-reverse changes.requires_user_interaction: whether the tool must stop and ask the user for missing information.concurrency:parallel_safeorexclusive. Reading context and generating candidates can run in parallel; writing a project, updating drafts, and creating versions must be exclusive.interrupt_behavior:cancelorblock. Generation tools can be cancelled; write tools cannot be interrupted freely after entering commit.idempotency: whether the tool supports safe retries and which fields form the idempotency key.base_version_policy: whether the tool requires a source version, publication version, proposal version, or checklist version before it can apply changes.progress_events: tools can streamqueued,running,waiting_permission,completed,failed.max_result_size: maximum model-visible result size before the raw result is persisted and replaced with a preview.result_mapper: converts implementation output into model-visible result, frontend artifact, and audit record.compact_summary: when the tool result is large, it must provide a short summary and raw-result reference to avoid polluting later context.Tool execution context:
workspace_id,project_id,session_id,context_snapshot_id.turn_id,tool_use_id,request_id, and monotonically increasing event sequence.default,plan,accept_edits,dont_ask,bypass. MPP should initially expose onlydefaultandplan; the rest should remain internal or future advanced settings.Initial tool groups:
read_project_context,read_publications,read_comments,read_versions,read_brand_profile,read_templates,read_media_summarysearch_project_history,search_workspace_memory,find_relevant_examplespropose_source_patch,propose_title_candidates,propose_prepublish_patch,propose_tags,propose_outlinecompile_platform_drafts,validate_adapted_content,resolve_media_assetsrun_brand_check,run_platform_check,run_publish_readiness_checkapply_source_patch,apply_prepublish_patch,update_project_metadata,create_project_comment,resolve_checklist_itementer_plan_mode,exit_plan_mode,ask_user_question,request_permission,create_drafting_checkpoint,compact_session_contextExecution rules:
AIToolExecutorcan execute them.tool_resultmessages must preserve request order.AIToolCallandProjectActivity, and createProjectVersionwhen needed inside the same database transaction.6.4 Long Context And Compaction Strategy
Vibe Drafting needs to keep "the draft currently being worked on" faithful while compacting "older chat and supporting material". It should not simply push all project history, comments, versions, and tool results into the model.
Context layers:
AIDraftingSessionSummaryCompaction triggers:
Compaction types:
project_version_id,publication_id, andproposal_id.Tool result storage rules:
raw_result_ref.Compaction output structure:
summary: summary that lets the session continue.user_intent: latest user goal and constraints.accepted_changes: accepted proposals and corresponding versions.rejected_directions: writing styles, strategies, or platform directions the user explicitly rejected.open_tasks: unfinished drafting subtasks.active_artifacts: proposals, title candidates, and draft candidates still under review.source_refs: references to original context.next_step_hint: what the next turn should continue first.Post-compaction recovery:
CompactBoundarymessage so the frontend can show "earlier context has been compacted".Implementation touchpoints:
AIContextBudgeterin the backend to estimate tokens, layer context, and decide whether to compact.AIContextCompactorin the backend to generate and persistAIDraftingSessionSummary./drafting/compactendpoint in the AI service. During compaction, business tools are disabled and only structured summary is returned.compact_summary; otherwise large results keep only a reference and a short prefix by default.7. Phase Plan
Phase 0A: Product Boundary And Harness Ownership
Goal: make the backend harness the clear runtime owner before adding new product behavior.
ai-serviceas model adapter, prompt renderer, structured-output parser, and quality-check caller.AIHarnessRuntimepackage boundary inbackend/internal/services/ai.turn_id,tool_use_id,event_id,sequence, andmodel_visiblesemantics.Acceptance:
Phase 0B: Contracts And Data Model Skeleton
Goal: add durable contracts without yet building the full drafting experience.
AIContextSnapshot,AIProposal,AIGrowthOptimizationRun,AIDraftingSession, andAIDraftingSessionSummary.AIToolDefinition,AIToolCall,AIToolEvent,AIPermissionRequest,AIPermissionDecision, andAIToolResultRef.contracts/components/ai.yaml.Acceptance:
Phase 0C: Context Snapshot And Budgeting
Goal: make project context stable, permission-scoped, and trimmable.
AIContextAssembler, initially aggregating Project, Publication, BrandProfile, ContentTemplate, Comments, Versions, and Media summary.AIContextBudgeter, defining trimming order for pinned context, working set, recent turns, session summary, and cold refs.Acceptance:
Phase 0D: Harness Skeleton And Event Replay
Goal: prove the harness loop before adding real write tools.
AIDraftingRunnerwith a fake model adapter and no-op tool registry.AIEventLogappend and replay.read_project_contexttool.Acceptance:
Phase 1A: Black-box Growth Optimization Contracts
Goal: users can create a growth optimization run that produces reviewable proposals.
wechat@growth-v1,zhihu@growth-v1,x@growth-v1,douyin@growth-v1./projects/{id}/ai/optimizeentry point.AIGrowthOptimizationRunlifecycle:running,ready,failed,cancelled./growth/optimize/stream, outputting title, source content, and platform draft proposal events.Acceptance:
Phase 1B: Growth Proposal Validation And Apply
Goal: accepted growth proposals apply safely through backend transactions.
content-pipeline-serviceto deterministically compile or validate platform candidates.ProjectVersion, update selected drafts, and record activity inside one transaction.Acceptance:
Phase 1C: Growth UI MVP
Goal: expose one-click optimization without leaking harness complexity.
Acceptance:
Phase 2A: Drafting Session Shell
Goal: create persistent sessions before adding write behavior.
AIDraftingSession, messages, tool calls, and artifacts.Acceptance:
Phase 2B: Tool Runtime MVP
Goal: make tool execution reliable before adding many tools.
AIToolExecutorwith schema validation, value validation, permission checks, parallel/exclusive execution, interrupt handling, and tool event streaming.AIToolRegistryand tool availability by workspace role, project role, plan, and feature flag.AIPermissionEnginewithdefaultandplanmodes.AIToolResultStorefor large results, stable previews, and raw-result refs.Acceptance:
Phase 2C: Drafting Proposal Tools
Goal: support the first useful professional drafting workflows.
read_project_context,read_comments,propose_source_patch,propose_title_candidates,propose_prepublish_patch,compile_platform_drafts, andrun_publish_readiness_check.apply_source_patch,apply_prepublish_patch, andcreate_project_comment.Acceptance:
Phase 2D: Plan Mode, Checkpoints, And Compaction
Goal: make long sessions survivable.
/drafting/compactendpoint that generatesAIDraftingSessionSummary.Acceptance:
Phase 2E: Drafting UI Hardening
Goal: make Vibe Drafting feel like a professional editing workspace.
AIEditAssistant, but gradually guide advanced entry points toward the drafting panel.Acceptance:
Phase 3A: Performance Snapshot Ingestion
Goal: add the data foundation for measuring optimization outcomes.
ContentPerformanceSnapshot.Acceptance:
Phase 3B: Performance Reporting And Context Use
Goal: use performance data without making it a first-phase hard dependency.
Acceptance:
Phase 4A: Governance And Audit
Goal: make AI behavior explainable to workspace admins.
Acceptance:
Phase 4B: Quotas And Commercialization
Goal: make AI capabilities measurable, governable, and billable SaaS product features.
Acceptance:
8. Current Code Touchpoints
Priority change areas:
contracts/components/ai.yaml: add growth, drafting, proposal, and quality check schemas.ai-service/schemas.py: add request/response models.ai-service/prompts.py: split growth optimization, drafting, and quality-check prompt builders.ai-service/routes.py: add internal/growth/*,/drafting/*, and/drafting/compactroutes.backend/internal/services/ai/client.go: extend the AI client interface for structured and streaming events.backend/internal/handlers/user_dashboard.go: add user-facing AI optimize/drafting routes.backend/internal/models/models.go: add AI run, proposal, session, snapshot, message, event, tool call, permission decision, tool result ref, session summary, and performance models.backend/internal/services/project: add context assembly, proposal application, and version creation reuse logic.backend/internal/services/ai: add harness runner, tool registry, permission engine, tool executor, event log, tool result store, context budgeter, context compactor, and event-stream adaptation.frontend/src/lib/dashboard/api/ai.ts: add new API client methods.frontend/src/components/dashboard/content/ai: add growth result, drafting panel, proposal list, tool timeline, permission prompt, compact boundary, and event stream components.content-pipeline-service: continue using it as the deterministic boundary for platform draft format. It should not own growth strategy directly.9. Risks And Governance
Growth claim risk:
Content safety risk:
Context leakage risk:
User content overwrite risk:
ProjectVersionafter acceptance.Cost and latency risk: