attention-manifest-protocol 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/CHANGELOG.zh-CN.md +29 -0
- package/README.md +57 -4
- package/README.zh-CN.md +59 -4
- package/docs/scoped-control.zh-CN.md +93 -0
- package/lib/context/workspaceService.d.ts +16 -14
- package/lib/context/workspaceService.js +73 -96
- package/lib/control/index.d.ts +4 -0
- package/lib/control/index.js +4 -0
- package/lib/control/search.d.ts +7 -0
- package/lib/control/search.js +39 -0
- package/lib/control/service.d.ts +32 -0
- package/lib/control/service.js +424 -0
- package/lib/control/sessionService.d.ts +23 -0
- package/lib/control/sessionService.js +51 -0
- package/lib/control/types.d.ts +21 -0
- package/lib/control/types.js +4 -0
- package/lib/database/adapter/workspaceSessionStore.d.ts +1 -0
- package/lib/database/adapter/workspaceSessionStore.js +3 -0
- package/lib/database/entity/catalog.d.ts +58 -0
- package/lib/database/entity/catalog.js +74 -0
- package/lib/database/entity/index.d.ts +1 -0
- package/lib/database/entity/index.js +1 -0
- package/lib/database/entity/workspaceSession.d.ts +4 -3
- package/lib/database/entity/workspaceSession.js +1 -0
- package/lib/database/repository/catalogPublication.d.ts +15 -0
- package/lib/database/repository/catalogPublication.js +41 -0
- package/lib/database/repository/catalogRepository.d.ts +56 -0
- package/lib/database/repository/catalogRepository.js +251 -0
- package/lib/database/repository/index.d.ts +1 -0
- package/lib/database/repository/index.js +1 -0
- package/lib/database/repository/workspaceSessionRepository.d.ts +1 -0
- package/lib/database/repository/workspaceSessionRepository.js +21 -7
- package/lib/database/service/catalogService.d.ts +54 -0
- package/lib/database/service/catalogService.js +271 -0
- package/lib/database/service/database.d.ts +8 -0
- package/lib/database/service/database.js +13 -0
- package/lib/database/service/index.d.ts +4 -0
- package/lib/database/service/index.js +2 -0
- package/lib/database/sql/schema.js +171 -2
- package/lib/database/store/catalogGuard.d.ts +5 -0
- package/lib/database/store/catalogGuard.js +34 -0
- package/lib/database/store/catalogStore.d.ts +20 -0
- package/lib/database/store/catalogStore.js +70 -0
- package/lib/database/store/database.js +77 -23
- package/lib/database/store/index.d.ts +1 -0
- package/lib/database/store/index.js +1 -0
- package/lib/discover/host.d.ts +3 -6
- package/lib/discover/host.js +39 -23
- package/lib/discover/tree.js +53 -5
- package/lib/discover/types.d.ts +62 -0
- package/lib/environment/catalog.d.ts +13 -0
- package/lib/environment/catalog.js +158 -0
- package/lib/environment/index.d.ts +5 -0
- package/lib/environment/index.js +3 -0
- package/lib/environment/types.d.ts +16 -0
- package/lib/environment/types.js +3 -0
- package/lib/file/runtime.d.ts +4 -0
- package/lib/file/runtime.js +6 -1
- package/lib/file/scopedStore.d.ts +4 -0
- package/lib/file/scopedStore.js +23 -0
- package/lib/file/service.js +5 -4
- package/lib/global/service.d.ts +7 -0
- package/lib/global/service.js +18 -2
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/module/index.d.ts +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/mcp/workspaceServer.d.ts +2 -0
- package/lib/module/mcp/workspaceServer.js +20 -4
- package/lib/module/tool/controlExecutor.d.ts +10 -0
- package/lib/module/tool/controlExecutor.js +25 -0
- package/lib/module/tool/globalExecutor.js +1 -1
- package/lib/module/tool/workspaceExecutor.js +5 -3
- package/lib/naming/ids.d.ts +10 -0
- package/lib/naming/ids.js +10 -0
- package/lib/protocol/control.d.ts +20 -0
- package/lib/protocol/control.js +77 -0
- package/lib/protocol/global.js +6 -1
- package/lib/protocol/index.d.ts +1 -0
- package/lib/protocol/index.js +1 -0
- package/lib/protocol/workspace.d.ts +1 -1
- package/lib/protocol/workspace.js +14 -11
- package/lib/runtime/cognitiveRuntime.d.ts +3 -0
- package/lib/runtime/cognitiveRuntime.js +6 -2
- package/lib/search/catalogSearch.d.ts +49 -0
- package/lib/search/catalogSearch.js +250 -0
- package/lib/search/elasticsearch.d.ts +53 -0
- package/lib/search/elasticsearch.js +473 -0
- package/lib/search/index.d.ts +6 -0
- package/lib/search/index.js +3 -0
- package/lib/search/projection.d.ts +26 -0
- package/lib/search/projection.js +213 -0
- package/lib/search/types.d.ts +55 -0
- package/lib/search/types.js +1 -0
- package/lib/semantic/jsonValue.d.ts +2 -0
- package/lib/semantic/jsonValue.js +38 -5
- package/lib/session/registry.d.ts +2 -0
- package/lib/session/registry.js +63 -10
- package/lib/session/types.d.ts +8 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,29 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this
|
|
6
6
|
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.5.0] - 2026-11-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Eight canonical scoped control tools for registry metadata, defaults, interaction and scenario settings across global, workspace and session scopes; host-bound identities, CAS, dry-run and atomic session batches.
|
|
13
|
+
- SQLite workspace ownership, default workspace selection, inherited settings and v4-to-v5 migration, with authenticated runtime settings applied on the next turn.
|
|
14
|
+
- Elasticsearch catalog search with independent immutable snapshot indices, verified namespace ownership, SQLite publication CAS, retryable timeout/restart recovery and guarded Catalog SQL writes.
|
|
15
|
+
- Environment defaults, typed catalog projections and serial module boundary audit reports.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **Breaking:** workspace/global discover now requires `queries` and asynchronous calls, returning a separate relation tree for each match. Migrate from the old `text`/`scope` filter arguments; configure and synchronize the host search backend before discovery.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Isolate session root storage while preserving public root IDs; prevent stale session registries from reviving revoked credentials, authentication reentry and revision overflow.
|
|
24
|
+
- Reject hidden JSON callbacks and mutable protocol schemas; enforce workspace ownership even when a stdio host is configured with search only.
|
|
25
|
+
|
|
26
|
+
### Validation
|
|
27
|
+
|
|
28
|
+
- Joint functional and boundary regression: 366/366; final audit recheck: 48/48; source/tools typechecks, library build and patch checks passed. Real Elasticsearch 9.2.0 single-node faults were previously verified 9/9; fixture tests are reported separately.
|
|
29
|
+
- Known repository limitation: the architecture check still fails on coexisting legacy dashed and camelCase scripts; it is excluded from the functional counts above.
|
|
30
|
+
|
|
8
31
|
## [0.4.6] - 2026-11-02
|
|
9
32
|
|
|
10
33
|
### Added
|
|
@@ -24,6 +47,12 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
24
47
|
|
|
25
48
|
### Added
|
|
26
49
|
|
|
50
|
+
- Elasticsearch search module using the official SDK, explicit strict index mapping, scoped metadata search, full snapshot synchronization and defensive response projection.
|
|
51
|
+
- Unified catalog entities, directed relations, cache, service, repository and SQLite tables with atomic snapshot replacement, persistent synchronization generations and retryable dirty states.
|
|
52
|
+
- Workspace/global discover now accepts one or multiple `queries` and returns a separate bounded relation tree for every matching root; services, executors and MCP support asynchronous search. This replaces the previous discover tool filter schema.
|
|
53
|
+
- Typed catalog projections for workspace, host projects/components, skills, knowledge, protocols, environments and generic module records; SDK wire, SQLite, projection and multi-tree isolation checks.
|
|
54
|
+
- Explicit environment defaults for runtimes, applications, languages and project types, backed by `HostCatalog`, with category/availability metadata and links.
|
|
55
|
+
|
|
27
56
|
- `amp_tool_workspace_project`: offline brand detection from manifest/lockfile evidence (npm/pnpm/yarn/bun, Maven, Gradle, CMake, Cargo, Go, Python, Make, Composer, .NET, Bundler, Swift, sbt) plus host-delegated `build`/`compile`/`run`/`test`. The agent never supplies a command string; the brand table produces one and `WorkspaceServiceOptions.runner` decides whether to run it (`run_unavailable`, `unsupported_action`, bounded tail of stdout/stderr).
|
|
28
57
|
- `amp_tool_workspace_outline`: one cascading project → directory → file → symbol/knowledge outline with 1-based ranges, bounded `maxDepth`/`limit`, `childCount`, `includeSymbols` and path/extension filters.
|
|
29
58
|
- `amp_tool_workspace_dependency`: project-level `project_depends_on` dependencies and dependents with the declaring source, method and paginated project list.
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -5,6 +5,29 @@
|
|
|
5
5
|
格式遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循
|
|
6
6
|
[语义化版本](https://semver.org/lang/zh-CN/)。
|
|
7
7
|
|
|
8
|
+
## [0.5.0] - 2026-11-03
|
|
9
|
+
|
|
10
|
+
### 新增
|
|
11
|
+
|
|
12
|
+
- 八个规范作用域控制工具,覆盖 global/workspace/session 的注册元数据、默认值、交互和情景配置;提供宿主固定身份、CAS、dry-run 和原子 session 批处理。
|
|
13
|
+
- SQLite workspace 归属、默认 workspace、配置继承及 v4→v5 迁移;已认证配置从运行时下一轮生效。
|
|
14
|
+
- Elasticsearch 统一目录检索、独立不可变快照索引、namespace 归属验证、SQLite 发布 CAS、超时/重启可重试和 Catalog SQL 写入防护。
|
|
15
|
+
- Environment 默认目录、类型化目录投影与串行模块边界审计报告。
|
|
16
|
+
|
|
17
|
+
### 变更
|
|
18
|
+
|
|
19
|
+
- **不兼容变更:** workspace/global discover 改用 `queries` 与异步调用,每个命中返回独立关系树;需迁移旧 `text`/`scope` 参数,并由宿主配置和同步搜索后端。
|
|
20
|
+
|
|
21
|
+
### 修复
|
|
22
|
+
|
|
23
|
+
- 保留公开 root ID 并隔离 session root 存储;阻止旧 registry 复活撤销凭据、认证重入及 revision 溢出。
|
|
24
|
+
- 拒绝隐藏 JSON 回调和可变协议 schema;search-only stdio 宿主同样校验已有 workspace 归属。
|
|
25
|
+
|
|
26
|
+
### 验证
|
|
27
|
+
|
|
28
|
+
- 联合功能与边界回归 366/366,最终审计复核 48/48;源代码/工具类型检查、库构建及补丁检查通过。真实 Elasticsearch 9.2.0 单节点故障此前通过 9/9,与 fixture 测试分别记录。
|
|
29
|
+
- 已知仓库限制:旧连字符脚本与 camelCase 脚本并存导致架构检查失败,未计入上述功能测试通过数。
|
|
30
|
+
|
|
8
31
|
## [0.4.6] - 2026-11-02
|
|
9
32
|
|
|
10
33
|
### 新增
|
|
@@ -24,6 +47,12 @@
|
|
|
24
47
|
|
|
25
48
|
### 新增
|
|
26
49
|
|
|
50
|
+
- 官方 Elasticsearch SDK 搜索模块:显式 strict 索引映射、项目范围元数据搜索、全量快照同步和防御性响应投影。
|
|
51
|
+
- 统一目录实体、定向关系、缓存、服务、仓储与 SQLite 表,提供原子快照替换、持久同步 generation 和可重试的 dirty 状态。
|
|
52
|
+
- workspace/global discover 改为接收一个或多个 `queries`,每个命中根条目独立返回有界关系树;服务、执行器和 MCP 支持异步搜索。旧 discover 工具过滤参数已移除。
|
|
53
|
+
- workspace、宿主项目/组件、skills、knowledge、protocol、environment 及通用模块记录的类型化投影,以及 SDK、SQLite、投影和多树隔离检查。
|
|
54
|
+
- 基于 `HostCatalog` 的 environment 默认目录,覆盖运行时、应用、语言与项目类型,支持显式加载和关联元数据。
|
|
55
|
+
|
|
27
56
|
- Agent 工作区:`File`/`Directory` 树、分页读、CAS 原子写、策略化大纲、import/export/dependency 图与 Office(DOCX/XLSX/PPTX,DOC/XLS/PPT/PUB/ACCDB best-effort)解析。
|
|
28
57
|
- Session 模块:`ses_` 身份、一次性 bearer 令牌、TTL、暂停/撤销/rotate、fork、每会话上下文隔离与配额;SQLite 适配器 `SqliteWorkspaceSessionStore` / `SqliteWorkspaceSessionContextStore`。
|
|
29
58
|
- `src/hook` 组合层:`useRead`、`useWrite`、`useDiff`、`useParse`、`useDependency`、`useExportation`、`useImportation`、`useOutline`、`useCode`、`useProject`;除 `useWrite` 外只读,并记录 `hook_runs`。
|
package/README.md
CHANGED
|
@@ -53,22 +53,74 @@ Offline parsers live in `tools/support/`. The runtime stays database-free and us
|
|
|
53
53
|
|
|
54
54
|
### Discovery
|
|
55
55
|
|
|
56
|
-
`amp_tool_workspace_discover`
|
|
56
|
+
`amp_tool_workspace_discover` and its global counterpart search a unified catalog through Elasticsearch. Pass `queries` as one string or up to eight strings. Each matching entry becomes the root of a separate structural tree, so a single query can return multiple trees. The response is `{ trees: [{ query, tree, total, totalRelation, took, timedOut, truncated }] }`; no matches produce an empty `trees` array. Each tree contains current metadata and `children` expanded from SQLite entity relations, without skill instructions or knowledge bodies. `limit` bounds hits per query; `maxDepth` and `nodeLimit` bound each tree. Optional `kinds` and `tags` filter metadata. Hosts project `HostCatalog`, `SkillRegistry`, `KnowledgeRegistry` and `ProtocolRegistry` entries into `CatalogRecord`; other modules use the same record and relation contract.
|
|
57
|
+
|
|
58
|
+
The catalog follows `entity → cache → service → repository → SQL → SQLite`. SQLite stores complete entries, directed relations and synchronization generations; Elasticsearch stores a rebuildable search projection. Hosts explicitly synchronize after snapshot changes. Failed builds or concurrent catalog updates leave the index dirty, and discover refuses stale results. Hits and every related node are checked against service-owned project authorization and workspace revision; global records are controlled by `includeGlobal`. Discovery grants no detail-read or execution access. `buildDiscoveryTree` remains available as a local structure-building API.
|
|
57
59
|
|
|
58
60
|
These registries are domain-owned catalogs, not a mandate to duplicate every concept as a generic registry. Existing runtime state and policies for ability, cognition, progress and behavior should stay in their domain models; add a read-only catalog/discovery projection only when enumeration is needed. Agents should not write directly to active registries by default. A future contribution flow should create a sourced, versioned proposal and require host authorization, review and audit before activation.
|
|
59
61
|
|
|
62
|
+
The `environment` module describes runtimes, applications, languages and project types as `HostCatalog` modules. `category` is `runtime`, `application`, `language` or `projectType`; `availability` is `unknown`, `available` or `unavailable`, independent of the component lifecycle `status`. Optional `platforms`, `extensions`, `relatedIds`, `skillIds`, `knowledgeIds`, `toolIds` and `protocolIds` link metadata without granting execution access. Hosts explicitly confirm availability; catalog registration does not install software or probe the machine.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { HostCatalog, loadDefaultEnvironments, WorkspaceAgentService } from "attention-manifest-protocol";
|
|
66
|
+
|
|
67
|
+
const host = new HostCatalog();
|
|
68
|
+
loadDefaultEnvironments(host);
|
|
69
|
+
// Project host into the catalog, synchronize Elasticsearch, then inject search into the service.
|
|
70
|
+
// Discover with { revision, queries: "runtime", kinds: ["module"] }.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Defaults cover PowerShell 7/Windows PowerShell 5.1, sh/bash/zsh, Word/Excel/PowerPoint/Publisher/Access/Microsoft Project, common programming languages and project types such as npm/Maven/CMake. All defaults start with `availability: "unknown"`. `getDefaultEnvironments()` returns independent definitions; `loadDefaultEnvironments(host)` returns only newly added entries and skips existing IDs, preserving host overrides. Register host-confirmed entries before loading defaults. Category, availability and platform metadata enter the search projection and can be searched through `queries`, with `kinds: ["module"]` restricting the entry type. Local `buildDiscoveryTree` retains category and availability filters.
|
|
74
|
+
|
|
75
|
+
Host wiring example (requires a running Elasticsearch 9 service; `index` is the prefix for independent namespace snapshots):
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { CatalogSearch, projectSearchRecords, WorkspaceAgentService } from "attention-manifest-protocol";
|
|
79
|
+
import { Database } from "attention-manifest-protocol/database/service";
|
|
80
|
+
|
|
81
|
+
const database = new Database("catalog.sqlite");
|
|
82
|
+
const search = CatalogSearch.create({
|
|
83
|
+
namespace: "host-catalog",
|
|
84
|
+
catalog: database.catalogService,
|
|
85
|
+
cache: database.catalogStore,
|
|
86
|
+
elasticsearch: {
|
|
87
|
+
connection: { node: "http://127.0.0.1:9200" },
|
|
88
|
+
index: "amp-host-catalog",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
search.replaceSnapshot(projectSearchRecords({
|
|
92
|
+
namespace: "host-catalog", revision: snapshot.revision,
|
|
93
|
+
workspace: snapshot.entities, relations: snapshot.relations,
|
|
94
|
+
projects: host.projects(), host: host.components(),
|
|
95
|
+
skills: skills.list(), knowledge: knowledge.list(), protocols: protocols.list(),
|
|
96
|
+
// records: [...CatalogRecord entries provided by other modules]
|
|
97
|
+
}));
|
|
98
|
+
await search.sync();
|
|
99
|
+
const service = new WorkspaceAgentService({ ...options, snapshot, search });
|
|
100
|
+
const response = await service.callAsync("amp_tool_workspace_discover", {
|
|
101
|
+
revision: snapshot.revision, queries: ["repository", "runtime"],
|
|
102
|
+
limit: 10, maxDepth: 3, nodeLimit: 50,
|
|
103
|
+
});
|
|
104
|
+
// Multiple roots and their relation trees can share the same query in response.data.trees.
|
|
105
|
+
// On shutdown: await search.close(), then database.close().
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`replaceSnapshot` replaces the complete namespace snapshot, pruning removed entries and outgoing relations. Its synchronous SQLite SAVEPOINT never spans network awaits. Each `sync` creates a separate namespace-owned concrete index, verifies its contents and write block, then publishes its index/digest/generation through a SQLite epoch CAS. A later attempt fences an earlier build, so failed or timed-out builds can be retried immediately; late remote writes affect only their unpublished indices. Configured indices and aliases are not cleared or adopted. Discovery rechecks concrete index ownership, the write block, document count and content digest before and after its search, and checks SQLite generation again before returning. `CatalogSearch` queues its own synchronization and discovery, while independent coordinators use separate builds and publication CAS. Sync cancellation and timeout include queue wait. Commit any outer SQLite transaction before synchronizing or searching, and do not open one on the shared connection while an operation awaits Elasticsearch. Failed attempts and older snapshots can leave unused indices; hosts manage their retention without deleting a currently published index or an active build. The write block and namespace marker do not isolate a privileged Elasticsearch administrator who can remove or alter them. Hosts configure SDK connection, authentication and TLS through `connection`; credentials do not enter the catalog. Without search configuration, discover returns `search_unavailable`; synchronous `call` returns `async_required` when search is configured. MCP integrations use `handleAsync`. Old discover tool parameters such as `text` and `scope` have been removed.
|
|
109
|
+
|
|
110
|
+
Scoped control adds eight canonical tools: global/workspace `adjust`, and global/workspace/session `interaction` and `scenario`. Host-bound identities, persistent workspace isolation, inherited settings, CAS, dry-run and stdio configuration are documented in [the scoped control guide](docs/scoped-control.zh-CN.md).
|
|
111
|
+
|
|
60
112
|
## Quick start
|
|
61
113
|
|
|
62
114
|
```sh
|
|
63
115
|
npm ci
|
|
64
116
|
npm run build
|
|
65
|
-
npm run
|
|
66
|
-
|
|
117
|
+
npm run build:lib
|
|
118
|
+
node --test tools/controlProtocolCheck.ts tools/controlPersistenceCheck.ts tools/controlIntegrationCheck.ts
|
|
67
119
|
```
|
|
68
120
|
|
|
69
121
|
## Library usage
|
|
70
122
|
|
|
71
|
-
`npm install attention-manifest-protocol` ships the compiled ESM build in `lib/` with its declarations,
|
|
123
|
+
`npm install attention-manifest-protocol` ships the compiled ESM build in `lib/` with its declarations, JSON Schemas and the scoped control guide. Source and executable checks are available in the GitHub repository. Node.js 24 or later is required. The root entry exposes the documented protocol surfaces; every module is also reachable as a subpath.
|
|
72
124
|
|
|
73
125
|
```js
|
|
74
126
|
import { generateSigningKey, signManifest, verifyManifest } from "attention-manifest-protocol";
|
|
@@ -225,6 +277,7 @@ Service errors: `invalid_arguments`, `unknown_tool`, `revision_mismatch`, `not_a
|
|
|
225
277
|
| [src/syntax](src/syntax/) | Charset detection/encoding, byte/line indexing, syntax registry and lossless read-only syntax trees |
|
|
226
278
|
| [src/outline](src/outline/) | Code/document outlines, range and label indexes, keyword/strategy registries, React/Shell/SQL/Visual Basic strategies and Office parsing |
|
|
227
279
|
| [src/hook](src/hook/) | Agent-facing composition hooks and run records |
|
|
280
|
+
| [src/environment](src/environment/) | Explicit defaults and availability/link metadata for runtimes, applications, languages and project types |
|
|
228
281
|
| [src/protocol](src/protocol/) | Wire contracts: envelopes, A2A, channels and the `amp_protocol_workspace` surface |
|
|
229
282
|
| [src/module](src/module/) | LLM/tool ports, MCP adapters and execution policies |
|
|
230
283
|
| [src/runtime](src/runtime/) | Agent turn/tool loop and governance integration |
|
package/README.zh-CN.md
CHANGED
|
@@ -53,22 +53,76 @@ Context 使用结构树和类型化关系图。项目依赖、导入、调用与
|
|
|
53
53
|
|
|
54
54
|
### 发现
|
|
55
55
|
|
|
56
|
-
`amp_tool_workspace_discover`
|
|
56
|
+
`amp_tool_workspace_discover` 和 global 对应工具通过 Elasticsearch 检索统一目录。传入 `queries`(一个字符串或最多八个字符串),每个命中条目作为根节点返回一棵结构树,因此一个查询也可以返回多棵树。响应为 `{ trees: [{ query, tree, total, totalRelation, took, timedOut, truncated }] }`;没有命中时 `trees` 为空。`tree` 包含元数据及由 SQLite 实体关系展开的 `children`,不返回 skill 指令或 knowledge 正文。`limit` 限制每个查询的命中数量,`maxDepth` 和 `nodeLimit` 分别限制每棵树的深度和节点数。可用 `kinds`、`tags` 筛选元数据。宿主通过 `HostCatalog`、`SkillRegistry`、`KnowledgeRegistry`、`ProtocolRegistry` 登记条目,再统一投影为 `CatalogRecord`;其他模块通过同一记录格式及关系接入。
|
|
57
|
+
|
|
58
|
+
目录沿 `entity → cache → service → repository → SQL → SQLite` 持久化。Elasticsearch 保存可重建的搜索投影,SQLite 保存完整条目、关系和同步 generation。宿主必须在快照变更后显式同步;失败或并发修改会保留未同步状态,discover 拒绝使用过期索引。查询命中及全部关联节点都按服务的 `projectIds` 和工作区 revision 再次检查,全局条目由 `includeGlobal` 控制。元数据发现不会授予详情读取或执行权限;原本的 `buildDiscoveryTree` 仍可作为本地结构构建 API 使用。
|
|
57
59
|
|
|
58
60
|
这些 registry 是各自领域的宿主目录,不要求每个概念都复制成同构 registry。Ability、cognition、progress 等若已有运行时状态、策略或事件模型,应由现有领域模块维护;需要统一枚举时增加只读 catalog/discovery 投影即可。Agent 默认只读正式目录;可选的登记工作流应先创建带来源、版本和提案状态的候选项,再经宿主权限校验、人工审核与审计后发布,不授予模型直接改写已生效条目的能力。
|
|
59
61
|
|
|
62
|
+
`environment` 模块将运行时、应用程序、编程语言与项目类型作为 `HostCatalog` 的 module 条目维护。`category` 为 `runtime`、`application`、`language` 或 `projectType`;`availability` 为 `unknown`、`available` 或 `unavailable`,与组件生命周期 `status` 分开。可选的 `platforms`、`extensions`、`relatedIds`、`skillIds`、`knowledgeIds`、`toolIds`、`protocolIds` 描述平台、格式与关联,不授予执行权限。可用性由宿主确认,登记目录不会安装软件或探测本机。
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { HostCatalog, loadDefaultEnvironments } from "attention-manifest-protocol";
|
|
66
|
+
|
|
67
|
+
const host = new HostCatalog();
|
|
68
|
+
loadDefaultEnvironments(host);
|
|
69
|
+
// 将 host 投影到统一目录并同步 Elasticsearch,然后注入服务的 search 选项。
|
|
70
|
+
// 发现参数:{ revision, queries: "runtime", kinds: ["module"] }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
默认目录包括 PowerShell 7/Windows PowerShell 5.1、sh/bash/zsh、Word/Excel/PowerPoint/Publisher/Access/Microsoft Project、常见编程语言,以及 npm/Maven/CMake 等项目类型,默认可用性全部为 `unknown`。`getDefaultEnvironments()` 返回独立定义副本;`loadDefaultEnvironments(host)` 只返回本次新增项,遇到已有 ID 会跳过并保留宿主覆盖。因此,宿主可在加载默认值之前登记已确认的条目。分类、可用性及平台信息会进入搜索投影,可在 `queries` 中检索并以 `kinds: ["module"]` 限定条目类型。本地 `buildDiscoveryTree` 保留原有分类和可用性筛选。
|
|
74
|
+
|
|
75
|
+
宿主接线示例(需要宿主提供已运行的 Elasticsearch 9 服务;`index` 用作各 namespace 独立快照索引的前缀):
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { CatalogSearch, projectSearchRecords, WorkspaceAgentService } from "attention-manifest-protocol";
|
|
79
|
+
import { Database } from "attention-manifest-protocol/database/service";
|
|
80
|
+
|
|
81
|
+
const database = new Database("catalog.sqlite");
|
|
82
|
+
const search = CatalogSearch.create({
|
|
83
|
+
namespace: "host-catalog",
|
|
84
|
+
catalog: database.catalogService,
|
|
85
|
+
cache: database.catalogStore,
|
|
86
|
+
elasticsearch: {
|
|
87
|
+
connection: { node: "http://127.0.0.1:9200" },
|
|
88
|
+
index: "amp-host-catalog",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
search.replaceSnapshot(projectSearchRecords({
|
|
92
|
+
namespace: "host-catalog", revision: snapshot.revision,
|
|
93
|
+
workspace: snapshot.entities, relations: snapshot.relations,
|
|
94
|
+
projects: host.projects(), host: host.components(),
|
|
95
|
+
skills: skills.list(), knowledge: knowledge.list(), protocols: protocols.list(),
|
|
96
|
+
// records: [...其他模块提供的 CatalogRecord]
|
|
97
|
+
}));
|
|
98
|
+
await search.sync();
|
|
99
|
+
const service = new WorkspaceAgentService({ ...options, snapshot, search });
|
|
100
|
+
const response = await service.callAsync("amp_tool_workspace_discover", {
|
|
101
|
+
revision: snapshot.revision, queries: ["repository", "runtime"],
|
|
102
|
+
limit: 10, maxDepth: 3, nodeLimit: 50,
|
|
103
|
+
});
|
|
104
|
+
// response.data.trees 中,同一个 query 可以对应多个根节点及其关联树。
|
|
105
|
+
// 宿主退出:先 await search.close(),再 database.close()。
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`replaceSnapshot` 替换该 namespace 的完整快照;已删除条目及其出边会清理。它通过同步 SQLite SAVEPOINT 提交,不跨越网络等待。每次 `sync` 创建独立、带 namespace 归属的 concrete index,验证内容并封锁写入,再通过 SQLite epoch CAS 发布索引名、digest 和 generation。后启动的尝试会阻止更早的构建发布,因此失败或超时后可立即重试;远程迟到写入只能影响它自身未发布的索引。配置的索引及 alias 不会被清空或接管。发现查询前后重新校验具体索引、归属 marker、写封锁、文档数量与内容摘要,返回前还要确认 SQLite generation。`CatalogSearch` 在实例内排队,独立协调器分别构建并通过发布 CAS 协调;同步取消和超时包含排队耗时。调用前必须提交外层 SQLite 事务,也不要在等待 Elasticsearch 时在共享连接上开启事务。失败尝试及旧快照可能遗留闲置索引,宿主应管理保留策略,避免删除正在发布的索引或活动构建。写封锁和 namespace marker 无法隔离能移除或修改它们的 Elasticsearch 管理员。连接、认证和 TLS 选项通过 SDK 的 `connection` 在宿主侧配置,不会写入目录。没有搜索配置时 discover 返回 `search_unavailable`,同步 `call` 返回 `async_required`;MCP 集成使用 `handleAsync`。旧的 discover 工具参数 `text`、`scope` 等已移除。
|
|
109
|
+
|
|
110
|
+
作用域控制新增八个规范工具:global/workspace 的 `adjust`,以及 global/workspace/session 的 `interaction`、`scenario`。注册元数据和默认值按 workspace 持久隔离,配置继承并接入运行时;完整身份接线、action、CAS、dry-run 与 stdio 配置见[作用域控制说明](docs/scoped-control.zh-CN.md)。
|
|
111
|
+
|
|
112
|
+
作用域控制新增八个规范工具:global/workspace `adjust`,以及 global/workspace/session 的 `interaction` 与 `scenario`。宿主绑定身份、workspace 持久隔离、配置继承、CAS、dry-run 和 stdio 配置见[作用域控制文档](docs/scoped-control.zh-CN.md)。
|
|
113
|
+
|
|
60
114
|
## 快速开始
|
|
61
115
|
|
|
62
116
|
```sh
|
|
63
117
|
npm ci
|
|
64
118
|
npm run build
|
|
65
|
-
npm run
|
|
66
|
-
|
|
119
|
+
npm run build:lib
|
|
120
|
+
node --test tools/controlProtocolCheck.ts tools/controlPersistenceCheck.ts tools/controlIntegrationCheck.ts
|
|
67
121
|
```
|
|
68
122
|
|
|
69
123
|
## 作为库使用
|
|
70
124
|
|
|
71
|
-
`npm install attention-manifest-protocol` 会安装 `lib/`
|
|
125
|
+
`npm install attention-manifest-protocol` 会安装 `lib/` 中的编译产物及其声明文件、JSON Schema 和作用域控制文档。源码和可执行检查保存在 GitHub 仓库中。运行时要求 Node.js 24 及以上。包根入口提供文档中的协议核心接口,其余模块均可按子路径导入。
|
|
72
126
|
|
|
73
127
|
```js
|
|
74
128
|
import { generateSigningKey, signManifest, verifyManifest } from "attention-manifest-protocol";
|
|
@@ -222,6 +276,7 @@ Frame、快照、ContentStore 与后备执行器由宿主提供;将 `tools` /
|
|
|
222
276
|
| [src/naming](src/naming/) | 冻结的 ID 表、ID 文法、兼容别名与 catalog 摘要 |
|
|
223
277
|
| [src/context](src/context/) | Context 生命周期、树/图投影、CAS、工作区事实、上下文装配与 agent 服务 |
|
|
224
278
|
| [src/session](src/session/) | 身份、令牌、TTL、上下文隔离、fork/revoke/rotate |
|
|
279
|
+
| [src/environment](src/environment/) | 运行时、应用、语言和项目类型的默认目录、可用性与关联元数据 |
|
|
225
280
|
| [src/skill](src/skill/) | 可复用 agent skill 注册、校验、查询与隔离副本 |
|
|
226
281
|
| [src/knowledge](src/knowledge/) | 带来源元数据的 knowledge 注册、校验、查询与隔离副本 |
|
|
227
282
|
| [src/protocol](src/protocol/) | 线上协议契约、通道,以及宿主维护的协议元数据注册中心 |
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# 作用域注册调整与交互配置
|
|
2
|
+
|
|
3
|
+
八个工具仅使用以下规范名称,不提供省略 `tool` 的别名:
|
|
4
|
+
|
|
5
|
+
| 工具 | 作用域 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `amp_tool_global_adjust` | 全局注册数据,或显式授权的 workspace 目标 |
|
|
8
|
+
| `amp_tool_workspace_adjust` | 当前宿主绑定的 workspace |
|
|
9
|
+
| `amp_tool_global_interaction` / `amp_tool_global_scenario` | 全局默认配置,或显式授权的 workspace 目标 |
|
|
10
|
+
| `amp_tool_workspace_interaction` / `amp_tool_workspace_scenario` | 当前 workspace 的默认配置与现有 session |
|
|
11
|
+
| `amp_tool_session_interaction` / `amp_tool_session_scenario` | 当前宿主绑定的 session |
|
|
12
|
+
|
|
13
|
+
## 身份与持久化
|
|
14
|
+
|
|
15
|
+
宿主使用 `database.controlService.bind(identity)` 绑定端口,并注入 `WorkspaceAgentService`、`GlobalAgentService` 或 `SessionControlService` 的 `control` 选项。`identity` 的 `workspaceId`、`sessionId`、`allowGlobal`、授权 workspace 集合与认证回调来自宿主。工具参数不能指定 session 身份;仅 global 工具接受目标 `workspaceId`,端口会再次验证授权。缺少端口返回 `control_unavailable`。
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Database } from "attention-manifest-protocol/database";
|
|
19
|
+
import { SessionRegistry } from "attention-manifest-protocol/session";
|
|
20
|
+
import { SessionControlService } from "attention-manifest-protocol/control";
|
|
21
|
+
import { registerSessionControlTools } from "attention-manifest-protocol/module";
|
|
22
|
+
|
|
23
|
+
const database = new Database("state.sqlite");
|
|
24
|
+
const identities = new SessionRegistry({ store: database.workspaceSessions });
|
|
25
|
+
// roots 由宿主审核;下面示例中的 roots 由应用传入。
|
|
26
|
+
const opened = identities.open({ agentId: "agent.example", roots });
|
|
27
|
+
const control = database.controlService.bind({
|
|
28
|
+
workspaceId: opened.descriptor.workspaceId!,
|
|
29
|
+
sessionId: opened.descriptor.id,
|
|
30
|
+
authenticate: () => {
|
|
31
|
+
identities.verify(opened.credential.sessionId, opened.credential.token);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const sessionControl = new SessionControlService({ control });
|
|
35
|
+
registerSessionControlTools(toolRegistry, sessionControl);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Session 执行器为 `SessionControlToolExecutor`。Workspace 和 Global 使用已有的注册函数与执行器,新增工具会随其 descriptors 注册。所有新增工具的静态风险为 `write`,包括同名工具的读取 action;宿主审批与工具策略继续生效。意外异常只返回 `internal_error`,不会回传后端错误内容。
|
|
39
|
+
|
|
40
|
+
`workspaces` 保存显式 workspace;默认 workspace 是普通 workspace,与 global scope 分开。宿主可使用 `createWorkspace(id, name)`、`defaultWorkspace()`、`setDefaultWorkspace(id, expectedVersion?)` 管理工作区。默认切换只影响之后省略 workspaceId 的新 session;既有 session 和 fork 保留原绑定。v4 数据库通过增量迁移升级到 v5,保留 scheduler 和证据 hash chain,未知未来版本拒绝打开。SQLite 连接是可信宿主边界,不应暴露任意 SQL 给 agent。
|
|
41
|
+
|
|
42
|
+
## 注册项调整
|
|
43
|
+
|
|
44
|
+
`registry` 为 `modules`、`skills`、`knowledge`、`protocols`、`environments`、`concepts` 之一。`value` 是 JSON 元数据,不允许修改可执行函数、工具 schema、风险或授权策略。
|
|
45
|
+
|
|
46
|
+
| action | 必填字段(除 action、registry) |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `list` | 无 |
|
|
49
|
+
| `get` / `remove` | `id` |
|
|
50
|
+
| `register` / `update` | `id`, `value`(对象) |
|
|
51
|
+
| `default_get` / `default_reset` | `key` |
|
|
52
|
+
| `default_set` | `key`, `value`(JSON) |
|
|
53
|
+
| `link` / `unlink` | `id`, `targetId`, `relation` |
|
|
54
|
+
|
|
55
|
+
变更 action 支持 `expectedVersion` 和 `dryRun`。首次本地写入的 CAS 版本为 0;继承项的 `get` 返回本地 `version`、来源和 `effectiveVersion`。Workspace 对全局项的 update/remove 创建本地覆盖或删除遮蔽。默认值 reset 恢复继承;条目 remove 保留版本和删除标记。Link 的目标属于同 registry,版本随源条目递增。
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{"action":"register","registry":"modules","id":"module.search","value":{"name":"Search","description":"Metadata search"},"expectedVersion":0}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{"action":"update","registry":"modules","id":"module.search","value":{"name":"Search v2"},"expectedVersion":1,"dryRun":true}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
宿主通过 `listRegistry(workspaceId, registry)` 读取有效注册目录,或 `applyControlRegistry(...)` 将覆盖和删除标记应用到搜索目录。此投影固定 record kind 和宿主 scope,不会创建可执行工具。一般嵌入式宿主应在调整后重建快照并同步搜索;stdio host 配置 control 与 search 时已接好更新链路。
|
|
66
|
+
|
|
67
|
+
## 交互模式与情景
|
|
68
|
+
|
|
69
|
+
两个域都支持 `get`、`set`、`reset`。set 提供一个模式选择器,或一个权重 `mix`,二者互斥。
|
|
70
|
+
|
|
71
|
+
- interaction 的 `mode`:`affect`、`think`、`inspire`、`converge`、`orchestrate`。
|
|
72
|
+
- scenario 的 `scenario`:`chat`、`writing`、`office`、`collaboration`、`investigation`、`research`、`engineering`、`iteration`。
|
|
73
|
+
- mix 只接受该域的合法 key,权重必须为有限非负数,至少一项正数;服务调用已有 resolver 归一化。
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{"action":"set","mode":"think","expectedVersion":0}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{"action":"set","mix":{"engineering":0.7,"research":0.3},"applyTo":"all","dryRun":true}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
有效配置按 global → workspace → session 继承,更具体的配置优先;reset 清除本地选择并恢复继承。get 返回 `mix`/`effectiveMix`、`source`、本地 `version`、`effectiveVersion` 与解析计划;没有配置时 mix 为 null。
|
|
84
|
+
|
|
85
|
+
Global/workspace 变更支持 `applyTo`:`defaults` 修改该 scope 的配置(默认);`existing` 写入当前授权范围内有效 session 的本地配置;`all` 同时修改默认和现有 session。批量操作在一个事务内完成,失败时全部回滚。Session 工具不接受 `applyTo`。授权集合只覆盖部分 workspace 的 global 端口,必须指定获准的目标 workspace,不能通过全局继承扩大影响。
|
|
86
|
+
|
|
87
|
+
`CognitiveRuntime` 的 `control` 选项接收同一个已认证 session 端口,每轮开始读取有效配置。显式 turn override 优先,其后依次采用作用域配置、runtime 显式默认、runtime session 默认、自动推断。工具在本轮改变配置后,从下一轮生效。凭据或 session 生命周期失效时,在调用模型前拒绝执行。
|
|
88
|
+
|
|
89
|
+
## stdio host
|
|
90
|
+
|
|
91
|
+
本地 bootstrap 可配置 `control: { databasePath: "state.sqlite", workspaceId?: "workspace-id" }`。省略 workspaceId 时绑定数据库的默认 workspace。若同时配置 search,两者使用同一数据库;搜索 namespace 持久绑定到该 workspace,不能被另一个 workspace 接管;仅配置 search 而未绑定 control 身份的宿主,也不能复用已绑定的 namespace。配置属于宿主启动输入,不能通过 tools/call 更改。
|
|
92
|
+
|
|
93
|
+
Control 工具的 workspace/global `revision` 可选,提供时执行既有快照版本检查;其他 workspace 工具仍遵循原 revision 契约。Session 工具独立于项目快照,不接受 revision。需要版本竞争保护时,变更请求应提供 `expectedVersion`。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { ControlPort } from "../control/types.js";
|
|
1
2
|
import type { Frame } from "../frame/frame.js";
|
|
2
|
-
import { HostCatalog } from "../discover/host.js";
|
|
3
|
+
import type { HostCatalog } from "../discover/host.js";
|
|
4
|
+
import type { DiscoverySearch } from "../discover/types.js";
|
|
3
5
|
import type { KnowledgeRegistry } from "../knowledge/registry.js";
|
|
4
6
|
import type { ProtocolRegistry } from "../protocol/registry.js";
|
|
5
7
|
import type { SkillRegistry } from "../skill/registry.js";
|
|
@@ -97,6 +99,8 @@ export interface WorkspaceRunner {
|
|
|
97
99
|
run(request: WorkspaceRunRequest): WorkspaceRunOutcome;
|
|
98
100
|
}
|
|
99
101
|
export interface WorkspaceServiceOptions {
|
|
102
|
+
/** Host-authenticated port; calls always bind the workspace scope. */
|
|
103
|
+
control?: ControlPort;
|
|
100
104
|
agentId: string;
|
|
101
105
|
projectIds: readonly string[];
|
|
102
106
|
snapshot: WorkspaceSnapshot;
|
|
@@ -119,6 +123,8 @@ export interface WorkspaceServiceOptions {
|
|
|
119
123
|
* components are filtered against `projectIds` before discovery sees them.
|
|
120
124
|
*/
|
|
121
125
|
host?: HostCatalog;
|
|
126
|
+
/** Host-managed search index; services never create or synchronize it. */
|
|
127
|
+
search?: DiscoverySearch;
|
|
122
128
|
skills?: SkillRegistry;
|
|
123
129
|
knowledge?: KnowledgeRegistry;
|
|
124
130
|
protocols?: ProtocolRegistry;
|
|
@@ -132,14 +138,12 @@ export declare class WorkspaceAgentService {
|
|
|
132
138
|
private readonly retired;
|
|
133
139
|
private readonly roots;
|
|
134
140
|
private readonly definitions;
|
|
135
|
-
private readonly
|
|
136
|
-
private readonly skills?;
|
|
137
|
-
private readonly knowledge?;
|
|
138
|
-
private readonly protocols?;
|
|
141
|
+
private readonly search?;
|
|
139
142
|
private readonly projectIds;
|
|
140
143
|
private readonly store;
|
|
141
144
|
private readonly writer?;
|
|
142
145
|
private readonly runner?;
|
|
146
|
+
private readonly control?;
|
|
143
147
|
/**
|
|
144
148
|
* Files the host already persisted through this service. The snapshot stays
|
|
145
149
|
* immutable, so this overlay is what keeps a read after a write honest.
|
|
@@ -155,7 +159,8 @@ export declare class WorkspaceAgentService {
|
|
|
155
159
|
private cacheVersion;
|
|
156
160
|
private cachedCatalog;
|
|
157
161
|
private calls;
|
|
158
|
-
|
|
162
|
+
/** The second argument is a host-only schema override for the global adapter. */
|
|
163
|
+
constructor(options: WorkspaceServiceOptions, controlDefinitions?: readonly WorkspaceToolDefinition[]);
|
|
159
164
|
/**
|
|
160
165
|
* Host-only registration. Frames bind to this snapshot revision explicitly;
|
|
161
166
|
* their digest remains the AMP Frame digest, not a workspace revision field.
|
|
@@ -190,16 +195,14 @@ export declare class WorkspaceAgentService {
|
|
|
190
195
|
*/
|
|
191
196
|
catalog(): ToolCatalog;
|
|
192
197
|
call(name: string, raw: unknown): WorkspaceResponse;
|
|
198
|
+
/** Search is asynchronous; other tools preserve their synchronous behavior. */
|
|
199
|
+
callAsync(name: string, raw: unknown): Promise<WorkspaceResponse>;
|
|
200
|
+
/** Every entry point spends one call before validating the same wire schema. */
|
|
201
|
+
private prepareCall;
|
|
202
|
+
private failure;
|
|
193
203
|
private reply;
|
|
194
204
|
private requireEntity;
|
|
195
205
|
private dispatch;
|
|
196
|
-
/**
|
|
197
|
-
* Agent-callable project discovery. The result is a structural tree over
|
|
198
|
-
* only the authorized snapshot plus host components that belong to the
|
|
199
|
-
* authorized project scope. Content matches are bounded snippets, never a
|
|
200
|
-
* replacement for a Frame-allocated detail read.
|
|
201
|
-
*/
|
|
202
|
-
private discover;
|
|
203
206
|
/**
|
|
204
207
|
* Project scope: one explicitly named project or every authorized root.
|
|
205
208
|
*/
|
|
@@ -268,7 +271,6 @@ export declare class WorkspaceAgentService {
|
|
|
268
271
|
* writer, CAS and overlay as `write`.
|
|
269
272
|
*/
|
|
270
273
|
private diffWrite;
|
|
271
|
-
private builtInComponents;
|
|
272
274
|
private materialize;
|
|
273
275
|
/**
|
|
274
276
|
* Bounded detail read. The page is addressed by characters, lines or bytes,
|