attention-manifest-protocol 0.4.5 → 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.
Files changed (125) hide show
  1. package/CHANGELOG.md +40 -10
  2. package/CHANGELOG.zh-CN.md +40 -10
  3. package/README.md +74 -19
  4. package/README.zh-CN.md +80 -21
  5. package/docs/scoped-control.zh-CN.md +93 -0
  6. package/lib/context/workspaceService.d.ts +22 -11
  7. package/lib/context/workspaceService.js +73 -87
  8. package/lib/control/index.d.ts +4 -0
  9. package/lib/control/index.js +4 -0
  10. package/lib/control/search.d.ts +7 -0
  11. package/lib/control/search.js +39 -0
  12. package/lib/control/service.d.ts +32 -0
  13. package/lib/control/service.js +424 -0
  14. package/lib/control/sessionService.d.ts +23 -0
  15. package/lib/control/sessionService.js +51 -0
  16. package/lib/control/types.d.ts +21 -0
  17. package/lib/control/types.js +4 -0
  18. package/lib/database/adapter/workspaceSessionStore.d.ts +1 -0
  19. package/lib/database/adapter/workspaceSessionStore.js +3 -0
  20. package/lib/database/entity/catalog.d.ts +58 -0
  21. package/lib/database/entity/catalog.js +74 -0
  22. package/lib/database/entity/index.d.ts +1 -0
  23. package/lib/database/entity/index.js +1 -0
  24. package/lib/database/entity/workspaceSession.d.ts +4 -3
  25. package/lib/database/entity/workspaceSession.js +1 -0
  26. package/lib/database/repository/catalogPublication.d.ts +15 -0
  27. package/lib/database/repository/catalogPublication.js +41 -0
  28. package/lib/database/repository/catalogRepository.d.ts +56 -0
  29. package/lib/database/repository/catalogRepository.js +251 -0
  30. package/lib/database/repository/index.d.ts +1 -0
  31. package/lib/database/repository/index.js +1 -0
  32. package/lib/database/repository/workspaceSessionRepository.d.ts +1 -0
  33. package/lib/database/repository/workspaceSessionRepository.js +21 -7
  34. package/lib/database/service/catalogService.d.ts +54 -0
  35. package/lib/database/service/catalogService.js +271 -0
  36. package/lib/database/service/database.d.ts +8 -0
  37. package/lib/database/service/database.js +13 -0
  38. package/lib/database/service/index.d.ts +4 -0
  39. package/lib/database/service/index.js +2 -0
  40. package/lib/database/sql/schema.js +171 -2
  41. package/lib/database/store/catalogGuard.d.ts +5 -0
  42. package/lib/database/store/catalogGuard.js +34 -0
  43. package/lib/database/store/catalogStore.d.ts +20 -0
  44. package/lib/database/store/catalogStore.js +70 -0
  45. package/lib/database/store/database.js +77 -23
  46. package/lib/database/store/index.d.ts +1 -0
  47. package/lib/database/store/index.js +1 -0
  48. package/lib/discover/host.d.ts +3 -6
  49. package/lib/discover/host.js +39 -23
  50. package/lib/discover/kinds.d.ts +1 -1
  51. package/lib/discover/kinds.js +1 -1
  52. package/lib/discover/tree.js +192 -86
  53. package/lib/discover/types.d.ts +76 -1
  54. package/lib/environment/catalog.d.ts +13 -0
  55. package/lib/environment/catalog.js +158 -0
  56. package/lib/environment/index.d.ts +5 -0
  57. package/lib/environment/index.js +3 -0
  58. package/lib/environment/types.d.ts +16 -0
  59. package/lib/environment/types.js +3 -0
  60. package/lib/file/path.js +15 -45
  61. package/lib/file/runtime.d.ts +4 -0
  62. package/lib/file/runtime.js +6 -1
  63. package/lib/file/scopedStore.d.ts +4 -0
  64. package/lib/file/scopedStore.js +23 -0
  65. package/lib/file/service.d.ts +1 -8
  66. package/lib/file/service.js +24 -122
  67. package/lib/global/service.d.ts +13 -0
  68. package/lib/global/service.js +21 -2
  69. package/lib/index.d.ts +8 -0
  70. package/lib/index.js +7 -0
  71. package/lib/knowledge/index.d.ts +2 -0
  72. package/lib/knowledge/index.js +1 -0
  73. package/lib/knowledge/registry.d.ts +19 -0
  74. package/lib/knowledge/registry.js +39 -0
  75. package/lib/module/index.d.ts +1 -0
  76. package/lib/module/index.js +1 -0
  77. package/lib/module/mcp/filesystemServer.d.ts +0 -1
  78. package/lib/module/mcp/filesystemServer.js +1 -14
  79. package/lib/module/mcp/workspaceServer.d.ts +2 -0
  80. package/lib/module/mcp/workspaceServer.js +20 -4
  81. package/lib/module/tool/controlExecutor.d.ts +10 -0
  82. package/lib/module/tool/controlExecutor.js +25 -0
  83. package/lib/module/tool/filesystemExecutor.d.ts +1 -1
  84. package/lib/module/tool/filesystemExecutor.js +1 -1
  85. package/lib/module/tool/globalExecutor.js +1 -1
  86. package/lib/module/tool/workspaceExecutor.js +5 -3
  87. package/lib/naming/aliases.js +0 -10
  88. package/lib/naming/ids.d.ts +20 -10
  89. package/lib/naming/ids.js +20 -10
  90. package/lib/protocol/control.d.ts +20 -0
  91. package/lib/protocol/control.js +77 -0
  92. package/lib/protocol/filesystem.js +12 -12
  93. package/lib/protocol/global.js +6 -1
  94. package/lib/protocol/index.d.ts +2 -0
  95. package/lib/protocol/index.js +2 -0
  96. package/lib/protocol/registry.d.ts +20 -0
  97. package/lib/protocol/registry.js +46 -0
  98. package/lib/protocol/workspace.d.ts +1 -1
  99. package/lib/protocol/workspace.js +14 -11
  100. package/lib/registry/index.d.ts +2 -0
  101. package/lib/registry/index.js +1 -0
  102. package/lib/registry/memory.d.ts +17 -0
  103. package/lib/registry/memory.js +33 -0
  104. package/lib/runtime/cognitiveRuntime.d.ts +3 -0
  105. package/lib/runtime/cognitiveRuntime.js +6 -2
  106. package/lib/search/catalogSearch.d.ts +49 -0
  107. package/lib/search/catalogSearch.js +250 -0
  108. package/lib/search/elasticsearch.d.ts +53 -0
  109. package/lib/search/elasticsearch.js +473 -0
  110. package/lib/search/index.d.ts +6 -0
  111. package/lib/search/index.js +3 -0
  112. package/lib/search/projection.d.ts +26 -0
  113. package/lib/search/projection.js +213 -0
  114. package/lib/search/types.d.ts +55 -0
  115. package/lib/search/types.js +1 -0
  116. package/lib/semantic/jsonValue.d.ts +2 -0
  117. package/lib/semantic/jsonValue.js +38 -5
  118. package/lib/session/registry.d.ts +2 -0
  119. package/lib/session/registry.js +63 -10
  120. package/lib/session/types.d.ts +8 -0
  121. package/lib/skill/index.d.ts +2 -0
  122. package/lib/skill/index.js +1 -0
  123. package/lib/skill/registry.d.ts +20 -0
  124. package/lib/skill/registry.js +37 -0
  125. package/package.json +76 -72
package/CHANGELOG.md CHANGED
@@ -5,24 +5,54 @@ 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
- ## [Unreleased]
8
+ ## [0.5.0] - 2026-11-03
9
+
10
+ ### Added
9
11
 
10
- ## [0.4.5] - 2026-10-31
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.
11
20
 
12
21
  ### Fixed
13
22
 
14
- - Bound discovery tree construction and subtree lookahead under small output limits, deep or cyclic input, and exhausted traversal budgets; extensionless file filters now work consistently.
15
- - Enforced filesystem session read/write/create permissions across MCP tools, sanitized classified failures, and kept stdio sessions alive after malformed or escaping requests.
16
- - Checked excluded paths against case-folded Windows paths and resolved symlink targets; preserved selected-root routing for multi-root outlines and dependency graphs.
17
- - Applied session and service read/tree/graph budgets consistently and report truncation instead of returning incomplete results as complete.
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
+
31
+ ## [0.4.6] - 2026-11-02
32
+
33
+ ### Added
34
+
35
+ - Host-owned `SkillRegistry`, `KnowledgeRegistry` and `ProtocolRegistry` with validated registration, duplicate rejection, defensive copies and deterministic listing.
36
+ - Metadata-only `skills`, `knowledge` and `protocols` discovery scopes, with registry injection through workspace and global agent services. Disabled skills and protocols are excluded from discovery.
18
37
 
19
38
  ### Changed
20
39
 
21
- - Standardized TypeScript tool filenames on lowerCamelCase and updated repository documentation and references.
22
- - Advanced the npm package version to 0.4.5.
40
+ - Share in-memory registry storage and query mechanics through `InMemoryRegistry` while keeping validation and list policies in each domain.
41
+
42
+ ### Fixed
43
+
44
+ - Reserve discovery node capacity for ancestors before visiting descendants so tight limits preserve tree structure and accurate summary counts.
45
+
46
+ ## [Unreleased]
23
47
 
24
48
  ### Added
25
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
+
26
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).
27
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.
28
58
  - `amp_tool_workspace_dependency`: project-level `project_depends_on` dependencies and dependents with the declaring source, method and paginated project list.
@@ -33,8 +63,8 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
33
63
  - Agent workspace: a `File`/`Directory` tree, paged reads, CAS atomic writes, strategy-based outlines, import/export/dependency graphs and Office parsing (DOCX/XLSX/PPTX, with best-effort DOC/XLS/PPT/PUB/ACCDB).
34
64
  - Session module: `ses_` identity, one-time bearer token, TTL, suspend/revoke/rotate, fork, per-session context isolation and quotas; SQLite adapters `SqliteWorkspaceSessionStore` / `SqliteWorkspaceSessionContextStore`.
35
65
  - `src/hook`: `useRead`, `useWrite`, `useDiff`, `useParse`, `useDependency`, `useExportation`, `useImportation`, `useOutline`, `useCode`, `useProject`. Every hook is read-only except `useWrite`, and runs are recorded in `hook_runs`.
36
- - `amp_tool_file_*` (ten tools), the `amp_tool_globalfs_*` global naming adapter, and `amp_service_filesystem` / `amp_protocol_filesystem`.
37
- - Lossless read-only syntax trees: `amp_tool_file_ast`, `useAst`, `src/syntax/syntaxTree.ts` and `src/syntax/syntaxRegistry.ts`; languages, token kinds and node kinds are registry data, every token keeps UTF-8 byte and line ranges, and the target file is never executed.
66
+ - `amp_tool_filesystem_*` (ten tools), the `amp_tool_globalfs_*` global naming adapter, and `amp_service_filesystem` / `amp_protocol_filesystem`.
67
+ - Lossless read-only syntax trees: `amp_tool_filesystem_ast`, `useAst`, `src/syntax/syntaxTree.ts` and `src/syntax/syntaxRegistry.ts`; languages, token kinds and node kinds are registry data, every token keeps UTF-8 byte and line ranges, and the target file is never executed.
38
68
  - SQLite tables: `workspace_sessions`, `session_roots`, `session_context`, `file_nodes`, `file_annotations`, `file_writes`, `file_outlines`, `file_imports`, `file_exports`, `file_dependencies`, `hook_runs`.
39
69
  - Data structures: `Trie`, `ByteLineIndex` (segment-tree prefix sums) and `OutlineIndex` (AST + Trie + SegmentTree).
40
70
  - Outline strategies cover code (TS/JS/Python/Java/C/C++/C#/Go/Rust), Vue, project manifests (npm/Maven/Gradle/CMake/Cargo/Go/pyproject/Make), prose (Markdown/TeX/plain text), HTML/CSS/SCSS/Sass/XML/OPML and Office; `outlineCoverageCheck` verifies 74 cases.
@@ -5,29 +5,59 @@
5
5
  格式遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循
6
6
  [语义化版本](https://semver.org/lang/zh-CN/)。
7
7
 
8
- ## [未发布]
8
+ ## [0.5.0] - 2026-11-03
9
+
10
+ ### 新增
9
11
 
10
- ## [0.4.5] - 2026-10-31
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` 参数,并由宿主配置和同步搜索后端。
11
20
 
12
21
  ### 修复
13
22
 
14
- - 对小输出限额、深层或循环输入以及遍历预算耗尽场景限制 discovery 树构建和子树探测;无扩展名文件过滤现在保持一致。
15
- - 在 MCP 工具中落实 filesystem session 的读取、写入和创建权限,统一错误分类并隐藏主机路径;畸形或越界请求后 stdio 会话仍可继续处理。
16
- - 路径排除检查覆盖 Windows 大小写折叠及符号链接真实目标;多根 workspace 的大纲和依赖查询保持所选根目录。
17
- - 一致执行 session 与 service 的读取、目录树和依赖图预算;结果截断时明确标记,不再伪报完整。
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
+
31
+ ## [0.4.6] - 2026-11-02
32
+
33
+ ### 新增
34
+
35
+ - 宿主维护的 `SkillRegistry`、`KnowledgeRegistry` 与 `ProtocolRegistry`,支持登记校验、重复 ID 拒绝、防御性副本与稳定列表。
36
+ - 只返回元数据的 `skills`、`knowledge`、`protocols` 发现范围,并贯通 workspace/global agent 服务的注册中心注入;发现时排除禁用的 skill 与 protocol。
18
37
 
19
38
  ### 变更
20
39
 
21
- - TypeScript 工具文件名统一为小写开头的 camelCase,并更新仓库内路径引用和文档。
22
- - npm 包版本升至 0.4.5。
40
+ - 通过 `InMemoryRegistry` 复用内存存储与查询机制,各领域保留独立校验和列表策略。
41
+
42
+ ### 修复
43
+
44
+ - 发现树先为祖先预留节点容量,紧凑预算下仍保留树结构并准确统计节点。
45
+
46
+ ## [未发布]
23
47
 
24
48
  ### 新增
25
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
+
26
56
  - Agent 工作区:`File`/`Directory` 树、分页读、CAS 原子写、策略化大纲、import/export/dependency 图与 Office(DOCX/XLSX/PPTX,DOC/XLS/PPT/PUB/ACCDB best-effort)解析。
27
57
  - Session 模块:`ses_` 身份、一次性 bearer 令牌、TTL、暂停/撤销/rotate、fork、每会话上下文隔离与配额;SQLite 适配器 `SqliteWorkspaceSessionStore` / `SqliteWorkspaceSessionContextStore`。
28
58
  - `src/hook` 组合层:`useRead`、`useWrite`、`useDiff`、`useParse`、`useDependency`、`useExportation`、`useImportation`、`useOutline`、`useCode`、`useProject`;除 `useWrite` 外只读,并记录 `hook_runs`。
29
- - `amp_tool_file_*` 十个工具与 `amp_tool_globalfs_*` 全局命名适配器;`amp_service_filesystem` / `amp_protocol_filesystem`。
30
- - 无损只读语法树:`amp_tool_file_ast`、`useAst`、`src/syntax/syntaxTree.ts` 与 `src/syntax/syntaxRegistry.ts`;语言/Token/节点类别由注册中心管理,全部 token 保留 UTF-8 字节与行范围,不执行目标文件。`syntaxTreeCheck` 8 例,完整 verify 135/135。
59
+ - `amp_tool_filesystem_*` 十个工具与 `amp_tool_globalfs_*` 全局命名适配器;`amp_service_filesystem` / `amp_protocol_filesystem`。
60
+ - 无损只读语法树:`amp_tool_filesystem_ast`、`useAst`、`src/syntax/syntaxTree.ts` 与 `src/syntax/syntaxRegistry.ts`;语言/Token/节点类别由注册中心管理,全部 token 保留 UTF-8 字节与行范围,不执行目标文件。`syntaxTreeCheck` 8 例,完整 verify 135/135。
31
61
  - SQLite 表:`workspace_sessions`、`session_roots`、`session_context`、`file_nodes`、`file_annotations`、`file_writes`、`file_outlines`、`file_imports`、`file_exports`、`file_dependencies`、`hook_runs`。
32
62
  - 数据结构:`Trie`、`ByteLineIndex`(SegmentTree 前缀和)、`OutlineIndex`(AST + Trie + SegmentTree)。
33
63
  - 大纲策略覆盖代码(TS/JS/Python/Java/C/C++/C#/Go/Rust)、Vue、项目清单(npm/Maven/Gradle/CMake/Cargo/Go/pyproject/Make)、文章(Markdown/TeX/plain text)、HTML/CSS/SCSS/Sass/XML/OPML 与 Office;`outlineCoverageCheck` 74 例逐项验证。
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **English** · [简体中文](README.zh-CN.md) · [Changelog](CHANGELOG.md)
4
4
 
5
- AMP is a metacognitive protocol for agents: declare knowledge and obligations, allocate finite attention, obtain evidence, and record costs and outcomes. The reference implementation is version `0.4.5`, requires **Node.js 24 or later**, and uses Apache-2.0.
5
+ AMP is a metacognitive protocol for agents: declare knowledge and obligations, allocate finite attention, obtain evidence, and record costs and outcomes. The reference implementation is version `0.4.2`, requires **Node.js 24 or later**, and uses Apache-2.0.
6
6
 
7
7
  ## Architecture
8
8
 
@@ -53,20 +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` returns one structural tree over the authorized projects. File nodes carry a module kind (`service`, `tool`, `controller`, `route`, `repository`, `model`, `config`, `test`, `middleware`, `component`, `util`), an extension and bounded content matches. Hosts register project descriptions, purposes, summaries, plugins, services and tools through `HostCatalog`; project metadata is attached to project nodes, and an unregistered project falls back to its workspace summary. Discovery is read-only, never widens `projectIds`, and returns snippets as discovery evidence rather than as a Frame-allocated detail read.
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.
59
+
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.
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).
57
111
 
58
112
  ## Quick start
59
113
 
60
114
  ```sh
61
115
  npm ci
62
116
  npm run build
63
- npm run verify
64
- npm run scenario
117
+ npm run build:lib
118
+ node --test tools/controlProtocolCheck.ts tools/controlPersistenceCheck.ts tools/controlIntegrationCheck.ts
65
119
  ```
66
120
 
67
121
  ## Library usage
68
122
 
69
- `npm install attention-manifest-protocol` ships the compiled ESM build in `lib/` with its declarations, alongside the source, JSON Schemas and executable checks. Node.js 24 or later is required. The root entry exposes the documented protocol surfaces; every module is also reachable as a subpath.
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.
70
124
 
71
125
  ```js
72
126
  import { generateSigningKey, signManifest, verifyManifest } from "attention-manifest-protocol";
@@ -85,7 +139,7 @@ import { ToolIds, parseId } from "attention-manifest-protocol/naming";
85
139
 
86
140
  `npm run build:lib` rebuilds `lib/` and `prepublishOnly` runs it before publishing. The build compiles only the library; the Vite demo entry (`src/main.ts`) is not part of it.
87
141
 
88
- Focused checks can be run directly with the corresponding camelCase tools, such as `node tools/workspaceAgentCheck.ts`, `node tools/workspaceProjectCheck.ts`, `node tools/workspaceDiffCheck.ts`, `node tools/workspaceReactiveDiffCheck.ts`, `node tools/discoverCheck.ts` and `node tools/discoverAgentCheck.ts`. `verify` runs the full chain and both type checks. Evaluation inputs/reports remain in [docs/eval](docs/eval/) and [docs/probes](docs/probes/) as JSON; fixture and recorded-probe results are not independent human studies or production-quality evidence.
142
+ Focused checks: `npm run workspace-agent-check`, `workspace-project-check`, `workspace-diff-check`, `workspace-reactive-diff-check` and the `workspace-*-boundary-check` suites, `workspace-context-check`, `document-context-check`, `tex-context-check`, `governance-check`, `assignment-check`, `interaction-binding-check`, `discover-check`, `discover-agent-check`, `typecheck` and `typecheck:tools`. `verify` runs the full chain and both type checks. Evaluation inputs/reports remain in [docs/eval](docs/eval/) and [docs/probes](docs/probes/) as JSON; fixture and recorded-probe results are not independent human studies or production-quality evidence.
89
143
 
90
144
  ## Agent tools
91
145
 
@@ -116,20 +170,20 @@ The `amp_protocol_workspace` v1 response contains `protocol`, `version`, `revisi
116
170
 
117
171
  ### Filesystem tools
118
172
 
119
- `amp_tool_file_*` is bound to one authenticated Session; the bearer token never appears in a tool argument. Every tool except `write` is read-only.
173
+ `amp_tool_filesystem_*` is bound to one authenticated Session; the bearer token never appears in a tool argument. Every tool except `write` is read-only.
120
174
 
121
175
  | Tool | Purpose |
122
176
  | --- | --- |
123
- | `amp_tool_file_session` | Current identity, roots, permissions, remaining TTL and quotas |
124
- | `amp_tool_file_file` | One File/Directory node; `depth`/`offset`/`limit` bound the subtree |
125
- | `amp_tool_file_directory` | Flat listing of direct children |
126
- | `amp_tool_file_read` | 1-based line page with fingerprint, charset and the next line |
127
- | `amp_tool_file_write` | Atomic write; create/overwrite/upsert/append, CAS, dry-run |
128
- | `amp_tool_file_outline` | Structural outline with `query`/`startLine`/`endLine` filters |
129
- | `amp_tool_file_import` | Outgoing, incoming or two-way imports |
130
- | `amp_tool_file_export` | Exported symbols, signatures and re-export edges |
131
- | `amp_tool_file_dependency` | Cycles, topological order and bounded closures |
132
- | `amp_tool_file_ast` | Lossless syntax tree: every non-whitespace token, declaration/markup hierarchy, UTF-8/line ranges; read-only, never executes |
177
+ | `amp_tool_filesystem_session` | Current identity, roots, permissions, remaining TTL and quotas |
178
+ | `amp_tool_filesystem_file` | One File/Directory node; `depth`/`offset`/`limit` bound the subtree |
179
+ | `amp_tool_filesystem_directory` | Flat listing of direct children |
180
+ | `amp_tool_filesystem_read` | 1-based line page with fingerprint, charset and the next line |
181
+ | `amp_tool_filesystem_write` | Atomic write; create/overwrite/upsert/append, CAS, dry-run |
182
+ | `amp_tool_filesystem_outline` | Structural outline with `query`/`startLine`/`endLine` filters |
183
+ | `amp_tool_filesystem_import` | Outgoing, incoming or two-way imports |
184
+ | `amp_tool_filesystem_export` | Exported symbols, signatures and re-export edges |
185
+ | `amp_tool_filesystem_dependency` | Cycles, topological order and bounded closures |
186
+ | `amp_tool_filesystem_ast` | Lossless syntax tree: every non-whitespace token, declaration/markup hierarchy, UTF-8/line ranges; read-only, never executes |
133
187
 
134
188
  The global variant is `amp_tool_globalfs_*`, a naming adapter in [src/global/filesystem.ts](src/global/filesystem.ts) that grants no new root or permission. Outline nodes carry `isFile`/`isDirectory`/`file?`/`directory?`/`path` (for example `add.py#add`) and `range` (UTF-8 bytes plus 1-based lines as bigint; decimal strings on the wire). Strategies cover code, Vue, project manifests, Markdown/TeX/plain text, CSS/SCSS/Sass, HTML, XML/OPML and Office; Office parsing covers DOCX/XLSX/PPTX and treats DOC/XLS/PPT/PUB/ACCDB as best-effort CFB.
135
189
 
@@ -153,8 +207,8 @@ await diff.run({ path: "src/new.ts", before: "" });
153
207
  ### MCP stdio
154
208
 
155
209
  ```sh
156
- node tools/workspaceAgentDemo.ts
157
- node tools/workspaceAgentServer.ts --config .cache/workspace-agent.local
210
+ npm run workspace-agent-demo
211
+ npm run workspace-agent -- --config .cache/workspace-agent.local
158
212
  ```
159
213
 
160
214
  For an MCP client, start Node directly to keep package-manager banners out of stdout. Replace absolute paths with your checkout location:
@@ -223,6 +277,7 @@ Service errors: `invalid_arguments`, `unknown_tool`, `revision_mismatch`, `not_a
223
277
  | [src/syntax](src/syntax/) | Charset detection/encoding, byte/line indexing, syntax registry and lossless read-only syntax trees |
224
278
  | [src/outline](src/outline/) | Code/document outlines, range and label indexes, keyword/strategy registries, React/Shell/SQL/Visual Basic strategies and Office parsing |
225
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 |
226
281
  | [src/protocol](src/protocol/) | Wire contracts: envelopes, A2A, channels and the `amp_protocol_workspace` surface |
227
282
  | [src/module](src/module/) | LLM/tool ports, MCP adapters and execution policies |
228
283
  | [src/runtime](src/runtime/) | Agent turn/tool loop and governance integration |
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](README.md) · **简体中文** · [更新日志](CHANGELOG.zh-CN.md)
4
4
 
5
- AMP 是供 agent 使用的元认知协议:声明知识和义务,分配有限注意力,获取证据,记录成本与结果。当前参考实现为 `0.4.5`,要求 **Node.js 24 或以上**,使用 Apache-2.0 许可证。
5
+ AMP 是供 agent 使用的元认知协议:声明知识和义务,分配有限注意力,获取证据,记录成本与结果。当前参考实现为 `0.4.2`,要求 **Node.js 24 或以上**,使用 Apache-2.0 许可证。
6
6
 
7
7
  ## 架构
8
8
 
@@ -38,7 +38,7 @@ Context 使用结构树和类型化关系图。项目依赖、导入、调用与
38
38
  - MCP 执行、参数 Schema 校验、摘要固定与旧式握手回退,以及 A2A 发现与消息绑定。
39
39
  - 项目树、项目依赖图、TS/JS 的部分静态导入/调用/引用图,以及知识库词法检索。
40
40
  - Agent 工作区:`File`/`Directory` 树(指纹、字符集、bigint 行数/字节数、时间、描述/摘要/用途);分页读、CAS 原子写、按策略提取的大纲(代码/项目/文章/Office);import/export/dependency 图(Tarjan SCC、拓扑序、有界闭包);Session 身份与上下文隔离;`src/hook` 组合层;SQLite 实体与仓储。
41
- - 宿主发现:以一棵结构树返回获准项目、内部模块(service/tool/controller/route/repository/model/config/test/...)、文件名、有界内容匹配,以及宿主注册的插件、服务与工具。项目节点带描述、用途与简介。
41
+ - 宿主发现:以一棵结构树返回获准项目、内部模块(service/tool/controller/route/repository/model/config/test/...)、文件名、有界内容匹配,以及宿主注册的插件、服务、工具、skills 和 knowledge。项目节点带描述、用途与简介;skill/knowledge 节点只暴露元数据,详情由注册中心按 ID 查询。
42
42
  - Markdown、TXT、DOCX、XLSX、PPTX、TeX/LaTeX/BibTeX 的结构提取、原生定位与摘要/详情分层。
43
43
  - `amp_protocol_workspace` v1 服务、8 个 agent 工具、本地运行时接入与 MCP stdio 服务端。
44
44
  - 带显式策略的指纹:值使用 RFC 8785 规范化 JSON,文件按字节哈希,目录树使用域分隔的 Merkle 根,`verify` 比较算法、`kind` 与策略,而不是只比对裸十六进制字符串。未配对代理项与 `-0` 被拒绝,而不是被静默改写。
@@ -53,20 +53,76 @@ Context 使用结构树和类型化关系图。项目依赖、导入、调用与
53
53
 
54
54
  ### 发现
55
55
 
56
- `amp_tool_workspace_discover` 以一棵结构树返回获准项目。文件节点带模块分类(`service`、`tool`、`controller`、`route`、`repository`、`model`、`config`、`test`、`middleware`、`component`、`util`)、扩展名与有界内容匹配。宿主通过 `HostCatalog` 登记项目的描述、用途、简介,以及插件、服务和工具;项目元数据附在项目节点上,未登记的项目回退到 workspace 摘要。发现是只读的,不会扩大 `projectIds`;内容匹配只是发现证据,不能替代 Frame 分配后的详情读取。
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 使用。
59
+
60
+ 这些 registry 是各自领域的宿主目录,不要求每个概念都复制成同构 registry。Ability、cognition、progress 等若已有运行时状态、策略或事件模型,应由现有领域模块维护;需要统一枚举时增加只读 catalog/discovery 投影即可。Agent 默认只读正式目录;可选的登记工作流应先创建带来源、版本和提案状态的候选项,再经宿主权限校验、人工审核与审计后发布,不授予模型直接改写已生效条目的能力。
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)。
57
113
 
58
114
  ## 快速开始
59
115
 
60
116
  ```sh
61
117
  npm ci
62
118
  npm run build
63
- npm run verify
64
- npm run scenario
119
+ npm run build:lib
120
+ node --test tools/controlProtocolCheck.ts tools/controlPersistenceCheck.ts tools/controlIntegrationCheck.ts
65
121
  ```
66
122
 
67
123
  ## 作为库使用
68
124
 
69
- `npm install attention-manifest-protocol` 会安装 `lib/` 中的编译产物及其声明文件,同时附带源码、JSON Schema 与可执行检查。运行时要求 Node.js 24 及以上。包根入口提供文档中的协议核心接口,其余模块均可按子路径导入。
125
+ `npm install attention-manifest-protocol` 会安装 `lib/` 中的编译产物及其声明文件、JSON Schema 和作用域控制文档。源码和可执行检查保存在 GitHub 仓库中。运行时要求 Node.js 24 及以上。包根入口提供文档中的协议核心接口,其余模块均可按子路径导入。
70
126
 
71
127
  ```js
72
128
  import { generateSigningKey, signManifest, verifyManifest } from "attention-manifest-protocol";
@@ -85,7 +141,7 @@ import { ToolIds, parseId } from "attention-manifest-protocol/naming";
85
141
 
86
142
  `npm run build:lib` 重新构建 `lib/`,发布前由 `prepublishOnly` 自动执行。该构建只编译库代码,Vite 演示入口(`src/main.ts`)不在其中。
87
143
 
88
- 专项检查可直接运行对应的 camelCase 工具,例如 `node tools/workspaceAgentCheck.ts`、`node tools/workspaceProjectCheck.ts`、`node tools/workspaceDiffCheck.ts`、`node tools/workspaceReactiveDiffCheck.ts`、`node tools/discoverCheck.ts` 与 `node tools/discoverAgentCheck.ts`。`verify` 执行完整验证链和两份类型检查。评测输入/结果以 JSON 保存在 [docs/eval](docs/eval/) 与 [docs/probes](docs/probes/),夹具与录制探针不等同于独立的人类研究或生产质量证明。
144
+ 专项检查为 `npm run workspace-agent-check`、`workspace-project-check`、`workspace-diff-check`、`workspace-reactive-diff-check` 与 `workspace-*-boundary-check` 系列、`workspace-context-check`、`document-context-check`、`tex-context-check`、`governance-check`、`assignment-check`、`interaction-binding-check`、`discover-check`、`discover-agent-check`、`typecheck` 与 `typecheck:tools`。`verify` 执行完整验证链和两份类型检查。评测输入/结果以 JSON 保存在 [docs/eval](docs/eval/) 与 [docs/probes](docs/probes/),夹具与录制探针不等同于独立的人类研究或生产质量证明。
89
145
 
90
146
  ## Agent 工具
91
147
 
@@ -116,20 +172,20 @@ import { ToolIds, parseId } from "attention-manifest-protocol/naming";
116
172
 
117
173
  ### 文件系统工具
118
174
 
119
- `amp_tool_file_*` 绑定一个已认证 Session;令牌不出现在工具参数里。除 `write` 外全部只读。
175
+ `amp_tool_filesystem_*` 绑定一个已认证 Session;令牌不出现在工具参数里。除 `write` 外全部只读。
120
176
 
121
177
  | 工具 | 用途 |
122
178
  | --- | --- |
123
- | `amp_tool_file_session` | 当前身份、根、权限、剩余 TTL 与配额 |
124
- | `amp_tool_file_file` | 返回一个 File/Directory 节点;`depth`/`offset`/`limit` 控制子树与分页 |
125
- | `amp_tool_file_directory` | 平铺列出一级子节点 |
126
- | `amp_tool_file_read` | 按 1-based 行号读取文本页;返回指纹、字符集与下一页行号 |
127
- | `amp_tool_file_write` | 原子写入;create/overwrite/upsert/append、CAS、dry-run |
128
- | `amp_tool_file_outline` | 结构化大纲;支持 `query`/`startLine`/`endLine` 过滤 |
129
- | `amp_tool_file_import` | 出边/入边/两向导入关系 |
130
- | `amp_tool_file_export` | 导出符号、签名与 re-export 边 |
131
- | `amp_tool_file_dependency` | 环、拓扑序、依赖/被依赖闭包 |
132
- | `amp_tool_file_ast` | 无损语法树:每个非空白 token、声明/块/标签层级、UTF-8 字节与行范围;只读,不执行 |
179
+ | `amp_tool_filesystem_session` | 当前身份、根、权限、剩余 TTL 与配额 |
180
+ | `amp_tool_filesystem_file` | 返回一个 File/Directory 节点;`depth`/`offset`/`limit` 控制子树与分页 |
181
+ | `amp_tool_filesystem_directory` | 平铺列出一级子节点 |
182
+ | `amp_tool_filesystem_read` | 按 1-based 行号读取文本页;返回指纹、字符集与下一页行号 |
183
+ | `amp_tool_filesystem_write` | 原子写入;create/overwrite/upsert/append、CAS、dry-run |
184
+ | `amp_tool_filesystem_outline` | 结构化大纲;支持 `query`/`startLine`/`endLine` 过滤 |
185
+ | `amp_tool_filesystem_import` | 出边/入边/两向导入关系 |
186
+ | `amp_tool_filesystem_export` | 导出符号、签名与 re-export 边 |
187
+ | `amp_tool_filesystem_dependency` | 环、拓扑序、依赖/被依赖闭包 |
188
+ | `amp_tool_filesystem_ast` | 无损语法树:每个非空白 token、声明/块/标签层级、UTF-8 字节与行范围;只读,不执行 |
133
189
 
134
190
  全局变体为 `amp_tool_globalfs_*`,由 [src/global/filesystem.ts](src/global/filesystem.ts) 做命名适配;它不扩大任何根或权限。
135
191
  大纲节点带 `isFile`/`isDirectory`/`file?`/`directory?`/`path`(如 `add.py#add`)与 `range`(UTF-8 字节 + 1-based 行,bigint;JSON 中为十进制字符串)。策略覆盖代码、Vue、项目清单、Markdown/TeX/纯文本、CSS/SCSS/Sass、HTML、XML/OPML 与 Office;Office 文件由 `office.ts` 解析 DOCX/XLSX/PPTX,DOC/XLS/PPT/PUB/ACCDB 为 CFB best-effort。
@@ -154,8 +210,8 @@ await diff.run({ path: "src/new.ts", before: "" });
154
210
  ### MCP stdio 接入
155
211
 
156
212
  ```sh
157
- node tools/workspaceAgentDemo.ts
158
- node tools/workspaceAgentServer.ts --config .cache/workspace-agent.local
213
+ npm run workspace-agent-demo
214
+ npm run workspace-agent -- --config .cache/workspace-agent.local
159
215
  ```
160
216
 
161
217
  真实 MCP 客户端应直接启动 Node,避免包管理器提示混入协议 stdout。将以下绝对路径替换为实际项目目录:
@@ -220,11 +276,14 @@ Frame、快照、ContentStore 与后备执行器由宿主提供;将 `tools` /
220
276
  | [src/naming](src/naming/) | 冻结的 ID 表、ID 文法、兼容别名与 catalog 摘要 |
221
277
  | [src/context](src/context/) | Context 生命周期、树/图投影、CAS、工作区事实、上下文装配与 agent 服务 |
222
278
  | [src/session](src/session/) | 身份、令牌、TTL、上下文隔离、fork/revoke/rotate |
279
+ | [src/environment](src/environment/) | 运行时、应用、语言和项目类型的默认目录、可用性与关联元数据 |
280
+ | [src/skill](src/skill/) | 可复用 agent skill 注册、校验、查询与隔离副本 |
281
+ | [src/knowledge](src/knowledge/) | 带来源元数据的 knowledge 注册、校验、查询与隔离副本 |
282
+ | [src/protocol](src/protocol/) | 线上协议契约、通道,以及宿主维护的协议元数据注册中心 |
223
283
  | [src/file](src/file/) | File/Directory 树、元数据、分页读、原子写、会话运行时/服务、模块图与 ZIP/CFB 容器 |
224
284
  | [src/syntax](src/syntax/) | 字符集检测/编解码、字节/行索引、语法注册表与无损只读语法树 |
225
285
  | [src/outline](src/outline/) | 代码/文档大纲、范围与标签索引、关键字/策略注册表、React/Shell/SQL/Visual Basic 策略与 Office 解析 |
226
286
  | [src/hook](src/hook/) | 面向 agent 的组合 hooks 与运行记录 |
227
- | [src/protocol](src/protocol/) | 线上契约:信封、A2A、通道与 `amp_protocol_workspace` 接口 |
228
287
  | [src/module](src/module/) | 模型/工具端口、MCP 适配器与执行策略 |
229
288
  | [src/runtime](src/runtime/) | agent 回合、工具循环与治理接入 |
230
289
  | [src/governance](src/governance/) | 清单、凭据、预算、工作流、签名与审计 |
@@ -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`。