feat(plugin-stack-persistence): add composeStrategies - #734
Conversation
🦋 Changeset detectedLatest commit: 8c88f65 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a typed ChangesPersistence strategy composition
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant composeStrategies
participant FirstStrategy
participant SecondStrategy
Caller->>composeStrategies: provide keyed strategies
composeStrategies->>FirstStrategy: createMetadata(args)
composeStrategies->>SecondStrategy: createMetadata(args)
FirstStrategy-->>composeStrategies: return keyed metadata
SecondStrategy-->>composeStrategies: return keyed metadata
composeStrategies->>FirstStrategy: shouldReuse(metadata, initialContext)
composeStrategies->>SecondStrategy: shouldReuse(metadata, initialContext)
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
stackflow-docs | 8c88f65 | Commit Preview URL | Jul 22 2026, 09:08 AM |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@extensions/plugin-stack-persistence/src/composeStrategies.ts`:
- Around line 27-29: Update the metadata validation condition in the
record-matching logic to first verify that record.metadata is a non-null object
before calling Object.hasOwn; return false for nullish or non-object metadata,
while preserving the existing keys.every validation for valid metadata.
In `@extensions/plugin-stack-persistence/src/index.ts`:
- Around line 1-5: Remove the stale ComposedStrategyMetadata re-export from the
barrel export in index.ts, while preserving composeStrategies and
StrategiesMetadata exports. Do not add the missing type to composeStrategies.ts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b58e6a6a-9645-4322-b73b-f77b3ba13353
📒 Files selected for processing (3)
.changeset/shaggy-foxes-compose.mdextensions/plugin-stack-persistence/src/composeStrategies.tsextensions/plugin-stack-persistence/src/index.ts
| if (!keys.every((key) => Object.hasOwn(record.metadata, key))) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline extensions/plugin-stack-persistence/src/composeStrategies.ts --view expanded || true
echo '---'
wc -l extensions/plugin-stack-persistence/src/composeStrategies.ts
echo '---'
cat -n extensions/plugin-stack-persistence/src/composeStrategies.tsRepository: daangn/stackflow
Length of output: 1805
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,220p' extensions/plugin-stack-persistence/src/StackSnapshotStrategy.ts
echo '---'
rg -n "metadata" extensions/plugin-stack-persistence/src -g '*.ts'Repository: daangn/stackflow
Length of output: 1080
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,220p' extensions/plugin-stack-persistence/src/StackSnapshotRecord.ts
echo '---'
sed -n '1,260p' extensions/plugin-stack-persistence/src/stackPersistencePlugin.tsRepository: daangn/stackflow
Length of output: 2457
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "composeStrategies" -g '*.ts' -g '*.tsx' .
echo '---'
sed -n '1,220p' extensions/plugin-stack-persistence/src/StackSnapshotStorage.tsRepository: daangn/stackflow
Length of output: 645
🏁 Script executed:
#!/bin/bash
set -euo pipefail
node - <<'JS'
try {
console.log(Object.hasOwn(null, 'a'));
} catch (e) {
console.log(e.name + ': ' + e.message);
}
try {
console.log(Object.hasOwn(undefined, 'a'));
} catch (e) {
console.log(e.name + ': ' + e.message);
}
console.log(Object.hasOwn('abc', 'length'));
JS
echo '---'
rg -n "implements StackSnapshotStorage|StackSnapshotStorage<|load\(\): StackSnapshotRecord" extensions/plugin-stack-persistence -g '*.ts'Repository: daangn/stackflow
Length of output: 613
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -a -t f 'StackSnapshotStorage' extensions/plugin-stack-persistence src . || true
echo '---'
rg -n "save\(|load\(" extensions/plugin-stack-persistence -g '*.ts'
echo '---'
rg -n "localStorage|sessionStorage|JSON.stringify|JSON.parse|StackSnapshotRecord" extensions/plugin-stack-persistence -g '*.ts'Repository: daangn/stackflow
Length of output: 2957
Guard nullish metadata before Object.hasOwn.
Legacy records with null or undefined metadata will throw here instead of returning false, turning a bad record into a load error. Add a null/object check before the key loop.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@extensions/plugin-stack-persistence/src/composeStrategies.ts` around lines 27
- 29, Update the metadata validation condition in the record-matching logic to
first verify that record.metadata is a non-null object before calling
Object.hasOwn; return false for nullish or non-object metadata, while preserving
the existing keys.every validation for valid metadata.
Removed ComposedStrategyMetadata export from index.ts
Summary
Adds
composeStrategies, a utility that composes multipleStackSnapshotStrategyinstances into one (FEP-2611).createMetadatapersists each strategy's metadata side by side under its key.shouldReuseis AND-composed — a snapshot is reused only when every strategy agrees; each strategy receives only the metadata under its own key and never learns it was composed.StackSnapshotStrategy, so composed strategies can be nested;stackPersistencePlugin's single-strategy option API is unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01TMTNfPxft5WXLjpJbN8etC