mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
feat(plugins): add workspace.rename and project names in workspace.list
Plugins that name workspaces had to read Orca's private runtime token and call worktree.set over the runtime socket, bypassing capability consent. workspace.rename (workspace:write, worker only, host API 1.5) does the same update as a sidebar rename. workspace.list rows gain the project name so plugins can prefix names without reading the runtime's repo list.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
<!-- Generated by `pnpm generate:plugin-schemas` from src/shared/plugins. Do not edit. -->
|
||||
|
||||
Host API 1.4 (`"pluginApi": 1`). Workers call a method with `await orca.host.call(name, params)`; panels and custom editors call the same methods through `window.orca.host.call(name, params)`. Each method lists the surfaces allowed to call it; any other surface gets `not_permitted`. `orca.host.has(name)` answers synchronously whether this Orca offers a method on the current surface, and `orca.api` is `{ major, minor }`. See [Plugin authoring](./plugin-authoring.md) for the frame API.
|
||||
Host API 1.5 (`"pluginApi": 1`). Workers call a method with `await orca.host.call(name, params)`; panels and custom editors call the same methods through `window.orca.host.call(name, params)`. Each method lists the surfaces allowed to call it; any other surface gets `not_permitted`. `orca.host.has(name)` answers synchronously whether this Orca offers a method on the current surface, and `orca.api` is `{ major, minor }`. See [Plugin authoring](./plugin-authoring.md) for the frame API.
|
||||
|
||||
Every call is checked against the capabilities the user approved, and params are validated before Orca runs anything: params are strict, so a field this Orca does not know is refused with `invalid_params` instead of being dropped. Mutations are recorded in the audit log as `plugin:<publisher>.<id>`.
|
||||
|
||||
@@ -35,6 +35,7 @@ Methods whose capability is `none` need no capability but still need the plugin
|
||||
| [`appearance.apply`](#appearanceapply) | `appearance:write` | worker | yes | 1.4 | Publishes owned app/editor and terminal colors and selects them in the desktop. Returns publication, not renderer acknowledgement. |
|
||||
| [`workspace.list`](#workspacelist) | `workspace:read` | worker | no | 1.3 | Lists every workspace, Git worktrees and folders, on every host Orca reaches. |
|
||||
| [`workspace.open`](#workspaceopen) | `workspace:write` | worker | yes | 1.3 | Shows a workspace in Orca, as clicking it in the sidebar does; a folder workspace needs the desktop app. |
|
||||
| [`workspace.rename`](#workspacerename) | `workspace:write` | worker | yes | 1.5 | Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again. |
|
||||
| [`terminal.create`](#terminalcreate) | `terminal:send` | worker | yes | 1.3 | Opens a terminal in a workspace, optionally running a command, in the background. |
|
||||
| [`terminal.read`](#terminalread) | `terminal:read` | worker | no | 1.3 | Reads a terminal's newest output as plain text, at most 2000 lines. |
|
||||
| [`agent.launch`](#agentlaunch) | `agent:launch` | worker | yes | 1.3 | Starts an agent's CLI in a new terminal of a workspace, in the background, and returns as soon as it starts; a `prompt` is sent once the agent is ready. |
|
||||
@@ -214,7 +215,7 @@ Publishes owned app/editor and terminal colors and selects them in the desktop.
|
||||
Lists every workspace, Git worktrees and folders, on every host Orca reaches.
|
||||
|
||||
```ts
|
||||
(params?: {}) => { workspaces: { id: string; kind: "worktree" | "folder"; name: string; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }
|
||||
(params?: {}) => { workspaces: { id: string; kind: "worktree" | "folder"; name: string; project: string | null; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }
|
||||
```
|
||||
|
||||
### `workspace.open`
|
||||
@@ -225,6 +226,14 @@ Shows a workspace in Orca, as clicking it in the sidebar does; a folder workspac
|
||||
(params: { workspaceId: string }) => { opened: true }
|
||||
```
|
||||
|
||||
### `workspace.rename`
|
||||
|
||||
Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again.
|
||||
|
||||
```ts
|
||||
(params: { workspaceId: string; name: string }) => { name: string }
|
||||
```
|
||||
|
||||
### `terminal.create`
|
||||
|
||||
Opens a terminal in a workspace, optionally running a command, in the background.
|
||||
|
||||
+11
-11
File diff suppressed because one or more lines are too long
+8
-2
@@ -1,5 +1,5 @@
|
||||
// Generated by `pnpm generate:plugin-author-typings` from src/shared/plugins. Do not edit.
|
||||
// Host API 1.4 types shared by frames (`window.orca`) and workers (`activate(orca)`).
|
||||
// Host API 1.5 types shared by frames (`window.orca`) and workers (`activate(orca)`).
|
||||
|
||||
declare module 'orca/host' {
|
||||
// Why from 'orca': authors declare `PluginRequests` and `PluginPanelEvents` there once, and
|
||||
@@ -163,7 +163,7 @@ declare module 'orca/host' {
|
||||
/** Lists every workspace, Git worktrees and folders, on every host Orca reaches. Since host API 1.3. */
|
||||
"workspace.list": {
|
||||
params: Record<string, never> | undefined
|
||||
result: { workspaces: { id: string; kind: "worktree" | "folder"; name: string; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }
|
||||
result: { workspaces: { id: string; kind: "worktree" | "folder"; name: string; project: string | null; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** Shows a workspace in Orca, as clicking it in the sidebar does; a folder workspace needs the desktop app. Since host API 1.3. */
|
||||
@@ -172,6 +172,12 @@ declare module 'orca/host' {
|
||||
result: { opened: true }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again. Since host API 1.5. */
|
||||
"workspace.rename": {
|
||||
params: { workspaceId: string; name: string }
|
||||
result: { name: string }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** Opens a terminal in a workspace, optionally running a command, in the background. Since host API 1.3. */
|
||||
"terminal.create": {
|
||||
params: { workspaceId: string; title?: string; command?: string }
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
<!-- Generated by config/scripts/generate-plugin-authoring-skill-references.mjs. Do not edit. -->
|
||||
|
||||
Host API 1.4 (`"pluginApi": 1`). Call `host.call(method, params, { signal })`; a surface not listed for a method gets `not_permitted`. Params are strict: a field this Orca does not know is refused with `invalid_params`, so check `host.has(method)` or `api.minor` before using a method newer than your `engines.orca` floor. Each call also needs the manifest capability and the user's approval.
|
||||
Host API 1.5 (`"pluginApi": 1`). Call `host.call(method, params, { signal })`; a surface not listed for a method gets `not_permitted`. Params are strict: a field this Orca does not know is refused with `invalid_params`, so check `host.has(method)` or `api.minor` before using a method newer than your `engines.orca` floor. Each call also needs the manifest capability and the user's approval.
|
||||
|
||||
## Methods per surface
|
||||
|
||||
- Worker (`trusted-worker`, `main`): `orca` passed to `activate(orca)`: `workspace.readContext`, `terminal.sendText`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `agents.list`, `statusBar.update`, `appearance.read`, `appearance.apply`, `workspace.list`, `workspace.open`, `terminal.create`, `terminal.read`, `agent.launch`, `editor.open`, `commands.run`
|
||||
- Worker (`trusted-worker`, `main`): `orca` passed to `activate(orca)`: `workspace.readContext`, `terminal.sendText`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `agents.list`, `statusBar.update`, `appearance.read`, `appearance.apply`, `workspace.list`, `workspace.open`, `workspace.rename`, `terminal.create`, `terminal.read`, `agent.launch`, `editor.open`, `commands.run`
|
||||
- Panel: global `orca` in an HTML panel; `host` imported from `orca` in a components panel: `workspace.readContext`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `shell.openExternal`, `files.saveAs`, `plugin.request`, `agents.list`, `events.subscribe`
|
||||
- Custom editor: global `orca` in the editor frame: `workspace.readContext`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `shell.openExternal`, `files.saveAs`, `plugin.request`, `agents.list`, `events.subscribe`
|
||||
|
||||
@@ -112,9 +112,11 @@ HTML panels and custom editors get these CSS variables from Orca's active theme,
|
||||
- `appearance.apply` (capability `appearance:write`; worker; since 1.4): Publishes owned app/editor and terminal colors and selects them in the desktop. Returns publication, not renderer acknowledgement.
|
||||
`(params: { expectedRevision: string; app: string; terminal: string }) => { revision: string; themeId: string; mode: "dark" | "light"; delivery: "published" }`
|
||||
- `workspace.list` (capability `workspace:read`; worker; since 1.3): Lists every workspace, Git worktrees and folders, on every host Orca reaches.
|
||||
`(params?: {}) => { workspaces: { id: string; kind: "worktree" | "folder"; name: string; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }`
|
||||
`(params?: {}) => { workspaces: { id: string; kind: "worktree" | "folder"; name: string; project: string | null; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }`
|
||||
- `workspace.open` (capability `workspace:write`; worker; since 1.3): Shows a workspace in Orca, as clicking it in the sidebar does; a folder workspace needs the desktop app.
|
||||
`(params: { workspaceId: string }) => { opened: true }`
|
||||
- `workspace.rename` (capability `workspace:write`; worker; since 1.5): Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again.
|
||||
`(params: { workspaceId: string; name: string }) => { name: string }`
|
||||
- `terminal.create` (capability `terminal:send`; worker; since 1.3): Opens a terminal in a workspace, optionally running a command, in the background.
|
||||
`(params: { workspaceId: string; title?: string; command?: string }) => { terminalId: string }`
|
||||
- `terminal.read` (capability `terminal:read`; worker; since 1.3): Reads a terminal's newest output as plain text, at most 2000 lines.
|
||||
@@ -150,7 +152,7 @@ List each in `contributes.hooks` (`{ "event", "onError"? }`; `main` and `trusted
|
||||
## Capabilities
|
||||
|
||||
- `workspace:read` (since 1.4.160): Read the name, branch, and terminal list of your focused workspace, and get notified when workspaces are created or removed
|
||||
- `workspace:write` (since 1.4.248): Open your workspaces and their files in Orca, and run its built-in commands
|
||||
- `workspace:write` (since 1.4.248): Open and rename your workspaces, open their files in Orca, and run its built-in commands
|
||||
- `agent:read` (since 1.4.245): Get notified when agent status changes
|
||||
- `agent:launch` (since 1.4.248): Start agents in your workspaces, local and SSH
|
||||
- `terminal:send` (since 1.4.160): Type and run commands in your terminals, local and SSH
|
||||
|
||||
@@ -2996,11 +2996,11 @@ const ORCA_PLUGIN_AUTHORING_HOST_API_REFERENCE_MARKDOWN = [
|
||||
"",
|
||||
"<!-- Generated by config/scripts/generate-plugin-authoring-skill-references.mjs. Do not edit. -->",
|
||||
"",
|
||||
"Host API 1.4 (`\"pluginApi\": 1`). Call `host.call(method, params, { signal })`; a surface not listed for a method gets `not_permitted`. Params are strict: a field this Orca does not know is refused with `invalid_params`, so check `host.has(method)` or `api.minor` before using a method newer than your `engines.orca` floor. Each call also needs the manifest capability and the user's approval.",
|
||||
"Host API 1.5 (`\"pluginApi\": 1`). Call `host.call(method, params, { signal })`; a surface not listed for a method gets `not_permitted`. Params are strict: a field this Orca does not know is refused with `invalid_params`, so check `host.has(method)` or `api.minor` before using a method newer than your `engines.orca` floor. Each call also needs the manifest capability and the user's approval.",
|
||||
"",
|
||||
"## Methods per surface",
|
||||
"",
|
||||
"- Worker (`trusted-worker`, `main`): `orca` passed to `activate(orca)`: `workspace.readContext`, `terminal.sendText`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `agents.list`, `statusBar.update`, `appearance.read`, `appearance.apply`, `workspace.list`, `workspace.open`, `terminal.create`, `terminal.read`, `agent.launch`, `editor.open`, `commands.run`",
|
||||
"- Worker (`trusted-worker`, `main`): `orca` passed to `activate(orca)`: `workspace.readContext`, `terminal.sendText`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `agents.list`, `statusBar.update`, `appearance.read`, `appearance.apply`, `workspace.list`, `workspace.open`, `workspace.rename`, `terminal.create`, `terminal.read`, `agent.launch`, `editor.open`, `commands.run`",
|
||||
"- Panel: global `orca` in an HTML panel; `host` imported from `orca` in a components panel: `workspace.readContext`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `shell.openExternal`, `files.saveAs`, `plugin.request`, `agents.list`, `events.subscribe`",
|
||||
"- Custom editor: global `orca` in the editor frame: `workspace.readContext`, `notifications.show`, `storage.get`, `storage.set`, `storage.delete`, `storage.keys`, `secrets.get`, `secrets.set`, `secrets.delete`, `secrets.protection`, `settings.get`, `settings.set`, `shell.openExternal`, `files.saveAs`, `plugin.request`, `agents.list`, `events.subscribe`",
|
||||
"",
|
||||
@@ -3106,9 +3106,11 @@ const ORCA_PLUGIN_AUTHORING_HOST_API_REFERENCE_MARKDOWN = [
|
||||
"- `appearance.apply` (capability `appearance:write`; worker; since 1.4): Publishes owned app/editor and terminal colors and selects them in the desktop. Returns publication, not renderer acknowledgement.",
|
||||
" `(params: { expectedRevision: string; app: string; terminal: string }) => { revision: string; themeId: string; mode: \"dark\" | \"light\"; delivery: \"published\" }`",
|
||||
"- `workspace.list` (capability `workspace:read`; worker; since 1.3): Lists every workspace, Git worktrees and folders, on every host Orca reaches.",
|
||||
" `(params?: {}) => { workspaces: { id: string; kind: \"worktree\" | \"folder\"; name: string; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }`",
|
||||
" `(params?: {}) => { workspaces: { id: string; kind: \"worktree\" | \"folder\"; name: string; project: string | null; path: string; branch: string | null; hostId: string | null }[]; truncated: boolean }`",
|
||||
"- `workspace.open` (capability `workspace:write`; worker; since 1.3): Shows a workspace in Orca, as clicking it in the sidebar does; a folder workspace needs the desktop app.",
|
||||
" `(params: { workspaceId: string }) => { opened: true }`",
|
||||
"- `workspace.rename` (capability `workspace:write`; worker; since 1.5): Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again.",
|
||||
" `(params: { workspaceId: string; name: string }) => { name: string }`",
|
||||
"- `terminal.create` (capability `terminal:send`; worker; since 1.3): Opens a terminal in a workspace, optionally running a command, in the background.",
|
||||
" `(params: { workspaceId: string; title?: string; command?: string }) => { terminalId: string }`",
|
||||
"- `terminal.read` (capability `terminal:read`; worker; since 1.3): Reads a terminal's newest output as plain text, at most 2000 lines.",
|
||||
@@ -3144,7 +3146,7 @@ const ORCA_PLUGIN_AUTHORING_HOST_API_REFERENCE_MARKDOWN = [
|
||||
"## Capabilities",
|
||||
"",
|
||||
"- `workspace:read` (since 1.4.160): Read the name, branch, and terminal list of your focused workspace, and get notified when workspaces are created or removed",
|
||||
"- `workspace:write` (since 1.4.248): Open your workspaces and their files in Orca, and run its built-in commands",
|
||||
"- `workspace:write` (since 1.4.248): Open and rename your workspaces, open their files in Orca, and run its built-in commands",
|
||||
"- `agent:read` (since 1.4.245): Get notified when agent status changes",
|
||||
"- `agent:launch` (since 1.4.248): Start agents in your workspaces, local and SSH",
|
||||
"- `terminal:send` (since 1.4.160): Type and run commands in your terminals, local and SSH",
|
||||
|
||||
@@ -43,7 +43,9 @@ const worktreeListAnswer = z.object({
|
||||
truncated: z.boolean().optional()
|
||||
})
|
||||
const repoListAnswer = z.object({
|
||||
repos: z.array(z.object({ id: z.string(), kind: z.string().optional() }))
|
||||
repos: z.array(
|
||||
z.object({ id: z.string(), kind: z.string().optional(), displayName: z.string().optional() })
|
||||
)
|
||||
})
|
||||
const folderListAnswer = z.object({
|
||||
folderWorkspaces: z.array(
|
||||
@@ -114,18 +116,18 @@ export const PLUGIN_WORKSPACE_ACTION_HANDLERS = {
|
||||
call('folderWorkspace.list', undefined)
|
||||
])
|
||||
const { worktrees, totalCount, truncated } = worktreeListAnswer.parse(listed)
|
||||
const repoRows = repoListAnswer.parse(repos).repos
|
||||
const folderRepos = new Set(
|
||||
repoListAnswer
|
||||
.parse(repos)
|
||||
.repos.filter((repo) => repo.kind === 'folder')
|
||||
.map((repo) => repo.id)
|
||||
repoRows.filter((repo) => repo.kind === 'folder').map((repo) => repo.id)
|
||||
)
|
||||
const projectNames = new Map(repoRows.map((repo) => [repo.id, repo.displayName || null]))
|
||||
const worktreeRows = worktrees.slice(0, PLUGIN_WORKSPACE_LIST_LIMIT).map((worktree) => {
|
||||
const folder = folderRepos.has(worktree.repoId)
|
||||
return {
|
||||
id: worktree.identity ? `identity:${worktree.identity.key}` : worktree.id,
|
||||
kind: folder ? ('folder' as const) : ('worktree' as const),
|
||||
name: worktree.displayName,
|
||||
project: projectNames.get(worktree.repoId)?.slice(0, 512) ?? null,
|
||||
path: worktree.path,
|
||||
branch: folder ? null : branchName(worktree.branch),
|
||||
hostId: worktree.hostId ?? null
|
||||
@@ -136,6 +138,7 @@ export const PLUGIN_WORKSPACE_ACTION_HANDLERS = {
|
||||
id: folderWorkspaceKey(folder.id),
|
||||
kind: 'folder' as const,
|
||||
name: folder.name,
|
||||
project: null,
|
||||
path: folder.folderPath,
|
||||
branch: null,
|
||||
hostId: folder.executionHostId ?? null
|
||||
@@ -160,6 +163,23 @@ export const PLUGIN_WORKSPACE_ACTION_HANDLERS = {
|
||||
await effect(ctx, 'worktree.activate', { worktree: workspaceSelector(workspaceId) })
|
||||
return { opened: true as const }
|
||||
}),
|
||||
'workspace.rename': bind(api['workspace.rename'], async ({ workspaceId, name }, ctx) => {
|
||||
const trimmed = name.trim()
|
||||
const scope = parseWorkspaceKey(workspaceId)
|
||||
if (scope?.type === 'folder') {
|
||||
await effect(ctx, 'folderWorkspace.update', {
|
||||
folderWorkspaceId: scope.folderWorkspaceId,
|
||||
updates: { name: trimmed }
|
||||
})
|
||||
return { name: trimmed }
|
||||
}
|
||||
// The same update as a rename in the sidebar: the name is pinned, so a branch change keeps it.
|
||||
await effect(ctx, 'worktree.set', {
|
||||
worktree: workspaceSelector(workspaceId),
|
||||
displayName: trimmed
|
||||
})
|
||||
return { name: trimmed }
|
||||
}),
|
||||
'terminal.create': bind(api['terminal.create'], async (params, ctx) => {
|
||||
const answer = await effect(ctx, 'terminal.create', {
|
||||
worktree: workspaceSelector(params.workspaceId),
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { executePluginHostCall, type PluginHostServices } from './plugin-host-methods'
|
||||
|
||||
function services(runtimeRpc: PluginHostServices['runtimeRpc']): PluginHostServices {
|
||||
return {
|
||||
resolveActiveWorktreeContext: vi.fn().mockResolvedValue(null),
|
||||
listWorktreeTerminals: vi.fn().mockResolvedValue([]),
|
||||
sendTerminalText: vi.fn().mockResolvedValue({ accepted: true }),
|
||||
listAgentStatuses: () => [],
|
||||
dispatchPluginNotification: vi.fn().mockResolvedValue({ delivered: true }),
|
||||
storage: {
|
||||
get: vi.fn(),
|
||||
set: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
keys: vi.fn().mockReturnValue([])
|
||||
},
|
||||
secrets: {
|
||||
get: vi.fn().mockReturnValue({ ok: true, value: null }),
|
||||
set: vi.fn().mockReturnValue({ ok: true }),
|
||||
delete: vi.fn(),
|
||||
protection: vi.fn().mockReturnValue('unavailable')
|
||||
},
|
||||
settings: {
|
||||
getAll: vi.fn().mockReturnValue({}),
|
||||
set: vi.fn().mockReturnValue({ ok: true })
|
||||
},
|
||||
runtimeRpc
|
||||
}
|
||||
}
|
||||
|
||||
const call = (
|
||||
method: string,
|
||||
params: unknown,
|
||||
rpc: PluginHostServices['runtimeRpc'],
|
||||
granted = ['workspace:write']
|
||||
) =>
|
||||
executePluginHostCall({
|
||||
pluginId: 'samples.demo',
|
||||
method,
|
||||
params,
|
||||
surface: 'worker',
|
||||
grantedCapabilities: granted as never,
|
||||
services: services(rpc),
|
||||
audit: { record: vi.fn().mockResolvedValue(undefined) }
|
||||
})
|
||||
|
||||
describe('workspace.rename', () => {
|
||||
it('renames a worktree as the sidebar does, with the name trimmed', async () => {
|
||||
const rpc = vi.fn().mockResolvedValue({ worktree: {} })
|
||||
const outcome = await call(
|
||||
'workspace.rename',
|
||||
{ workspaceId: 'identity:abc', name: ' Mac|Login fix ' },
|
||||
rpc
|
||||
)
|
||||
expect(outcome).toMatchObject({
|
||||
ok: true,
|
||||
value: { name: 'Mac|Login fix' }
|
||||
})
|
||||
expect(rpc).toHaveBeenCalledWith(
|
||||
'worktree.set',
|
||||
{ worktree: 'identity:abc', displayName: 'Mac|Login fix' },
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
it('renames a project folder through its folder workspace', async () => {
|
||||
const rpc = vi.fn().mockResolvedValue({ folderWorkspace: {} })
|
||||
await call('workspace.rename', { workspaceId: 'folder:f1', name: 'Notes' }, rpc)
|
||||
expect(rpc).toHaveBeenCalledWith(
|
||||
'folderWorkspace.update',
|
||||
{ folderWorkspaceId: 'f1', updates: { name: 'Notes' } },
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
it('refuses blank or multi-line names and plugins without workspace:write', async () => {
|
||||
const rpc = vi.fn()
|
||||
for (const name of [' ', 'a\nb', 'x'.repeat(201)]) {
|
||||
expect(await call('workspace.rename', { workspaceId: 'id-1', name }, rpc)).toMatchObject({
|
||||
ok: false,
|
||||
code: 'invalid_params'
|
||||
})
|
||||
}
|
||||
expect(
|
||||
await call('workspace.rename', { workspaceId: 'id-1', name: 'ok' }, rpc, ['workspace:read'])
|
||||
).toMatchObject({ ok: false })
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('workspace.list project names', () => {
|
||||
it("names each worktree's project and leaves project folders without one", async () => {
|
||||
const rpc = vi.fn(async (method: string) => {
|
||||
if (method === 'worktree.list') {
|
||||
return {
|
||||
worktrees: [
|
||||
{
|
||||
id: 'w1',
|
||||
repoId: 'r1',
|
||||
displayName: 'main',
|
||||
path: '/src/app',
|
||||
branch: 'refs/heads/main'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
if (method === 'repo.list') {
|
||||
return { repos: [{ id: 'r1', displayName: 'App' }] }
|
||||
}
|
||||
return {
|
||||
folderWorkspaces: [{ id: 'f1', name: 'Notes', folderPath: '/notes' }]
|
||||
}
|
||||
})
|
||||
const outcome = await call('workspace.list', {}, rpc, ['workspace:read'])
|
||||
expect(outcome).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
workspaces: [
|
||||
{ id: 'w1', name: 'main', project: 'App', branch: 'main' },
|
||||
{ id: 'folder:f1', name: 'Notes', project: null }
|
||||
]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -68,7 +68,8 @@ export type PluginCapability = z.infer<typeof pluginCapabilitySchema>
|
||||
export const PLUGIN_CAPABILITY_DESCRIPTIONS: Record<PluginCapabilityKind, string> = {
|
||||
'workspace:read':
|
||||
'Read the name, branch, and terminal list of your focused workspace, and get notified when workspaces are created or removed',
|
||||
'workspace:write': 'Open your workspaces and their files in Orca, and run its built-in commands',
|
||||
'workspace:write':
|
||||
'Open and rename your workspaces, open their files in Orca, and run its built-in commands',
|
||||
'agent:read': 'Get notified when agent status changes',
|
||||
'agent:launch': 'Start agents in your workspaces, local and SSH',
|
||||
'terminal:send': 'Type and run commands in your terminals, local and SSH',
|
||||
|
||||
@@ -28,6 +28,8 @@ const workspaceListResult = z.object({
|
||||
/** `folder`: a plain folder, with no Git branch. */
|
||||
kind: z.enum(['worktree', 'folder']),
|
||||
name: z.string().max(512),
|
||||
/** The project (repository) it belongs to; null for a folder outside one. Host API 1.5+. */
|
||||
project: z.string().max(512).nullable(),
|
||||
/** The path on the host that owns it, which may be WSL or an SSH machine. */
|
||||
path: z.string().max(ID_MAX),
|
||||
branch: z.string().max(512).nullable(),
|
||||
@@ -43,6 +45,22 @@ const workspaceListResult = z.object({
|
||||
const workspaceOpenParams = z.strictObject({ workspaceId })
|
||||
const workspaceOpenResult = z.object({ opened: z.literal(true) })
|
||||
|
||||
export const PLUGIN_WORKSPACE_NAME_MAX = 200
|
||||
const workspaceRenameParams = z.strictObject({
|
||||
workspaceId,
|
||||
/** The name the sidebar shows. It replaces an automatic (branch) name or a person's rename. */
|
||||
name: z
|
||||
.string()
|
||||
.max(PLUGIN_WORKSPACE_NAME_MAX)
|
||||
.refine((name) => name.trim().length > 0, 'name must not be blank')
|
||||
// A sidebar label is one line of plain text: no newlines or other control characters.
|
||||
.refine(
|
||||
(name) => [...name].every((char) => char >= ' ' && char !== '\u007f'),
|
||||
'name must be one line of plain text'
|
||||
)
|
||||
})
|
||||
const workspaceRenameResult = z.object({ name: z.string() })
|
||||
|
||||
const terminalCreateParams = z.strictObject({
|
||||
workspaceId,
|
||||
title: z.string().min(1).max(512).optional(),
|
||||
@@ -125,6 +143,17 @@ export const PLUGIN_WORKSPACE_ACTIONS_API = {
|
||||
params: workspaceOpenParams,
|
||||
result: workspaceOpenResult
|
||||
}),
|
||||
'workspace.rename': spec({
|
||||
summary:
|
||||
"Renames a workspace in Orca's sidebar, as renaming it by hand does; the name stays until it is renamed again.",
|
||||
since: 5,
|
||||
scope: 'any-workspace',
|
||||
capability: 'workspace:write',
|
||||
mutation: true,
|
||||
surfaces: WORKER_ONLY,
|
||||
params: workspaceRenameParams,
|
||||
result: workspaceRenameResult
|
||||
}),
|
||||
'terminal.create': spec({
|
||||
summary: 'Opens a terminal in a workspace, optionally running a command, in the background.',
|
||||
since: 3,
|
||||
|
||||
Reference in New Issue
Block a user