Skip to content

Content Calendar Tool

A complete example of an AI-powered content calendar plugin that plans editorial calendars, researches topics, and drafts channel-optimized content.

What It Does

The Content Calendar plugin:

  1. Stores a user's content strategy profile (business description, audience, goals, channels, keywords)
  2. Uses context.search() to research trends, competitors, and search intent
  3. Generates a dated editorial calendar with AI using context.ai.analyze()
  4. Drafts channel-optimized content for LinkedIn, X/Twitter, and SEO blog posts
  5. Provides a launchable widget for browsing and managing the calendar

Tool Contract

The plugin exposes one tool — content_calendar — with these actions:

ActionDescriptionKey Parameters
showOpens the calendar widget
setup_strategyStores content strategybusinessSummary, audience, offers, goals, preferredChannels
plan_calendarGenerates calendar itemsstartDate, endDate, instructions?
list_itemsLists calendar itemschannel?, status?, startDate?, endDate?
items_for_dateItems for a specific datedate (YYYY-MM-DD or "tomorrow")
update_itemEdits a calendar itemitemId, plus any fields to update
refresh_researchRe-runs web searchitemId?, query?
write_itemDrafts one calendar itemitemId
write_for_dateDrafts all ready items for a datedate

Database Schema

The plugin uses four single-user tables with pie_user_id RLS:

  • cc_strategy_profiles — One row per user. Business summary, audience, offers, goals, voice, channels, cadence, keywords.
  • cc_research_runs — One row per search pass. Query, provider, normalized results, summaries, takeaways.
  • cc_calendar_items — One row per content piece. Date, channel, status, pillar, title, hook, angle, CTA, brief, SEO fields.
  • cc_drafts — One row per draft version. Item ID, version number, content payload, model metadata.

Status Flow

idea → scheduled → ready_to_write → drafting → drafted
                                   ↘ needs_refresh ↗
                                      archived

Using context.search() for Research

The plugin uses the platform search primitive to gather topical context:

js
var searchResult = await context.search('b2b saas content marketing trends 2026', {
  type: 'web',
  limit: 8,
  includeText: true,
  includeHighlights: true,
});

// Normalize results into research context
for (var i = 0; i < searchResult.results.length; i++) {
  var r = searchResult.results[i];
  console.log(r.title, r.url, r.snippet);
}

Research results are stored in cc_research_runs and linked to calendar items via research_run_id.

Prompt Stack Architecture

The plugin uses a layered prompt builder for AI generation:

  1. Base system prompt — Action-specific instructions (plan_calendar, write_item, etc.)
  2. Content Playbook — Verbatim injection of the full content writing playbook with forbidden lexicon, formatting rules, and platform-specific optimization guides
  3. Channel guide — LinkedIn, X/Twitter, or blog-specific writing rules
  4. User strategy — Business summary, audience, offers, goals, voice
  5. Research context — Normalized search findings, source URLs, takeaways
  6. Calendar item brief — Title, angle, hook, CTA, date, channel, SEO fields
  7. Output schema — JSON structure expected in the response

Model Policy

All core AI tasks use google/gemini-3.1-pro-preview:

js
var result = await context.ai.analyze({
  prompt: fullPromptStack,
  data: { startDate: '2026-04-01', endDate: '2026-04-30', channels: ['linkedin', 'twitter', 'blog'] },
  model: 'google/gemini-3.1-pro-preview',
});

Cross-Chat Drafting

Any PIE chat can invoke the calendar tool to draft content:

"Write the content from the calendar for tomorrow"

This maps to the write_for_date action, which:

  1. Resolves "tomorrow" to a concrete date
  2. Finds all items with status scheduled, ready_to_write, or needs_refresh
  3. Generates drafts for each item using the full prompt stack
  4. Stores each draft as a versioned row in cc_drafts
  5. Updates each item's status to drafted

Widget UI

The launchable widget provides:

  • Calendar view — Month grid with channel-colored dots per day
  • Agenda view — Chronological list grouped by date with status badges
  • Strategy form — Editable profile for business gist, audience, channels, and keywords
  • Plan modal — Date range picker with optional instructions for AI calendar generation
  • Item detail — Full brief display with write/research/delete actions and draft preview

The widget communicates with the handler via PIE.sendAction() and receives updates via PIE.onData(). Dark mode is supported via PIE.onTheme().

Built with VitePress