Skip to content

feat(sdk): own schema primitives and modernize init prefixes - #563

Merged
unbraind merged 3 commits into
mainfrom
feat/sdk-schema-ownership-init-prefix
Jul 14, 2026
Merged

unbraind merged 3 commits into
mainfrom
feat/sdk-schema-ownership-init-prefix

Conversation

@unbraind

@unbraind unbraind commented Jul 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • move the complete schema inspection/mutation engine into src/sdk/schema.ts, leaving the CLI command as a compatibility re-export and routing SDK/MCP runtime dispatch through the SDK owner
  • remove 17 CLI private-core boundary edges, prune four stale schema suppressions, and tighten the hard ESLint suppression budget from 174 to 170
  • add pm init --id-prefix <value> with --prefix alias, positional compatibility, equivalent-input normalization, deterministic conflict guidance, contracts, bash/zsh/fish completion, and docs
  • reconcile GitHub dependency/security state and preserve the package-owned changelog generated by pm-changelog@2026.7.14-2

pm items

Verification

  • node scripts/run-tests.mjs coverage: 290 files, 5,701 tests, exact 100% statements (36,848/36,848), branches (26,463/26,463), functions (7,438/7,438), and lines (35,963/35,963)
  • pnpm typecheck, pnpm lint:eslint, pnpm lint:duplicates, pnpm quality:static, pnpm quality:docs-skills, pnpm contracts:check
  • pnpm security:scan, pnpm audit --audit-level high, pnpm version:check
  • packed npm smoke plus fresh external consumer: installed tarball, initialized a temporary vcs- workspace, registered a custom ChangeSet type through the installed CLI, and created/read it through installed PmClient
  • 88-command package-first dogfood passed
  • tracker-aware linked acceptance tests passed for all three pm items
  • live GitHub Dependabot/code-scanning/secret-scanning APIs each report zero open alerts
  • telemetry is healthy (finish_error_rate_pct=0.34, zero failures missing error_code); strict Sentry release readiness remains independently blocked by the already tracked external integration issues pm-d4ns / PM-CLI-2B and pm-7n5a / PM-CLI-29, neither introduced or modified by this branch

Summary by cubic

Moves schema inspection and mutation into SDK-owned primitives and adds canonical --id-prefix/--prefix to pm init with robust, cross‑platform validation. This reduces CLI/MCP coupling and fixes the init prefix UX.

  • Refactors

    • Schema engine now lives in src/sdk/schema.ts; the CLI schema command is a thin adapter and CLI/MCP calls route through the SDK for consistent behavior.
    • Removed 17 private-core import edges and tightened the ESLint suppression budget from 174 to 170.
  • Bug Fixes

Written for commit 4c2786c. Summary will update on new commits.

Review in cubic

Move the complete schema inspection and mutation engine into the public SDK while retaining a thin CLI compatibility adapter. Burn 17 private-core import edges and tighten the ESLint suppression ratchet from 174 to 170.

Add canonical pm init --id-prefix support with --prefix alias, deterministic positional conflict handling, shell completions, runtime contracts, docs, tracker evidence, and packed-consumer coverage.

Verified 5,701 tests at 100/100/100/100 coverage, strict static/docstring/package/token gates, contracts, security/version checks, packed npm smoke, 88-command dogfood, and fresh temporary-workspace SDK/CLI acceptance.

@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

@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review the current head.

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 59 minutes.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds pm init --id-prefix and --prefix support with conflict validation, moves schema command ownership into the SDK, rewires CLI/runtime consumers, updates completion and contract coverage, and records related quality, documentation, and project-tracking changes.

Changes

Init ID-prefix support

Layer / File(s) Summary
Init prefix contract and wiring
src/cli/register-setup.ts, src/sdk/cli-contracts/..., src/cli/commands/completion.ts, docs/COMMANDS.md, tests/fixtures/...
Adds --id-prefix with --prefix alias across registration, contracts, completions, fixtures, documentation, and changelog tracking.
Init prefix resolution and validation
src/cli/commands/init.ts, tests/unit/commands/init-command.spec.ts
Resolves positional and flagged prefixes, rejects empty values and conflicting inputs, and persists the normalized prefix.
Init integration and behavior coverage
tests/integration/init-path-guard.integration.spec.ts, tests/unit/commands/init-command.spec.ts
Expands coverage for init path safety, guidance, presets, hooks, interactive flows, repairs, and prefix forwarding.

SDK schema ownership

Layer / File(s) Summary
SDK schema contracts and engine
src/sdk/schema.ts
Adds typed schema command contracts and SDK implementations for schema mutation, inspection, presets, inference, persistence, warnings, and formatting.
CLI compatibility and SDK runtime wiring
src/cli/commands/schema.ts, src/sdk/runtime.ts
Replaces the CLI schema implementation with an SDK re-export and imports schema runners directly from the SDK runtime module.
Boundary and quality updates
scripts/release/..., eslint-suppressions.json, docs/SDK.md, tests/unit/mcp/..., .agents/pm/...
Removes obsolete schema boundary and lint baselines, updates quality limits, documents SDK ownership, and adjusts tracking and mocks.
Completion generation validation
tests/unit/commands/completion-command.spec.ts
Validates shell completion output, runtime schema choices, flag deduplication, and schema-subcommand drift.

Project tracking reconciliation

Layer / File(s) Summary
Dependency and security tracking
.agents/pm/chores/..., .agents/pm/epics/..., .agents/pm/history/...
Adds reconciliation comments and refreshed timestamps for dependency compatibility and security-scan status.

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

Possibly related issues

  • unbraind/pm-cli#562 — Directly tracks the pm init --id-prefix/--prefix behavior implemented here.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% 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 clearly summarizes the two main changes: SDK-owned schema primitives and init prefix support.
Description check ✅ Passed The description is directly related to the changeset and accurately covers the schema refactor, init prefix work, and related cleanup.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@codecov

codecov Bot commented Jul 14, 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!

@greptile-apps

greptile-apps Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR moves schema ownership into the SDK and adds explicit init prefix flags. The main changes are:

  • Schema inspection and mutation now live in src/sdk/schema.ts.
  • CLI schema handling stays available through a compatibility re-export.
  • SDK runtime dispatch imports schema primitives directly.
  • pm init now accepts --id-prefix and --prefix.
  • Init prefix inputs are normalized and path-like flag values are rejected.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • Reviewed the general-contract-validation-proof and confirmed that the init-prefix validation run completed with exit code 0 for both the Init/path guard suite and the Completion command suite.
  • Opened the proof artifact titled Init-prefix validation log to verify that it documents the exact commands, working directory, Vitest output, and exit codes used during validation.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/cli/commands/init.ts Adds init prefix resolution, conflict handling, and path-like prefix rejection.
src/cli/register-setup.ts Registers the init prefix flags and forwards their value into the init action.
src/sdk/schema.ts Moves schema inspection and mutation behavior into the SDK.
src/cli/commands/schema.ts Keeps the CLI schema module as a compatibility re-export.
src/sdk/runtime.ts Routes schema runtime actions through SDK-owned schema primitives.

Reviews (6): Last reviewed commit: "fix(init): reject drive-relative prefix ..." | Re-trigger Greptile

Comment thread src/cli/commands/init.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR moves schema ownership into the SDK and adds a flag-based init prefix path. The main changes are:

  • Schema command logic moved into src/sdk/schema.ts.
  • CLI schema command kept as a compatibility re-export.
  • SDK and MCP schema dispatch routed through the SDK module.
  • pm init docs, contracts, and completions updated for --id-prefix and --prefix.
  • Import-boundary and lint suppression budgets tightened.

Confidence Score: 4/5

The changed CLI parsing path needs attention before merging.

pm init --prefix <value> can parse the value under options.prefix, while the init handler only forwards options.idPrefix; that can silently initialize with the wrong item ID prefix. The schema ownership move looks consistent with the inspected import and dispatch paths.

src/cli/register-setup.ts

T-Rex T-Rex Logs

What T-Rex did

  • Built the CLI with pnpm build and ran the harness against the built CLI to exercise the three init variants, verifying the id_prefix value is ops- across all runs and that both the CLI JSON output and the settings file reflected the prefix.
  • Validated the id-prefix proof with targeted Vitest tests, which reported all tests passed (35/35) for the init-id-prefix suite.
  • Ran a fresh-workspace init to confirm the id_prefix value is vcs- and that the settings grep matched accordingly.
  • Performed an end-to-end init plus create sequence, confirming the id_prefix is vcs- and a generated task id vcs-gz3s, with a smoke script used to drive and capture the proof.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/cli/register-setup.ts Adds the new init prefix option wiring, but the alias value can be parsed under a name the handler does not forward.
src/cli/commands/init.ts Adds prefix normalization and conflict handling for positional and flag-based init inputs.
src/sdk/schema.ts Owns the moved schema inspection and mutation engine for SDK and runtime callers.
src/cli/commands/schema.ts Keeps the old CLI schema module path as a re-export from the SDK implementation.
src/sdk/runtime.ts Imports schema runners from the SDK-owned module for runtime dispatch.
src/cli/commands/completion.ts Adds shell completions for the new init prefix flags.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/cli/register-setup.ts:1036
**Init Prefix Value Is Dropped**

When `pm init --prefix ops` is parsed, the option value is stored under the `prefix` option name while `runInitCommandAction` only forwards `options.idPrefix`. That makes the new alias silently fall back to the default or positional prefix, so the initialized tracker can use the wrong item ID prefix.

Reviews (2): Last reviewed commit: "feat(sdk): make schema ownership SDK-fir..." | Re-trigger Greptile

Comment thread src/cli/register-setup.ts Resolved

@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: 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 `@src/sdk/schema.ts`:
- Around line 576-581: Replace the duplicated tracker-initialization checks in
runSchemaAddType and loadSchemaInspectionContext with calls to the shared
ensureInitialized(pmRoot) helper. Preserve the existing error behavior by
keeping ensureInitialized as the single implementation of the pathExists check,
message, and EXIT_CODE.NOT_FOUND handling.
- Around line 702-706: Extract the repeated warning deduplication and
locale-aware sorting into a shared finalizeWarnings(warnings: string[]):
string[] helper in the schema module, then replace the inline expressions in all
eight run* mutation functions with calls to that helper while preserving the
existing generated_at handling and warning semantics.
🪄 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

Run ID: 2b41f620-f1e5-4948-9244-f99e3a03a605

📥 Commits

Reviewing files that changed from the base of the PR and between d5c181e and 50c9aad.

📒 Files selected for processing (28)
  • .agents/pm/chores/pm-2a9n.toon
  • .agents/pm/epics/pm-qwoy.toon
  • .agents/pm/features/pm-3mna.toon
  • .agents/pm/history/pm-2a9n.jsonl
  • .agents/pm/history/pm-3mna.jsonl
  • .agents/pm/history/pm-9x6e.jsonl
  • .agents/pm/history/pm-nmzx.jsonl
  • .agents/pm/history/pm-qwoy.jsonl
  • .agents/pm/issues/pm-nmzx.toon
  • .agents/pm/tasks/pm-9x6e.toon
  • CHANGELOG.md
  • docs/COMMANDS.md
  • docs/SDK.md
  • eslint-suppressions.json
  • scripts/release/sdk-import-boundary-baseline.json
  • scripts/release/static-quality-gate.mjs
  • src/cli/commands/completion.ts
  • src/cli/commands/init.ts
  • src/cli/commands/schema.ts
  • src/cli/register-setup.ts
  • src/sdk/cli-contracts/flag-contracts.ts
  • src/sdk/runtime.ts
  • src/sdk/schema.ts
  • tests/fixtures/contracts/full.json
  • tests/integration/init-path-guard.integration.spec.ts
  • tests/unit/commands/completion-command.spec.ts
  • tests/unit/commands/init-command.spec.ts
  • tests/unit/mcp/mcp-server-branch-residual.spec.ts
💤 Files with no reviewable changes (2)
  • scripts/release/sdk-import-boundary-baseline.json
  • eslint-suppressions.json

Comment thread src/sdk/schema.ts Resolved
Comment thread src/sdk/schema.ts Resolved
Reject path-like --id-prefix values with structured recovery guidance, centralize schema initialization checks, and deduplicate stable warning finalization across all mutation results.

Record round-one Greptile and CodeRabbit decisions in pm, including evidence that the --prefix alias is correctly forwarded. Verified focused tests, static quality, and all 5,701 tests at exact 100/100/100/100 coverage.
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review the updated current head 8b2f6a2.

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 35 minutes.

Comment thread src/cli/commands/init.ts Resolved
Treat Windows drive-relative values such as C:tracker as path-shaped init input, keep structured error guidance consistent across platforms, and add unit plus built-CLI integration coverage. Record the second PR review round and exact 100/100/100/100 repository coverage in pm-nmzx before closing and releasing the actively worked item.
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai please review updated current head 4c2786c.

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 17 minutes.

@unbraind

Copy link
Copy Markdown
Owner Author

Acknowledged @gemini-code-assist: this final-head request is quota-limited, so no Gemini finding was available to act on. The exact head is covered by the complete local and hosted gates plus the completed Greptile and CodeRabbit surfaces.

@unbraind

Copy link
Copy Markdown
Owner Author

Acknowledged @coderabbitai: the final-head review completed without a new inline finding. All earlier actionable threads were addressed, answered, and resolved on commit 4c2786c.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@unbraind Acknowledged — thanks for confirming. Glad the final head at commit 4c2786c has all actionable threads addressed and resolved with no new findings from the review. Let me know if anything else comes up.

@unbraind

Copy link
Copy Markdown
Owner Author

Acknowledged final automated status comments 4974028895 and 4974030496: the quota notice introduces no actionable finding, and the chat-usage tip likewise requires no code change. Both were read and positively reacted to; the exact-head review inventory has zero unresolved threads.

@unbraind

unbraind commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

Tracked in PM: pm-3mna, pm-7n5a, pm-9x6e, pm-d4ns, pm-nmzx.

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