npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

capacitor-native-agent

v0.4.2

Published

Native AI agent loop for Capacitor — runs LLM completions, tool execution, and cron jobs in native Rust, enabling background execution.

Downloads

2,882

Readme

capacitor-native-agent

Native AI agent loop for Capacitor apps. Runs LLM completions, tool execution, cron jobs, and session persistence in native Rust via UniFFI, enabling true background execution on mobile.

Features

  • Native agent loop — LLM streaming, multi-turn tool calling, abort/steer
  • Built-in tools — File I/O, git (libgit2), grep, shell exec, fetch
  • SQLite persistence — Sessions, cron jobs, skills, scheduler/heartbeat config
  • Background execution — Runs outside the WebView lifecycle (WorkManager / BGProcessingTask)
  • Auth management — API key and OAuth token storage with refresh
  • Cron & heartbeat — Scheduled agent runs with wake evaluation
  • MCP support — Model Context Protocol server integration
  • Event bridge — Streams events (text_delta, tool_use, tool_result, etc.) to the WebView

Install

npm install capacitor-native-agent
npx cap sync

Android Setup

The npm package includes the Kotlin plugin source and UniFFI bindings, but not the compiled Rust shared library. You must build and place it yourself:

1. Build the Rust .so

cd rust/native-agent-ffi
cargo ndk -t arm64-v8a build --release

2. Place the .so in your app

Copy the built library to your Android app's jniLibs:

cp target/aarch64-linux-android/release/libnative_agent_ffi.so \
   <your-app>/android/app/src/main/jniLibs/arm64-v8a/

3. Sync and build

npx cap sync android
cd android && ./gradlew assembleDebug

Usage

import { NativeAgent } from 'capacitor-native-agent'

// Listen for agent events
NativeAgent.addListener('nativeAgentEvent', (event) => {
  const { eventType, payloadJson } = event
  const payload = JSON.parse(payloadJson)

  if (eventType === 'text_delta') {
    process.stdout.write(payload.text)
  }
})

// Initialize
await NativeAgent.initialize({
  dbPath: 'files://agent.db',
  workspacePath: '/path/to/workspace',
  authProfilesPath: '/path/to/auth-profiles.json',
})

// Set auth
await NativeAgent.setAuthKey({
  key: 'sk-ant-...',
  provider: 'anthropic',
  authType: 'api_key',
})

// Send a message
const { runId } = await NativeAgent.sendMessage({
  prompt: 'Hello!',
  sessionKey: 'session-1',
  systemPrompt: 'You are a helpful assistant.',
})

API

See definitions.ts for the full TypeScript interface.

Core Methods

| Method | Description | |--------|-------------| | initialize() | Create the native agent handle | | sendMessage() | Start an agent turn | | followUp() | Continue the conversation | | abort() | Cancel the running turn | | steer() | Inject guidance into a running turn |

Auth

| Method | Description | |--------|-------------| | getAuthToken() | Get stored auth token | | setAuthKey() | Store API key or OAuth token | | deleteAuth() | Remove auth for a provider | | refreshToken() | Refresh an OAuth token | | getAuthStatus() | Get masked key status |

Sessions

| Method | Description | |--------|-------------| | listSessions() | List all sessions | | loadSession() | Load session message history | | resumeSession() | Resume a previous session | | clearSession() | Clear current session |

Cron & Scheduling

| Method | Description | |--------|-------------| | addCronJob() | Create a scheduled job | | updateCronJob() | Update job config | | removeCronJob() | Delete a job | | listCronJobs() | List all jobs | | runCronJob() | Force-trigger a job | | handleWake() | Evaluate due jobs (called from WorkManager) | | getSchedulerConfig() | Get scheduler + heartbeat config | | setSchedulerConfig() | Update scheduler config | | setHeartbeatConfig() | Update heartbeat config |

Tools

| Method | Description | |--------|-------------| | invokeTool() | Execute a tool directly | | startMcp() | Start MCP server | | restartMcp() | Restart MCP with new tools |

Event Types

Events are emitted via addListener('nativeAgentEvent', handler):

  • text_delta — Streaming text chunk
  • thinking — Model thinking content
  • tool_use — Tool invocation started
  • tool_result — Tool completed
  • agent.completed — Turn finished with usage stats
  • agent.error — Error occurred
  • approval_request — Tool needs user approval
  • cron.job.started / cron.job.completed / cron.job.error — Cron lifecycle
  • heartbeat.* — Heartbeat lifecycle
  • scheduler.status — Scheduler state updates

Platform Support

| Platform | Status | |----------|--------| | Android | Supported | | iOS | Not yet implemented | | Web | N/A (throws unavailable error) |

License

MIT