Skip to content

Development

jkrandom-sudo edited this page Jul 18, 2026 · 1 revision

Development

Entry points

  • opencode-plugin-loop and opencode-plugin-loop/server: scheduling server plugin
  • opencode-plugin-loop/tui: native interactive result dialog
  • Root export: backward-compatible server entrypoint

OpenCode 1.17.18 or newer detects the server and TUI targets when the package is installed through opencode plugin.

Runtime model

Each task owns a sessionID. A 5-second ticker checks due tasks, but a task fires only when its session is active. Persistent state lives under .opencode/cache/loop/; deterministic jitter spreads execution times; TTL cleanup removes expired tasks; inflight guards prevent duplicate firing during overlapping ticks or hot reloads.

The server tracks the active session through OpenCode hooks. Session deletion cancels that session's tasks, and legacy persisted tasks without a sessionID are dropped during state migration.

Build from source

git clone https://github.com/jkrandom-sudo/opencode-plugin-loop.git
cd opencode-plugin-loop
npm install
npm run build
npm test
opencode plugin "file:///absolute/path/to/opencode-plugin-loop" --global --force

Rebuild after editing src/, then restart OpenCode to reload the file plugin.

Build pipeline

scripts/build.mjs first runs TypeScript in declaration-only mode. It then compiles TypeScript and TSX with Babel. TUI TSX uses Solid's universal transform with @opentui/solid, which keeps selected-row style properties reactive in the OpenTUI renderer.

Published JavaScript and declarations are written to dist/. The package exposes the server, TUI, and bundled command definition through explicit package exports.

Source map

File Responsibility
src/index.ts Plugin initialization, defaults, OpenCode hooks, ticker lifecycle
src/scheduler.ts Command parsing, task scheduling, firing, pause/resume/cancel behavior
src/store.ts Persistent task state, limits, TTL cleanup, session filtering
src/tools/loop-tools.ts loop_schedule and loop_status tool definitions
src/tui.ts TUI-only plugin entrypoint and dialog lifecycle
src/tui-feedback-model.ts Recognition and modeling of plugin-owned feedback
src/tui-dialog-actions.ts Copy ID, Copy all, Close actions and clipboard outcomes
src/tui-dialog-interaction.ts Keyboard and mouse event mapping
src/tui-dialog-layout.ts Responsive dialog sizing and viewport allocation
src/tui-dialog-view.tsx Reactive OpenTUI dialog rendering

Supporting modules include cron-parser.ts, jitter.ts, runtime-feedback.ts, and types.ts.

Tests

npm test

The test command builds fresh output before running all Node test files. Package tests also verify the published entrypoints and confirm that the compiled dialog contains Solid reactive updates rather than a static JSX runtime result.

Local OpenCode verification

Before publishing a change:

  1. Install the local file plugin and restart OpenCode.
  2. Create a fixed task, for example /loop 1h local smoke test.
  3. Run /loop list and verify the task appears only in the current session.
  4. Move through Copy ID, Copy all, and Close with Up/Down and Tab/Shift+Tab, including wraparound.
  5. Verify Enter and Space activate the selected action.
  6. Verify mouse hover changes selection and click activates the exact row.
  7. Confirm a successful copy closes the dialog and a clipboard failure keeps it open.
  8. Cancel the test task and verify /loop list reports no tasks.
  9. Run npm test again.

Clone this wiki locally