@aliyunrds/ctxdb-shared

中文文档
0.0.12发布于 2026/10/30Apache-2.0TypeScriptES Module零依赖近 30 天下载 1835

Shared B-rule modules + memory/KB types for RDS ContextDatabase access layers (OpenClaw fork + Qoder hooks).

原始使用文档
文档目录7 节
  1. Why this package
  2. What's in here
  3. What's NOT in here
  4. Usage
  5. Versioning
  6. Build / test
  7. Public CLI authentication

@aliyunrds/ctxdb-shared

Shared B-rule modules + memory/KB types for RDS ContextDatabase access layers.

Why this package

ctxdb-dev ships two access layers that both implement the same B-rules (B-0 wrapper strip / B-1 KB anti-injection preamble / B-2 KB content sanitize / B-3c KB-create-or-update-turn skip) and the same memory/KB type system:

  • openclaw_memory_rds_ctxdb — OpenClaw plugin (Mem0-mode platform / OSS)
  • @aliyunrds/ctxdb-qoder — Qoder hooks + rds-ctxdb CLI

Without this shared package, the two access layers had to keep two parallel implementations of the B-rules in sync — a TS implementation in the OpenClaw fork and (formerly) a Python port for Qoder. That bug-for-bug sync became a recurring source of drift (see ctxdb-dev WHOLE.md for the audit trail). This package is the single source of truth.

What's in here

ModulePurpose
kb-detection.tsB-3c — detect KB create/update turns by scanning assistant tool_use blocks; short-circuits autoCapture
graph-context.tsClassify GraphRAG synthesis rows and normalize graph content, KB IDs, and citation semantics
external-knowledge.tsB-1 + B-2 — preamble + chunk sanitize; render graph synthesis and document evidence separately inside <external-knowledge>
filtering.tsB-0 — strip wrappers and noise; redact Core API Keys in automatic extraction copies before truncation, leaving transcripts and CLI output unchanged
capture-slicing.tsselectTurnMessages — pick the current turn from a multi-turn parsed transcript
recall.tsToken-budgeted, category-ranked recall engine (memories search → format)
types.tsShared types: MemoryItem / ExternalContext{Chunk} / Mem0Provider / SearchOptions etc.

What's NOT in here

  • Plugin SDK shapes (OpenClaw plugin entry / hooks system) — fork-internal
  • Mem0Config / Mem0Mode / FileConfig — Mem0 SDK config (fork-private)
  • HTTP client / backend implementation — both consumers do their own
  • CLI / hooks / setup logic — those are consumer-specific

Usage

import {
  isKnowledgeBaseUploadTurn,
  isGraphContextChunk,
  buildExternalKnowledgeBlock,
  filterMessagesForExtraction,
  selectTurnMessages,
  recall,
  type MemoryItem,
  type SearchOptions,
} from "@aliyunrds/ctxdb-shared";

Versioning

Released as @aliyunrds/[email protected] on npm. Both consumer packages declare it as a dependencies entry — npm resolves at install time, no bundling.

Build / test

pnpm install
pnpm test    # → vitest unit tests
pnpm build   # → dist/index.{js,d.ts}

Public CLI authentication

selectDataApiCredential preserves environment AT/API-Key priority. DataApiAuthorizationProvider rereads the persistent Agent choice before requests and delegates Device refresh to OAuthProfileProvider / OAuthSessionStore. Legacy profile references retain their profile check; shared references require the explicit Agent → login ID → credential relationship.

login-bindings.ts owns shared registration, switching, unbind and optimistic login commits. auth-config.ts supplies short config-lock transactions used by ordinary CLI config writers too. The config lock is never held across a network request; credential locks can acquire it, and config writers never wait for credential locks. Login IDs are stable, credential references are replaced on reauthorization, and rotation/ambiguity/tombstone behavior is common to all consumers.

See configuration and lifecycle contract.

版本与发布记录

@aliyunrds/ctxdb-shared 共发布 21 个版本,首次发布于 2026/05/22;过去 12 个月发布了 21 个版本。

版本发布日期距今
0.0.12latest2026/10/308 天前
0.0.12-beta.6beta2026/10/308 天前
0.0.12-beta.52026/10/309 天前
0.0.12-beta.22026/10/2712 天前
0.0.12-beta.12026/10/2712 天前
0.0.12-beta.02026/10/2118 天前

关于 @aliyunrds/ctxdb-shared 的常见问题

@aliyunrds/ctxdb-shared 是什么?

Shared B-rule modules + memory/KB types for RDS ContextDatabase access layers (OpenClaw fork + Qoder hooks).

如何安装 @aliyunrds/ctxdb-shared?

在项目目录运行 npm install @aliyunrds/ctxdb-shared,或使用 pnpm add / yarn add / bun add。

@aliyunrds/ctxdb-shared 支持 TypeScript 吗?

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

@aliyunrds/ctxdb-shared 支持 ESM 还是 CommonJS?

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

@aliyunrds/ctxdb-shared 需要什么版本的 Node.js?

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

@aliyunrds/ctxdb-shared 可以商用吗?

@aliyunrds/ctxdb-shared 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aliyunrds/ctxdb-shared 的下载量有多少?

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

@aliyunrds/ctxdb-shared 还在维护吗?

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