@dolusoft/command-console

中文文档
1.9.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 3053

A headless command console for Vue 3: a scrollback above one input line, with recall, Tab completion, a context stack and redaction of sensitive lines. Ships no CSS.

原始使用文档
文档目录4 节
  1. The component
  2. Styling
  3. The composable
  4. License

@dolusoft/command-console

A headless command console for Vue 3: useCommandConsole and the CommandConsole component of Command Console. A scrollback of entries above one input line with a prompt: the user types a line, the console runs your command for it and shows what the command returns. Line editing, recall, completion, cancellation, a context stack and the redaction of sensitive lines are the library's; the commands, every text and all styling are yours. Ships no CSS; vue 3.5+ is its only peer.

pnpm add @dolusoft/command-console

The full guide (commands, returns and effects, completion, recall, keys, sensitive lines) is the repository README.

The component

<script setup lang="ts">
import { ref } from 'vue'
import {
  CommandConsole,
  type CommandDefinition,
  type ConsoleEntry
} from '@dolusoft/command-console'

const commands: CommandDefinition[] = [
  { name: 'echo', run: request => request.rest },
  // From argument 1 on the line is secret: it is never kept, shown or emitted.
  {
    name: 'set',
    sensitive: { fromArg: 1 },
    run: (request, run) => save(request.args, run.signal)
  },
  { name: 'exit', run: () => ({ effects: [{ type: 'close' }] }) }
]
const entries = ref<ConsoleEntry[]>([])
const open = ref(true)
</script>

<template>
  <CommandConsole
    v-if="open"
    v-model:entries="entries"
    :commands="commands"
    prompt="app>"
    autofocus
    @close="open = false"
  />
</template>
  • Recall, completion and context are always on. entries, recall and context are the console's own unless bound with v-model:*; initialState gives the first value of an unbound slice.
  • Props: commands, prompt, initialState, createId, maxEntries, beforeRun, onError, formatError, isSensitive, recallLimit, shouldRecord, labels, autofocus, entries / recall / context, and console.
  • A console that outlives the component: :console="pageConsole" draws a console created elsewhere with every optional feature, and never disposes it, so a panel mounted again shows the same entries and live input. Its options are its creator's: with console, commands to shouldRecord and entries / recall / context throw a TypeError; labels and autofocus apply.
  • Events: update:entries, update:recall, update:context (for v-model, each resolved against the value last emitted, so two changes in one tick are both kept), close (a command's close effect) and submit ({ inputId, sensitive }, never the line; for Enter and the exposed run).
  • Slots: block-text, block-json, block-table, block-list, block-message, block-custom ({ block, entry }, inside a div.cc-block), prompt, busy, completion. A slot replaces content, never the element that carries the hooks.
  • Labels: every text the component shows is in labels, over English defaults; messages and actors merge one level deep and a message may be a function of its parameters. A line from the assistant or an external agent (InputEntry.actor) shows labels.actors[actor] (AI, Agent) in a span.cc-actor before its prompt, and its entry has data-actor.
  • Expose: focus(), run(line), cancel(), reset(), clear(), console and state (unwrapped by the template ref: consoleRef.value.state.running).

Styling

The component renders plain elements with cc-* classes and data-* attributes, listed in contract/dom.ts. Nothing has a size or a style of its own: give .cc-log a height and overflow-y: auto and it scrolls, staying at the bottom while the user is there.

.cc-log {
  height: 20rem;
  overflow-y: auto;
}
.cc-block {
  margin: 0;
  white-space: pre-wrap;
}
.cc-entry[data-tone='error'] {
  color: crimson;
}
.cc-console[data-busy] .cc-input {
  opacity: 0.6;
}
.cc-completion[aria-selected='true'] {
  background: highlight;
}

The composable

useCommandConsole(options) gives the same console without markup: { console, state }, where state is a read-only ShallowRef of the console's state. A value option (commands, prompt, state, maxEntries, recallLimit) takes a value, a ref or a getter; a function option takes the function or a ref to it. features and initialState are read once, and the console is disposed with the calling scope; useCommandConsole({ console }) mirrors a console created elsewhere, takes no other option and never disposes it. The optional features come from @dolusoft/command-console-core:

import { useCommandConsole } from '@dolusoft/command-console'
import { consoleFeatures, recallFeature } from '@dolusoft/command-console-core'

const { console, state } = useCommandConsole({
  features: consoleFeatures({ recallFeature }),
  commands: () => commands.value
})

License

MIT, see LICENSE.md.

版本与发布记录

@dolusoft/command-console 共发布 18 个版本,首次发布于 2026/10/27;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.0latest2026/11/112 天前
1.8.22026/11/112 天前
1.8.12026/11/112 天前
1.8.02026/11/112 天前
1.7.22026/11/112 天前
1.7.12026/11/112 天前

关于 @dolusoft/command-console 的常见问题

@dolusoft/command-console 是什么?

A headless command console for Vue 3: a scrollback above one input line, with recall, Tab completion, a context stack and redaction of sensitive lines. Ships no CSS.

如何安装 @dolusoft/command-console?

在项目目录运行 npm install @dolusoft/command-console,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.5.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dolusoft/command-console 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dolusoft/command-console 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dolusoft/command-console 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dolusoft/command-console 可以商用吗?

@dolusoft/command-console 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dolusoft/command-console 的下载量有多少?

根据 npm 官方下载统计,@dolusoft/command-console 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,053 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dolusoft/command-console 还在维护吗?

最新版本 1.9.0 发布于 2026/11/11(2 天前);至今共发布 18 个版本,其中过去 12 个月发布了 18 个;首次发布于 2026/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。