Skip to content

feat(sdk): indexed reads, workspace memory, and cursor contracts - #655

Merged
unbraind merged 4 commits into
mainfrom
feat/sdk-indexed-memory-and-cursor-contracts
Jul 23, 2026
Merged

unbraind merged 4 commits into
mainfrom
feat/sdk-indexed-memory-and-cursor-contracts

Conversation

@unbraind

@unbraind unbraind commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • add a rebuildable, cursor-bound SQLite metadata query index with atomic publication, transactional mutation maintenance, corruption/staleness fallback, and an SDK-owned query surface
  • use the index for safe bounded list reads while preserving authoritative scan behavior for hooks, rich projections, custom schemas, and unsupported filters
  • add deterministic epoch, quarter, and nearest-epic workspace-memory rollups that keep large closed histories available to context/search within bounded token budgets
  • replace list/context/search cursor deny-lists with contract-declared presentation semantics and a shared SDK selector
  • make standard pm get child context compact through counts, status summaries, and continuations while retaining explicit/full child samples
  • extract typed search contracts, document all new SDK/runtime behavior, and refresh the package-owned changelog with pm-changelog 2026.7.23
  • replace the CodeQL-alerted trailing-separator regex with a linear scan plus a 100,000-separator regression test

Why

The CLI and SDK need reusable project-management primitives that treat project management as bounded, precise context management. This change makes large workspaces cheaper to query, preserves source files as the sole authority, gives package authors public customization surfaces, and removes presentation-only cursor invalidation drift.

Tracked work

The completed workspace-memory, cursor-contract, and security items are closed. The broader 1M-index and rolling SDK-reference items were returned to open with their remaining acceptance recorded; no work item remains in progress.

Verification

  • release gates: build, typecheck, docs/links, strict static quality, SDK boundary, token budgets, version sync, secrets, packed-package smoke, and 88-command dogfood passed
  • exact coverage: 6,120 tests; 100% statements (41,544/41,544), branches (29,316/29,316), functions (8,438/8,438), and lines (40,383/40,383)
  • pnpm benchmark:scale:check: CLI and SDK 10k budgets passed
  • isolated packed consumer: npm audit reported zero vulnerabilities; strict erasable TypeScript SDK imports passed; installed pm init/create/list/context/search passed
  • changelog: latest pm-changelog 2026.7.23 installed; generation and check are reproducible

The local Greptile gate reached the external service but returned free_reviews_limit_reached; hosted checks and available reviewer feedback will be handled on this PR.


Summary by cubic

Delivers a rebuildable SQLite metadata query index for fast, bounded list reads and adds deterministic workspace‑memory rollups that keep large histories searchable. Unifies cursor identities via flag contracts, compacts single‑item child projections by default, and fixes a CodeQL‑flagged ReDoS in path trimming.

  • New Features

    • SQLite metadata query index with atomic rebuilds, transactional updates, and scan fallback; default‑order light list pages serve windowed rows and counts from the index; SDK exposes queryItemMetadataIndex (pm-801d, pm-px153l).
    • Workspace‑memory rollups (epoch, quarter, nearest‑epic) for compact historical context/search on large workspaces; context auto‑attaches; SDK surfaces read/select/search APIs (pm-5qmm).
    • Cursor fingerprints driven by flag contracts; shared selector ignores presentation‑only flags so list/context/search cursors stay stable; typed search contracts extracted (pm-fgih).
    • pm get children are compact by default (counts, status summary, continuation); deep/full retains bounded samples.
  • Bug Fixes

    • Replaced trailing‑separator regex with a linear scan to remove polynomial ReDoS; added a 100k‑separator regression test (pm-v3zd3o).

Written for commit 0badc41. Summary will update on new commits.

Review in cubic

unbraind added 2 commits July 23, 2026 09:59
Deliver a cursor-bound SQLite metadata query index with transactional maintenance and authoritative scan fallback, plus deterministic workspace-memory rollups for bounded context and search.

Converge cursor fingerprints on contract-declared semantics, compact get child projections, extract typed search contracts, remediate CodeQL alert 30 with a linear path primitive, refresh SDK documentation and generated changelog, and record the linked pm lifecycle evidence.
Record PR #655 on every implemented tracker item so the hosted review and exact-head evidence remain discoverable from pm history.
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head.\n\n@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

@unbraind I’ll perform a full review of the current PR head.

✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 59 minutes.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@unbraind, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7f2e0af9-3a2f-430d-89bf-2a4d2faa70d8

📥 Commits

Reviewing files that changed from the base of the PR and between 221980a and 0badc41.

📒 Files selected for processing (46)
  • .agents/pm/chores/pm-fgih.toon
  • .agents/pm/extensions/.managed-extensions.json
  • .agents/pm/features/pm-5qmm.toon
  • .agents/pm/features/pm-801d.toon
  • .agents/pm/features/pm-px153l.toon
  • .agents/pm/history/pm-5qmm.jsonl
  • .agents/pm/history/pm-801d.jsonl
  • .agents/pm/history/pm-b0twiy.jsonl
  • .agents/pm/history/pm-ds3b.jsonl
  • .agents/pm/history/pm-fgih.jsonl
  • .agents/pm/history/pm-px153l.jsonl
  • .agents/pm/history/pm-v3zd3o.jsonl
  • .agents/pm/issues/pm-b0twiy.toon
  • .agents/pm/issues/pm-v3zd3o.toon
  • .agents/pm/tasks/pm-ds3b.toon
  • CHANGELOG.md
  • docs/COMMANDS.md
  • docs/CONTEXT_RELEVANCE.md
  • docs/PERFORMANCE.md
  • docs/SDK.md
  • src/cli/commands/context.ts
  • src/cli/commands/get.ts
  • src/core/shared/primitives.ts
  • src/core/store/item-metadata-cache.ts
  • src/core/store/item-metadata-query-index.ts
  • src/sdk/cli-contracts/flag-contracts.ts
  • src/sdk/index.ts
  • src/sdk/item-children.ts
  • src/sdk/item-metadata-index.ts
  • src/sdk/pagination.ts
  • src/sdk/query/list.ts
  • src/sdk/query/search-contracts.ts
  • src/sdk/query/search-pagination.ts
  • src/sdk/query/search.ts
  • src/sdk/workspace-memory.ts
  • tests/fixtures/contracts/full.json
  • tests/unit/commands/get-append-command.spec.ts
  • tests/unit/commands/list-command.spec.ts
  • tests/unit/commands/search-command.spec.ts
  • tests/unit/commands/workspace-memory-command-integration.spec.ts
  • tests/unit/core/item/item-metadata-derived-index.spec.ts
  • tests/unit/core/item/item-metadata-query-index.spec.ts
  • tests/unit/core/shared/shared-primitives.spec.ts
  • tests/unit/sdk/history-read-primitives.spec.ts
  • tests/unit/sdk/pagination.spec.ts
  • tests/unit/sdk/workspace-memory.spec.ts
📝 Walkthrough

Walkthrough

Adds deterministic workspace-memory rollups, a rebuildable SQLite metadata query index, contract-driven cursor fingerprinting, shared search contracts, indexed list execution, child projection adjustments, security regression coverage, documentation, and project-tracking metadata.

Changes

Workspace memory and query surfaces

Layer / File(s) Summary
Workspace memory lifecycle and integration
src/sdk/workspace-memory.ts, src/cli/commands/context.ts, src/sdk/query/search.ts, tests/unit/sdk/workspace-memory.spec.ts, tests/unit/commands/workspace-memory-command-integration.spec.ts
Workspace memory is built, persisted, validated, selected within token budgets, searched, and attached to context and search outputs.
Persistent metadata index and indexed list path
src/core/store/item-metadata-query-index.ts, src/core/store/item-metadata-cache.ts, src/sdk/query/list.ts, tests/unit/core/item/*, tests/unit/commands/list-command.spec.ts
A cursor-validated SQLite projection supports bounded metadata queries, transactional updates, atomic rebuilds, invalidation, and indexed list pages with fallback behavior.
Cursor and search contracts
src/sdk/cli-contracts/flag-contracts.ts, src/sdk/pagination.ts, src/sdk/query/search-contracts.ts, src/sdk/query/search-pagination.ts, tests/fixtures/contracts/full.json, tests/unit/sdk/pagination.spec.ts
Presentation-only flags are declared centrally, cursor fingerprints select semantic options, and search parsing/configuration contracts are centralized and re-exported.
Read projections and regressions
src/cli/commands/get.ts, src/sdk/item-children.ts, src/core/shared/primitives.ts, tests/unit/commands/get-append-command.spec.ts, tests/unit/sdk/history-read-primitives.spec.ts, tests/unit/core/shared/shared-primitives.spec.ts
Child continuation limits and samples are adjusted, and trailing-slash trimming uses a backward scan with adversarial regression coverage.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • unbraind/pm-cli#415: Touches the same exported CLI flag contract compositions used for cursor semantics.
  • unbraind/pm-cli#525: Overlaps the list, search, and context cursor-pagination surfaces.
  • unbraind/pm-cli#636: Overlaps derived item-metadata index plumbing and transactional projection behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant runSearch
  participant readWorkspaceMemory
  participant searchWorkspaceMemoryReadResult
  Client->>runSearch: execute search
  runSearch->>readWorkspaceMemory: load corpus memory
  readWorkspaceMemory->>searchWorkspaceMemoryReadResult: provide snapshot and cache status
  searchWorkspaceMemoryReadResult->>runSearch: return matching rollups
  runSearch->>Client: return search results with workspace_memory
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title succinctly summarizes the main changes: indexed reads, workspace memory, and cursor contract updates.
Description check ✅ Passed The description matches the changeset and objectives, covering the index, workspace memory, cursor semantics, docs, changelog, and security fix.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@sourcery-ai sourcery-ai 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.

Sorry @unbraind, your pull request is larger than the review limit of 150000 diff characters

@codspeed

codspeed Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 6 benchmarks

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 5 improved benchmarks
❌ 6 regressed benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ createQueryFingerprint 516.2 µs 517.8 µs -0.31%
❌ stableStringify (nested contract) 161.3 µs 161.5 µs -0.1%
❌ normalizeLowercaseWhitespace 135.8 µs 135.9 µs -0.02%
❌ tokenize + score query over 2000 docs 7.5 ms 7.5 ms -0.01%
❌ tokenizeAlphaNumeric 367.3 µs 367.3 µs 0%
❌ score query over 2000 docs 5.6 ms 5.6 ms 0%
⚡ decodeQueryCursor 116.1 µs 114.2 µs +1.64%
⚡ encodeQueryCursor 101.2 µs 101 µs +0.24%
⚡ build index (2000 docs x 80 words) 161.4 ms 161.3 ms +0.03%
⚡ jaccardSimilarity 153.3 µs 153.3 µs +0.03%
⚡ build index (200 docs x 40 words) 8.4 ms 8.4 ms 0%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/sdk-indexed-memory-and-cursor-contracts (0badc41) with main (221980a)

Open in CodSpeed

@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 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 @.agents/pm/history/pm-801d.jsonl:
- Line 77: Update the completion evidence in the metadata comment to remove the
unsupported claim of automatic external-mutation fallback, or explicitly state
that in-place external edits require forceSourceScan or reindex for recovery.
Keep the evidence limited to mutation paths actually supported by the
implementation.

In @.agents/pm/history/pm-v3zd3o.jsonl:
- Around line 8-9: Keep the issue open while hosted exact-head CodeQL closure
remains unverified. Update the metadata status and closure fields associated
with the close operation, or create an explicit follow-up task, so closure
occurs only after the hosted CodeQL result is recorded.

In @.agents/pm/issues/pm-v3zd3o.toon:
- Line 5: Update the issue status from closed to an open verification state
while hosted CodeQL exact-head closure remains pending. Keep it closed only
after confirming the hosted alert is cleared, consistent with the existing
closed-line comments and close_reason.

In `@CHANGELOG.md`:
- Around line 3-16: Add bullets under CHANGELOG.md’s Unreleased section
describing the persistent SQLite metadata query index with bounded indexed reads
and the compact standard pm get child projection. Place these user-visible
deliverables in the existing Unreleased categories, using the project’s
established issue references where available.
🪄 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: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4d42bd26-ae4d-4137-b299-cf752e832bac

📥 Commits

Reviewing files that changed from the base of the PR and between 221980a and c1c3ef0.

📒 Files selected for processing (44)
  • .agents/pm/chores/pm-fgih.toon
  • .agents/pm/extensions/.managed-extensions.json
  • .agents/pm/features/pm-5qmm.toon
  • .agents/pm/features/pm-801d.toon
  • .agents/pm/history/pm-5qmm.jsonl
  • .agents/pm/history/pm-801d.jsonl
  • .agents/pm/history/pm-b0twiy.jsonl
  • .agents/pm/history/pm-ds3b.jsonl
  • .agents/pm/history/pm-fgih.jsonl
  • .agents/pm/history/pm-v3zd3o.jsonl
  • .agents/pm/issues/pm-b0twiy.toon
  • .agents/pm/issues/pm-v3zd3o.toon
  • .agents/pm/tasks/pm-ds3b.toon
  • CHANGELOG.md
  • docs/COMMANDS.md
  • docs/CONTEXT_RELEVANCE.md
  • docs/PERFORMANCE.md
  • docs/SDK.md
  • src/cli/commands/context.ts
  • src/cli/commands/get.ts
  • src/core/shared/primitives.ts
  • src/core/store/item-metadata-cache.ts
  • src/core/store/item-metadata-query-index.ts
  • src/sdk/cli-contracts/flag-contracts.ts
  • src/sdk/index.ts
  • src/sdk/item-children.ts
  • src/sdk/item-metadata-index.ts
  • src/sdk/pagination.ts
  • src/sdk/query/list.ts
  • src/sdk/query/search-contracts.ts
  • src/sdk/query/search-pagination.ts
  • src/sdk/query/search.ts
  • src/sdk/workspace-memory.ts
  • tests/fixtures/contracts/full.json
  • tests/unit/commands/get-append-command.spec.ts
  • tests/unit/commands/list-command.spec.ts
  • tests/unit/commands/search-command.spec.ts
  • tests/unit/commands/workspace-memory-command-integration.spec.ts
  • tests/unit/core/item/item-metadata-derived-index.spec.ts
  • tests/unit/core/item/item-metadata-query-index.spec.ts
  • tests/unit/core/shared/shared-primitives.spec.ts
  • tests/unit/sdk/history-read-primitives.spec.ts
  • tests/unit/sdk/pagination.spec.ts
  • tests/unit/sdk/workspace-memory.spec.ts

Comment thread .agents/pm/history/pm-801d.jsonl Resolved
Comment thread .agents/pm/history/pm-v3zd3o.jsonl Resolved
Comment thread .agents/pm/issues/pm-v3zd3o.toon Resolved
Comment thread CHANGELOG.md Resolved
Append the direct-edit recovery correction, record exact-head CodeQL verification, add the non-duplicate completed indexed-read child boundary with full evidence, and regenerate the package-owned changelog.
@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit’s review invocation: acknowledged the included-review limit notice. The service subsequently completed its current-head analysis and posted four actionable threads, all of which have now been individually answered and resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit’s walkthrough: the architecture summary is accurate, but the generic 50% docstring warning is not. The repository-owned static gate measured 100% source, exported, and member docstring coverage, and the hosted static gate is green; no generated docstring mutation was applied.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding Gemini Code Assist: acknowledged that this consumer reviewer has been sunset. It supplied no code findings for this head, so no implementation action is applicable.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodSpeed’s report: reviewed and acknowledged. The report flags different runtime environments; the largest displayed regression is 0.24%, while six benchmarks improve and the repository’s hosted benchmark gate plus the 10k CLI/SDK scale gate pass. This is measurement noise below the project’s enforced budgets, so no code change is justified.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding Codecov: acknowledged. All modified coverable lines are covered, hosted coverage is green, and the literal all-source run remains exactly 100% statements, branches, functions, and lines.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding Sourcery’s review: acknowledged the service’s 150,000-character review ceiling. It produced no code findings; repository gates and the other current-head review surfaces cover the full broad PR.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit’s four-finding review: all four threads were verified against current code, answered inline, reacted to, and resolved. ac2fad2 records the recovery-contract correction, exact-head CodeQL evidence, and generated indexed-read/compact-get changelog entry.

@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head ac2fad2.\n\n@coderabbitai full review

Persist the accepted recovery clarification, exact-head CodeQL disposition, and generated-changelog resolution on their canonical tracker items.
@unbraind unbraind closed this Jul 23, 2026
@unbraind unbraind reopened this Jul 23, 2026
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review exact head 0badc41 after GitHub head refresh.\n\n@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

@unbraind I’ll perform a full review of the refreshed PR head 0badc416.

✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 35 minutes.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

@unbraind I’ll perform a full review of the current PR head (ac2fad26).

✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 34 minutes.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit invocation 66fb8baf: acknowledged. It targeted the true refreshed head 0badc41 but supplied only the included-review rate-limit notice and no new findings; the exact-head hosted check suite is fully green.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit invocation e834ca30: acknowledged as a stale pre-refresh invocation against ac2fad2. It supplied no findings, and the later 0badc41 invocation plus exact-head checks supersede it.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit empty review 4762222796: acknowledged. The review contains no body, inline comment, or actionable finding; current-head thread inventory remains empty.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit empty review 4762226384: acknowledged. The review contains no body, inline comment, or actionable finding; current-head thread inventory remains empty.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit empty review 4762232990: acknowledged. The review contains no body, inline comment, or actionable finding; current-head thread inventory remains empty.

@unbraind

Copy link
Copy Markdown
Owner Author

Regarding CodeRabbit empty review 4762233726: acknowledged. The review contains no body, inline comment, or actionable finding; current-head thread inventory remains empty.

@unbraind

unbraind commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

Tracked in PM: pm-5qmm, pm-801d, pm-ds3b, pm-fgih, pm-px153l, pm-v3zd3o.

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.

1 participant