@vibecontrols/vibe-plugin-desk 0.0.0-stage → 2026.1125.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +106 -2
- package/dist/actions.d.ts +39 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +3 -0
- package/dist/manager.d.ts +74 -0
- package/dist/routes.d.ts +107 -0
- package/package.json +77 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Burdenoff Consultancy Services Private Limited,
|
|
4
|
+
Algoshred Technologies Private Limited,
|
|
5
|
+
and all its sister companies.
|
|
6
|
+
|
|
7
|
+
Maintainer: Vignesh T.V <https://github.com/tvvignesh>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is furnished
|
|
14
|
+
to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vibecontrols/vibe-plugin-desk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The desk meta plugin for [VibeControls](https://vibecontrols.com). It lets a BotManor Steward use a desk (a browser or a desktop) through the VibeControls agent, and keeps the person who owns the machine in control.
|
|
4
|
+
|
|
5
|
+
The meta does not drive a screen itself. Desk providers do the work, and the meta routes each action to one of them:
|
|
6
|
+
|
|
7
|
+
| Provider | Package | Status |
|
|
8
|
+
| ------------------------------ | ---------------------------------------------------- | ------- |
|
|
9
|
+
| Managed browser (Playwright) | `@vibecontrols/vibe-plugin-desk-browser` | planned |
|
|
10
|
+
| Linux desktop (Xvfb + xdotool) | `@vibecontrols/vibe-plugin-desk-x11` | planned |
|
|
11
|
+
| macOS, Windows | `vibe-plugin-desk-macos`, `vibe-plugin-desk-windows` | planned |
|
|
12
|
+
|
|
13
|
+
No provider is installed by default. Each one is installed on purpose.
|
|
14
|
+
|
|
15
|
+
## What the meta enforces
|
|
16
|
+
|
|
17
|
+
Every provider is wrapped in the desk guard from `@vibecontrols/plugin-sdk/desk`, so these rules hold for every provider:
|
|
18
|
+
|
|
19
|
+
- **Remote control is off by default.** Nothing runs until the machine's owner turns it on.
|
|
20
|
+
- **Kill switch.** When it is on, every action is refused at once.
|
|
21
|
+
- **Fencing.** Each desk remembers the highest fencing token it has seen. A lower token is refused with `STALE_FENCING_TOKEN`. When a person takes over, the fence is raised, so the Steward cannot act again until it gets a new lease. Fences survive a provider reload.
|
|
22
|
+
- **Idempotency.** A repeated `idempotencyKey` returns the stored result and does not act twice.
|
|
23
|
+
- **Workspace folder.** `read_file`, `write_file` and `shell` stay inside one folder, after symlinks are resolved.
|
|
24
|
+
- **Timeouts.** An action that overruns returns `TIMEOUT` and is aborted.
|
|
25
|
+
- **Untrusted output.** Every result is marked `provenance: "UNTRUSTED"`, whatever the provider says.
|
|
26
|
+
- **Audit without payloads.** Each decision is audited (provider, desk, action type, outcome). Typed text, file content, commands and screenshots are never audited.
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
Set these with `vibe config set <key> <value>`:
|
|
31
|
+
|
|
32
|
+
| Key | Default | Meaning |
|
|
33
|
+
| ----------------------- | ----------------------------------- | -------------------------------------------------------------- |
|
|
34
|
+
| `desk.remote-control` | off | `on` allows a Steward to act on this machine |
|
|
35
|
+
| `desk.kill-switch` | off | `on` refuses every action immediately |
|
|
36
|
+
| `desk.workspace-folder` | `<profile data dir>/desk-workspace` | The only folder file and shell actions may use. Read at start. |
|
|
37
|
+
| `desk.default-provider` | the elected provider | The provider used when a request names none |
|
|
38
|
+
|
|
39
|
+
## HTTP API
|
|
40
|
+
|
|
41
|
+
The agent mounts these routes under `/api/desk`, behind its own authentication:
|
|
42
|
+
|
|
43
|
+
| Route | Purpose |
|
|
44
|
+
| ---------------- | --------------------------------------------------------------- |
|
|
45
|
+
| `GET /providers` | Registered providers, their kind, and the actions each supports |
|
|
46
|
+
| `GET /health` | Readiness, remote control and kill switch state |
|
|
47
|
+
| `POST /act` | Run one action |
|
|
48
|
+
| `POST /fence` | Raise a desk's fence after a takeover |
|
|
49
|
+
|
|
50
|
+
`POST /act` body:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"provider": "desk-browser",
|
|
55
|
+
"deskId": "desk-1",
|
|
56
|
+
"fencingToken": "42",
|
|
57
|
+
"idempotencyKey": "step-17",
|
|
58
|
+
"timeoutMs": 10000,
|
|
59
|
+
"action": { "type": "click", "target": { "by": "ref", "ref": "e12" } }
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`fencingToken` is a decimal string, because JSON has no big integers. A screenshot comes back as `screenshotPngBase64`. A request that is not valid gets `400`. A desk-level refusal (stale token, kill switch, outside the folder) gets `200` with `ok: false` and an `error.code`.
|
|
64
|
+
|
|
65
|
+
Other plugins reach the same manager in process as the `desk` / `manager` service.
|
|
66
|
+
|
|
67
|
+
## Actions
|
|
68
|
+
|
|
69
|
+
The vocabulary is the one in `@vibecontrols/plugin-sdk/desk`, shared with the BotManor server: `screenshot`, `snapshot`, `click`, `type`, `secret_fill`, `key`, `scroll`, `navigate`, `focus_window`, `shell`, `read_file` and `write_file`. Every action is validated field by field before a provider sees it.
|
|
70
|
+
|
|
71
|
+
## Writing a provider
|
|
72
|
+
|
|
73
|
+
A provider implements `DeskBackend` and registers it from `onServerStart`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import type { DeskBackend } from "@vibecontrols/plugin-sdk/desk";
|
|
77
|
+
|
|
78
|
+
const backend: DeskBackend = {
|
|
79
|
+
kind: "x11",
|
|
80
|
+
actions: ["screenshot", "click", "type", "key"],
|
|
81
|
+
async act(action, { signal, paths }) {
|
|
82
|
+
// Use `paths.path` / `paths.cwd` for file and shell actions, never the raw action fields.
|
|
83
|
+
return { ok: true };
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function createPlugin() {
|
|
88
|
+
return {
|
|
89
|
+
name: "desk-x11",
|
|
90
|
+
version: "1.0.0",
|
|
91
|
+
onServerStart(_app, host) {
|
|
92
|
+
host.serviceRegistry?.registerProvider?.("desk", backend, "desk-x11");
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
bun install
|
|
102
|
+
bun run sanity # format, lint, type check, build, tests
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation for desk actions arriving over the wire.
|
|
3
|
+
*
|
|
4
|
+
* The SDK's `DeskAction` type describes the vocabulary, but a type is not a
|
|
5
|
+
* check: requests reach this plugin as JSON from the BotManor command channel
|
|
6
|
+
* or the agent HTTP API. Every action is parsed here, field by field, before a
|
|
7
|
+
* guard or backend sees it. Unknown action types, unknown target kinds,
|
|
8
|
+
* missing fields and out-of-range values are refused, and the parsed action
|
|
9
|
+
* holds only the fields the vocabulary defines (extra keys are dropped).
|
|
10
|
+
*/
|
|
11
|
+
import { type DeskAction, type DeskTarget } from "@vibecontrols/plugin-sdk/desk";
|
|
12
|
+
/** Upper bounds for one action. Larger work is split into several actions. */
|
|
13
|
+
export declare const DESK_LIMITS: {
|
|
14
|
+
/** Longest single action, in milliseconds. */
|
|
15
|
+
readonly maxTimeoutMs: 120000;
|
|
16
|
+
/** `type` text, shell command, key list entries and window titles. */
|
|
17
|
+
readonly maxTextLength: 10000;
|
|
18
|
+
/** `read_file.maxBytes` and `write_file.content` length. */
|
|
19
|
+
readonly maxFileBytes: number;
|
|
20
|
+
/** Keys pressed together in one `key` action. */
|
|
21
|
+
readonly maxKeys: 16;
|
|
22
|
+
/** Scroll distance per action, in either direction. */
|
|
23
|
+
readonly maxScroll: 10000;
|
|
24
|
+
/** Screen coordinates. */
|
|
25
|
+
readonly maxCoordinate: 32767;
|
|
26
|
+
/** Paths, URLs, refs and identifiers. */
|
|
27
|
+
readonly maxShortString: 4096;
|
|
28
|
+
};
|
|
29
|
+
export type ParseResult<T> = {
|
|
30
|
+
ok: true;
|
|
31
|
+
value: T;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
error: string;
|
|
35
|
+
};
|
|
36
|
+
/** Parse a target (`by: "ref" | "point" | "window"`). */
|
|
37
|
+
export declare function parseDeskTarget(value: unknown): ParseResult<DeskTarget>;
|
|
38
|
+
/** Parse one action of the spec 10 §7.2 vocabulary. */
|
|
39
|
+
export declare function parseDeskAction(value: unknown): ParseResult<DeskAction>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MetaProviderRef, type VibePluginFactory } from "@vibecontrols/plugin-sdk/contract";
|
|
2
|
+
/**
|
|
3
|
+
* Desk providers this meta routes to. None is a platform default: a desk
|
|
4
|
+
* hands a machine to a Steward, so every provider is installed on purpose,
|
|
5
|
+
* never as a side effect of installing the meta.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DESK_PROVIDERS: ReadonlyArray<MetaProviderRef>;
|
|
8
|
+
/**
|
|
9
|
+
* Plugin Contract v2 factory. Per-profile state (the DeskManager, with its
|
|
10
|
+
* fencing tokens and idempotency keys) lives in this closure, so two profiles
|
|
11
|
+
* never share a desk.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createPlugin: VibePluginFactory;
|
|
14
|
+
export default createPlugin;
|
|
15
|
+
export { DESK_LIMITS, parseDeskAction, parseDeskTarget } from "./actions.js";
|
|
16
|
+
export { DESK_CONFIG, DESK_PROVIDER_TYPE, DeskManager, DeskManagerError, type DeskProviderInfo, isDeskBackend, } from "./manager.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{existsSync,readFileSync}from"fs";import{dirname,join as joinPath}from"path";import{fileURLToPath}from"url";function createLifecycleHooks(spec){let{name,onInit,onShutdown,onNuke,telemetryEventName,skipPlatforms}=spec;return{onServerStart:async(_app,hostServices)=>{if(skipPlatforms&&skipPlatforms.includes(process.platform)){process.stderr.write(`[${name}] skipping init on unsupported platform '${process.platform}'
|
|
3
|
+
`);return}if(onInit)await onInit(hostServices);if(telemetryEventName)hostServices.telemetry?.emit(telemetryEventName,{plugin:name})},onServerStop:async(context)=>{if(onShutdown)await onShutdown(context)},onNuke:async(hostServices,ctx)=>{if(onNuke)return onNuke(hostServices,ctx)}}}var BoundLogger=class{logger;source;constructor(logger,source){this.logger=logger,this.source=source}info(message,meta){this.logger?.info?.(this.source,message,meta)}warn(message,meta){this.logger?.warn?.(this.source,message,meta)}error(message,meta){this.logger?.error?.(this.source,message,meta)}debug(message,meta){this.logger?.debug?.(this.source,message,meta)}};function currentSupportedOS(p=process.platform){if(p==="darwin")return"darwin";if(p==="win32")return"win32";return"linux"}async function provisionMetaProviders(host,metaProviders,platform=currentSupportedOS()){let plugins=host.plugins;if(!plugins||!metaProviders?.length)return;let skip=plugins.skipInstall?.()??!1;for(let ref of metaProviders){if(!ref.defaultOn?.includes(platform))continue;try{if(!skip)await plugins.install?.(ref.packageName,{refreshLatest:!0});if(await plugins.loadProvider?.(ref.packageName),await plugins.runPrereqs?.(ref.packageName,{skipInstall:skip}),ref.providerType&&ref.pluginName)await plugins.electDefault?.(ref.providerType,ref.pluginName)}catch{}}}import{mkdir}from"fs/promises";import{join}from"path";import{promises}from"fs";import path from"path";var DESK_ACTION_TYPES=["screenshot","snapshot","click","type","secret_fill","key","scroll","navigate","focus_window","shell","read_file","write_file"];var fail=(code,message)=>({ok:!1,provenance:"UNTRUSTED",error:{code,message}});function toToken(value){if(typeof value==="bigint")return value>=0n?value:null;if(!/^\d{1,30}$/.test(value))return null;return BigInt(value)}async function confineToFolder(root,input){if(!input||input.includes("\x00"))return null;let existing=path.resolve(root,input),tail=[];for(;;)try{let real=await promises.realpath(existing),resolved=path.join(real,...tail),rel=path.relative(root,resolved);if(rel===""||!rel.startsWith("..")&&!path.isAbsolute(rel))return resolved;return null}catch{let parent=path.dirname(existing);if(parent===existing)return null;tail.unshift(path.basename(existing)),existing=parent}}function createDeskGuard(backend,options){let fences=new Map,completed=new Map,maxEntries=options.maxIdempotencyEntries??1000,rootPromise=null,root=()=>rootPromise??=promises.realpath(options.workspaceFolder),remember=(key,result)=>{let{screenshotPng:_dropped,...kept}=result;completed.set(key,kept);while(completed.size>maxEntries){let oldest=completed.keys().next().value;if(oldest===void 0)break;completed.delete(oldest)}};async function confine(action){if(action.type==="read_file"||action.type==="write_file"){let p=await confineToFolder(await root(),action.path);if(!p)return fail("OUTSIDE_WORKSPACE_FOLDER","path is outside the workspace folder");return{path:p}}if(action.type==="shell"){let cwd=await confineToFolder(await root(),action.cwd??".");if(!cwd)return fail("OUTSIDE_WORKSPACE_FOLDER","working directory is outside the workspace folder");return{cwd}}return{}}async function run(request){if(options.killSwitchEngaged?.())return fail("KILL_SWITCH","the kill switch is engaged");if(options.consentGranted&&!options.consentGranted())return fail("LOCAL_CONSENT_OFF","remote control is off on this machine");if(!backend.actions.includes(request.action.type))return fail("DESK_OFFLINE",`this ${backend.kind} desk cannot ${request.action.type}`);let paths;try{paths=await confine(request.action)}catch{return fail("DESK_OFFLINE","the workspace folder is not available")}if("ok"in paths)return paths;let controller=new AbortController,timer,timeout=new Promise((resolve)=>{timer=setTimeout(()=>{controller.abort(),resolve(fail("TIMEOUT",`action did not finish in ${request.timeoutMs}ms`))},request.timeoutMs)});try{return await Promise.race([backend.act(request.action,{deskId:request.deskId,signal:controller.signal,paths}).then((r)=>({...r,provenance:"UNTRUSTED"})),timeout])}catch(err){return fail("DESK_OFFLINE",err instanceof Error?err.message:"desk backend failed")}finally{clearTimeout(timer)}}return{async act(request){let token=toToken(request.fencingToken);if(token===null)return fail("STALE_FENCING_TOKEN","malformed fencing token");if(!request.idempotencyKey)return fail("DESK_OFFLINE","idempotencyKey is required");if(!Number.isFinite(request.timeoutMs)||request.timeoutMs<=0)return fail("TIMEOUT","timeoutMs must be positive");let highest=fences.get(request.deskId);if(highest!==void 0&&token<highest)return fail("STALE_FENCING_TOKEN",`fencing token ${token} is below ${highest}`);fences.set(request.deskId,token);let key=`${request.deskId}\x00${request.idempotencyKey}`,stored=completed.get(key);if(stored)return stored;let result=await run(request);return remember(key,result),result},raiseFence(deskId,value){let token=toToken(value);if(token===null)return;let highest=fences.get(deskId);if(highest===void 0||token>highest)fences.set(deskId,token)},fenceOf(deskId){return fences.get(deskId)??null}}}var DESK_PROVIDER_TYPE="desk",DESK_CONFIG={remoteControl:"desk.remote-control",killSwitch:"desk.kill-switch",workspaceFolder:"desk.workspace-folder",defaultProvider:"desk.default-provider"},ON=new Set(["on","true","1","yes"]);class DeskManagerError extends Error{code;constructor(code,message){super(message);this.code=code;this.name="DeskManagerError"}}function isDeskBackend(value){if(typeof value!=="object"||value===null)return!1;let candidate=value;return typeof candidate.kind==="string"&&Array.isArray(candidate.actions)&&typeof candidate.act==="function"}class DeskManager{options;host;registry;folder;guards=new Map;consent=!1;killed=!1;stopped=!1;constructor(options){this.options=options}async init(host){this.host=host,this.registry=host.serviceRegistry;let folder=(await host.getConfig?.(DESK_CONFIG.workspaceFolder))?.trim()||join(this.options.dataDir,"desk-workspace");await mkdir(folder,{recursive:!0,mode:448}),this.folder=folder,this.stopped=!1,await this.refreshSafety(),this.options.logger?.info(`desk manager ready (remote control ${this.consent?"on":"off"})`)}stop(){this.stopped=!0,this.guards.clear()}get workspaceFolder(){return this.folder}entries(){return(this.registry?.listProvidersForType?.(DESK_PROVIDER_TYPE)??[]).map((entry)=>typeof entry==="string"?{pluginName:entry,isDefault:!1}:entry)}backendOf(pluginName){let value=this.registry?.getProviderByName?.(DESK_PROVIDER_TYPE,pluginName);return isDeskBackend(value)?value:void 0}listProviders(){return this.entries().map(({pluginName,isDefault})=>{let backend=this.backendOf(pluginName);return backend?{pluginName,isDefault,kind:backend.kind,actions:[...backend.actions]}:{pluginName,isDefault,actions:[]}})}async resolveProviderName(requested){let entries=this.entries(),has=(name)=>entries.some((e)=>e.pluginName===name),explicit=requested?.trim();if(explicit){if(!has(explicit))throw new DeskManagerError("NO_PROVIDER",`desk provider '${explicit}' is not registered`);return explicit}let configured=(await this.host?.getConfig?.(DESK_CONFIG.defaultProvider))?.trim();if(configured&&has(configured))return configured;let elected=entries.find((e)=>e.isDefault);if(elected)return elected.pluginName;if(entries.length===1)return entries[0].pluginName;throw new DeskManagerError("NO_PROVIDER",entries.length===0?"no desk provider is installed":"several desk providers are installed; name one or set desk.default-provider")}async refreshSafety(){let read=async(key)=>ON.has((await this.host?.getConfig?.(key)??"").trim().toLowerCase());this.consent=await read(DESK_CONFIG.remoteControl),this.killed=await read(DESK_CONFIG.killSwitch)}guardFor(pluginName){let existing=this.guards.get(pluginName);if(existing)return existing;let folder=this.folder;if(!folder)throw new DeskManagerError("NOT_READY","desk manager is not started");let live=()=>this.backendOf(pluginName),guard=createDeskGuard({get kind(){return live()?.kind??pluginName},get actions(){return live()?.actions??[]},act(action,context){let backend=live();if(!backend)return Promise.reject(Error(`desk provider '${pluginName}' is gone`));return backend.act(action,context)}},{workspaceFolder:folder,consentGranted:()=>this.consent,killSwitchEngaged:()=>this.killed});return this.guards.set(pluginName,guard),guard}async act(request,provider){if(this.stopped)return{ok:!1,provenance:"UNTRUSTED",error:{code:"DESK_OFFLINE",message:"the desk plugin is stopping"}};let pluginName=await this.resolveProviderName(provider);await this.refreshSafety();let result=await this.guardFor(pluginName).act(request);return this.host?.audit?.emit("desk.act",{provider:pluginName,deskId:request.deskId,action:request.action.type,ok:result.ok,...result.error?{error:result.error.code}:{}}),result}async raiseFence(deskId,token,provider){let pluginName=await this.resolveProviderName(provider);this.guardFor(pluginName).raiseFence(deskId,token),this.host?.audit?.emit("desk.fence",{provider:pluginName,deskId,token:String(token)})}async health(){return await this.refreshSafety(),{ready:Boolean(this.folder)&&!this.stopped,remoteControl:this.consent,killSwitch:this.killed,providers:this.entries().length}}}import{Elysia}from"elysia";var DESK_LIMITS={maxTimeoutMs:120000,maxTextLength:1e4,maxFileBytes:10485760,maxKeys:16,maxScroll:1e4,maxCoordinate:32767,maxShortString:4096},isObject=(value)=>typeof value==="object"&&value!==null&&!Array.isArray(value),ok=(value)=>({ok:!0,value}),bad=(error)=>({ok:!1,error});function str(fields,key,max=DESK_LIMITS.maxShortString){let value=fields[key];if(typeof value!=="string"||value.length===0)return bad(`${key} must be a non-empty string`);if(value.length>max)return bad(`${key} is longer than ${max} characters`);return ok(value)}function optStr(fields,key,max=DESK_LIMITS.maxShortString){return fields[key]===void 0?ok(void 0):str(fields,key,max)}function int(fields,key,min,max){let value=fields[key];if(typeof value!=="number"||!Number.isInteger(value)||value<min||value>max)return bad(`${key} must be an integer from ${min} to ${max}`);return ok(value)}function parseDeskTarget(value){if(!isObject(value))return bad("target must be an object");switch(value.by){case"ref":{let ref=str(value,"ref");return ref.ok?ok({by:"ref",ref:ref.value}):ref}case"point":{let x=int(value,"x",0,DESK_LIMITS.maxCoordinate);if(!x.ok)return x;let y=int(value,"y",0,DESK_LIMITS.maxCoordinate);if(!y.ok)return y;return ok({by:"point",x:x.value,y:y.value})}case"window":{let app=str(value,"app");if(!app.ok)return app;let title=optStr(value,"title");if(!title.ok)return title;return ok(title.value===void 0?{by:"window",app:app.value}:{by:"window",app:app.value,title:title.value})}default:return bad('target.by must be "ref", "point" or "window"')}}function optTarget(fields){return fields.target===void 0?ok(void 0):parseDeskTarget(fields.target)}var isActionType=(value)=>typeof value==="string"&&DESK_ACTION_TYPES.includes(value);function parseDeskAction(value){if(!isObject(value))return bad("action must be an object");let type=value.type;if(!isActionType(type))return bad(`unknown action type: ${String(type)}`);switch(type){case"screenshot":case"snapshot":return ok({type});case"click":{let target=parseDeskTarget(value.target);if(!target.ok)return target;let action={type,target:target.value},button=value.button;if(button!==void 0){if(button!=="left"&&button!=="right")return bad('button must be "left" or "right"');action.button=button}let count=value.count;if(count!==void 0){if(count!==1&&count!==2)return bad("count must be 1 or 2");action.count=count}return ok(action)}case"type":{let text=str(value,"text",DESK_LIMITS.maxTextLength);if(!text.ok)return text;let target=optTarget(value);if(!target.ok)return target;return ok(target.value===void 0?{type,text:text.value}:{type,target:target.value,text:text.value})}case"secret_fill":{let target=parseDeskTarget(value.target);if(!target.ok)return target;let secretRef=str(value,"secretRef");if(!secretRef.ok)return secretRef;let origin=str(value,"expectedOrigin");if(!origin.ok)return origin;let parsed;try{parsed=new URL(origin.value)}catch{return bad("expectedOrigin must be an origin such as https://example.com")}if(parsed.origin!==origin.value)return bad("expectedOrigin must be an origin such as https://example.com");return ok({type,target:target.value,secretRef:secretRef.value,expectedOrigin:origin.value})}case"key":{let keys=value.keys;if(!Array.isArray(keys)||keys.length===0||keys.length>DESK_LIMITS.maxKeys||!keys.every((k)=>typeof k==="string"&&k.length>0&&k.length<=64))return bad(`keys must be 1 to ${DESK_LIMITS.maxKeys} non-empty key names`);return ok({type,keys:[...keys]})}case"scroll":{let dx=int(value,"dx",-DESK_LIMITS.maxScroll,DESK_LIMITS.maxScroll);if(!dx.ok)return dx;let dy=int(value,"dy",-DESK_LIMITS.maxScroll,DESK_LIMITS.maxScroll);if(!dy.ok)return dy;let target=optTarget(value);if(!target.ok)return target;return ok(target.value===void 0?{type,dx:dx.value,dy:dy.value}:{type,target:target.value,dx:dx.value,dy:dy.value})}case"navigate":{let url=str(value,"url");if(!url.ok)return url;let parsed;try{parsed=new URL(url.value)}catch{return bad("url must be an absolute http(s) URL")}if(parsed.protocol!=="http:"&&parsed.protocol!=="https:")return bad("url must be an absolute http(s) URL");return ok({type,url:url.value})}case"focus_window":{let app=str(value,"app");if(!app.ok)return app;let title=optStr(value,"title");if(!title.ok)return title;return ok(title.value===void 0?{type,app:app.value}:{type,app:app.value,title:title.value})}case"shell":{let command=str(value,"command",DESK_LIMITS.maxTextLength);if(!command.ok)return command;let timeoutMs=int(value,"timeoutMs",1,DESK_LIMITS.maxTimeoutMs);if(!timeoutMs.ok)return timeoutMs;let cwd=optStr(value,"cwd");if(!cwd.ok)return cwd;return ok(cwd.value===void 0?{type,command:command.value,timeoutMs:timeoutMs.value}:{type,command:command.value,cwd:cwd.value,timeoutMs:timeoutMs.value})}case"read_file":{let path=str(value,"path");if(!path.ok)return path;let maxBytes=int(value,"maxBytes",1,DESK_LIMITS.maxFileBytes);if(!maxBytes.ok)return maxBytes;return ok({type,path:path.value,maxBytes:maxBytes.value})}case"write_file":{let path=str(value,"path");if(!path.ok)return path;let content=value.content;if(typeof content!=="string"||content.length>DESK_LIMITS.maxFileBytes)return bad(`content must be a string of at most ${DESK_LIMITS.maxFileBytes} characters`);return ok({type,path:path.value,content})}}}var isBody=(value)=>typeof value==="object"&&value!==null&&!Array.isArray(value),MAX_ID=256,ID=/^[A-Za-z0-9._:-]+$/;function id(body,key){let value=body[key];return typeof value==="string"&&value.length<=MAX_ID&&ID.test(value)?value:null}function token(body){let value=body.fencingToken;return typeof value==="string"&&/^\d{1,30}$/.test(value)?value:null}function provider(body){let value=body.provider;if(value===void 0)return;return typeof value==="string"&&value.length<=MAX_ID&&ID.test(value)?value:null}function toWire(result){let{screenshotPng,...rest}=result;return screenshotPng?{...rest,screenshotPngBase64:Buffer.from(screenshotPng).toString("base64")}:rest}function createDeskRoutes(manager){let fail=(set,status,error)=>(set.status=status,{error}),managerFailure=(set,err)=>{if(err instanceof DeskManagerError)return fail(set,err.code==="NO_PROVIDER"?404:503,err.message);return fail(set,500,"desk request failed")};return new Elysia().get("/providers",()=>({providers:manager.listProviders()})).get("/health",()=>manager.health()).post("/act",async({body,set})=>{if(!isBody(body))return fail(set,400,"body must be a JSON object");let deskId=id(body,"deskId");if(!deskId)return fail(set,400,"deskId is required");let idempotencyKey=id(body,"idempotencyKey");if(!idempotencyKey)return fail(set,400,"idempotencyKey is required");let fencingToken=token(body);if(!fencingToken)return fail(set,400,"fencingToken must be a decimal string");let timeoutMs=body.timeoutMs;if(typeof timeoutMs!=="number"||!Number.isInteger(timeoutMs)||timeoutMs<1||timeoutMs>DESK_LIMITS.maxTimeoutMs)return fail(set,400,`timeoutMs must be an integer from 1 to ${DESK_LIMITS.maxTimeoutMs}`);let name=provider(body);if(name===null)return fail(set,400,"provider must be a plugin name");let action=parseDeskAction(body.action);if(!action.ok)return fail(set,400,action.error);try{let result=await manager.act({deskId,fencingToken,idempotencyKey,timeoutMs,action:action.value},name);return toWire(result)}catch(err){return managerFailure(set,err)}}).post("/fence",async({body,set})=>{if(!isBody(body))return fail(set,400,"body must be a JSON object");let deskId=id(body,"deskId");if(!deskId)return fail(set,400,"deskId is required");let fencingToken=token(body);if(!fencingToken)return fail(set,400,"fencingToken must be a decimal string");let name=provider(body);if(name===null)return fail(set,400,"provider must be a plugin name");try{return await manager.raiseFence(deskId,fencingToken,name),{ok:!0}}catch(err){return managerFailure(set,err)}})}var PLUGIN_NAME="desk",PLUGIN_PACKAGE_NAME="@vibecontrols/vibe-plugin-desk",PLUGIN_VERSION=getPluginVersion();function getPluginVersion(){try{let dir=dirname(fileURLToPath(import.meta.url));for(let i=0;i<10&&dir&&dir!==dirname(dir);i++){let pkgPath=joinPath(dir,"package.json");if(existsSync(pkgPath))try{let pkg=JSON.parse(readFileSync(pkgPath,"utf8"));if(pkg.name===PLUGIN_PACKAGE_NAME&&typeof pkg.version==="string")return pkg.version}catch{}dir=dirname(dir)}}catch{}return"0.0.0"}var DESK_PROVIDERS=[{packageName:"@vibecontrols/vibe-plugin-desk-browser",pluginName:"desk-browser",providerType:"desk"},{packageName:"@vibecontrols/vibe-plugin-desk-x11",pluginName:"desk-x11",providerType:"desk"}],createPlugin=(ctx)=>{let log=new BoundLogger(ctx.logger,PLUGIN_NAME),manager=new DeskManager({dataDir:ctx.dataDir,logger:log}),lifecycle=createLifecycleHooks({name:PLUGIN_NAME,telemetryEventName:"desk.meta.ready",onInit:async(hostServices)=>{await manager.init(hostServices),hostServices.serviceRegistry?.registerService?.(PLUGIN_NAME,"manager",manager)},onShutdown:(context)=>{manager.stop(),log.info(`desk manager stopped (${context?.reason??"shutdown"})`)}});return{name:PLUGIN_NAME,version:PLUGIN_VERSION,description:"Desk manager: routes Steward desk actions to a registered desk provider",tags:["backend","integration"],apiPrefix:"/api/desk",capabilities:{audit:!0,telemetry:!0},metaProviders:DESK_PROVIDERS,provisionProviders:(hostServices)=>provisionMetaProviders(hostServices,DESK_PROVIDERS),createRoutes:()=>createDeskRoutes(manager),onServerStart:lifecycle.onServerStart,onServerStop:lifecycle.onServerStop}},src_default=createPlugin;export{DESK_CONFIG,DESK_LIMITS,DESK_PROVIDERS,DESK_PROVIDER_TYPE,DeskManager,DeskManagerError,createPlugin,src_default as default,isDeskBackend,parseDeskAction,parseDeskTarget};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { HostServices } from "@vibecontrols/plugin-sdk/contract";
|
|
2
|
+
import { type DeskActionType, type DeskActRequest, type DeskActResult, type DeskBackend } from "@vibecontrols/plugin-sdk/desk";
|
|
3
|
+
import { BoundLogger } from "@vibecontrols/plugin-sdk/log";
|
|
4
|
+
export declare const DESK_PROVIDER_TYPE = "desk";
|
|
5
|
+
/** Agent config keys (`vibe config set <key> <value>`). */
|
|
6
|
+
export declare const DESK_CONFIG: {
|
|
7
|
+
/** Must be "on" before any action runs. Off by default (spec §5.8). */
|
|
8
|
+
readonly remoteControl: "desk.remote-control";
|
|
9
|
+
/** "on" refuses every action immediately. */
|
|
10
|
+
readonly killSwitch: "desk.kill-switch";
|
|
11
|
+
/** The only folder file and shell actions may touch. */
|
|
12
|
+
readonly workspaceFolder: "desk.workspace-folder";
|
|
13
|
+
/** Provider plugin used when a request names none. */
|
|
14
|
+
readonly defaultProvider: "desk.default-provider";
|
|
15
|
+
};
|
|
16
|
+
export interface DeskProviderInfo {
|
|
17
|
+
pluginName: string;
|
|
18
|
+
isDefault: boolean;
|
|
19
|
+
/** Missing when the registered object is not a valid desk backend. */
|
|
20
|
+
kind?: string;
|
|
21
|
+
actions: DeskActionType[];
|
|
22
|
+
}
|
|
23
|
+
export declare class DeskManagerError extends Error {
|
|
24
|
+
readonly code: "NO_PROVIDER" | "NOT_READY";
|
|
25
|
+
constructor(code: "NO_PROVIDER" | "NOT_READY", message: string);
|
|
26
|
+
}
|
|
27
|
+
/** True when `value` has the shape of a `DeskBackend`. */
|
|
28
|
+
export declare function isDeskBackend(value: unknown): value is DeskBackend;
|
|
29
|
+
export interface DeskManagerOptions {
|
|
30
|
+
/** Profile data directory; the default workspace folder lives under it. */
|
|
31
|
+
dataDir: string;
|
|
32
|
+
logger?: BoundLogger;
|
|
33
|
+
}
|
|
34
|
+
export declare class DeskManager {
|
|
35
|
+
private readonly options;
|
|
36
|
+
private host;
|
|
37
|
+
private registry;
|
|
38
|
+
private folder;
|
|
39
|
+
private readonly guards;
|
|
40
|
+
private consent;
|
|
41
|
+
private killed;
|
|
42
|
+
private stopped;
|
|
43
|
+
constructor(options: DeskManagerOptions);
|
|
44
|
+
/** Bind to the host and prepare the workspace folder. */
|
|
45
|
+
init(host: HostServices): Promise<void>;
|
|
46
|
+
/** Forget every guard. In-flight actions finish; new ones are refused. */
|
|
47
|
+
stop(): void;
|
|
48
|
+
get workspaceFolder(): string | undefined;
|
|
49
|
+
private entries;
|
|
50
|
+
private backendOf;
|
|
51
|
+
/** Every registered desk provider, with what it can do. */
|
|
52
|
+
listProviders(): DeskProviderInfo[];
|
|
53
|
+
/**
|
|
54
|
+
* The provider a request goes to: the named one, else the configured
|
|
55
|
+
* default, else the registry's elected default, else the only provider.
|
|
56
|
+
*/
|
|
57
|
+
resolveProviderName(requested?: string): Promise<string>;
|
|
58
|
+
private refreshSafety;
|
|
59
|
+
private guardFor;
|
|
60
|
+
/** Run one action on a desk. Never throws for desk-level failures. */
|
|
61
|
+
act(request: DeskActRequest, provider?: string): Promise<DeskActResult>;
|
|
62
|
+
/**
|
|
63
|
+
* A person took over the desk, or the lease moved: every fencing token
|
|
64
|
+
* below `token` is now stale on that provider.
|
|
65
|
+
*/
|
|
66
|
+
raiseFence(deskId: string, token: bigint | string, provider?: string): Promise<void>;
|
|
67
|
+
/** Current safety state, for `GET /health` and `vibe status`. */
|
|
68
|
+
health(): Promise<{
|
|
69
|
+
ready: boolean;
|
|
70
|
+
remoteControl: boolean;
|
|
71
|
+
killSwitch: boolean;
|
|
72
|
+
providers: number;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP routes, mounted by the agent under `/api/desk`. The agent's own
|
|
3
|
+
* authentication applies to every route here.
|
|
4
|
+
*
|
|
5
|
+
* GET /providers registered desk providers and the actions each supports
|
|
6
|
+
* GET /health remote-control, kill-switch and readiness state
|
|
7
|
+
* POST /act run one action { provider?, deskId, fencingToken,
|
|
8
|
+
* idempotencyKey, timeoutMs, action }
|
|
9
|
+
* POST /fence raise a desk's fence { provider?, deskId, fencingToken }
|
|
10
|
+
*
|
|
11
|
+
* JSON has no bytes or bigints: `fencingToken` is a decimal string, and a
|
|
12
|
+
* screenshot comes back as `screenshotPngBase64`.
|
|
13
|
+
*/
|
|
14
|
+
import type { DeskActResult } from "@vibecontrols/plugin-sdk/desk";
|
|
15
|
+
import { Elysia } from "elysia";
|
|
16
|
+
import { type DeskManager } from "./manager.js";
|
|
17
|
+
/** The JSON form of a result: bytes become base64. */
|
|
18
|
+
export declare function toWire(result: DeskActResult): Record<string, unknown>;
|
|
19
|
+
export declare function createDeskRoutes(manager: DeskManager): Elysia<"", {
|
|
20
|
+
decorator: {};
|
|
21
|
+
store: {};
|
|
22
|
+
derive: {};
|
|
23
|
+
resolve: {};
|
|
24
|
+
}, {
|
|
25
|
+
typebox: {};
|
|
26
|
+
error: {};
|
|
27
|
+
}, {
|
|
28
|
+
schema: {};
|
|
29
|
+
standaloneSchema: {};
|
|
30
|
+
macro: {};
|
|
31
|
+
macroFn: {};
|
|
32
|
+
parser: {};
|
|
33
|
+
response: {};
|
|
34
|
+
}, {
|
|
35
|
+
providers: {
|
|
36
|
+
get: {
|
|
37
|
+
body: unknown;
|
|
38
|
+
params: {};
|
|
39
|
+
query: unknown;
|
|
40
|
+
headers: unknown;
|
|
41
|
+
response: {
|
|
42
|
+
200: {
|
|
43
|
+
providers: import("./manager.js").DeskProviderInfo[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
} & {
|
|
49
|
+
health: {
|
|
50
|
+
get: {
|
|
51
|
+
body: unknown;
|
|
52
|
+
params: {};
|
|
53
|
+
query: unknown;
|
|
54
|
+
headers: unknown;
|
|
55
|
+
response: {
|
|
56
|
+
200: {
|
|
57
|
+
ready: boolean;
|
|
58
|
+
remoteControl: boolean;
|
|
59
|
+
killSwitch: boolean;
|
|
60
|
+
providers: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
} & {
|
|
66
|
+
act: {
|
|
67
|
+
post: {
|
|
68
|
+
body: unknown;
|
|
69
|
+
params: {};
|
|
70
|
+
query: unknown;
|
|
71
|
+
headers: unknown;
|
|
72
|
+
response: {
|
|
73
|
+
200: Record<string, unknown> | {
|
|
74
|
+
error: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
} & {
|
|
80
|
+
fence: {
|
|
81
|
+
post: {
|
|
82
|
+
body: unknown;
|
|
83
|
+
params: {};
|
|
84
|
+
query: unknown;
|
|
85
|
+
headers: unknown;
|
|
86
|
+
response: {
|
|
87
|
+
200: {
|
|
88
|
+
error: string;
|
|
89
|
+
} | {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}, {
|
|
96
|
+
derive: {};
|
|
97
|
+
resolve: {};
|
|
98
|
+
schema: {};
|
|
99
|
+
standaloneSchema: {};
|
|
100
|
+
response: {};
|
|
101
|
+
}, {
|
|
102
|
+
derive: {};
|
|
103
|
+
resolve: {};
|
|
104
|
+
schema: {};
|
|
105
|
+
standaloneSchema: {};
|
|
106
|
+
response: {};
|
|
107
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibecontrols/vibe-plugin-desk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2026.1125.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"description": "Desk meta plugin for BotManor Stewards: routes desk actions (screenshot, input, files, shell) to the registered desk provider and enforces fencing, idempotency, workspace-folder confinement, timeouts, local consent and the kill switch.",
|
|
8
|
+
"engines": {
|
|
9
|
+
"bun": ">=1.4.4"
|
|
10
|
+
},
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Vignesh T.V",
|
|
13
|
+
"url": "https://github.com/tvvignesh"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target bun --minify-syntax --minify-whitespace --external elysia && tsc -p tsconfig.build.json",
|
|
18
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"format": "bun fmt",
|
|
21
|
+
"format:check": "bun fmt --check",
|
|
22
|
+
"type:check": "boff gate -- bun check --no-pretty",
|
|
23
|
+
"clean": "rimraf dist",
|
|
24
|
+
"prebuild": "bun run clean",
|
|
25
|
+
"prepublishOnly": "bun run build",
|
|
26
|
+
"sanity": "boff sanity",
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"sanity:force": "boff sanity --force",
|
|
29
|
+
"audit": "bun audit --audit-level=high"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@vibecontrols/plugin-sdk": "2026.1125.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@burdenoff/toolchain": "2026.1107.14",
|
|
36
|
+
"@types/bun": "^1.4.4",
|
|
37
|
+
"eslint": "^9.39.5",
|
|
38
|
+
"knip": "^6.44.1",
|
|
39
|
+
"rimraf": "^6.1.4",
|
|
40
|
+
"typescript": "6.0.3",
|
|
41
|
+
"elysia": "^1.4.29"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@vibecontrols/agent": ">=2026.1125.1"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"@vibecontrols/agent": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"vibecontrols",
|
|
53
|
+
"vibe",
|
|
54
|
+
"vibe-plugin",
|
|
55
|
+
"desk",
|
|
56
|
+
"stewards",
|
|
57
|
+
"computer-use",
|
|
58
|
+
"meta",
|
|
59
|
+
"bun"
|
|
60
|
+
],
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/Algoshred/vibe-plugin-desk.git"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/Algoshred/vibe-plugin-desk/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/Algoshred/vibe-plugin-desk#readme",
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public",
|
|
71
|
+
"registry": "https://registry.npmjs.org/"
|
|
72
|
+
},
|
|
73
|
+
"files": [
|
|
74
|
+
"dist/**/*",
|
|
75
|
+
"!dist/**/*.map",
|
|
76
|
+
"README.md",
|
|
77
|
+
"LICENSE"
|
|
78
|
+
]
|
|
79
|
+
}
|