@donmai/architectural-intelligence

中文文档
0.10.0发布于 2026/10/28MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1.9万

DEPRECATED — Architectural Intelligence (TypeScript). Superseded by the native Go donmai arch implementation; preserved for OSS continuity / downstream pins only.

此软件包已被标记为弃用

@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.

原始使用文档
文档目录9 节
  1. What it does
  2. Installation
  3. Quick start
  4. Workflow verb integration
  5. Multi-tenant deployments (Postgres + RLS)
  6. Wiring transactions
  7. RLS DDL exemplar
  8. Status
  9. License

@donmai/architectural-intelligence

DEPRECATED. This package is deprecated. The architectural-intelligence layer is being reimplemented natively in Go inside the donmai binary, and this TypeScript package has no live runtime consumer. It is preserved (not removed) for OSS continuity because downstream npm consumers may pin it, but it will receive no further feature work and will be removed in a future major. New work should target the native donmai arch surface.

System-level synthesis of patterns, conventions, decisions, and drift across a codebase.

Part of the Donmai toolchain.

What it does

Architectural Intelligence observes a codebase's evolution and synthesizes structured knowledge about it:

  • Patterns — recurring structural shapes (e.g. "all routes export a POST handler that calls requireOrgAccess")
  • Conventions — agreed-upon norms (e.g. "tests live next to source as *.test.ts")
  • Decisions — recorded architectural choices (e.g. "auth uses WorkOS, not Auth0")
  • Deviations — places the codebase departs from its own patterns/conventions/decisions
  • Drift — quantified deviation pressure that crosses a threshold and warrants intervention

The package ships:

CapabilityEntry points
Single-tenant local storeSqliteArchitecturalIntelligence
Multi-tenant store (injected Postgres handle)PostgresArchitecturalIntelligence, adapterFromPostgresJs
Observation pipelinerunObservationPass, attachPipelineSubscribers, readDiffObservations
Synthesis prompts (versioned registry)promptRegistry, currentPrompt, versionedPrompt
Eval / A/B test harnessevaluatePrompt, compareABPrompts
Drift detectionassessChange, resolveDriftGatePolicy, evaluateGate
Workflow verb registrationregisterArchitectureVerbs, ASSESS_CHANGE_VERB

Installation

pnpm add @donmai/architectural-intelligence

Node >= 22 required.

Quick start

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
}

Workflow verb integration

For platform consumers that drive Donmai through the workflow engine, register the assess-change verb:

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

registerArchitectureVerbs(verbRegistry)

The verb accepts a changeRef input and emits an assessment output (drift score + flagged deviations) that downstream workflow nodes can branch on.

Multi-tenant deployments (Postgres + RLS)

PostgresArchitecturalIntelligence is designed for SaaS deployments where many tenants share a database. It enforces tenant isolation at two layers:

  1. Application layer. Every read includes WHERE org_id = $orgId; every write stamps org_id on the row.
  2. Database layer (recommended). When the consumer applies the shipped RLS DDL, the SDK additionally wraps each operation in a transaction that runs SET LOCAL rensei.current_org_id = '<orgId>' so Postgres row-level security policies enforce isolation as defence-in-depth.

Wiring transactions

Provide a transaction runner on your adapter. The reference postgres-js helper already does this — adapterFromPostgresJs(sql) plumbs through sql.begin(...) and JSONB parameter unboxing.

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,
})

When the adapter does not expose transaction, the SDK falls back to plain queries — app-level scoping still applies, but database-level RLS is skipped.

RLS DDL exemplar

Apply this DDL once per database (via your migration tool of choice — drizzle, dbmate, sqitch, etc.). The SDK does NOT run DDL itself.

-- 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);

A literal copy of this DDL is exported from the package as RLS_DDL_EXAMPLE and the GUC name is exported as RLS_ORG_ID_SETTING so consumers can reference both without typos.

Requirements:

  • The application database role must NOT have BYPASSRLS. Superusers and BYPASSRLS roles ignore policies; create a least-privilege app role.
  • Admin/migration tooling that needs to operate cross-tenant should use a separate role configured with BYPASSRLS and document the carve-out in your runbook.
  • SET LOCAL is used (not SET) so the GUC scope dies at COMMIT/ROLLBACK and does not leak to the next checked-out connection from a pool.

Status

Deprecated. No live runtime consumer remains — the architectural-intelligence layer is moving to a native Go implementation inside the donmai binary. This package is kept published for OSS continuity and downstream pins only; expect no further feature work.

License

MIT — see LICENSE.

版本与发布记录

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

版本发布日期距今
0.10.0latest2026/10/2816 天前
0.9.152026/09/122 个月前
0.9.142026/08/252 个月前
0.9.132026/08/232 个月前
0.9.122026/08/232 个月前
0.9.112026/08/142 个月前

关于 @donmai/architectural-intelligence 的常见问题

@donmai/architectural-intelligence 是什么?

DEPRECATED — Architectural Intelligence (TypeScript). Superseded by the native Go donmai arch implementation; preserved for OSS continuity / downstream pins only.注意:该包已被作者标记为弃用——@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。作者已将其标记为弃用,新项目建议寻找替代方案。