Skip to content

About

Policy Management & AI Policy Assistant, built on ObjectStack.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

98 Commits

Folders and files

Repository files navigation

BrightRule 明规

集团制度管理与智能问询 — Policy Management & AI Policy Assistant, built on ObjectStack.

条款级、可追溯效力、问完就能办的集团制度平台:

  • 条款级管理 — 制度拆到「条」入库,回答精确引用条款号,效力与版本落到条款粒度。
  • 效力可追溯 — 起草→审批→发布→修订→废止全生命周期,可查任一历史日期的有效版本。
  • 带权限的 AI 问询 — 智能体直接按提问人的行级权限读取制度,看不到的制度不会出现在回答里。
  • 问完就能办 — 「怎么办」类问题直接引导到对应业务流程。

产品定位、架构判断与分期见 docs/product-brief.md(草案,待评审); 制度全生命周期与 AI 问询的解决方案见 docs/solution.md(草案,待评审)。 选中一份制度问 AI(记录范围问询)、字段 / 子表 / 关联 / 附件怎样交给 AI、技能怎么用,见 docs/design-record-scoped-ai.md(草案,待评审)。

分支 feature/policy-inquiry 是领域模型与问询的原型:制度、版本、条款、问询四个对象, 版本设为现行时条款现行状态自动联动。脚手架自带的 note 示例对象尚未删除。

怎么问

  • 对话问询(主入口,ObjectOS):员工在 ObjectOS 的 AI 对话面板里直接提问。 src/skills/policy-inquiry.skill.ts 是「制度问询」技能:只依据提问人有权查看的现行版本脱敏正文 (制度的 current_version → 版本的 body_md,规范性附件一并读)作答、注明《制度》版本 第 N 条;点名或选中制度时只读这一份; 找不到依据时回答「未找到相关规定」(一期不转人工,brightrule#18)。 ⚠️ 截至 ObjectOS 18.6.0,平台的 ask 智能体还不加载应用技能(objectstack-ai/cloud#4935), 对话的回答来自 ask 自带的数据查询能力,技能里的规则尚未生效。
  • MCP 问询(外部 AI 客户端):客户自带的大模型(Claude、DeepSeek 等)连 /api/v1/mcp, 平台把「制度问询」技能作为提示词 brightrule-brightrule_policy_inquiry 下发,已实测可用。
  • 表单问询(兜底):在「制度问询 → 我要问询」新建一条问题,保存即自动答复 (src/qa/question-answer.hook.ts):先检索出提问人可见的现行条款,再由平台配置的大模型 (系统设置 → AI)判断哪几条能回答、依据它们作答并注明出处(src/qa/judge.ts)。没有配置大模型、 调用失败或超时,则只列出可能相关的条款供参考,并转人工;不会把检索第一名直接当作答案。
  • 转人工:表单问询转人工的问题进入「待人工答复」,由归口部门答复。

在 ObjectOS 企业版上部署见 deploy/objectos-ee; 三条问询路径的实测数据见 docs/evaluation-2026-11-23.md。

问询检索方式(环境变量)

设置 检索方式
不设 OS_KNOWLEDGE_EMBEDDING_MODEL 关键词检索(中文按相邻两字切分),仅用于演示与测试
设 OS_KNOWLEDGE_EMBEDDING_MODEL + _API_KEY + _BASE_URL 语义检索,向量默认存内存(OS_KNOWLEDGE_VECTOR_STORE=memory)
再设 OS_KNOWLEDGE_VECTOR_STORE=pgvector + OS_KNOWLEDGE_PGVECTOR_URL 向量持久化到 PostgreSQL + pgvector(生产)

全部变量见 src/qa/vector/env.ts。检索只负责缩小范围(取前 8 条交给大模型),是否作答由大模型判断。 src/qa/answer.ts 中的 MIN_ANSWER_SCORE_BY_ADAPTER 只决定无大模型时列出哪些参考条款, 其中 vector 的取值是暂定值,上线前须按所选向量模型校准。


Development

Scaffolded with create-objectstack (blank template, ObjectStack 18.6.0).

Getting started

pnpm install
pnpm dev

After editing any metadata (an object, view, flow, …), run pnpm validate — see Verify your changes below. It is the one command this project's AGENTS.md calls unskippable: it catches mistakes that otherwise fail silently at runtime.

The REST API is served at http://localhost:3000/api/v1. Data endpoints require a session — the dev server seeds a login-ready admin (admin@objectos.ai / admin123) on an empty database:

curl -c cookies.txt -X POST http://localhost:3000/api/v1/auth/sign-in/email \
  -H "Content-Type: application/json" \
  -d '{"email":"admin@objectos.ai","password":"admin123"}'

curl -b cookies.txt "http://localhost:3000/api/v1/data/<your_object>"

The sample note object

src/objects/note.object.ts is a sample, there so a blank project has one object to boot, query and test on day one. It is not part of the app you are building: until you remove it, it ships in every build, is served over REST, is listed to any MCP client next to your own objects, and is the one entry of the starter app. Delete or replace it once your own objects exist:

  1. Delete src/objects/note.object.ts and its export line in src/objects/index.ts.
  2. Delete src/views/note.view.ts and its export line in src/views/index.ts, and the Notes entry in src/apps/main.app.ts (put your own objects there instead — see The Console below).
  3. Point note.test.ts at one of your own objects (rename the file to match). It imports Note, as do the view and the app, so they stop compiling until you do.
  4. Run pnpm validate and pnpm test.

The Console

pnpm dev also serves the admin Console at http://localhost:3000/_console/, and prints the link on boot. Open it and you will see this project's app, Main, beside the platform's own apps (Setup, Account); its Notes entry opens the list of sample notes.

An object appears in Console navigation only when an app lists it. src/apps/main.app.ts lists the sample object, and src/views/note.view.ts draws its list. A package whose manifest type is app holds at most one app, so main.app.ts is the one: to show another object, add a navigation entry for it to that app's navigation (a group entry with children nests them) rather than a second app, and give it a list view. objectstack generate view OBJECT writes the view and its export line together; the Console renders both after the next pnpm dev rebuild. The objectstack-ui skill covers the shape; describing the app you want to your coding agent is the intended path.

Your app is an MCP server

Every ObjectStack app is itself a Model Context Protocol server — on by default, no plugin to install. pnpm dev prints the endpoint and a ready-to-paste connect command on boot; point a coding agent (Claude Code, Cursor, any MCP client) at it and it can read your schema, query data, and run your exposed actions — all under the caller's own permissions and RLS:

claude mcp add --transport http my-app http://localhost:3000/api/v1/mcp

Set OS_MCP_SERVER_ENABLED=false to turn it off. This is the serve side — the reverse of the mcp connector below (which lets your app call other MCP servers). See Connect an MCP Client for OAuth, API keys, and which objects/actions become tools.

Layout

  • objectstack.config.ts — environment manifest (objects, API, plugins), and the wiring for every directory below
  • src/objects/ — object definitions (one file per object); note.object.ts is the sample described above
  • src/apps/ — the starter app, main.app.ts, described in The Console; src/views/ — the sample object's list view
  • src/actions/, src/flows/, src/dashboards/, src/skills/, src/picklists/, src/security/ (permission sets), src/datasets/ (analytics datasets) — empty to start. Each directory's index.ts exports what it holds and objectstack.config.ts hands those exports to the stack, so objectstack generate flow NAME (or view, action, …) adds a file and one export line, and the item is loaded, and counted by pnpm validate, with no edit to the config
  • note.test.ts — the starter test pnpm test runs, configured by vitest.config.ts

Connectors (default providers)

objectstack.config.ts wires the three generic connector executors, so you can call an external system from a flow as pure metadata — no host code:

Provider Package Use for
rest @objectstack/connector-rest Any JSON/HTTP REST API
openapi @objectstack/connector-openapi An API described by an OpenAPI document
mcp @objectstack/connector-mcp A Model Context Protocol server

Add a connectors: entry that names one of these providers and the automation capability materializes it into a live, dispatchable connector at boot — see Automation → Connectors for how that materialization works; a flow's connector_action node then calls it. To add a brand connector (e.g. Slack), install its package and add new ConnectorSlackPlugin() to plugins:; to drop a provider, remove its plugin.

Security — declarative MCP over stdio. An mcp connector whose transport spawns a local process (stdio) is denied by default, because the command comes from metadata. Opt in per host with new ConnectorMcpPlugin({ declarativeStdio: ['node'] }); http transports need no opt-in.

See Automation → Flows for the full connector and connector_action guide.

Verify your changes

After editing any metadata, run:

pnpm validate     # schema + CEL predicates + widget bindings (no artifact)
pnpm lint         # authoring rules validate does not run — e.g. a handler that
                  # stopped lowering to a metadata-only body
pnpm typecheck    # TypeScript types against @objectstack/spec
pnpm test         # your app's own tests, against the real engine

pnpm validate runs the same gates as pnpm build and catches mistakes that otherwise fail silently at runtime — e.g. a bare done (instead of record.done) in an action predicate that would hide the action on every record. See AGENTS.md for the full convention.

pnpm test checks what the app does. note.test.ts boots this app's stack in-process with bootStack from @objectstack/verify (in-memory database, no server) and asserts one business fact through its handle: a note without a title is refused. Write your own the same way: stack.hooks.run makes a real write through validation, permissions and hooks, and the same handle runs flows and actions, seeds fixtures and reads rows as a given user.

Deploy

The project ships container-ready — the Dockerfile builds your metadata into an artifact and runs it on the official ObjectStack runtime image (ghcr.io/objectstack-ai/objectstack):

# Image only
docker build -t my-app .

# Or the full app + Postgres stack
cat > .env <<EOF
POSTGRES_PASSWORD=$(openssl rand -hex 16)
OS_AUTH_SECRET=$(openssl rand -hex 32)
OS_SECRET_KEY=$(openssl rand -hex 32)
EOF
docker compose up -d
curl -fsS http://localhost:8080/api/v1/health

Bare Node, Kubernetes, reverse-proxy wiring, and the required secrets are covered in Self-Hosted Deployment.

A Studio change is not in the image

The image carries what src/ builds into, and nothing else. A change you save in Studio, in the Console pnpm dev serves, is stored in that environment's database (locally, .objectstack/data/) as an item of the package <this app's package id>.custom. It is never written to src/, so pnpm build, the Dockerfile and docker compose leave it behind.

  • To make it part of the app, make the same change in src/: that is what is validated, reviewed and deployed. Ask your coding agent to do it in code, not in Studio.
  • To keep it as a customization, take it out as a package while pnpm dev runs: npx os login --url http://localhost:3000 once, then npx os package export --url http://localhost:3000, writes every package the database holds that src/ does not register, the .custom package among them, to objectstack-export/NN-ID/objectstack.json. Commit that directory, and once the deployment is up install each file into it in the numbered order with npx os package install objectstack-export/NN-ID/objectstack.json --url URL.

pnpm build prints a notice when your local dev database holds such a change.

Next steps

  • Add an object: see the objectstack-data skill.
  • Add a view or app: see objectstack-ui.
  • Add a flow or automation: see objectstack-automation.
  • Add an AI agent: see objectstack-ai.

Skills live in .claude/skills/ and are committed with this project, once. They come from the @objectstack/skills dev dependency, at the version of @objectstack/spec, are installed one agent runtime at a time (see AGENTS.md), and also show up in the in-IDE assistant catalog. Re-install them from node_modules after upgrading the @objectstack/* packages:

npx skills@1.7.2 experimental_sync --agent claude-code --copy -y

About

Policy Management & AI Policy Assistant, built on ObjectStack.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages