# @donmai/architectural-intelligence 中文文档

规范地址：https://npmcn.com/package/%40donmai/architectural-intelligence/

版本：0\.10\.0
npm 元数据更新时间：2026-10-27T16:23:07.257Z
中文译文更新时间：2026-11-12T16:14:44.082Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40donmai/architectural-intelligence
原文对照：https://npmcn.com/package/%40donmai/architectural-intelligence/?lang=original
项目主页：https://github.com/RenseiAI/donmai-libraries/tree/main/packages/architectural-intelligence
源码仓库：https://github.com/RenseiAI/donmai-libraries

弃用说明：@donmai/architectural-intelligence is deprecated and will be removed in a future major\. The architectural-intelligence layer is now native Go inside the donmai binary \(use \`donmai arch\`\)\. This package is preserved for OSS continuity / downstream pins only and receives no further feature work\.

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：320 kB，69 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.23\.4
- 运行依赖：0 个
- peer 依赖：postgres \>=3\.4\.0，drizzle-orm \>=0\.40\.0
- 首次发布：2026-05-24T22:15:17.920Z
- 最新版本发布：2026-10-27T16:23:06.683Z
- 近 30 天下载量：19324（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：18（近 12 个月 18 个）

## 中文简介

(原始内容存档于2017-10-21). DePRECATED——建筑智能 (TypeScript). 被土生土长的人所取代 `donmai arch` 执行;只为开放源码软件的连续性/下游针头保留.

## 安装

```sh
npm install @donmai/architectural-intelligence
```

也可以使用：`pnpm add @donmai/architectural-intelligence`、`yarn add @donmai/architectural-intelligence`、`bun add @donmai/architectural-intelligence`

## README

# @domai/architectural-intelligence (英语)

> **失败.** 此包被堕. 建筑情报 层正在原地执行 `donmai` 二进制,以及 此 TypeScript 软件包没有实时运行时间消费者 。 保留下来(不是 由于下游npm的消费者可能会把它钉上 今后将取消该课程. 新工作应针对当地人 `donmai arch` 表面.

系统层面综合图案,公约,决定,并跨代码库漂移.

部分 [东迈](https://github.com/RenseiAI/donmai-libraries) 工具链.

## 它会做什么

建筑智能观察一个代码库的进化,并综合了有关它的结构化知识:

-   **模式** ——反复出现的结构形状(例如"所有路线输出a") `POST` 打电话的管理员 `requireOrgAccess`" )
-   **公约** ——所商定的规范(例如,“试验在源头旁边进行,作为 `*.test.ts`" )
-   **决定** ——有记录的建筑选择(例如"Auth使用WorkOS,不是Auth0")
-   **绕行** 将密码库置于偏离自身模式/公约/决定的地方
-   **漂流** 跨越阈值并需要干预的量化偏离压力

包裹船:

| 能力 | 入境点 |
| --- | --- |
| 当地单租店 | `SqliteArchitecturalIntelligence` |
| 多租户商店(注入Postgres手柄) | `PostgresArchitecturalIntelligence`, (中文(简体) ), `adapterFromPostgresJs` |
| 观察管道 | `runObservationPass`, (中文(简体) ), `attachPipelineSubscribers`, (中文(简体) ), `readDiffObservations` |
| 综合提示(版本登记册) | `promptRegistry`, (中文(简体) ), `currentPrompt`, (中文(简体) ), `versionedPrompt` |
| Eval / A/B 测试带 | `evaluatePrompt`, (中文(简体) ), `compareABPrompts` |
| 漂流探测 | `assessChange`, (中文(简体) ), `resolveDriftGatePolicy`, (中文(简体) ), `evaluateGate` |
| 工作流程动词登记 | `registerArchitectureVerbs`, (中文(简体) ), `ASSESS_CHANGE_VERB` |

## 安装

```bash
pnpm add @donmai/architectural-intelligence
```

22号节点.

## 快开始

```ts
import {
  SqliteArchitecturalIntelligence,
  runObservationPass,
  assessChange,
} from '@donmai/architectural-intelligence'

// 1. Open or create the per-tenant store
const store = new SqliteArchitecturalIntelligence({ dbPath: '.donmai/arch.db' })

// 2. Run an observation pass over the change set
const result = await runObservationPass({
  store,
  changeRef: { sha: 'abc123', baseSha: 'main', files: [/* PrDiff entries */] },
})

// 3. Gate on drift — block the merge / open a review issue when the threshold trips
const drift = await assessChange({ store, changeRef: result.changeRef })
if (drift.driftScore > drift.policy.maxDrift) {
  // surface the deviations to the agent or human reviewer
}
```

## 工作流程动词集成

对通过工作流程引擎驱动Donmai的平台消费者,注册 `assess-change` 动词 :

```ts
import { registerArchitectureVerbs } from '@donmai/architectural-intelligence'

registerArchitectureVerbs(verbRegistry)
```

动词接受 `changeRef` 输入和输出 a `assessment` 输出(drift分数+标出偏差),下游工作流程节点可以上分.

## 多租户部署(Postgres + RLS)

`PostgresArchitecturalIntelligence` 为SaaS的部署设计,许多租户共用一个数据库。 它分两层实施租户隔离:

1.  **应用层.** 每个读取包括 `WHERE org_id = $orgId`; 每张邮票 `org_id` 在排队.
2.  **数据库层 (推荐).** 当消费者应用已运出的 RLS DDL 时, SDK 会在运行的交易中将每个操作附加包装 `SET LOCAL rensei.current_org_id = '<orgId>'` 因此,Postgres的行级安全政策 强制隔离作为防御深度.

### 联网交易

提供a `transaction` 运行在您的适配器。 参考文献 postgres -js 助手已经这样做了.. `adapterFromPostgresJs(sql)` 羽毛穿过 `sql.begin(...)` 和 JSONB 参数解框.

```ts
import postgres from 'postgres'
import { adapterFromPostgresJs, PostgresArchitecturalIntelligence } from '@donmai/architectural-intelligence'

const sql = postgres(process.env.DATABASE_URL!)
const arch = new PostgresArchitecturalIntelligence({
  db: adapterFromPostgresJs(sql),
  orgId: ctx.orgId,
  projectId: ctx.projectId,
})
```

当适配器不曝光时 `transaction`,SDK又回到了平面查询——应用程序级范围界定仍然适用,但数据库级的RLS被跳过.

### RLS DDL 示例

每个数据库一次应用此 DDL( 通过您所选择的迁移工具 ) 。 SDK不运行DDL本身.

```sql
-- Multi-tenant RLS for @donmai/architectural-intelligence
ALTER TABLE observations ENABLE ROW LEVEL SECURITY;
ALTER TABLE graph_nodes  ENABLE ROW LEVEL SECURITY;

-- FORCE so the table owner is not exempt — a misconfigured connection
-- string can't accidentally bypass tenant isolation.
ALTER TABLE observations FORCE ROW LEVEL SECURITY;
ALTER TABLE graph_nodes  FORCE ROW LEVEL SECURITY;

CREATE POLICY arch_intel_observations_tenant_isolation ON observations
  USING (org_id = current_setting('rensei.current_org_id', true)::uuid)
  WITH CHECK (org_id = current_setting('rensei.current_org_id', true)::uuid);

CREATE POLICY arch_intel_graph_nodes_tenant_isolation ON graph_nodes
  USING (org_id = current_setting('rensei.current_org_id', true)::uuid)
  WITH CHECK (org_id = current_setting('rensei.current_org_id', true)::uuid);
```

从软件包中导出此 DDL 的正文副本为 `RLS_DDL_EXAMPLE` gUC 名称导出为 `RLS_ORG_ID_SETTING` 这样消费者就可以不用打字就可以参考两者.

所需经费:

-   应用程序数据库的作用不得有 `BYPASSRLS`超级用户和 `BYPASSRLS` 角色忽略了政策;创造了一个最不优惠的应用角色.
-   需要操作跨租户的行政管理/移民工具应使用一个单独的角色,配置为 `BYPASSRLS` 并记录在您的运行簿中.
-   `SET LOCAL` 被使用(不是) `SET`因此GUC范围在 `COMMIT`编号 :`ROLLBACK` 并且不会从池中漏出到下一个检出连接.

## 状态

**堕地.** 没有现成的消费者遗迹——建筑智能 层正在移动到本地 `donmai` 二进制. 这个 软件包只为开放源码软件的连续性和下游针头而保留;预计没有 其他专题工作.

## 许可证

麻省理工学院——见 [自由主义](https://npmcn.com/package/%40donmai/architectural-intelligence/LICENSE)。 。 。 .

## 常见问题

### @donmai/architectural-intelligence 是什么？

\(原始内容存档于2017-10-21\)\. DePRECATED——建筑智能 \(TypeScript\)\. 被土生土长的人所取代 donmai arch 执行;只为开放源码软件的连续性/下游针头保留\.注意：该包已被作者标记为弃用——@donmai/architectural-intelligence is deprecated and will be removed in a future major\. The architectural-intelligence layer is now native Go inside the donmai binary \(use \`donmai arch\`\)\. This package is preserved for OSS continuity / downstream pins only and receives no further feature work\.

### 如何安装 @donmai/architectural-intelligence？

在项目目录运行 npm install @donmai/architectural-intelligence，或使用 pnpm add / yarn add / bun add。

### @donmai/architectural-intelligence 支持 TypeScript 吗？

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

### @donmai/architectural-intelligence 支持 ESM 还是 CommonJS？

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

### @donmai/architectural-intelligence 需要什么版本的 Node\.js？

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

### @donmai/architectural-intelligence 可以商用吗？

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

### @donmai/architectural-intelligence 的下载量有多少？

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

### @donmai/architectural-intelligence 还在维护吗？

最新版本 0\.10\.0 发布于 2026/10/28（16 天前）；至今共发布 18 个版本，其中过去 12 个月发布了 18 个；首次发布于 2026/05/25。作者已将其标记为弃用，新项目建议寻找替代方案。

