Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/design/daemon-skill-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Daemon Skill Toggle

## Goal

Expose the CLI `/skills` panel's workspace enable/disable behavior through daemon REST and the TypeScript SDK, including immediate refresh of active ACP sessions.

## Public contract

- `POST /workspace/skills/:name/enable`
- `POST /workspaces/:workspace/skills/:name/enable`
- Request body: `{ "enabled": boolean }`
- SDK: `DaemonClient.setWorkspaceSkillEnabled` and `WorkspaceDaemonClient.setWorkspaceSkillEnabled`
- Capability: `workspace_skill_toggle`

The response contains the canonical skill name, requested state, whether persistence changed, activation state, and session refresh counts. `applied` means every active session refreshed, `deferred` means no ACP child was running, and `partial` means at least one session failed to refresh after persistence committed.

## Semantics

The API changes only workspace `skills.disabled`. Skill lookup is case-insensitive, but the canonical discovered name is persisted. Updating one target removes target duplicates and case variants without deleting orphan entries for unavailable skills. A second identical request is a no-op.

The route rejects states the CLI panel cannot toggle:

- unknown skill: `404 skill_not_found`;
- `userInvocable === false`: `409 skill_not_toggleable`;
- skill from an inactive extension: `409 skill_not_toggleable`;
- disabled in system defaults, user, or system scope: `409 skill_not_toggleable` with the locking scope;
- untrusted workspace: `403 untrusted_workspace`.

The scope lock check and workspace read-modify-write happen inside the daemon's per-workspace settings lock. A failed write stops before refresh and event publication.

## `skills.disabled` versus `disable-model-invocation`

`skills.disabled` is an operator setting merged as a case-insensitive union across scopes. It removes matching skill slash commands and model-visible skill entries, and execution-time validation rejects the skill. The daemon endpoint writes the workspace member of this union.

`disable-model-invocation` is SKILL.md metadata. It hides a skill from model invocation while preserving direct user invocation. The existing managed-skill ACP operation edits that metadata and is intentionally not reused by this API.

## Activation flow

1. Resolve the canonical, toggleable skill from the workspace status snapshot.
2. Under the workspace settings lock, re-read every scope, reject higher-scope locks, and commit the canonical workspace list.
3. Invalidate the daemon's cached skill status.
4. If an ACP child is live, invoke `qwen/control/workspace/skills/refresh`.
5. The child reloads workspace-scope settings and refreshes every active session, including busy sessions.
6. Each session reloads its own workspace settings, rebuilds and pushes `available_commands_update`, and notifies SkillManager consumers.
7. Publish the existing workspace `settings_changed` event for `skills.disabled`.

An in-flight model request cannot be rewritten. Subsequent skill execution checks, command snapshots, and model contexts read the new state.

## Downstream consumers

- Settings merge: system defaults, user, workspace, and system `skills.disabled` form the effective disabled-name set.
- Workspace status: ACP and daemon-local skill mapping expose disabled state and false-only `userInvocable`.
- Slash commands: available-command construction removes disabled skills and sends updated command metadata to daemon clients.
- Model context: SkillManager change listeners refresh the Skill tool description and available-skill context.
- Execution validation: the Skill tool re-reads the disabled-name provider before invocation, so later calls are rejected immediately.
- Extension state: inactive extension skills remain non-toggleable even when they are not disabled by settings.
- Daemon cache: the cached live-child skill snapshot is invalidated after persistence so later GET requests cannot replay stale state.
- SDK consumers: both primary-workspace and workspace-qualified clients share the response and error contract.
- Events: existing `settings_changed` consumers observe the committed `skills.disabled` value; there is no new event type.

## Failure behavior

- Persistence failure: the HTTP request fails; no ACP refresh and no event.
- No child: persistence succeeds with `deferred`; the next child loads the setting at startup.
- Per-session refresh failure: persistence remains committed; successful sessions stay refreshed and the response is `partial`.
- Child transport race: if the child disappears after the liveness check, the response is `deferred`; other refresh failures are reported as `partial`.
35 changes: 24 additions & 11 deletions docs/developers/daemon/13-sdk-daemon-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ new DaemonClient({

Method groups (every method takes an optional `clientId` to stamp `X-Qwen-Client-Id`):

| Group | Methods |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Plumbing | `health()`, `capabilities()`, `auth` (lazy `DaemonAuthFlow` accessor) |
| Sessions | `createOrAttachSession`, `loadSession`, `resumeSession`, `listSessions`, `closeSession`, `setSessionMetadata`, `getSessionContext`, `getSessionSupportedCommands`, `setSessionApprovalMode`, `setSessionModel` |
| Prompting | `prompt`, `cancel`, `heartbeat` |
| Events | `subscribeEvents` (SSE generator), `subscribeEventsStream` (raw response) |
| Permissions | `respondToPermission`, `respondToSessionPermission` |
| Workspace snapshots | `getWorkspaceMcp`, `getWorkspaceSkills`, `getWorkspaceProviders`, `getWorkspaceEnv`, `getWorkspacePreflight` |
| Workspace mutations | `writeWorkspaceMemory`, `readWorkspaceMemory`, `rememberWorkspaceMemory`, `getWorkspaceMemoryRememberTask`, `forgetWorkspaceMemory`, `getWorkspaceMemoryForgetTask`, `dreamWorkspaceMemory`, `getWorkspaceMemoryDreamTask`, `listWorkspaceAgents`, `getWorkspaceAgent`, `createWorkspaceAgent`, `updateWorkspaceAgent`, `deleteWorkspaceAgent`, `toggleWorkspaceTool`, `restartMcpServer`, `initializeWorkspace` |
| Files | `readFile`, `readFileBytes`, `writeFile`, `editFile`, `listDirectory`, `globPaths`, `statPath` |
| Auth | `startDeviceFlow`, `pollDeviceFlow`, `cancelDeviceFlow`, `getAuthStatus` |
| Group | Methods |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Plumbing | `health()`, `capabilities()`, `auth` (lazy `DaemonAuthFlow` accessor) |
| Sessions | `createOrAttachSession`, `loadSession`, `resumeSession`, `listSessions`, `closeSession`, `setSessionMetadata`, `getSessionContext`, `getSessionSupportedCommands`, `setSessionApprovalMode`, `setSessionModel` |
| Prompting | `prompt`, `cancel`, `heartbeat` |
| Events | `subscribeEvents` (SSE generator), `subscribeEventsStream` (raw response) |
| Permissions | `respondToPermission`, `respondToSessionPermission` |
| Workspace snapshots | `getWorkspaceMcp`, `getWorkspaceSkills`, `getWorkspaceProviders`, `getWorkspaceEnv`, `getWorkspacePreflight` |
| Workspace mutations | `writeWorkspaceMemory`, `readWorkspaceMemory`, `rememberWorkspaceMemory`, `getWorkspaceMemoryRememberTask`, `forgetWorkspaceMemory`, `getWorkspaceMemoryForgetTask`, `dreamWorkspaceMemory`, `getWorkspaceMemoryDreamTask`, `listWorkspaceAgents`, `getWorkspaceAgent`, `createWorkspaceAgent`, `updateWorkspaceAgent`, `deleteWorkspaceAgent`, `setWorkspaceToolEnabled`, `setWorkspaceSkillEnabled`, `restartMcpServer`, `initWorkspace` |
| Files | `readFile`, `readFileBytes`, `writeFile`, `editFile`, `listDirectory`, `globPaths`, `statPath` |
| Auth | `startDeviceFlow`, `pollDeviceFlow`, `cancelDeviceFlow`, `getAuthStatus` |

### `fetchWithTimeout`

Expand Down Expand Up @@ -141,6 +141,19 @@ await client.dreamWorkspaceMemory();
await client.getWorkspaceMemoryDreamTask('dream-...');
```

Workspace skill toggles are available on both client shapes:

```ts
await client.setWorkspaceSkillEnabled('review', false, {
clientId: 'dashboard-1',
});
await client
.workspaceByCwd('/work/secondary')
.setWorkspaceSkillEnabled('review', true, { clientId: 'dashboard-1' });
```

Pre-flight `capabilities.features.includes('workspace_skill_toggle')`. The typed `DaemonSkillToggleResult` reports the canonical `skillName`, whether disk state `changed`, activation state (`applied`, `deferred`, or `partial`), and refreshed/failed session counts. `DaemonWorkspaceSkillStatus.userInvocable` is an optional false-only field; absence means the skill is user-invocable.

## Workflow

### Create-or-attach + first prompt
Expand Down
Loading
Loading