# Device Manager

> Central device registry: add/edit/remove devices (Windows/Linux/macOS/Android/iOS) from the widget, other plugins via invoke(), or ai-chat's AI agent via MCP tools

| | |
|---|---|
| Version | 1.0.2 |
| Category | System |
| Depends on | ai-chat |

# Device Manager

Central device registry: add/edit/remove devices (Windows/Linux/macOS/Android/iOS) from the widget,
other plugins via `invoke()`, or ai-chat's AI agent via MCP tools.

**Type:** `backend` — see `.claude/skills/kazuo-create-plugin/references/plugin-examples.md`

> Phase 1 (skeleton): CRUD only. A device stores `{ id, name, os, note, createdAt, updatedAt }`.
> Connection/control fields (host, port, credentials, live status) are intentionally deferred to a
> later phase.

## Files

- `manifest.json` — metadata, `defaultSettings = { devices: [] }`, `defaultWidgetConfig`. No `settings`
  entry point (nothing to configure yet).
- `widget.html` / `js/widget.js` / `css/widget.css` — main UI: OS filter, add/edit form, device list
  with Edit/Delete per row.
- `locales/en.json5` / `locales/vi.json5` — UI strings, `widget.*` / `filter.*` / `os.*` namespaces.
- `main/index.ts` (+ compiled `main/index.js`) — runs in the Electron main process; the central device
  store. Registers `plugin:device-manager:list/get/upsert/update/remove` (open to any caller) and
  `:clear` (self-gated). Optional `getMcpTools` exposes `device_list/device_add/device_update/device_remove`
  to ai-chat's AI agent (Dev Mode only).
- `package.json` — declares `zod` (only needed for the MCP tools; host runs `npm install --omit=dev` on
  install). Missing zod → `getMcpTools` returns `[]`, everything else still works.

## Default settings

- `devices` — default: `[]`

## Public API (for other plugins)

```js
// Create (no id) or update (known id). Returns the saved device.
await window['kazuo-ai'].invoke('plugin:device-manager:upsert', { name: 'Server 1', os: 'linux', note: '' });
await window['kazuo-ai'].invoke('plugin:device-manager:update', { id, patch: { note: 'prod' } });
await window['kazuo-ai'].invoke('plugin:device-manager:remove', id);
const devices = await window['kazuo-ai'].invoke('plugin:device-manager:list', { os: 'linux' }); // os optional
```

`os` is one of `windows | linux | macos | android | ios` (anything else is coerced to `unknown`).

## Test

Open Kazuo AI → Plugin Manager — this plugin appears automatically (the host scans `plugins-library/`
on its own, no registration needed) → Install → Enable.

After editing `main/index.ts`, recompile before testing: `npx tsc -p tsconfig.plugins.json` (run from
the project root).
