Skip to content

Dogfood TypeScript SDK into CLI (#35)#69

Open
shwetank-dev wants to merge 11 commits intomainfrom
issue-35-dogfood-SDK-into-CLI
Open

Dogfood TypeScript SDK into CLI (#35)#69
shwetank-dev wants to merge 11 commits intomainfrom
issue-35-dogfood-SDK-into-CLI

Conversation

@shwetank-dev
Copy link
Copy Markdown
Collaborator

Summary

  • Migrates all CLI commands to use the TypeScript SDK facade (MpakSDK) instead of direct API calls, eliminating duplicated logic
  • Rewires run command to use SDK.prepareServer, adding local bundle support
  • Migrates config commands to use SDK.MpakConfigManager
  • Cleans up bundle/skill commands: removes unsafe casts, deduplicates search param types, routes all human-readable output to stderr via logger
  • Rewrites integration tests to run the CLI as a subprocess; adds bundle and skill integration test suites
  • Formats all changed files with prettier

Test plan

  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes
  • Integration tests: ./node_modules/.bin/vitest run --config /dev/null tests/integration/bundle.integration.test.ts
  • Integration tests: ./node_modules/.bin/vitest run --config /dev/null tests/integration/skill.integration.test.ts

🤖 Generated with Claude Code

shwetank-dev and others added 11 commits March 30, 2026 15:46
… 1A)

Replace the CLI's internal ConfigManager with the SDK's MpakConfigManager
across all config command handlers (set, get, list, clear). This is the
first step in dogfooding the SDK within the CLI.

Changes:
- Add shared `mpakConfigManager` singleton in `cli/src/utils/config.ts`
  that reads MPAK_HOME and MPAK_REGISTRY_URL from env vars
- Rewrite `config.ts` to use the SDK singleton instead of instantiating
  CLI's ConfigManager per handler
- Rename `listPackagesWithConfig()` → `getPackageNames()` (SDK API)
- Export `PackageConfig` type from SDK's barrel (`index.ts`)
- Fix bug in `handleConfigGet` where non-JSON output was silently
  swallowed due to a nested conditional
- Remove unused `ConfigSetOptions` and `ConfigClearOptions` interfaces
- Add 23 end-to-end CLI tests for all config subcommands covering
  happy paths, --json output, and error cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…andling (#59 Phase 3C prereqs)

Extends the Mpak facade's prepareServer() to accept both registry and local
bundles via a discriminated union spec: { name, version? } for registry,
{ local } for local .mcpb files. This is the SDK groundwork needed before
the CLI can be thinned down to a dispatcher over prepareServer().

SDK changes:
- New PrepareServerSpec type replaces the old string-based packageName param
- prepareLocalBundle: hash-based cache dir, mtime-aware extraction, zip bomb
  protection, manifest schema validation
- New MpakInvalidBundleError for local bundle failures (distinct from
  MpakCacheCorruptedError which is for registry cache issues)
- readJsonFromFile now throws generic MpakError instead of MpakCacheCorruptedError;
  callers wrap with context-specific errors
- Helper functions: hashBundlePath, localBundleNeedsExtract
- 10 new tests for local bundle path through prepareServer
- All 182 tests pass, typecheck and lint clean

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace ~350 lines of inline cache management, manifest reading, command
resolution, env substitution, and python detection in run.ts with a
single call to mpak.prepareServer(). The CLI now only owns what it
should: --local path validation, interactive config prompting (catching
MpakConfigError), process spawning, signal forwarding, and the async
update-check notice.

SDK side: add `description` field to MpakConfigError.missingFields so
the CLI can render prompt hints (e.g. "API Key (Your OpenAI API key):").

Key changes:
- run.ts: delete parsePackageSpec, readManifest, resolveArgs,
  resolveWorkspace, substituteUserConfig, substituteEnvVars,
  getLocalCacheDir, localBundleNeedsExtract, findPythonCommand,
  gatherUserConfigValues, and all local type interfaces — all now in SDK
- run.ts: use shared mpak singleton from utils/config.ts
- run.ts: skip async update check when --update flag is set (just pulled
  latest) and log debug messages instead of silently swallowing errors
- Delete old src/commands/packages/run.test.ts (tested deleted helpers)
- Add tests/run.test.ts with 28 tests covering registry/local/update
  flows, async update check, config errors, CLI validation, process
  spawning, signal forwarding, and SDK error propagation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#59 Phase 4A+4B)

Replace createClient() with mpak.client across all search/show/pull/install
commands, delete cli/src/utils/client.ts, export z.input types from schemas
so the SDK reuses them instead of hand-rolling duplicates, and add search
command tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…se 4C)

Drop `as string` casts on `published_at` (already typed `string | Date`),
replace deprecated `fmtError` with `logger.error`, and add show.test.ts
with 9 tests covering all output paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Phase 4C)

Replace manual fetch with mpak.client.downloadBundle() which adds SHA-256
integrity verification. Use SDK's parsePackageSpec, formatSize helper, and
logger.error. Clean up partial file on error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Migrates skills/install, skills/pull, skills/search, skills/show to SDK
facade. Removes deleted utils (cache, config-manager) and their tests.
Moves all tests to tests/ tree with bundles/ and skills/ subdirectories.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ase 4C)

Adds logger.info (writes to stderr) and routes all status/table/progress
output through it. JSON output (--json) stays on stdout via console.log,
keeping stdout machine-readable. Updates all tests to assert on stderrSpy
for human output and stdoutSpy for JSON. Adds unified search.ts test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e skill error swallow (#59 Phase 4C)

- Replace hand-shaped UnifiedResult interface with Bundle | SkillSummary discriminated union
- Remove .catch(() => null) on skill search (stale workaround from pre-deployment era)
- Use real schema field names (latest_version, certification_level, description ?? "")
- Type predicate filters for proper TS narrowing after results.filter()
- Fix biome template literal warnings in table row builders
- Update test: "swallows skill errors" → "logs error when skill search throws"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ill integration tests

- Rewrite registry-client.test.ts: test bundle search/show via `node dist/index.js` instead of MpakClient directly
- Rewrite update-flow.test.ts: fix broken cache.js/client.js imports, test outdated/update commands as subprocesses with SDK for cache setup
- Add bundle.integration.test.ts: smoke tests for bundle pull (file download + JSON metadata)
- Add skill.integration.test.ts: smoke tests for skill search and show
- Add helpers.ts: shared run() helper that spawns the CLI and captures stdout/stderr/exitCode

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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