Repository navigation
feat(plugin): let plugins create, list and delete automations - #65747
Conversation
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 asclient.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.
How it works
Automation.Service, so the HTTP handler and the plugin API share them instead of keeping two copies:listtakes adirectory(the project that owns it, or automations that ran there). It fails on a relative path, on an unknownsessionID, and when the session's or the directory's folder hasautomationsoff. It leaves out automations whose folder hasautomationsoff.get,pause,resumeandremovefail withDisabledErrorwhen the automation's folder hasautomationsoff. An automation whose folder is gone stays manageable, so it can still be deleted.createruns withPermission.Unattended, like HTTP callers, because plugins have no UI to answer a permission prompt.Pluginfromplugin/service.jsinstead ofplugin.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
automationsoff, the same as HTTP.Flag
No new flag. The API is under
ctx.experimental, and the existingautomationsconfig key still controls access.Proof
Backend only. On
dev,ctx.experimental.automationdoesn't exist. On this branch:test/plugin/automation.test.tscreates, lists and deletes an automation from an Effect plugin and a Promise plugin, and checks that deleting it twice fails.test/automation.test.tsturnsautomationsoff in an automation's folder and checks thatlisthides it,listby that directory or session fails, andpauseandremovefail. After turning it back on, the automation can be deleted.bun run checkandtypecheck:tscin 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)