Repository navigation
Expose SDK runtime action client - #456
Conversation
Promote the shared pm action dispatcher into the public SDK runtime as runAction and PmClient so programmatic integrations can execute pm actions without spawning the CLI. Route MCP pm_run and narrow tools through the SDK dispatcher, document the new surface, cover it with focused SDK/MCP/docs-example tests, and refresh pm-changelog plus tracker evidence. Verification: pnpm typecheck; pnpm build; pnpm lint; pnpm quality:docs-skills; pnpm security:scan; node scripts/run-tests.mjs coverage (100/100/100/100); installed-package temp smoke; pnpm changelog:pm:check; pm validate --check-resolution --check-history-drift.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
📝 WalkthroughWalkthroughAdds a public SDK execution surface ( ChangesSDK execution surface and MCP integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant MCPServer
participant runAction
participant withActiveExtensions
participant SDK_ACTION_HANDLERS
MCPServer->>runAction: pm_run args
runAction->>withActiveExtensions: serialized dispatch
withActiveExtensions->>SDK_ACTION_HANDLERS: built-in action
SDK_ACTION_HANDLERS-->>runAction: result
runAction-->>MCPServer: result
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
|
@greptileai review |
|
@coderabbitai full review |
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
✅ Action performedFull review finished. |
|
Bot follow-up note after the first trigger round:
|
|
Your plan includes PR reviews subject to rate limits. More reviews will be available in 45 minutes. |
Greptile SummaryThis PR exposes the pm action runtime through the SDK and reuses it from MCP. The main changes are:
Confidence Score: 5/5Safe to merge with low risk. No blocking correctness or security issues were identified in the changed runtime, MCP, docs, or test paths. The shared dispatcher path has focused tests for SDK use, MCP behavior, filtering, and extension lifecycle cleanup. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant SDK as SDK consumer
participant Client as PmClient/runAction
participant MCP as MCP tools/call
participant Runtime as SDK runtime dispatcher
participant Extensions as Extension activation
participant Commands as pm command runners
SDK->>Client: create/list/update/close or runAction(args)
MCP->>Runtime: "runAction({ action, args })"
Client->>Runtime: "runAction({ defaults, action, options })"
Runtime->>Extensions: load + activate workspace extensions
Extensions-->>Runtime: active registries/commands
Runtime->>Commands: dispatch native or extension action
Commands-->>Runtime: action result
Runtime->>Extensions: reset globals + deactivate
Runtime-->>Client: result
Runtime-->>MCP: result
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant SDK as SDK consumer
participant Client as PmClient/runAction
participant MCP as MCP tools/call
participant Runtime as SDK runtime dispatcher
participant Extensions as Extension activation
participant Commands as pm command runners
SDK->>Client: create/list/update/close or runAction(args)
MCP->>Runtime: "runAction({ action, args })"
Client->>Runtime: "runAction({ defaults, action, options })"
Runtime->>Extensions: load + activate workspace extensions
Extensions-->>Runtime: active registries/commands
Runtime->>Commands: dispatch native or extension action
Commands-->>Runtime: action result
Runtime->>Extensions: reset globals + deactivate
Runtime-->>Client: result
Runtime-->>MCP: result
Reviews (1): Last reviewed commit: "Expose SDK runtime action client" | Re-trigger Greptile |
There was a problem hiding this comment.
1 issue found across 14 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sdk/runtime.ts">
<violation number="1" location="src/sdk/runtime.ts:1298">
P2: `pm plan` dispatch can fail with `Missing required argument: subcommand` when callers provide `subcommand` at the top level (the common narrow-tool shape), because `runMcpPlanAction` now reads only `ctx.options.subcommand`. Reading from top-level args first (then falling back to nested options) would keep plan consistent with other action handlers and avoid breaking existing callers.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Replace regex-based action-name sanitization with a linear scanner to clear the CodeQL polynomial-regex alert. Wrap JSON parsing in SDK reference scripts with contextual errors that preserve the original cause, and add malformed-output coverage for both examples. Record the CodeQL and Greptile follow-up evidence on pm-xzhz.
|
/gemini review |
|
@greptileai review |
|
@coderabbitai full review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 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 `@docs/examples/sdk-contract-consumer/inspect-contracts.mjs`:
- Around line 4-11: `parseContractsJson` should match the empty-stdout behavior
of `parsePmJson` in the sibling example by treating empty or whitespace-only
stdout as an empty object instead of trying to parse it. Update the
`parseContractsJson` helper in `inspect-contracts.mjs` so it trims the input and
returns a fallback `{}` for empty output before calling `JSON.parse`, keeping
the existing error wrapping for real parse failures.
In `@src/sdk/runtime.ts`:
- Around line 363-414: The PmClient SDK methods and runAction currently erase
native action result types by returning Promise<unknown>, so add typed overloads
or an action-to-result mapping for the built-in actions before stabilizing the
API. Update the runtime in runtime.ts around run, context, list, search, get,
create, update, and close so native actions return precise typed results while
keeping extension/custom actions as unknown, and ensure the typing flows through
runAction without changing the call sites.
- Around line 1589-1595: The dispatch context in McpActionDispatchContext is
only reading force from top-level args, so claim/release can miss a force value
passed via options. Update the ctx construction in the dispatch path (around
runAction and the ctx.force field) to honor options.force as the primary source,
with args.force as fallback if needed, so actions like claim and release see the
correct force state.
- Around line 1292-1299: The parseMcpIntegerPrefix helper is truncating
fractional numeric inputs because it uses Number.parseInt on numbers, so update
parseMcpIntegerPrefix to reject non-integer numeric values instead of coercing
them. In the typeof value === "number" branch, validate the raw number with
Number.isInteger/Number.isFinite (or equivalent) and throw the existing
PmCliError for values like 1.5, while keeping the current handling for valid
integers and the rest of runtime.ts unchanged.
- Around line 846-852: The early return paths in runtime.ts’s activation flow
call run(null) without resetting the process-global extension registry state, so
clear the active registries before both the global.noExtensions branch and the
missing-settings branch. Update the logic around resolvePmRoot, getSettingsPath,
and run so that any built-in handlers consulting registry state cannot see stale
data from a previous activation when noExtensions is enabled or no workspace
settings exist.
In `@tests/unit/docs-examples/sdk-app-embedding.spec.ts`:
- Line 37: The `node:child_process` mock in `sdk-app-embedding.spec.ts` includes
an unused `execFile` stub that is dead scaffolding. Remove the `execFile:
vi.fn()` entry from the relevant `vi.doMock` setup and keep only the `spawnSync`
mock, since `run-embedded-pm.mjs` is exercised through `spawnSync` only; check
the `vi.doMock` calls in this spec to update both mock declarations
consistently.
🪄 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: 83dfbea1-0f9c-4e6c-820f-21106eb64a77
📒 Files selected for processing (17)
.agents/pm/decisions/pm-muhw.toon.agents/pm/features/pm-xzhz.toon.agents/pm/history/pm-muhw.jsonl.agents/pm/history/pm-xzhz.jsonlCHANGELOG.mddocs/SDK.mddocs/examples/sdk-app-embedding/run-embedded-pm.mjsdocs/examples/sdk-contract-consumer/inspect-contracts.mjseslint-suppressions.jsonscripts/release/sdk-import-boundary-baseline.jsonscripts/release/static-quality-gate.mjssrc/mcp/server.tssrc/sdk/runtime.tstests/unit/docs-examples/sdk-app-embedding.spec.tstests/unit/docs-examples/sdk-contract-consumer.spec.tstests/unit/mcp/mcp-server-branch-residual.spec.tstests/unit/sdk/sdk-index.spec.ts
💤 Files with no reviewable changes (1)
- eslint-suppressions.json
There was a problem hiding this comment.
1 issue found across 8 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
/gemini review |
|
@greptileai review |
|
@coderabbitai full review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
✅ Action performedFull review finished. |
efd47f2 to
763570c
Compare
Summary
runActionandPmClientfrom the SDK runtime/barrel so integrations can execute pm actions in-process without spawning the CLI.PM tracking
pm-xzhzunder the SDK customization lineagepm-usfg.pm-muhwas the architecture decision supporting the SDK runtime-first path.Verification
node scripts/run-tests.mjs test -- tests/unit/sdk/sdk-index.spec.ts tests/integration/mcp-handshake.spec.ts tests/unit/mcp/mcp-server-branch-residual.spec.tsnode scripts/run-tests.mjs test -- tests/unit/docs-examples/sdk-app-embedding.spec.ts tests/unit/docs-examples/sdk-contract-consumer.spec.tspnpm typecheckpnpm buildpnpm lint(ESLint, jscpd 0 clones, static quality gate)pnpm quality:docs-skillspnpm security:scanpnpm audit --audit-level moderatepm validate --check-resolution --check-history-drift(history drift ok; existing closed-item resolution metadata warnings remain)pnpm changelog:pm && pnpm changelog:pm:checknode scripts/run-tests.mjs coverage-> 264 files, 5424 tests, 100% statements/branches/functions/lines@unbrained/pm-cli, installed it, imported@unbrained/pm-cli/sdk/runtime, initialized a tracker, and usedPmClient/runActionfor create/list/search/get/update/context/direct-context/close.node scripts/release/sentry-telemetry-gate.mjs --json --telemetry-mode best-effort --sentry-window-days 14 --max-critical 0 --max-high 0passed with recent critical/high Sentry counts at 0 and telemetry rows present.greptile review --agent --branch origin/mainran before push. The CLI returned cached review88db4c20-531f-4c98-8148-df5f43caf6d2; both returned comments were already fixed in the pushed head (src/mcp/server.tsno duplicate helper;src/sdk/runtime.tsdeactivates after activation).External state checked
pm-changeloglatest available npm version is2026.6.30; package-owned changelog generation/check passed with that version.Summary by cubic
Expose an in-process action client in the SDK so integrations can run pm actions without spawning the CLI; MCP tools now use the same dispatcher. Adds workspace contracts caching and typed action alias support, with tighter dispatch and safer example parsing.
New Features
PmClientandrunActionare exported from@unbrained/pm-cli/sdk/runtimeand re-exported in@unbrained/pm-cli/sdk; MCPpm_runand narrow tools use this dispatcher; docs add usage, shared SDK/MCP activation serialization, and per-call runtime overrides.ctx, task lifecycle, andpackage-*flows) via the shared runtime path.clearWorkspaceContractsCacheto reset long‑lived hosts.Bug Fixes
plantop-level dispatch from narrow tool calls and routed aliases through the runtime.pm contractsstdout.Written for commit 8c40979. Summary will update on new commits.