Project & Story context assets — slice 1: schema, models, uploader, writers#110
Merged
Conversation
Lays the schema, models, storage uploader, and approval-aware writers for project- and story-scoped AI context assets. Story-scoped CRUD reopens the owning Story for approval; project-scoped CRUD does not. Selection toggling is bulk-aware to avoid approval-reopen storms. File uploads land on a new `private` disk; summarisation is intentionally deferred to a later slice. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
There was a problem hiding this comment.
Pull request overview
Introduces the first slice of “project & story context assets” by adding the underlying schema, Eloquent models/relations, and service-layer write/select/upload primitives needed to store and manage AI context items (text/link/file) at both project and story scope.
Changes:
- Adds
context_itemsandcontext_item_storytables (with soft deletes, FKs, and indexes) plus schema verification tests. - Adds
ContextItemmodel + enums, and extendsProject/Storywith context-item relationships and query helpers. - Adds storage configuration (
privatedisk +specify.context.assets.*) and service classes for uploading assets and approval-aware CRUD/selection.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Feature/ContextItem/SchemaTest.php | Verifies new tables/columns exist. |
| tests/Feature/ContextItem/ContextItemWriterTest.php | Covers writer behavior (approval reopen rules, create/update/delete semantics). |
| tests/Feature/ContextItem/ContextItemSelectorTest.php | Covers selection toggling/bulk replacement and validation rules. |
| tests/Feature/ContextItem/ContextItemModelTest.php | Covers scoping helpers, bodyForContext(), and relationships. |
| tests/Feature/ContextItem/AssetUploaderTest.php | Covers upload persistence, cross-project guard, size/MIME validation. |
| database/migrations/2026_05_10_000001_create_context_items_table.php | Creates context_items schema (scoping columns, summary fields, soft deletes, indexes). |
| database/migrations/2026_05_10_000002_create_context_item_story_table.php | Creates pivot table for story inclusion with audit fields. |
| database/factories/ContextItemFactory.php | Adds factory + states for text/link/file items. |
| config/specify.php | Adds specify.context.assets.* configuration (disk, size cap, MIME allow-list, threshold). |
| config/filesystems.php | Adds private local disk for storing context assets. |
| app/Services/Context/AssetUploader.php | Implements file storage + ContextItem row creation. |
| app/Services/Context/ContextItemWriter.php | Implements approval-aware create/update/delete for non-file items (and file deletion on soft delete). |
| app/Services/Context/ContextItemSelector.php | Implements story inclusion toggling and bulk replacement behavior. |
| app/Models/Story.php | Adds context-item relationships + available-items query helper. |
| app/Models/Project.php | Adds project context-items relationship. |
| app/Models/ContextItem.php | Adds the ContextItem model, casts, relationships, and prompt-body rendering logic. |
| app/Enums/ContextItemType.php | Adds enum for context item types. |
| app/Enums/ContextItemSummaryStatus.php | Adds enum for summary lifecycle state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- AssetUploader records server-detected MIME (getMimeType()) instead of the spoofable client MIME header. - ContextItemWriter::update refuses to mutate metadata on file-typed items so callers cannot retarget the underlying file via the writer. - Defense-in-depth in deleteUnderlyingFile(): only deletes when the metadata-claimed disk is both registered and equals the configured assets disk; otherwise refuses the delete. - ContextItemSelector::bulkSet now rejects all story-scoped IDs (not just cross-story ones) since the picker only owns project-scoped selections; story-scoped items are managed by ContextItemWriter. Docblock updated to match. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
"cannot be project-scoped after creation" was confusing two distinct constraints. Spell out the actual behaviour: story-scoped items are auto-attached at create time and ContextItemSelector refuses to detach them via the picker; they leave the selection only on delete. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lays the schema, models, storage uploader, and approval-aware writers for project- and story-scoped AI context assets. First of 5 stacked PRs implementing the project-and-story context-assets feature (plan → ADR-0015 lands in slice 7-docs).
context_items+context_item_storymigrations (id, project/story FKs, type/title/description/metadata/summary*, soft deletes, indexes).ContextItemmodel withbodyForContext()(summary → truncated raw fallback),Project::contextItems(),Story::ownedContextItems()/includedContextItems()/availableContextItems(). Enums + factory states (forFile/forLink/forText).privatedisk inconfig/filesystems.php+context.assets.*config keys.AssetUploader(ULID paths, MIME/size validation, cross-project guard).ContextItemWriterandContextItemSelector(story-scoped CRUD reopens approval, project-scoped does not, bulk-aware to avoid storms).Slice 2 (summarisation), 3 (TasksGenerator injection), 4 (subtask context builder, opt-in), and 7-docs (ADR + AGENTS.md + CONTEXT.md) stack on top.
Test plan
tests/Feature/ContextItem/— all green🤖 Generated with Claude Code