Skip to content

Refactor x-integration skill architecture#129

Open
baijunjie wants to merge 1 commit intoqwibitai:mainfrom
baijunjie:refactor/x-integration
Open

Refactor x-integration skill architecture#129
baijunjie wants to merge 1 commit intoqwibitai:mainfrom
baijunjie:refactor/x-integration

Conversation

@baijunjie
Copy link
Copy Markdown
Contributor

@baijunjie baijunjie commented Feb 7, 2026

Summary

Overhaul the x-integration skill architecture to eliminate duplicated logic and fragile path dependencies, while adding image posting and post verification.

Architecture refactoring

The old skill had a monolithic design — agent.ts and host.ts lived directly in the skill directory and were imported via fragile paths. Each script manually located selectors, checked button states, and handled errors independently, resulting in a lot of duplicated code.

This refactoring:

  • Introduced a plugin architecture with templates/ directory — agent.ts and host.ts are standalone files copied to their destinations (container/agent-runner/src/plugins/ and src/plugins/) during installation, with no runtime dependency on the skill directory
  • Extracted shared logic into focused modules: lib/utils.ts (validation, UI interaction, toggle actions, dialog submission, post verification), lib/script.ts (stdin/stdout IO framework), lib/env.ts (.env loader replacing dotenv-cli), lib/browser.ts (browser context management)
  • Centralized all X page selectors into config.selectors — UI changes only need updating in one place
  • Gave the skill its own package.json with isolated dependencies (playwright, pino), keeping the root project clean
  • Renamed tool IDs from x_post/x_like to x-integration_post/x-integration_like for naming consistency
  • Added graceful SIGTERM handling for browser cleanup
  • Rewrote SKILL.md with clearer installation steps and architecture docs

New features

  • Image posting — post, reply, and quote now accept imagePaths, supporting up to 4 images per tweet
  • Post verification with tweet URL — after posting/quoting/replying, the script navigates to the user's profile to confirm the tweet actually went through, and returns the published tweet URL back to the agent. Previously there was no way to know if a tweet was actually posted — now the agent gets definitive confirmation with a direct link.

Dependency

⚠️ Depends on #128 — without it the agent can't access images sent via WhatsApp, so image posting won't work end-to-end. Please merge #128 first.

@baijunjie baijunjie requested a review from gavrielc as a code owner February 7, 2026 12:52
@baijunjie baijunjie closed this Feb 7, 2026
@baijunjie baijunjie reopened this Feb 7, 2026
@baijunjie
Copy link
Copy Markdown
Contributor Author

baijunjie commented Feb 7, 2026

Why this Skill modifies source files

X blocks browsers running inside containers, so this skill has to run Playwright on the host machine using the user's real Chrome. The IPC layer is the only way to bridge container agents to host-side scripts.

However, there's currently no plugin or hook mechanism in the MCP/IPC layer to register additional tools without modifying src/index.ts and container/agent-runner/src/ipc-mcp.ts directly.

@baijunjie baijunjie changed the title Refactor x-integration skill + WhatsApp media support Refactor x-integration skill architecture Feb 7, 2026
@baijunjie baijunjie force-pushed the refactor/x-integration branch 2 times, most recently from 19677c0 to be46541 Compare February 8, 2026 05:22
@baijunjie
Copy link
Copy Markdown
Contributor Author

Update: Extracted browser automation scripts (lib/ and scripts/) into a standalone package skill-x-social. The x-integration skill now only contains NanoClaw-specific integration code (templates/agent.ts and templates/host.ts), reducing the maintenance burden for developers.

@baijunjie baijunjie force-pushed the refactor/x-integration branch from 4e39cd0 to 9a7d583 Compare February 12, 2026 04:38
@baijunjie
Copy link
Copy Markdown
Contributor Author

Rebased and updated for the latest codebase. Integration points now reference the post-refactor files (ipc-mcp-stdio.ts and src/ipc.ts).

@TomGranot TomGranot added the Type: Skill Skill-only PR (no source code changes) label Feb 12, 2026
@TomGranot
Copy link
Copy Markdown
Collaborator

@gavrielc Skill-only PR — updates .claude/skills/x-integration/SKILL.md with cleaner npm-based approach. No source code changes. Reviewed and ready to merge.

@baijunjie
Copy link
Copy Markdown
Contributor Author

This test failure doesn’t seem to be related to my changes.

@baijunjie baijunjie force-pushed the refactor/x-integration branch 2 times, most recently from e1b5170 to a4a3825 Compare February 18, 2026 06:50
@Andy-NanoClaw-AI Andy-NanoClaw-AI added PR: Refactor Code restructuring without behavior change Status: Blocked Blocked by merge conflicts or dependencies labels Mar 5, 2026
@Andy-NanoClaw-AI
Copy link
Copy Markdown
Collaborator

Hey @baijunjie 👋 Thanks for working on refactoring the X integration skill — eliminating duplicated logic and fragile paths is exactly the right instinct!

Unfortunately this PR has merge conflicts with the current codebase. The X skill from #52 (merged) has also been the foundation for further development.

We plan to close this soon, but if you'd like to apply this refactor against the current main, a fresh PR would be very welcome! The architectural improvements you've outlined are solid. 🙌

- Replace local lib/ and scripts/ with skill-x-social npm package;
  host.ts resolves scripts via createRequire from skill directory
- Streamline implementation with shared libraries, reducing code
  duplication and minimizing installation footprint to 2 file changes
- Update integration points for post-refactor codebase: container
  ipc-mcp.ts → ipc-mcp-stdio.ts, host index.ts → ipc.ts
@baijunjie baijunjie force-pushed the refactor/x-integration branch from b77cbb4 to c1ddf77 Compare March 8, 2026 03:05
@baijunjie
Copy link
Copy Markdown
Contributor Author

I've rebased and updated this against the latest main branch. If you find this refactor useful, please merge it at your earliest convenience.

kenansun-dev-bot bot pushed a commit to kenansun-dev/nanoclaw-github-copilot that referenced this pull request Apr 12, 2026
…wibitai#129)

Allows agent (host or sandbox) to control nanoclaw via IPC:
- restart: delayed restart (2s to allow IPC cycle completion)
- reload_config: reload nanoclaw.json in memory
- set_config: change a config field and persist

Security:
- Only main group can issue control commands (isMain check)
- Whitelist of actions (no arbitrary command execution)
- Uses existing IPC file-based architecture

Agent-side: nanoclaw_control MCP tool in ipc-mcp-stdio.ts
Host-side: handleControlIpc in ipc.ts

2 files. 344/344 pass.

Co-authored-by: Kenan VM Claw <vm-claw@kenan.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Refactor Code restructuring without behavior change Status: Blocked Blocked by merge conflicts or dependencies Status: Pending Closure PR flagged for closure during triage Type: Skill Skill-only PR (no source code changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants