Skip to content

feat(plugin): let plugins create, list and delete automations - #65747

Merged
vimtor merged 2 commits into
devfrom
plugin-automations
Nov 23, 2026
Merged

vimtor merged 2 commits into
devfrom
plugin-automations

Conversation

@vimtor

@vimtor vimtor commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Plugins can now create, list and delete automations through ctx.experimental.automation, in both Effect and Promise plugins. The methods have the same inputs and outputs as client.experimental.automation.{create,list,delete}.

This lets a plugin define automations from files, for example one Markdown file per scheduled prompt. Today the only way to get automations onto a new machine is to recreate them by hand.

const session = await ctx.session.create({ id: "ses_automation_inbox", agent: "inbox" })
await ctx.experimental.automation.create({
  directory: ctx.location.directory,
  name: "inbox",
  trigger: { type: "cron", cron: "0 * * * *" },
  action: { type: "prompt", prompt: "Clean up the inboxes now.", to: { session: session.id } },
})

How it works

  • The rules for which automations a caller can see and manage now live in Automation.Service, so the HTTP handler and the plugin API share them instead of keeping two copies:
    • list takes a directory (the project that owns it, or automations that ran there). It fails on a relative path, on an unknown sessionID, and when the session's or the directory's folder has automations off. It leaves out automations whose folder has automations off.
    • get, pause, resume and remove fail with DisabledError when the automation's folder has automations off. An automation whose folder is gone stays manageable, so it can still be deleted.
    • The HTTP handler now only maps these errors to responses, which are the same as before.
  • create runs with Permission.Unattended, like HTTP callers, because plugins have no UI to answer a permission prompt.
  • The automation modules import Plugin from plugin/service.js instead of plugin.js. Session already does this, and it breaks the import cycle between the plugin host and automations.

One side effect: the agent's automation tools use the same service. They already require automations to be on where the calling session runs. Now they also hide or refuse automations in other folders of the same project that have automations off, the same as HTTP.

Flag

No new flag. The API is under ctx.experimental, and the existing automations config key still controls access.

Proof

Backend only. On dev, ctx.experimental.automation doesn't exist. On this branch:

  • test/plugin/automation.test.ts creates, lists and deletes an automation from an Effect plugin and a Promise plugin, and checks that deleting it twice fails.
  • A new test in test/automation.test.ts turns automations off in an automation's folder and checks that list hides it, list by that directory or session fails, and pause and remove fail. After turning it back on, the automation can be deleted.
core:   757 pass, 0 fail (test/plugin, plugin, automation, automation-shell, automation-event, tool-automation)
server: test/automation.test.ts 3 pass
plugin: 38 pass

bun run check and typecheck:tsc in core, plugin and server pass. I also ran a local server on this branch with the file-based automations plugin built on this API, and creating, editing and deleting a file created, recreated and deleted its automation.


Added by the opencode bot (AI-generated).

Public API: adds ctx.experimental.automation.{create,list,delete} to the plugin Context (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described: the new tests create, list and delete automations from Effect and Promise plugins, the rest of test/plugin (677) and the plugin package tests (38) pass, and typecheck:tsc is clean in core, plugin and server.

Public API: this adds ctx.experimental.automation.{create, list, delete} to the plugin Context, for both Effect and Promise plugins. Nothing is removed or changed, so it's backwards compatible. The one catch is that code building a full Context by hand, like the test host stub, now has to provide these three methods.

Main concern (inline): list and delete don't match the HTTP API. They don't check the automations flag, and list doesn't reject a sessionID that doesn't exist. The directory filter is also copied from the server handler.

Comment thread packages/core/src/plugin/host.ts Outdated
automation: {
// A plugin has no UI listener to answer an interactive ask, so asks settle unattended, as they do over HTTP.
create: (input) => automations.create(input).pipe(Effect.provideService(Permission.Unattended, [])),
list: Effect.fn(function* (input) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't quite match GET /api/experimental/automation, although the description says it does. The HTTP handler (packages/server/src/handlers/automation.ts) hides automations in folders where automations is off, fails on a sessionID that doesn't exist, and its remove refuses automations where the flag is off. Here only create is gated, so a plugin can list and delete automations that HTTP hides or refuses.

The directory/project filter is also copied word for word from the handler. Could this filtering (and the flag check, if you want them to match) move into Automation.Service, e.g. list({ sessionID, directory })? Then the plugin host and the HTTP handler share one implementation and can't drift apart.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commits fix the earlier thread. The list/visibility rules now live in Automation.Service, so plugins and HTTP follow the same rules, and the HTTP handler only maps errors. I re-ran the core automation and plugin tests (57 pass) and the server test/automation.test.ts (3 pass). typecheck:tsc is clean in core and plugin, and tsc --noEmit is clean in server. Nothing new to raise.

Public API: this adds ctx.experimental.automation.{create, list, delete} to the plugin Context. The HTTP responses are unchanged. It's backwards compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant