Skip to content

refactor: monorepo adapter separation (clis/ at root)#782

Merged
jackwener merged 6 commits intomainfrom
refactor/monorepo-adapters
Apr 4, 2026
Merged

refactor: monorepo adapter separation (clis/ at root)#782
jackwener merged 6 commits intomainfrom
refactor/monorepo-adapters

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

  • Move src/clis/ → root clis/ to separate adapters from CLI runtime
  • Create root-level shim files (registry.ts, errors.ts, types.ts, utils.ts, logger.ts, launcher.ts, browser/, download/, pipeline/*) so adapter relative imports (../../registry.js) resolve correctly without modifying any adapter code
  • Change tsconfig.json rootDir from "src" to "." — output becomes dist/src/ + dist/clis/
  • Update all build scripts (build-manifest, copy-yaml, main.ts, discovery.ts) for new path structure
  • Expand ensureUserCliCompatShims() to cover all 14 adapter import targets
  • Add scripts/fetch-adapters.js postinstall script for ~/.opencli/clis/ sync (git sparse-checkout with tarball fallback)
  • Add files field in package.json to exclude adapters from npm package
  • Update vitest.config.ts adapter test paths

Update Strategy

  • Official adapter files (tracked in adapter-manifest.json) are unconditionally overwritten on update
  • User-created files not in the manifest are preserved
  • File-level granularity — no conflict if user adds new site adapters

Test plan

  • tsc compiles cleanly
  • npm run build (clean-dist + tsc + clean-yaml + copy-yaml + build-manifest) succeeds
  • Manifest: 479 entries (121 YAML, 358 TS)
  • Unit tests: 42 files, 490 tests pass
  • Adapter tests: 125 files, 738 tests pass
  • CLI entry point (dist/src/main.js) runs correctly

…aration

Separates CLI adapters from the core runtime to prepare for independent
adapter distribution via postinstall fetch.

Key changes:
- Move src/clis/ → clis/ (adapters at repo root)
- Change tsconfig rootDir from "src" to "." so tsc compiles both
- Create root-level shim files (registry.ts, errors.ts, etc.) so adapter
  relative imports (../../registry.js) resolve correctly
- Update build-manifest.ts, main.ts paths for new dist/src/ structure
- Expand ensureUserCliCompatShims() to cover all adapter import targets
  (types, utils, logger, launcher, browser/*, download/*, pipeline/*)
- Add scripts/fetch-adapters.js postinstall for ~/.opencli/clis/ sync
- Update vitest.config.ts adapter test paths
- Add package.json files field to exclude adapters from npm package

Official adapter files are unconditionally overwritten on update;
user-created files not in the manifest are preserved.
…adapters

- Add dist/clis/ and dist/cli-manifest.json to package.json files field
  so built-in adapters and manifest ship with the npm package
- Replace execSync with execFileSync to prevent command injection
- Add version check to skip redundant adapter fetches
- Track tmpRoot explicitly for reliable cleanup
…tch, first-run fallback

1. Manifest-based update strategy:
   - Read old manifest to identify previously-official files
   - Clean up files removed upstream (in old manifest but not new)
   - User-created files (never in any manifest) remain untouched

2. Only run fetch-adapters on global install (npm_config_global=true)
   or explicit OPENCLI_FETCH=1, preventing heavy side effects for
   local/dev installs

3. First-run fallback in discovery.ts:
   - ensureUserAdapters() checks for adapter-manifest.json
   - If missing and ~/.opencli/clis/ is empty, spawns fetch-adapters.js
   - Guarantees adapters are available even with --ignore-scripts
Adapters already ship in the npm package (dist/clis/), so there's no
need to clone from GitHub. Copy directly from the installed package:

- Eliminates git, curl, tar dependencies
- No network calls in postinstall
- No timeout/offline issues
- Version always matches the installed CLI
- ~65 lines of clone/download code replaced by one cpSync loop
@jackwener jackwener merged commit 80eef46 into main Apr 4, 2026
10 of 11 checks passed
@jackwener jackwener deleted the refactor/monorepo-adapters branch April 4, 2026 17:46
jackwener added a commit that referenced this pull request Apr 4, 2026
check-doc-coverage.sh still referenced src/clis/ after PR #782 moved
adapters to root clis/. This caused CI to fail with "0/1 documented".
jackwener added a commit that referenced this pull request Apr 4, 2026
* fix: review follow-ups — better first-run log, OPENCLI_FETCH=1 skips version check

- Clarify first-run log message: "copying adapters (one-time setup)"
- Add comment explaining why scriptPath uses two levels of ../
- OPENCLI_FETCH=1 now bypasses version-skip to allow forced refresh

* fix: update doc-coverage script path after clis/ move

check-doc-coverage.sh still referenced src/clis/ after PR #782 moved
adapters to root clis/. This caused CI to fail with "0/1 documented".

* fix: resolve package root dynamically for symlink and first-run paths

The symlink at ~/.opencli/node_modules/@jackwener/opencli pointed to
dist/ instead of the package root in prod mode, breaking user TS CLIs
that import from '@jackwener/opencli/registry'.

The first-run scriptPath also resolved incorrectly in dev mode.

Extract findPackageRoot() that walks up to find package.json, fixing
both paths for dev (src/) and prod (dist/src/) layouts.
jackwener added a commit to gucasbrg/opencli that referenced this pull request Apr 4, 2026
- Rebase onto main after clis/ move (PR jackwener#782)
- Remove installInterceptor calls (no longer used after waitForCapture removal)
- Change strategy from INTERCEPT to PUBLIC (browser: true) to match actual behavior
- Improve polling loop readability
jackwener added a commit that referenced this pull request Apr 4, 2026
* fix(36kr): replace waitForCapture with DOM polling for search/hot

waitForCapture(6) always times out on 36kr because the API intercept
never captures a matching request. However, the DOM is already fully
rendered with search/hot results by the time the timeout fires.

Replace the 6-second intercept wait with a DOM polling loop that checks
for article links (a[href*="/p/"]) every 300ms, returning immediately
once content is available (typically ~1s vs 6s timeout + error).

Tested on opencli 1.6.2 with both CDP and Browser Bridge modes.

* fix: rebase onto main, remove unused interceptor, fix strategy

- Rebase onto main after clis/ move (PR #782)
- Remove installInterceptor calls (no longer used after waitForCapture removal)
- Change strategy from INTERCEPT to PUBLIC (browser: true) to match actual behavior
- Improve polling loop readability

---------

Co-authored-by: buruguo <buruguo@lambdafintech.com>
Co-authored-by: jackwener <jakevingoo@gmail.com>
jackwener added a commit to linxule/opencli that referenced this pull request Apr 4, 2026
New adapter files were created at src/clis/lesswrong/ but PR jackwener#782 moved
all adapters to root clis/. Move to correct location.
jackwener added a commit that referenced this pull request Apr 4, 2026
* feat(lesswrong): add LessWrong adapter

15 commands for the LessWrong rationality and AI alignment community:
- Post listings: curated, frontpage, new, top, top-week/month/year
- Content: read (full post), comments, shortform (quick takes)
- Discovery: tag, tags, sequences
- Users: user (profile), user-posts

All commands use the public GraphQL API (no browser required).
Time-filtered views use the `after` date parameter.
Tag lookup resolves slugs to IDs via the `tagBySlug` view.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: move lesswrong adapter to clis/ (post PR #782 restructure)

New adapter files were created at src/clis/lesswrong/ but PR #782 moved
all adapters to root clis/. Move to correct location.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: jackwener <jakevingoo@gmail.com>
jackwener added a commit to zhangtaopy/opencli that referenced this pull request Apr 4, 2026
Post PR jackwener#782 restructure: adapter files live at root clis/, not src/clis/.
jackwener added a commit that referenced this pull request Apr 4, 2026
* feat(hupu): add hupu cli adapter

* fix(hupu): prevent detail from returning the wrong thread

* refactor: deduplicate shared utilities in hupu adapter

- Merge postHupuJson and postHupuReplyJson into single function with mode parameter
- Move stripHtml and decodeHtmlEntities to utils.ts, remove duplicate definitions

* fix(hupu): add mentions command

* fix: move mentions.ts to clis/hupu/, remove src/clis/hupu duplicates

Post PR #782 restructure: adapter files live at root clis/, not src/clis/.

---------

Co-authored-by: jackwener <jakevingoo@gmail.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