Skip to content

feat(agent): let the agent list and update scheduled posts#1689

Closed
giladresisi wants to merge 1 commit into
fix/tiktok-upload-method-defaultfrom
feat/agent-update-posts
Closed

feat(agent): let the agent list and update scheduled posts#1689
giladresisi wants to merge 1 commit into
fix/tiktok-upload-method-defaultfrom
feat/agent-update-posts

Conversation

@giladresisi

Copy link
Copy Markdown
Collaborator

🔗 Stacked on #1687 — merge #1687 first. This PR is based on fix/tiktok-upload-method-default (it reuses the buildSettings helper from there); GitHub will auto-retarget it to main once #1687 lands. Kept as a draft until then.

What

Two agent/MCP tools so an agent (web-app chat or an external MCP client) can change already-scheduled posts, not just create them:

  • postsListTool — lists the user's upcoming (not-yet-published) posts: all drafts + scheduled posts still in the future. Default returns everything in one call (so "list all my unpublished posts" needs no args); past posts are never listed. Optional state narrows to drafts or scheduled; filterable by platform/channel; paginated; each item carries its state (draft/scheduled) and current provider settings.
  • updatePostTool — updates one post by its stable id: settings are merged (only passed keys change), date and content optional. Refuses published/past posts, runs the same server-side validation as the dashboard, preserves the root post id (keeps the Temporal workflow identity), and only restarts the workflow when the publish date actually changed.

Plus: prompt guidance (apply changes to existing posts via the tool, never the create-modal; never offer deletion — there is no delete tool), keepGroup so out-of-band updates don't invalidate an open calendar, and a defense-in-depth guard turning a stale-group 500 into a 404 + calendar self-heal.

Testing

Exercised end-to-end via both the internal agent and an external MCP client:

  • Internal agent: list posts; reschedule / change settings applied directly via updatePostTool; no delete offered; no create-modal opened for existing posts.
  • postsListTool: default (all upcoming), platform + integrationId filters, draft/scheduled states, and pagination across pages (page/total/hasMore, no overlap).
  • updatePostTool happy paths: settings-only update leaves the Temporal workflow untouched (checked the run list); a real date change restarts it (TERMINATE_EXISTING, one new run); post id + group stable, no duplicate; content grow/shrink and bulk multi-post.
  • updatePostTool guards (each rejected, post left unchanged): published post, a comment's id, a non-existent id, content that fails validation.

🤖 Generated with Claude Code

Adds two agent/MCP tools so an agent (web-app chat or an external MCP
client) can change already-scheduled posts, not just create them:

- postsListTool: lists the user's upcoming (not-yet-published) posts -
  both drafts and scheduled posts whose publish time is still in the
  future. By default returns all of them in one call, so "list all my
  unpublished posts" needs no arguments. Past posts (including old
  forgotten drafts) are never listed. Optional "state" narrows to only
  future drafts or only future scheduled. Filterable by platform/channel,
  paginated, each item carries its state (draft/scheduled) and current
  provider settings so the agent can pick what to change. Backed by a
  new getAgentPostsList repository + service method.
- updatePostTool: updates one post by its stable id - settings are
  merged (only the passed keys change), date and content optional.
  Refuses published/past posts, runs the same server-side validation
  as the dashboard, preserves the root post id (so the Temporal
  workflow identity is kept) and only restarts the workflow when the
  publish date actually changed on a queued post.

Agent prompt guidance: changes to existing posts are always applied
directly with updatePostTool; the agent must not open the "populated
modal" (manualPosting) for an existing post since that only creates a
new post (would duplicate). No delete tool exists (deletion is
destructive); the prompt tells the agent never to offer deletion and,
if asked, to defer it to the user in the Postiz app. External MCP
agents can't delete either (no tool), so they infer it from the toolset.

keepGroup: out-of-band updates keep the post's group id stable instead
of rotating it (removed comments are swept by id instead). The group
rotation on every edit would otherwise invalidate an open calendar that
still holds the old group. The dashboard keeps its rotate-and-sweep
behavior unchanged.

Guard (defense-in-depth for the same stale-group race, which also
predates this via multi-device dashboard edits/deletes):
- getPostsByGroup throws 404 instead of a 500 when the group has no
  posts.
- calendar editPost detects an empty group, shows a toast and reloads
  the calendar instead of crashing on posts[0].

Tested end-to-end, both the internal agent and an external MCP client:
- Internal agent (web-app chat): "list my posts" returns the upcoming
  posts; asking to reschedule or change a setting is applied directly
  via updatePostTool - no delete offered, and no populated modal opened
  for an existing post.
- postsListTool: default (all upcoming), platform and integrationId
  filters, draft/scheduled states, and pagination across pages
  (verified page/total/hasMore and no overlap with the page size
  temporarily lowered).
- updatePostTool happy paths: a settings-only update leaves the Temporal
  workflow untouched (verified against the Temporal run list); a real
  date change restarts it (TERMINATE_EXISTING, exactly one new run); the
  post id and group stay stable with no duplicate; content grow/shrink
  and bulk multi-post updates apply correctly.
- updatePostTool guards, each confirmed to reject and leave the post
  unchanged: a published post, a comment's id (must pass the root post),
  a non-existent id, and content that fails validation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@postiz-contribution postiz-contribution Bot added the contribution:approved Approved contributor label Jul 8, 2026
@postiz-contribution

Copy link
Copy Markdown

Contribution-checker quality warning
Heuristic score: 0/100 (low). This is a non-blocking warning surfaced by the project's quality settings.

Heuristics that flagged:

  • Excessive inline code references: 13 inline refs (>3)
  • PR doesn't use the repo's PR template: 5 required checkbox items missing (max 1, match ≥80%)
  • Body adds too many extra headers beyond the template: 2 extra headers (>1)
  • AI watermark phrase: Matched: "Generated with Claude Code"
  • Commit message too long: Longest: 3428 chars
  • Excessive added comments: 27 added comment lines (ratio 0.05)

If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it.

@postiz-agent

postiz-agent Bot commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ Snyk checks are incomplete.

Status Scan Engine Critical High Medium Low Total (0)
⚠️ Open Source Security 0 0 0 0 See details
⚠️ Licenses 0 0 0 0 See details
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@nevo-david

Copy link
Copy Markdown
Contributor

There should be only a settings update

@nevo-david nevo-david closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution:approved Approved contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants