Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(chat): complete plugin and synced skills in the ⌘M composer; color /commands
Paul Robertson163fa6f56915
diff --git a/CLAUDE.md b/CLAUDE.mdindex 839a4f8b0..877386e73 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4572,8 +4572,16 @@ command-bearing opens; this does not add a human-confirm dialog or change mobileotherwise it is the terminal as before. Every refusal says so in one `nodeterm:toast`(`announceChatDictationRefusal`, naming the composer mic) instead of a silent dead key.- **The composer completes `/` and `@` (2026-09-30).** Typing `/` at the START of the message (after- optional whitespace — every CLI measured reads `/x` mid-sentence as text) opens a menu of the- node's CATALOG; `@` at the start of a word opens the node's files. Arrows move, Enter/Tab ACCEPT,+ optional whitespace) opens a menu of the node's CATALOG, and so does a `/` after whitespace anywhere+ in the message once a character follows it (2026-11-05, matching Claude Code 2.1.318's TUI, which+ opens its menu there too: `please use /tid`; never inside a word or path, `src/tid`). Mid-message a+ `/name` is text the model reads (a skill it may use), not a command the CLI runs, so the+ interactive-built-in flip (`isInteractiveBuiltin`) still looks at the start only. `@` at the start+ of a word opens the node's files. **A known `/command` is colored, as the TUI colors it**+ (`lib/chatComposerHighlight.ts`): a textarea cannot color part of its text, so while the draft holds+ one the textarea's text goes transparent and a layer behind it draws the same text (same box, font,+ padding and wrap; nothing that changes a glyph's width), and spell checking is off for that draft+ (a textarea checks all of its text or none). A draft with no known command renders as before. Arrows move, Enter/Tab ACCEPT,Esc closes the menu only (CardModal's capture-phase Esc already stands aside inside`.term-chat__compose`). **Accepting only inserts text** (`/name ` / `@path `): nothing is typed intothe pane, and the send is still the composer's own gated Enter (`chatSendRefusal`) — completing@@ -4615,6 +4623,21 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilecustom-commands reference). Precedence project > user > built-in, deduped by name. Other agents'custom locations were not measured, so they list none — a guessed location offers commands theCLI does not have.+ - **Plugins, synced skills and `skillOverrides` (claude, LOCAL nodes; `claudeLocalExtras`)**,+ measured 2026-11-05 against Claude Code 2.1.318's own `/` menu with test settings passed by+ `--settings`. A plugin lists `/<plugin>:<skill>` and `/<plugin>:<command>` only when it is in+ `<configDir>/plugins/installed_plugins.json` AND `enabledPlugins["<plugin>@<marketplace>"]` is+ `true` (user < project < local settings); a plugin only in the cache, a disabled one, or a+ `project`/`local` install for another folder lists nothing. Files come from the install's+ `installPath` (older cached versions are ignored), the plugin manifest's `skills` / `commands`+ paths when it names them (a listed folder holding a SKILL.md is one skill), never a path outside+ the plugin. claude.ai-synced skills (`<configDir>/skills/synced/<bucket>/<name>/SKILL.md`) list+ as `/<name>`. `skillOverrides: "off"` hides a user, project or synced skill (`"<name>"`, and for a+ synced one `"anthropic-skills:<name>"`); `name-only` and `user-invocable-only` keep it; nothing+ hides a PLUGIN's skill that way (measured). Note that Claude Code's `/skills` menu writes to the+ folder's `.claude/settings.local.json`, so an "off" there applies to that folder only. **SSH nodes+ do not get any of this yet** (the remote leg reads the base roots only): a follow-up needs the+ host's settings and `installed_plugins.json`, i.e. a second round trip.- **A PROJECT root follows no symlink, at any level** (`CatalogRoot.within`). A cloned repository's`.claude/commands/notes.md -> ~/.git-credentials` otherwise put the token-bearing first line inthe menu and in the phone's catalog (reproduced in review, both legs). Locally entries arediff --git a/src/core/chat-catalog.test.ts b/src/core/chat-catalog.test.tsindex c717f660e..40ee82972 100644--- a/src/core/chat-catalog.test.ts+++ b/src/core/chat-catalog.test.ts@@ -61,6 +61,9 @@ describe('parsers', () => {it('reads flat frontmatter and leaves a file without it as body', () => {expect(parseFrontmatter('---\nname: "x"\ndescription: hi there\n---\nbody').fields.description).toBe('hi there')expect(parseFrontmatter('no fm').body).toBe('no fm')+ // YAML single-quoted scalars escape a quote by doubling it; double-quoted ones are left as they are.+ expect(parseFrontmatter("---\ndescription: 'the project''s build'\n---\n").fields.description).toBe("the project's build")+ expect(parseFrontmatter('---\ndescription: "it\'\'s"\n---\n').fields.description).toBe("it''s")// A prototype key is just a key.expect(Object.getPrototypeOf(parseFrontmatter('---\n__proto__: y\n---\n').fields)).toBeNull()})@@ -195,6 +198,138 @@ describe('claude, local', () => {})})+// Measured on Claude Code 2.1.318 (see `claudeLocalExtras`): what its own `/` menu lists.+describe('claude, local: plugins, synced skills and skillOverrides', () => {+ const skill = (dir: string, name: string, extra = ''): void =>+ write(path.join(dir, name, 'SKILL.md'), `---\nname: ${name}\ndescription: ${name} desc\n${extra}---\nbody\n`)+ const claude = (...p: string[]): string => path.join(home, '.claude', ...p)+ const settings = (file: string, v: unknown): void => write(file, JSON.stringify(v))+ const install = (key: string, installPath: string, extra: Record<string, unknown> = {}) => ({+ [key]: [{ scope: 'user', installPath, version: '1.0.0', ...extra }]+ })+ const build = (cwd = proj) => buildLocalCatalog({ agentId: 'claude', accountId: undefined, cwd }, { home })++ it('lists the skills claude.ai syncs under their plain names', async () => {+ skill(claude('skills', 'synced', 'org_user'), 'xlsx')+ skill(claude('skills', 'synced', '.staging'), 'half-written')++ const c = await build()++ expect(byName(c, 'xlsx')).toMatchObject({ kind: 'skill', scope: 'user', description: 'xlsx desc' })+ expect(names(c)).not.toContain('half-written')+ })++ it("lists an enabled plugin's skills and commands as plugin:name, from its install path", async () => {+ const root = claude('plugins', 'cache', 'mkt', 'tools', '2.0.0')+ write(path.join(root, '.claude-plugin', 'plugin.json'), JSON.stringify({ name: 'tools' }))+ skill(path.join(root, 'skills'), 'tidy-up')+ skill(path.join(claude('plugins', 'cache', 'mkt', 'tools', '1.0.0'), 'skills'), 'old-version')+ write(path.join(root, 'commands', 'tidy-now.md'), '---\ndescription: now\n---\n')+ settings(claude('plugins', 'installed_plugins.json'), { version: 2, plugins: install('tools@mkt', root) })+ settings(claude('settings.json'), { enabledPlugins: { 'tools@mkt': true } })++ const c = await build()++ expect(byName(c, 'tools:tidy-up')).toMatchObject({ kind: 'skill', scope: 'user' })+ expect(byName(c, 'tools:tidy-now')).toMatchObject({ kind: 'command', description: 'now' })+ expect(names(c)).not.toContain('tools:old-version')+ })++ it('lists nothing for a disabled plugin, one only in the cache, or one installed for another folder', async () => {+ const plugin = (name: string): string => {+ const root = claude('plugins', 'cache', 'mkt', name, '1.0.0')+ skill(path.join(root, 'skills'), `${name}-skill`)+ return root+ }+ settings(claude('plugins', 'installed_plugins.json'), {+ version: 2,+ plugins: {+ ...install('off@mkt', plugin('off')),+ ...install('elsewhere@mkt', plugin('elsewhere'), { scope: 'project', projectPath: '/some/other/repo' }),+ ...install('here@mkt', plugin('here'), { scope: 'project', projectPath: proj })+ }+ })+ plugin('cached')+ settings(claude('settings.json'), {+ enabledPlugins: { 'off@mkt': false, 'elsewhere@mkt': true, 'here@mkt': true, 'cached@mkt': true }+ })++ const c = await build()++ expect(names(c).filter((n) => n.endsWith('-skill'))).toEqual(['here:here-skill'])+ })++ it('reads the skill folders a plugin manifest lists, and refuses one outside the plugin', async () => {+ const root = claude('plugins', 'cache', 'mkt', 'mp', '1.0.0')+ write(path.join(root, '.claude-plugin', 'plugin.json'), JSON.stringify({ name: 'mp', skills: ['./skills/grill-me', '../../escape'] }))+ skill(path.join(root, 'skills'), 'grill-me')+ skill(path.join(root, 'skills'), 'not-listed')+ skill(claude('plugins', 'cache', 'mkt'), 'escape')+ settings(claude('plugins', 'installed_plugins.json'), { version: 2, plugins: install('mp@mkt', root) })+ settings(claude('settings.json'), { enabledPlugins: { 'mp@mkt': true } })++ const c = await build()++ expect(names(c).filter((n) => n.startsWith('mp:'))).toEqual(['mp:grill-me'])+ })++ it('hides a skill set to "off", merging user < project < local, and keeps the other modes', async () => {+ skill(claude('skills'), 'explain')+ skill(claude('skills'), 'gone')+ skill(claude('skills'), 'kept')+ skill(claude('skills'), 'back')+ skill(claude('skills', 'synced', 'org_user'), 'pdf')+ skill(claude('skills', 'synced', 'org_user'), 'pptx')+ skill(path.join(proj, '.claude', 'skills'), 'local-one')+ settings(claude('settings.json'), { skillOverrides: { gone: 'off', back: 'off', kept: 'name-only' } })+ settings(path.join(proj, '.claude', 'settings.json'), { skillOverrides: { 'local-one': 'off', pdf: 'off' } })+ settings(path.join(proj, '.claude', 'settings.local.json'), {+ skillOverrides: { back: 'on', 'anthropic-skills:pptx': 'off', explain: 'user-invocable-only' }+ })++ const c = await build()++ expect(names(c)).toEqual(expect.arrayContaining(['explain', 'kept', 'back']))+ for (const n of ['gone', 'pdf', 'pptx', 'local-one']) expect(names(c)).not.toContain(n)+ })++ it("never hides a plugin's skill (measured: skillOverrides has no effect on one)", async () => {+ const root = claude('plugins', 'cache', 'mkt', 'tools', '1.0.0')+ skill(path.join(root, 'skills'), 'tidy-up')+ settings(claude('plugins', 'installed_plugins.json'), { version: 2, plugins: install('tools@mkt', root) })+ settings(claude('settings.json'), {+ enabledPlugins: { 'tools@mkt': true },+ skillOverrides: { 'tidy-up': 'off', 'tools:tidy-up': 'off' }+ })++ const c = await build()++ expect(names(c)).toContain('tools:tidy-up')+ })++ it('reads no project settings through a symlink', async () => {+ skill(claude('skills'), 'explain')+ settings(path.join(home, 'elsewhere.json'), { skillOverrides: { explain: 'off' } })+ fs.mkdirSync(path.join(proj, '.claude'), { recursive: true })+ fs.symlinkSync(path.join(home, 'elsewhere.json'), path.join(proj, '.claude', 'settings.local.json'))++ const c = await build()++ expect(names(c)).toContain('explain')+ })++ it('reads none of it for another agent, or for a remote node', async () => {+ skill(claude('skills', 'synced', 'org_user'), 'xlsx')++ const codex = await buildLocalCatalog({ agentId: 'codex', accountId: undefined, cwd: proj }, { home })++ expect(names(codex)).not.toContain('xlsx')+ expect(catalogRoots({ agentId: 'claude', accountId: undefined, cwd: proj }, { remote: true }).map((r) => r.kind)).not.toContain(+ 'synced-skills'+ )+ })+})+describe('other agents', () => {it('gemini: toml commands with `:` namespaces and an optional description', async () => {write(path.join(proj, '.gemini/commands/git/commit.toml'), 'description = "Commit it"\nprompt = "x"\n')diff --git a/src/core/chat-catalog.ts b/src/core/chat-catalog.tsindex 3bfdfe8e4..ccfcd2d92 100644--- a/src/core/chat-catalog.ts+++ b/src/core/chat-catalog.ts@@ -11,6 +11,10 @@// frontmatter `name`, else the folder; `user-invocable: false` hides it). `<configDir>` is the// managed or linked account's dir when the node is bound to one — it REPLACES `~/.claude`, it// does not add to it — else `~/.claude`.+// Locally also (measured 2026-11-05 on 2.1.318, see `claudeLocalExtras`): the skills claude.ai+// syncs to `<configDir>/skills/synced/<bucket>/<name>/SKILL.md` (listed as `/<name>`), and every+// ENABLED plugin's skills and commands (listed as `/<plugin>:<name>`), and `skillOverrides` "off"+// hides a user, project or synced skill.// - gemini: `~/.gemini/commands/**/*.toml` and `<cwd>/.gemini/commands/**/*.toml` (the shipped// custom-commands reference: subfolders are `:` namespaces, `description` is optional).// - every other agent: built-ins only. Their custom-command and skill locations were not measured,@@ -45,7 +49,10 @@ export const CATALOG_ROOT_MAX_FILES = 200export const CATALOG_COMMAND_MAX_DEPTH = 3export const CATALOG_HEAD_BYTES = 4096-export type CatalogRootKind = 'md-commands' | 'toml-commands' | 'skills'+// `skills` = a SKILL.md in each folder of `dir`; `skill-dir` = `dir` itself is one skill folder (a+// plugin manifest may list skill folders one by one); `synced-skills` = `dir/<bucket>/<name>/SKILL.md`+// (claude.ai's sync).+export type CatalogRootKind = 'md-commands' | 'toml-commands' | 'skills' | 'skill-dir' | 'synced-skills'export interface CatalogRoot {kind: CatalogRootKind@@ -62,6 +69,11 @@ export interface CatalogRoot {* an account dir.*/within?: string+ /** A plugin's name: every entry of the root is listed as `<prefix>:<name>`. */+ prefix?: string+ /** `skillOverrides` "off" may hide this root's skills. Measured: it hides a user, project or synced+ * skill and has no effect on a plugin's. */+ overridable?: boolean}export interface ChatCatalogQuery {@@ -70,6 +82,20 @@ export interface ChatCatalogQuery {cwd: string | undefined}+/** Claude's config dir for a node: the bound account's dir, else `~/.claude`. Null for an account id+ * that is not safe or not known — never the system dir in its place, which would list another+ * identity's commands under this node. */+function claudeCatalogConfigDir(accountId: string | undefined, opts: { remote: boolean; home: string }): string | null {+ if (accountId === undefined || accountId === '') return opts.remote ? '~/.claude' : path.join(opts.home, '.claude')+ if (!isSafeAccountId(accountId)) return null+ if (opts.remote) return remoteAccountConfigDir(accountId)+ try {+ return claudeConfigDirFor(accountId)+ } catch {+ return null+ }+}+/** The roots a node's agent reads, in PRECEDENCE order (project before user). */export function catalogRoots(q: ChatCatalogQuery, opts: { remote: boolean; home?: string }): CatalogRoot[] {const base = q.agentId ? capabilityAgentId(q.agentId) : ''@@ -78,27 +104,14 @@ export function catalogRoots(q: ChatCatalogQuery, opts: { remote: boolean; home?const join = (a: string, ...b: string[]) => (opts.remote ? [a.replace(/\/+$/, ''), ...b].join('/') : path.join(a, ...b))const roots: CatalogRoot[] = []if (base === 'claude') {- let configDir: string | null- if (q.accountId) {- // A bad id is no account: its roots are simply absent (never the system dir in its place —- // that would list another identity's commands under this node).- if (!isSafeAccountId(q.accountId)) configDir = null- else if (opts.remote) configDir = remoteAccountConfigDir(q.accountId)- else {- try {- configDir = claudeConfigDirFor(q.accountId)- } catch {- configDir = null- }- }- } else configDir = opts.remote ? '~/.claude' : path.join(home, '.claude')+ const configDir = claudeCatalogConfigDir(q.accountId, { remote: opts.remote, home })if (cwd) {roots.push({ kind: 'md-commands', scope: 'project', dir: join(cwd, '.claude', 'commands'), within: cwd })- roots.push({ kind: 'skills', scope: 'project', dir: join(cwd, '.claude', 'skills'), within: cwd })+ roots.push({ kind: 'skills', scope: 'project', dir: join(cwd, '.claude', 'skills'), within: cwd, overridable: true })}if (configDir) {roots.push({ kind: 'md-commands', scope: 'user', dir: join(configDir, 'commands') })- roots.push({ kind: 'skills', scope: 'user', dir: join(configDir, 'skills') })+ roots.push({ kind: 'skills', scope: 'user', dir: join(configDir, 'skills'), overridable: true })}} else if (base === 'gemini') {if (cwd) roots.push({ kind: 'toml-commands', scope: 'project', dir: join(cwd, '.gemini', 'commands'), within: cwd })@@ -121,7 +134,9 @@ export function parseFrontmatter(text: string): { fields: Record<string, string>const m = /^([A-Za-z][A-Za-z0-9_-]*)\s*:\s*(.*)$/.exec(line)if (!m) continuelet v = m[2].trim()- if ((v.startsWith('"') && v.endsWith('"') && v.length >= 2) || (v.startsWith("'") && v.endsWith("'") && v.length >= 2)) v = v.slice(1, -1)+ if (v.startsWith('"') && v.endsWith('"') && v.length >= 2) v = v.slice(1, -1)+ // YAML's single-quoted scalar escapes a quote by doubling it (`'the project''s build'`).+ else if (v.startsWith("'") && v.endsWith("'") && v.length >= 2) v = v.slice(1, -1).replace(/''/g, "'")fields[m[1].toLowerCase()] = v}const after = t.indexOf('\n', end + 1)@@ -180,9 +195,15 @@ export function tomlCommandEntry(rel: string, text: string, scope: CatalogRoot['/** One file of one root → its entry (or null). */export function entryFor(root: CatalogRoot, rel: string, text: string): ChatCatalogEntry | null {- if (root.kind === 'md-commands') return markdownCommandEntry(rel, text, root.scope)- if (root.kind === 'toml-commands') return tomlCommandEntry(rel, text, root.scope)- return skillEntry(rel, text, root.scope)+ const e =+ root.kind === 'md-commands'+ ? markdownCommandEntry(rel, text, root.scope)+ : root.kind === 'toml-commands'+ ? tomlCommandEntry(rel, text, root.scope)+ : skillEntry(rel, text, root.scope)+ if (e === null || root.prefix === undefined) return e+ const name = catalogName(`${root.prefix}:${e.name}`)+ return name === null ? null : { ...e, name }}/** Built-ins last, custom entries in root order (project first), deduped. */@@ -287,9 +308,21 @@ async function localRootFiles(root: CatalogRoot): Promise<{ rel: string; file: s}if (real !== realWithin && !real.startsWith(realWithin.endsWith(path.sep) ? realWithin : realWithin + path.sep)) return null}+ if (root.kind === 'skill-dir') return [{ rel: path.basename(root.dir), file: path.join(root.dir, 'SKILL.md') }]const top = await listLocalDir(root.dir, follow)if (!top) return nullconst out: { rel: string; file: string }[] = []+ if (root.kind === 'synced-skills') {+ for (const bucket of top) {+ if (!bucket.dir || bucket.name.startsWith('.')) continue+ const skills = await listLocalDir(path.join(root.dir, bucket.name), follow).catch(() => null)+ for (const e of skills ?? []) {+ if (out.length >= CATALOG_ROOT_MAX_FILES) return out+ if (e.dir && !e.name.startsWith('.')) out.push({ rel: e.name, file: path.join(root.dir, bucket.name, e.name, 'SKILL.md') })+ }+ }+ return out+ }if (root.kind === 'skills') {for (const e of top) {if (out.length >= CATALOG_ROOT_MAX_FILES) break@@ -315,7 +348,8 @@ async function localRootFiles(root: CatalogRoot): Promise<{ rel: string; file: s}export async function buildLocalCatalog(q: ChatCatalogQuery, opts: { home?: string } = {}): Promise<ChatCatalog> {- const roots = catalogRoots(q, { remote: false, home: opts.home })+ const extras = await claudeLocalExtras(q, opts.home ?? os.homedir())+ const roots = [...catalogRoots(q, { remote: false, home: opts.home }), ...extras.roots]let partial = falseconst perRoot = await Promise.all(roots.map(async (root) => {@@ -331,7 +365,7 @@ export async function buildLocalCatalog(q: ChatCatalogQuery, opts: { home?: striconst text = await readLocalHead(f.file, root.within === undefined)if (text === null) continueconst e = entryFor(root, f.rel, text)- if (e) out.push(e)+ if (e !== null && !(root.overridable === true && skillTurnedOff(e, root, extras.overrides))) out.push(e)}return out})@@ -339,6 +373,126 @@ export async function buildLocalCatalog(q: ChatCatalogQuery, opts: { home?: strireturn assembleCatalog(q.agentId, perRoot, partial)}+// ── Plugins, synced skills and skill overrides (claude, local) ───────────────────────────────────+//+// MEASURED 2026-11-05 on Claude Code 2.1.318 (its own `/` menu, fresh sessions, test settings passed+// with `--settings`):+// - A plugin's skills and commands are listed as `/<plugin>:<name>` when the plugin is in+// `<configDir>/plugins/installed_plugins.json` AND `enabledPlugins["<plugin>@<marketplace>"]` is+// true. A disabled one lists nothing; a plugin that is only in the cache lists nothing; an install+// of scope `project` / `local` lists only in the folder it was installed for. The files are read+// from the install's `installPath` (older cached versions beside it are not).+// - claude.ai-synced skills (`<configDir>/skills/synced/<bucket>/<name>/SKILL.md`) are listed as+// `/<name>`.+// - `skillOverrides: { "<name>": "off" }` hides a user, project or synced skill (for a synced one+// `"anthropic-skills:<name>"` works too); `name-only` and `user-invocable-only` keep it in the+// menu; nothing hides a PLUGIN's skill this way. Settings are merged user < project < local, as+// for every other setting.++/** Bounds on what is read from settings: at most this many plugins, files this large. */+export const CATALOG_PLUGINS_MAX = 64+const SETTINGS_MAX_BYTES = 1024 * 1024+/** A synced skill's other spelling in `skillOverrides` (both measured to work). */+const SYNCED_OVERRIDE_PREFIX = 'anthropic-skills:'++interface ClaudeExtras {+ roots: CatalogRoot[]+ /** skillOverrides, merged; only "off" is acted on. */+ overrides: Map<string, string>+}++function skillTurnedOff(e: ChatCatalogEntry, root: CatalogRoot, overrides: Map<string, string>): boolean {+ if (e.kind !== 'skill') return false+ if (overrides.get(e.name) === 'off') return true+ return root.kind === 'synced-skills' && overrides.get(`${SYNCED_OVERRIDE_PREFIX}${e.name}`) === 'off'+}++/** A small JSON object file, or null (absent, too large, not JSON, not an object, or — `follow`+ * false, a project file — a symlink). */+async function readLocalJson(file: string, follow: boolean): Promise<Record<string, unknown> | null> {+ try {+ const fh = await fsp.open(file, follow ? fsConstants.O_RDONLY : fsConstants.O_RDONLY | O_NOFOLLOW)+ try {+ const st = await fh.stat()+ if (!st.isFile() || st.size > SETTINGS_MAX_BYTES) return null+ const v: unknown = JSON.parse((await fh.readFile()).toString('utf8'))+ return v !== null && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : null+ } finally {+ await fh.close()+ }+ } catch {+ return null+ }+}++const recordOf = (v: unknown): Record<string, unknown> =>+ v !== null && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : {}++/** The paths a manifest field names (a string or a list of strings), each resolved inside `root`. */+function manifestPaths(v: unknown, root: string, fallback: string): string[] {+ const raw = v === undefined ? [fallback] : typeof v === 'string' ? [v] : Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []+ const out: string[] = []+ for (const r of raw as string[]) {+ const abs = path.resolve(root, r)+ const rel = path.relative(root, abs)+ if (rel.startsWith('..') || path.isAbsolute(rel)) continue+ out.push(abs)+ }+ return out+}++/** The extra roots and the skill overrides of a LOCAL claude node. Never throws: a file that cannot+ * be read adds nothing. */+export async function claudeLocalExtras(q: ChatCatalogQuery, home: string): Promise<ClaudeExtras> {+ const none: ClaudeExtras = { roots: [], overrides: new Map() }+ if (q.agentId === undefined || capabilityAgentId(q.agentId) !== 'claude') return none+ const configDir = claudeCatalogConfigDir(q.accountId, { remote: false, home })+ if (configDir === null) return none+ const cwd = typeof q.cwd === 'string' && q.cwd.trim() !== '' ? q.cwd : undefined+ const settings = [+ await readLocalJson(path.join(configDir, 'settings.json'), true),+ ...(cwd === undefined+ ? []+ : [+ await readLocalJson(path.join(cwd, '.claude', 'settings.json'), false),+ await readLocalJson(path.join(cwd, '.claude', 'settings.local.json'), false)+ ])+ ]+ const enabled = new Map<string, boolean>()+ const overrides = new Map<string, string>()+ for (const s of settings) {+ for (const [k, v] of Object.entries(recordOf(s?.enabledPlugins))) if (typeof v === 'boolean') enabled.set(k, v)+ for (const [k, v] of Object.entries(recordOf(s?.skillOverrides))) if (typeof v === 'string') overrides.set(k, v)+ }++ const roots: CatalogRoot[] = [{ kind: 'synced-skills', scope: 'user', dir: path.join(configDir, 'skills', 'synced'), overridable: true }]+ const installed = recordOf((await readLocalJson(path.join(configDir, 'plugins', 'installed_plugins.json'), true))?.plugins)+ let count = 0+ for (const [key, installs] of Object.entries(installed)) {+ if (enabled.get(key) !== true || !Array.isArray(installs)) continue+ if (++count > CATALOG_PLUGINS_MAX) break+ const install = installs.map(recordOf).find((i) => {+ if (i.scope === 'user' || i.scope === undefined) return true+ return cwd !== undefined && typeof i.projectPath === 'string' && path.resolve(i.projectPath) === path.resolve(cwd)+ })+ const installPath = install?.installPath+ if (typeof installPath !== 'string' || !path.isAbsolute(installPath)) continue+ const manifest = await readLocalJson(path.join(installPath, '.claude-plugin', 'plugin.json'), true)+ const prefix = catalogName(manifest?.name) ?? catalogName(key.split('@')[0])+ if (prefix === null) continue+ for (const dir of manifestPaths(manifest?.skills, installPath, 'skills')) {+ // A listed folder is one skill when it holds a SKILL.md, else a folder of skills.+ const one = await fsp+ .stat(path.join(dir, 'SKILL.md'))+ .then((st) => st.isFile())+ .catch(() => false)+ roots.push({ kind: one ? 'skill-dir' : 'skills', scope: 'user', dir, prefix })+ }+ for (const dir of manifestPaths(manifest?.commands, installPath, 'commands')) roots.push({ kind: 'md-commands', scope: 'user', dir, prefix })+ }+ return { roots, overrides }+}+// ── Remote reader (one ssh round trip) ──────────────────────────────────────────────────────────// Record marker at the start of a line. Every file's bytes go through `tr -d` of the marker byte, sodiff --git a/src/renderer/lib/chatComposerComplete.test.ts b/src/renderer/lib/chatComposerComplete.test.tsindex 0ecd180a6..feb6a891c 100644--- a/src/renderer/lib/chatComposerComplete.test.ts+++ b/src/renderer/lib/chatComposerComplete.test.ts@@ -20,15 +20,24 @@ const e = (name: string, description = '', kind: ChatCatalogEntry['kind'] = 'bui})describe('completionTriggerAt', () => {- it('a slash is a command only at the start of the message', () => {+ it('a slash opens at the start of the message, even bare', () => {expect(completionTriggerAt('/mo', 3)).toEqual({ kind: 'slash', query: 'mo', start: 0, end: 3 })expect(completionTriggerAt(' /', 3)).toEqual({ kind: 'slash', query: '', start: 2, end: 3 })- expect(completionTriggerAt('see /usr', 8)).toBeNull()expect(completionTriggerAt('/model x', 8)).toBeNull()// Caret inside the word: the token runs to its end.expect(completionTriggerAt('/model', 2)).toEqual({ kind: 'slash', query: 'm', start: 0, end: 6 })})+ it('mid-message, a slash opens after whitespace once a character follows it, as in the TUI', () => {+ expect(completionTriggerAt('please use /tid', 15)).toEqual({ kind: 'slash', query: 'tid', start: 11, end: 15 })+ expect(completionTriggerAt('line one\n/tid', 13)).toEqual({ kind: 'slash', query: 'tid', start: 9, end: 13 })+ expect(completionTriggerAt('see /usr and', 7)).toEqual({ kind: 'slash', query: 'us', start: 4, end: 8 })++ expect(completionTriggerAt('x /', 3)).toBeNull()+ expect(completionTriggerAt('see src/tid', 11)).toBeNull()+ expect(completionTriggerAt('a/tid', 5)).toBeNull()+ })+it('an @ opens only at the start of a word, anywhere in the message', () => {expect(completionTriggerAt('read @src/ma', 12)).toEqual({ kind: 'file', query: 'src/ma', start: 5, end: 12 })expect(completionTriggerAt('@', 1)).toEqual({ kind: 'file', query: '', start: 0, end: 1 })diff --git a/src/renderer/lib/chatComposerComplete.ts b/src/renderer/lib/chatComposerComplete.tsindex 83badff2a..f12034208 100644--- a/src/renderer/lib/chatComposerComplete.ts+++ b/src/renderer/lib/chatComposerComplete.ts@@ -21,21 +21,26 @@ export interface CompletionTrigger {const NAME_CHAR = /[A-Za-z0-9._:-]//**- * The token the caret is in, or null. A slash command is only a command at the very start of the- * message (after optional whitespace) — every CLI measured reads `/x` mid-sentence as text — so- * `see /usr` never opens the menu. An `@` opens it at the start of a word only, so an e-mail address+ * The token the caret is in, or null. The `/` menu follows Claude Code's TUI (measured on 2.1.318):+ * it opens for a `/` at the start of the message (even bare) and, once a character follows it, for a+ * `/` after whitespace anywhere in the message (`please use /tid`); never inside a word or a path+ * (`src/tid`, `a/tid`). A `/name` mid-message is text the model reads (a skill it may use), not a+ * command the CLI runs. An `@` opens the menu at the start of a word only, so an e-mail address* (`a@b`) does not. A selection (caret range) never completes.*/export function completionTriggerAt(text: string, caret: number, selectionEnd = caret): CompletionTrigger | null {if (caret !== selectionEnd || caret < 0 || caret > text.length) return nullconst before = text.slice(0, caret)const after = text.slice(caret)- const slash = /^(\s*)\/([A-Za-z0-9._:-]*)$/.exec(before)- if (slash) {+ const slashEnd = (): number => {let end = caretwhile (end < text.length && NAME_CHAR.test(text[end])) end++- return { kind: 'slash', query: slash[2], start: slash[1].length, end }+ return end}+ const lead = /^(\s*)\/([A-Za-z0-9._:-]*)$/.exec(before)+ if (lead) return { kind: 'slash', query: lead[2], start: lead[1].length, end: slashEnd() }+ const mid = /\s\/([A-Za-z0-9._:-]+)$/.exec(before)+ if (mid) return { kind: 'slash', query: mid[1], start: caret - mid[1].length - 1, end: slashEnd() }const at = /(^|\s)@([^\s@]*)$/.exec(before)if (at) {const start = caret - at[2].length - 1diff --git a/src/renderer/lib/chatComposerHighlight.test.ts b/src/renderer/lib/chatComposerHighlight.test.tsnew file mode 100644index 000000000..668664d1b--- /dev/null+++ b/src/renderer/lib/chatComposerHighlight.test.ts@@ -0,0 +1,44 @@+import { describe, expect, it } from 'vitest'+import { commandSegments, mentionsSlashToken } from './chatComposerHighlight'++const known = new Set(['explain', 'tools:tidy-up', 'compact'])++describe('commandSegments', () => {+ it('cuts out known commands at the start or after whitespace, as the TUI colors them', () => {+ const segs = commandSegments('/compact then /tools:tidy-up and /notaskill', known)++ expect(segs).toEqual([+ { text: '/compact', command: true },+ { text: ' then ', command: false },+ { text: '/tools:tidy-up', command: true },+ { text: ' and /notaskill', command: false }+ ])+ })++ it('needs the command to end the word, and to start one', () => {+ expect(commandSegments('/explainx', known)).toBeNull()+ expect(commandSegments('a/explain', known)).toBeNull()+ expect(commandSegments('/explain,', known)).toBeNull()+ })++ it('keeps every character, newlines included', () => {+ const text = 'one\n/explain\n\ntwo '++ const segs = commandSegments(text, known)++ expect(segs?.map((s) => s.text).join('')).toBe(text)+ })++ it('is null for a draft with no known command', () => {+ expect(commandSegments('plain text /nothing', known)).toBeNull()+ expect(commandSegments('', known)).toBeNull()+ })+})++describe('mentionsSlashToken', () => {+ it('spots a /name where the menu would open', () => {+ expect(mentionsSlashToken('use /explain')).toBe(true)+ expect(mentionsSlashToken('/x')).toBe(true)+ expect(mentionsSlashToken('src/x and /')).toBe(false)+ })+})diff --git a/src/renderer/lib/chatComposerHighlight.ts b/src/renderer/lib/chatComposerHighlight.tsnew file mode 100644index 000000000..7dbc35484--- /dev/null+++ b/src/renderer/lib/chatComposerHighlight.ts@@ -0,0 +1,41 @@+// The ⌘M composer's command highlight (ChatComposer): Claude Code's TUI colors a `/name` in its+// input when the name is a real command (measured on 2.1.318: a skill's `/name` mid-sentence is colored,+// `/notaskill` stays plain). A textarea cannot color part of its text, so the composer draws these+// segments in a layer behind it — only while the draft holds a known command, so an ordinary draft+// renders exactly as before.++export interface ComposerSegment {+ text: string+ command: boolean+}++/** A `/name` at the start of the text or after whitespace (the places the `/` menu opens). */+const COMMAND_RE = /(^|\s)(\/[A-Za-z0-9._:-]+)/g++/** The draft cut into plain text and known `/commands`. Null when it holds none, so the caller can+ * leave the plain textarea alone. */+export function commandSegments(text: string, known: ReadonlySet<string>): ComposerSegment[] | null {+ const out: ComposerSegment[] = []+ let from = 0+ let found = false+ for (const m of text.matchAll(COMMAND_RE)) {+ const start = (m.index ?? 0) + m[1].length+ const token = m[2]+ if (!known.has(token.slice(1))) continue+ // The token must end the word: `/explainx` is not `/explain`.+ const next = text[start + token.length]+ if (next !== undefined && !/\s/.test(next)) continue+ if (start > from) out.push({ text: text.slice(from, start), command: false })+ out.push({ text: token, command: true })+ from = start + token.length+ found = true+ }+ if (!found) return null+ if (from < text.length) out.push({ text: text.slice(from), command: false })+ return out+}++/** Whether the draft holds a `/x` the catalog should be fetched for (to color it). */+export function mentionsSlashToken(text: string): boolean {+ return /(^|\s)\/[A-Za-z0-9]/.test(text)+}diff --git a/src/renderer/nodes/ChatComposer.complete.test.tsx b/src/renderer/nodes/ChatComposer.complete.test.tsxindex 7c7297e8e..5c6499dfe 100644--- a/src/renderer/nodes/ChatComposer.complete.test.tsx+++ b/src/renderer/nodes/ChatComposer.complete.test.tsx@@ -248,3 +248,38 @@ describe('ChatComposer completion', () => {expect(options().some((t) => t.startsWith('/compact'))).toBe(true)})})++describe('command highlight', () => {+ it('colors a known /command anywhere in the draft and turns spell checking off while it is there', async () => {+ await mount()++ await type('please /git:commit now and /nothing')++ const cmds = [...host.querySelectorAll('.term-chat__composer-command')].map((n) => n.textContent)+ expect(cmds).toEqual(['/git:commit'])+ expect(host.querySelector('.term-chat__composer-highlight')?.textContent).toBe('please /git:commit now and /nothing\u200b')+ expect(ta().getAttribute('spellcheck')).toBe('false')+ expect(ta().classList.contains('term-chat__composer-input--over')).toBe(true)+ })++ it('leaves an ordinary draft exactly as before', async () => {+ await mount()++ await type('just words, spelled badly')++ expect(host.querySelector('.term-chat__composer-highlight')).toBeNull()+ expect(ta().getAttribute('spellcheck')).toBe('true')+ expect(ta().classList.contains('term-chat__composer-input--over')).toBe(false)+ })++ it('opens the menu mid-message and inserts the name there', async () => {+ await mount()+ await type('please run /git:co')++ await key('Enter')++ expect(draft()).toBe('please run /git:commit ')+ expect(onSend).not.toHaveBeenCalled()+ })+})+diff --git a/src/renderer/nodes/ChatComposer.tsx b/src/renderer/nodes/ChatComposer.tsxindex 0f80d7e57..4866f69b4 100644--- a/src/renderer/nodes/ChatComposer.tsx+++ b/src/renderer/nodes/ChatComposer.tsx@@ -3,6 +3,8 @@ import {useCallback,useEffect,useId,+ useLayoutEffect,+ useMemo,useRef,useState,type ClipboardEvent as ReactClipboardEvent,@@ -24,6 +26,7 @@ import { IconMic, IconPlus } from '../components/icons'import { Spinner } from '../components/Spinner'import { builtinSlashCommands, sanitizeChatCatalog, type ChatCatalogEntry } from '@shared/chat-catalog'import { prepareQuickOpenFiles, type QuickOpenIndexedFile } from '../lib/quickOpenSearch'+import { commandSegments, mentionsSlashToken } from '../lib/chatComposerHighlight'import {CATALOG_REUSE_MS,applyCompletion,@@ -197,9 +200,29 @@ export function ChatComposer({if (token !== lastTokenRef.current) setActiveIdx(0)lastTokenRef.current = tokenif (t) ensureLists(t.kind)+ // A `/name` anywhere in the draft is colored once the catalog knows it (below), so a draft that+ // holds one asks for the catalog even with no menu open.+ else if (mentionsSlashToken(text)) ensureLists('slash')},[disabled, ensureLists])+ // Known `/commands` in the draft, drawn colored in a layer behind the textarea+ // (lib/chatComposerHighlight.ts). Null = none: the textarea renders exactly as it always did. While+ // there is one, spell checking is off for the whole draft — a textarea can only check all of its+ // text or none, and a command name is not a word. A half-typed `/tid` keeps its underline: until it+ // names a command, it is a misspelling.+ const knownNames = useMemo(() => new Set(catalog.map((e) => e.name)), [catalog])+ const segments = useMemo(() => commandSegments(value, knownNames), [value, knownNames])+ const highlightRef = useRef<HTMLDivElement>(null)+ const syncHighlightScroll = useCallback(() => {+ const ta = inputRef.current+ const hl = highlightRef.current+ if (ta === null || hl === null) return+ // A visible scrollbar narrows the textarea's text; the layer must wrap at the same width.+ hl.style.paddingRight = `${6 + Math.max(0, ta.offsetWidth - ta.clientWidth)}px`+ hl.scrollTop = ta.scrollTop+ }, [])+ useLayoutEffect(syncHighlightScroll, [segments, syncHighlightScroll])// A composer that cannot flip to the terminal (no `onShowTerminal`) does not offer a built-in that// opens a dialog there: the dialog would be invisible and the next Enter would answer it.const offered = onShowTerminal ? catalog : catalog.filter((e) => !e.interactive)@@ -207,6 +230,19 @@ export function ChatComposer({trigger && dismissedAt !== trigger.start ? completionItems(trigger, offered, fileIndex) : []const menuOpen = items.length > 0const active = Math.min(activeIdx, Math.max(0, items.length - 1))+ // Keep the active row in view as the arrows move it. The menu's own scroll only, by hand:+ // `scrollIntoView` also scrolls every scrollable ancestor, and an `overflow: hidden` one inside+ // the canvas would shift the node under the user.+ const menuRef = useRef<HTMLDivElement>(null)+ useLayoutEffect(() => {+ const menu = menuRef.current+ const row = menuOpen ? (menu?.children[active] as HTMLElement | undefined) : undefined+ if (menu === null || row === undefined) return+ if (row.offsetTop < menu.scrollTop) menu.scrollTop = active === 0 ? 0 : row.offsetTop+ else if (row.offsetTop + row.offsetHeight > menu.scrollTop + menu.clientHeight) {+ menu.scrollTop = row.offsetTop + row.offsetHeight - menu.clientHeight+ }+ }, [menuOpen, active])const accept = (item: CompletionItem) => {if (!trigger || disabled) return@@ -419,6 +455,7 @@ export function ChatComposer({<div className="term-chat__compose">{menuOpen && (<div+ ref={menuRef}className="term-chat__complete"id={listboxId}role="listbox"@@ -467,40 +504,59 @@ export function ChatComposer({onDragLeave={onDragLeave}onDrop={onDrop}>- <textarea- ref={inputRef}- className="term-chat__composer-input"- value={value}- onChange={(e) => {- onChange(e.target.value)- const caret = e.target.selectionStart ?? e.target.value.length- // A new token (or none) forgets an Esc on the previous one.- if (dismissedAt !== null && completionTriggerAt(e.target.value, caret)?.start !== dismissedAt) setDismissedAt(null)- syncTrigger(e.target.value, caret, e.target.selectionEnd ?? caret)- }}- onKeyUp={(e) => {- // Caret moves (arrows, Home/End) — keys that edit already went through onChange. The menu's- // own navigation keys are not caret moves while it is open.- if (e.nativeEvent.isComposing || (menuOpen && (e.key === 'ArrowDown' || e.key === 'ArrowUp'))) return- const el = e.currentTarget- syncTrigger(el.value, el.selectionStart ?? el.value.length, el.selectionEnd ?? el.value.length)- }}- onClick={(e) => {- const el = e.currentTarget- syncTrigger(el.value, el.selectionStart ?? el.value.length, el.selectionEnd ?? el.value.length)- }}- onBlur={closeMenu}- role="combobox"- aria-autocomplete="list"- aria-expanded={menuOpen}- aria-controls={menuOpen ? listboxId : undefined}- aria-activedescendant={menuOpen ? `${listboxId}-${active}` : undefined}- onKeyDown={onKeyDown}- onPaste={onPaste}- placeholder={placeholder}- disabled={disabled}- rows={2}- />+ <div className="term-chat__composer-field">+ {segments !== null && (+ <div ref={highlightRef} className="term-chat__composer-highlight" aria-hidden="true">+ {segments.map((seg, i) =>+ seg.command ? (+ <span key={i} className="term-chat__composer-command">+ {seg.text}+ </span>+ ) : (+ seg.text+ )+ )}+ {/* A trailing newline needs a character after it to take up its line, as in the textarea. */}+ {'\u200b'}+ </div>+ )}+ <textarea+ ref={inputRef}+ className={`term-chat__composer-input${segments !== null ? ' term-chat__composer-input--over' : ''}`}+ spellCheck={segments === null}+ onScroll={syncHighlightScroll}+ value={value}+ onChange={(e) => {+ onChange(e.target.value)+ const caret = e.target.selectionStart ?? e.target.value.length+ // A new token (or none) forgets an Esc on the previous one.+ if (dismissedAt !== null && completionTriggerAt(e.target.value, caret)?.start !== dismissedAt) setDismissedAt(null)+ syncTrigger(e.target.value, caret, e.target.selectionEnd ?? caret)+ }}+ onKeyUp={(e) => {+ // Caret moves (arrows, Home/End) — keys that edit already went through onChange. The menu's+ // own navigation keys are not caret moves while it is open.+ if (e.nativeEvent.isComposing || (menuOpen && (e.key === 'ArrowDown' || e.key === 'ArrowUp'))) return+ const el = e.currentTarget+ syncTrigger(el.value, el.selectionStart ?? el.value.length, el.selectionEnd ?? el.value.length)+ }}+ onClick={(e) => {+ const el = e.currentTarget+ syncTrigger(el.value, el.selectionStart ?? el.value.length, el.selectionEnd ?? el.value.length)+ }}+ onBlur={closeMenu}+ role="combobox"+ aria-autocomplete="list"+ aria-expanded={menuOpen}+ aria-controls={menuOpen ? listboxId : undefined}+ aria-activedescendant={menuOpen ? `${listboxId}-${active}` : undefined}+ onKeyDown={onKeyDown}+ onPaste={onPaste}+ placeholder={placeholder}+ disabled={disabled}+ rows={2}+ />+ </div><div className="term-chat__toolbar">{pathsForFiles && (<>diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 7651b9254..a2216a008 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -4106,6 +4106,38 @@ body,.term-chat__composer-input:focus {outline: none;}+/* The command highlight (lib/chatComposerHighlight.ts): while the draft holds a known `/command`, the+ textarea's text goes transparent (its caret, selection and input stay) and a layer behind it draws+ the same text, with the command in the accent color, as Claude Code's TUI colors it. The layer must+ lay text out exactly like the textarea: same box, font, padding and wrapping, and nothing that+ changes a glyph's width (no bold, no padding on the command). */+.term-chat__composer-field {+ position: relative;+}+.term-chat__composer-highlight {+ position: absolute;+ inset: 0;+ box-sizing: border-box;+ padding: 4px 6px;+ overflow: hidden;+ white-space: pre-wrap;+ overflow-wrap: break-word;+ font-family: var(--md-font-family);+ font-size: var(--md-font-size);+ line-height: normal;+ color: var(--text-strong);+ pointer-events: none;+}+.term-chat__composer-command {+ color: var(--accent);+ background: color-mix(in srgb, var(--accent) 14%, transparent);+ border-radius: 3px;+}+.term-chat__composer-input--over {+ position: relative;+ color: transparent;+ caret-color: var(--text-strong);+}.term-chat__composer-input:disabled {opacity: 0.5;}