Skip to content

feat(ai): add Co-DM 'Draft with AI' and per-event edit affordance for timeline events (#1310) - #2207

Merged
AwsomeFox merged 1 commit into
mainfrom
codex/backlog-1310-timeline-ai-drafting
Aug 11, 2026
Merged

AwsomeFox merged 1 commit into
mainfrom
codex/backlog-1310-timeline-ai-drafting

Conversation

@AwsomeFox

Copy link
Copy Markdown
Owner

Fixes #1310

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed0cf82116

ℹ️ 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".

// proposable for Co-DM drafting and are create-only in v1 (direct faction writes remain
// DM-gated; the proposal queue is the co-DM intermediary).
export type ProposableEntityType = Exclude<EntityType, 'campaign'> | 'map' | 'story_arc' | 'story_beat' | 'rule_entry';
export type ProposableEntityType = Exclude<EntityType, 'campaign'> | 'map' | 'story_arc' | 'story_beat' | 'timeline_event' | 'rule_entry';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add timeline events to the shared proposal contract

When a timeline draft is returned, toDomain() casts timeline_event to Proposal['entityType'], but the exported ProposalEntityType in packages/schema/src/index.ts:8718-8721 still excludes it. Consequently these REST/MCP responses violate the shared Proposal schema, and schema-validating clients will reject every timeline proposal even though the server accepts it; add timeline_event to the shared proposal entity contract instead of defining it only in the server union.

AGENTS.md reference: AGENTS.md:L34-L35

Useful? React with 👍 / 👎.

Comment on lines +343 to +348
this.timeline.updateEvent(
id,
payload as Parameters<TimelineService['updateEvent']>[1],
user,
role,
opts,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the timeline update concurrency token

When another DM edits the event after approve() performs its freshness read but before the proposal write runs, the generic approval branch invokes this adapter without opts, so TimelineService.updateEvent() receives no expectedUpdatedAt and unconditionally overwrites the intervening edit. Route timeline-event updates through the compare-and-set path using existing.baseUpdatedAt, as storyline updates already do, so this race returns a conflict rather than losing user changes.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed0cf82116

ℹ️ 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".

// proposable for Co-DM drafting and are create-only in v1 (direct faction writes remain
// DM-gated; the proposal queue is the co-DM intermediary).
export type ProposableEntityType = Exclude<EntityType, 'campaign'> | 'map' | 'story_arc' | 'story_beat' | 'rule_entry';
export type ProposableEntityType = Exclude<EntityType, 'campaign'> | 'map' | 'story_arc' | 'story_beat' | 'timeline_event' | 'rule_entry';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add timeline events to the shared proposal contract

When a timeline draft is returned, toDomain() casts timeline_event to Proposal['entityType'], but the exported ProposalEntityType in packages/schema/src/index.ts:8718-8721 still excludes it. Consequently these REST/MCP responses violate the shared Proposal schema, and schema-validating clients will reject every timeline proposal even though the server accepts it; add timeline_event to the shared proposal entity contract instead of defining it only in the server union.

AGENTS.md reference: AGENTS.md:L34-L35

Useful? React with 👍 / 👎.

Comment on lines +343 to +348
this.timeline.updateEvent(
id,
payload as Parameters<TimelineService['updateEvent']>[1],
user,
role,
opts,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the timeline update concurrency token

When another DM edits the event after approve() performs its freshness read but before the proposal write runs, the generic approval branch invokes this adapter without opts, so TimelineService.updateEvent() receives no expectedUpdatedAt and unconditionally overwrites the intervening edit. Route timeline-event updates through the compare-and-set path using existing.baseUpdatedAt, as storyline updates already do, so this race returns a conflict rather than losing user changes.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Co-DM “Draft with AI” support to timeline events end-to-end (schema → server draft/proposal plumbing → web affordances), including an “Edit with AI” button on existing events that files update proposals.

Changes:

  • Extend Co-DM draft target enum to include timeline_event, and wire it through MCP draft_content.
  • Add proposal create/update support for timeline_event (schemas, proposal approval routing, proposal snapshot reads).
  • Add Timeline UI entry points: page-level “Draft with AI” and per-event “Edit with AI”, plus basic component test coverage and server e2e coverage.

Reviewed changes

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

Show a summary per file
File Description
packages/schema/src/index.ts Adds timeline_event to CoDmDraftTarget (shared contract used by web/server/MCP).
apps/web/src/features/timeline/TimelinePage.tsx Adds “Draft with AI” to page header and “Edit with AI” in the per-event edit actions.
apps/web/src/features/ai-dm/DraftWithAiButton.tsx Adds timeline-specific UI copy/labels/plurals and enables multi-draft for timeline_event.
apps/web/test/component/TimelineDraftWithAi.spec.tsx Component-level coverage ensuring the button renders and opens its modal for timeline targets.
apps/server/src/modules/ai-dm/co-dm.service.ts Implements timeline draft validation, rewrite context loading, and proposal filing for create/update.
apps/server/src/modules/mcp/mcp-tools.ts Updates MCP tool docs/arg descriptions to include timeline_event support.
apps/server/src/modules/proposals/proposals.service.ts Adds proposal approve routing for timeline_event create/update/remove via TimelineService.
apps/server/src/modules/proposals/proposals.module.ts Registers TimelineModule so proposals can apply timeline proposals.
apps/server/src/modules/proposals/proposal-records.service.ts Adds snapshot reads for timeline_event proposals (visibility + soft-delete aware).
apps/server/src/modules/ai-dm/ai-dm.module.ts Imports TimelineModule for CoDmService timeline rewrite context.
apps/server/test/co-dm.e2e-spec.ts E2E coverage for drafting and rewriting timeline events through proposals/approve.
apps/server/test/unit/proposals-approve.spec.ts Updates unit test wiring for new ProposalsService dependency list.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +141 to +142
if (editing && input.target !== 'arc' && input.target !== 'beat' && input.target !== 'timeline_event') {
throw new BadRequestException('entityId is supported only when rewriting an existing story arc, beat, or timeline event');
Comment on lines +9995 to 9996
export const CoDmDraftTarget = z.enum(['npc', 'location', 'arc', 'beat', 'recap', 'encounter', 'map', 'quest', 'faction', 'timeline_event']);
export type CoDmDraftTarget = z.infer<typeof CoDmDraftTarget>;
Comment on lines 83 to 97
const service = new ProposalsService(
records as unknown as ProposalRecordsService,
audit as never,
{ notifyUser: jest.fn() } as never,
quests as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
storylines,
{} as never,
);
...(typeof raw.inWorldDate === 'string' ? { inWorldDate: raw.inWorldDate } : {}),
...(typeof raw.era === 'string' ? { era: raw.era } : {}),
...(typeof raw.sortIndex === 'number' || typeof raw.sortIndex === 'string' ? { sortIndex: Number(raw.sortIndex) } : {}),
...(typeof raw.body === 'string' ? { body: raw.body } : {}),
...(typeof raw.inWorldDate === 'string' ? { inWorldDate: raw.inWorldDate } : {}),
...(typeof raw.era === 'string' ? { era: raw.era } : {}),
...(typeof raw.sortIndex === 'number' || typeof raw.sortIndex === 'string' ? { sortIndex: Number(raw.sortIndex) } : {}),
...(typeof raw.body === 'string' ? { body: raw.body } : {}),
@AwsomeFox
AwsomeFox merged commit dc175bf into main Aug 11, 2026
17 checks passed
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.

Timeline: add Co-DM 'Draft with AI' and per-event AI edit affordances

2 participants