@sakanano-moe/agenthelm 6.13.1 → 6.14.0-rc.2
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/package.json +1 -1
- package/runtime/index.json +6 -6
- package/runtime/plugins/agent-pack/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/agent-pack/plugin.json +1 -1
- package/runtime/plugins/agent-pack/references/capability-config.md +10 -0
- package/runtime/plugins/agent-pack/references/check-opinion-migrate.en.md +31 -0
- package/runtime/plugins/agent-pack/references/check-opinion-migrate.md +31 -0
- package/runtime/plugins/agent-pack/references/dedupe-contract.en.md +27 -0
- package/runtime/plugins/agent-pack/references/dedupe-contract.md +27 -0
- package/runtime/plugins/agent-pack/references/inventory-contract.en.md +83 -0
- package/runtime/plugins/agent-pack/references/inventory-contract.md +83 -0
- package/runtime/plugins/agent-pack/references/nudge.en.md +10 -2
- package/runtime/plugins/agent-pack/references/nudge.md +10 -2
- package/runtime/plugins/agent-pack/references/relocate-contract.en.md +41 -0
- package/runtime/plugins/agent-pack/references/relocate-contract.md +41 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_claude.py +572 -30
- package/runtime/plugins/agent-pack/runtime/agent_pack_clients.py +233 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_config.py +112 -4
- package/runtime/plugins/agent-pack/runtime/agent_pack_dedupe.py +502 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_desktop.py +92 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_ext_common.py +251 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_inventory.py +989 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_mcp_write.py +447 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_nudge.py +29 -4
- package/runtime/plugins/agent-pack/runtime/agent_pack_relocate.py +385 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_scope.py +233 -0
- package/runtime/plugins/agent-pack/runtime/agenthelm.py +183 -14
- package/runtime/plugins/agent-pack/runtime/locale/en.json +250 -1
- package/runtime/plugins/agent-pack/runtime/mcp_server.py +12 -0
- package/runtime/plugins/agent-pack/runtime/nudge_text.py +8 -2
- package/runtime/plugins/agent-pack/runtime/user_settings.py +2 -1
- package/runtime/plugins/agent-pack/skills/agent-pack/SKILL.md +15 -0
- package/runtime/plugins/agents-init/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/agents-init/content.json +4 -2
- package/runtime/plugins/agents-init/plugin.json +1 -1
- package/runtime/plugins/agents-init/skills/agents-init/SKILL.md +2 -0
- package/runtime/plugins/agents-init/skills/agents-init/launcher.en.sh +93 -0
- package/runtime/plugins/agents-init/skills/agents-init/project.schema.json +27 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/baseline.py +4 -1
- package/runtime/plugins/agents-init/skills/agents-init/scripts/init_project.py +24 -9
- package/runtime/plugins/agents-init/skills/agents-init/skill.json +1 -1
- package/runtime/plugins/opinion-manager/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/opinion-manager/catalog/README.md +3 -1
- package/runtime/plugins/opinion-manager/catalog/rules/om.align-requirements/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.assumptions-authority/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.batch-questions/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.bilingual-terms/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.calculations/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.chinese-response/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.clean-deliverable/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.complete-options/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.conclusion-first/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.concrete-titles/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.consistent-items/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.device-readable/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.editable-diagrams/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.evidence-inference/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.maintenance-chinese/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.maintenance-project-language/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.markdown-structure/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.portable-files/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.report-context/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.report-formats/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.report-review/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.response-brief/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.response-dense/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.rules-tools/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.semantic-wrap/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.solutions-proportional/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.solutions-three-level/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.tables-compact/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.tables-list-first/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.test-evidence/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/rules/om.versioned-files/versions/1.1.0.json +34 -0
- package/runtime/plugins/opinion-manager/catalog/templates/delivery-standard/compact-tables/versions/1.1.0.json +32 -0
- package/runtime/plugins/opinion-manager/catalog/templates/delivery-standard/list-first/versions/1.1.0.json +32 -0
- package/runtime/plugins/opinion-manager/catalog/templates/development-standard/chinese-maintenance/versions/1.1.0.json +26 -0
- package/runtime/plugins/opinion-manager/catalog/templates/development-standard/project-language/versions/1.1.0.json +26 -0
- package/runtime/plugins/opinion-manager/catalog/templates/response-style/brief-chinese/versions/1.1.0.json +30 -0
- package/runtime/plugins/opinion-manager/catalog/templates/response-style/dense-chinese/versions/1.1.0.json +30 -0
- package/runtime/plugins/opinion-manager/catalog/templates/scenario/concise-project/versions/1.1.0.json +181 -0
- package/runtime/plugins/opinion-manager/catalog/templates/scenario/reviewed-project/versions/1.1.0.json +179 -0
- package/runtime/plugins/opinion-manager/catalog/templates/work-method/proportional/versions/1.1.0.json +31 -0
- package/runtime/plugins/opinion-manager/catalog/templates/work-method/three-level/versions/1.1.0.json +31 -0
- package/runtime/plugins/opinion-manager/content.json +44 -3
- package/runtime/plugins/opinion-manager/plugin.json +1 -1
- package/runtime/plugins/opinion-manager/references/inbox.en.md +25 -4
- package/runtime/plugins/opinion-manager/references/inbox.md +25 -4
- package/runtime/plugins/opinion-manager/references/profile.schema.json +19 -2
- package/runtime/plugins/opinion-manager/references/rule.schema.json +25 -3
- package/runtime/plugins/opinion-manager/references/versioned-template.schema.json +5 -4
- package/runtime/plugins/opinion-manager/references/versioning.md +89 -4
- package/runtime/plugins/opinion-manager/runtime/context.py +26 -19
- package/runtime/plugins/opinion-manager/runtime/inbox.py +400 -25
- package/runtime/plugins/opinion-manager/runtime/inbox_relations.py +106 -0
- package/runtime/plugins/opinion-manager/runtime/inbox_routes.py +132 -0
- package/runtime/plugins/opinion-manager/runtime/inbox_text.py +117 -11
- package/runtime/plugins/opinion-manager/runtime/lifecycle.py +35 -5
- package/runtime/plugins/opinion-manager/runtime/locale/en.json +137 -2
- package/runtime/plugins/opinion-manager/runtime/migrate.py +582 -0
- package/runtime/plugins/opinion-manager/runtime/opinion_manager.py +9 -4
- package/runtime/plugins/opinion-manager/runtime/rule_lines.py +247 -0
- package/runtime/plugins/opinion-manager/runtime/tags.py +217 -0
- package/runtime/plugins/opinion-manager/runtime/versioned.py +289 -41
- package/runtime/plugins/opinion-manager/skills/opinion-manager/SKILL.md +8 -7
- package/runtime/plugins/project-orchestrator/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/project-orchestrator/plugin.json +1 -1
- package/runtime/plugins/project-orchestrator/runtime/locale/en.json +305 -3
- package/runtime/plugins/project-orchestrator/runtime/private_paths.py +11 -1
- package/runtime/plugins/project-orchestrator/runtime/project_cli.py +101 -1
- package/runtime/plugins/project-orchestrator/runtime/project_demo.py +13 -1
- package/runtime/plugins/project-orchestrator/runtime/project_ext_actions.py +415 -0
- package/runtime/plugins/project-orchestrator/runtime/project_extensions.py +971 -0
- package/runtime/plugins/project-orchestrator/runtime/project_extensions_demo.py +86 -0
- package/runtime/plugins/project-orchestrator/runtime/project_menu.py +345 -2
- package/runtime/plugins/project-orchestrator/runtime/project_real.py +17 -1
- package/runtime/plugins/project-orchestrator/skills/project-orchestrator/SKILL.md +2 -0
|
@@ -23,19 +23,40 @@
|
|
|
23
23
|
|
|
24
24
|
以下命令都在 `opinion_manager.py inbox <动作>` 下,`--project` 必填;`--lang zh|en` 指定提示语言(缺省按 `AGENTHELM_LANG`、系统 locale 决定,最后用英文);输出为 JSON,`list` 可用 `--output markdown` 得到给用户看的编号列表。
|
|
25
25
|
|
|
26
|
-
- `add --title --text --scope [--quote] [--client] [--session]`:暂存。标题 ≤120、正文 ≤1200、原话 ≤600 个字符;至少一个 `--scope`。内容相同(忽略空白与大小写)的候选合并,新原话追加为证据。
|
|
27
|
-
- `
|
|
26
|
+
- `add --title --text --scope --trigger --purpose [--exclude] [--relation] [--quote] [--client] [--session]`:暂存。标题 ≤120、正文 ≤1200、原话 ≤600、各字段 ≤300 个字符;至少一个 `--scope`。内容相同(忽略空白与大小写)的候选合并,新原话追加为证据。
|
|
27
|
+
- `--trigger`(何时适用)与 `--purpose`(为什么)由 Agent 暂存时填写,用户在集中裁决时一次看到。本版为**软必填**:缺失时仍暂存成功,返回 `warnings` 且 `complete: false`,列表按「不完整」展示;严格拒绝缺失项留给之后的 major(代码里集中开关 `STRICT_REQUIRED`)。
|
|
28
|
+
- 传入了但无效的值一律拒绝:空白,以及「所有」「全部」「相关」「一切」「any」「all」「everything」「relevant」「n/a」等占位词。
|
|
29
|
+
- 全局声明:用户明确要求全局时,`--trigger` 必须用固定标准值「全部场景,用户要求全局」/ "All scenarios; the user asked for this to apply globally",并同时带非空 `--quote`;列表标注「全局(请用户确认)」。**工具只做形式校验,无法验证是谁提出的全局**,需由用户在裁决时确认。
|
|
30
|
+
- `--exclude` 写不适用情形;`--relation` 是 Agent 对与现有规则关系的备注,工具原样保存和展示,不解释。
|
|
31
|
+
- 采纳写入时,自定义行为 `- **标题**(适用:…;条件:…;目的:…;不适用:…):正文`(没有这些字段的旧候选与此前渲染逐字节相同)。行内标签与 `OPINION.md` 的框架文字随**项目文件语言**(Project Profile 的 `language`,缺省 zh),不随界面语言;`en` 项目的文件里不出现中文(用户自己写的内容除外)。`language` 非 zh 的项目,`opinion.lock.json` 带可选键 `"language": "en"` 供 `verify` 复现渲染;zh 项目的锁格式不变。旧版运行时读不了带 `language` 的锁,需先升级。
|
|
32
|
+
- `list [--status a,b] [--session ID] [--unpresented]`:列出候选。json 里每项带 `relations`(机械关系提示,没有则为空列表),markdown 里以「可能相关」行展示。
|
|
33
|
+
- 关系提示的对象:其他候选(不含已丢弃)、`OPINION.md` 自定义行(按本工具自己的两种渲染格式解析)、Profile 里已选的公开规则文本。三种提示:规范化文本相同(`same_text`)、字符二元组 Jaccard 重合度 ≥ 0.5(`text_overlap`,两边规范化后都至少 6 个字符)、触发条件重合度 ≥ 0.4(`condition_overlap`,不含全局声明)。每条带证据片段与「机械比对,仅供参考」,最多 5 条,永不阻断;阈值保守,宁可漏报。冲突、合并、放大缩小、拆分等语义判断由 Agent 做,写入 `--relation` 备注,工具原样保存和展示,不解释。
|
|
34
|
+
- `check`:只读,不写任何文件。列出缺 trigger / purpose 的候选(`pending`、`trial`)与 `OPINION.md` 自定义行;认不出格式的行标 `unstructured`(未结构化),只报告。输出带每个候选的 `revise_command`,供 Agent 逐条提出建议值。`OPINION.md` 里的行补全走 `adopt` 的完整预览流程,由用户一次批量确认,不新增写入命令。
|
|
35
|
+
- `revise <编号> [--title --text --scope --trigger --purpose --exclude --relation --quote]`:修订候选。状态为 `pending` 且从未展示(`presented` 为 0)时无需 `--confirmed`;其他状态必须带 `--confirmed`。`history` 追加 `{to: 原状态, note: revised, previous: 被改字段的旧值}`,状态不变;重算摘要,与其他候选撞摘要时报错;`--scope` 整体替换,`--quote` 追加。`formal` 候选的修订不改 `OPINION.md`(返回警告)。
|
|
28
36
|
- `decide <编号…> --to pending|trial|formal|held|rejected --confirmed [--note]`:裁决。没有 `--confirmed` 一律拒绝;多个编号要么全部成功,要么都不改。
|
|
29
37
|
- `adopt <编号…> [--apply --confirm SHA256]`:从采纳到写入的一步确认入口。用户在对话里明确说「采纳」时用它,不再单独 `decide`。
|
|
30
38
|
- 不带 `--apply`:只预览,零写入。把候选正文作为个人规则追加到项目现有 Profile 的自定义段(没有 Profile 时新建 `private.my-opinion@1.0.0`),经 `profile` 与 `compose` 同一套预览,返回完整 `content`(将成为 `OPINION.md` 的全文)、`blocked`(已有人工内容等需先处理的情况)和 `confirmation_sha256`。
|
|
39
|
+
- 预览还返回 `added_lines`(采纳后将追加到自定义段的行,与 `content` 里的一致)和 `shown_matches`:全部候选都有展示快照、快照与此刻渲染行一致、没有 `blocked`、没有冲突时为 `true`;`shown` 逐个候选列出是否一致。它只是事实记录,不改变保护:写入仍必须带预览指纹,不因 `shown_matches` 放宽。
|
|
31
40
|
- 带 `--apply --confirm <预览的 confirmation_sha256>`:用户确认后一次写入新 Profile 版本、`OPINION.md` 与 `opinion.lock.json`,用 `verify` 读回核对,最后才把候选置为 `formal`。预览之后候选、Profile 或 `OPINION.md` 有变化则指纹不符,拒绝并零写入。不使用 `--confirmed`:确认凭据是预览指纹。
|
|
32
41
|
- 多个编号一次预览、一次确认,全部成功或都不改;不存在的编号、已是 `formal` 的编号整体报错并点名。写入或读回失败时,`OPINION.md`、锁、本次新建的 Profile 文件恢复原状,候选状态不变。
|
|
33
42
|
- 已被 `decide --to formal` 记录、但尚未写入的候选:先 `decide --to pending --confirmed` 退回,再 `adopt`。
|
|
34
|
-
- `present <编号…>`:记录已向用户展示过(hook
|
|
43
|
+
- `present <编号…>`:记录已向用户展示过(hook 在发出确认请求时调用,避免同一候选反复提示),同时记录**展示快照**:此刻候选将被渲染成的规则行的摘要(`shown`:`at`、`language`、`line_sha256`)。之后候选被修订或项目语言改变,摘要就对不上。输出带这些候选(含 `relations`)。
|
|
44
|
+
- `gate [--session ID] [--cooldown-hours N] [--max-per-session N] [--peek]`:询问节流,只记账,不决定要不要问。同项目 N 小时内(默认 24)最多放行一次,同会话最多放行 `--max-per-session` 次(默认 1);返回 `allowed`、`reason`(`ok` / `cooldown` / `session_limit`)、`next_allowed_at`。放行且没有 `--peek` 时才记一次;`--peek` 只读,不创建任何文件。没有 `--session` 时只看冷却。状态在项目私有的 `.opinion/ask-state.json`(保留最近 50 个会话),拒绝符号链接,读改写持有 `.opinion/.ask.lock`;状态文件格式不对时报错,不当作放行。本命令只提供计数;何时调用、询问的措辞由协议和 hook 决定。
|
|
35
45
|
- `expire --days N`:把试行超过 N 天的候选退回 `pending`。退回保留 `last_action_at`,因此仍计入“久未处理”。
|
|
36
46
|
- `pending [--session ID]`:待确认项提供者,见下。
|
|
37
47
|
- `exposure`:只读,报告 `.opinion/inbox.json` 在 Git 里的状态与提醒文字。
|
|
38
|
-
- `brief [--session ID] [--max-chars N]`:生成会话开始时注入的协议与试行候选全文,默认上限 6000
|
|
48
|
+
- `brief [--session ID] [--max-chars N] [--mode ask|digest|quiet] [--cooldown-hours N] [--max-per-session N]`:生成会话开始时注入的协议与试行候选全文,默认上限 6000 字符。**确认时机的单一来源是这份协议**(SKILL.md 只指向它)。`--mode`:`ask`(默认)要求任务收尾前先运行 `gate`,放行才询问,询问时同步 `present`;`digest` 不单独询问,只在回复末尾顺带一句;`quiet` 只靠会话开始的汇总。`--cooldown-hours` 默认 24,`--max-per-session` 默认 1,与缺省值不同时才写入 `ask` 协议里的 `gate` 命令行(与 gate 自身缺省一致,省略即等价)。三种模式的协议都规定:`adopt` 预览的 `shown_matches` 为真、无 `blocked`、无冲突时,Agent 可视为用户已确认展示过的内容,直接 `--apply --confirm`(指纹保护不变),并告知结果与回退方式(上一个 Profile 版本仍在 `.opinion/profiles/` 下,没有一步撤销命令);否则展示预览差异后再问一次。用户之后更新需求本身不触发确认。
|
|
49
|
+
- **限制**:hook 路径(agent-pack 的 `nudge`)有硬限制——`stop` 每会话最多一次,并先问 `gate`。模型自判路径(无 hook 的客户端,或模型自己决定何时问)没有任何硬限制,只能靠协议措辞,本工具不保证。各客户端真实行为(Cursor 的 sessionStart 注入、Codex `/hooks` 信任、Claude Stop 的 `additionalContext` 在各版本的表现)未经实机验证。
|
|
50
|
+
|
|
51
|
+
## 路由规则(把某类任务路由到某个 skill)
|
|
52
|
+
|
|
53
|
+
规则可以指定「做某类事时使用某个 skill」,例如「所有文字成果最终都用去 AI 味的 skill 处理」。**路由只是规则里的一段文字:它能提高模型调用该 skill 的概率,不能保证模型照做**,不要在对用户的说明里写成「保证」「强制」。它与 skill 自己的 `description` 触发叠加,不互斥。
|
|
54
|
+
|
|
55
|
+
- `add` / `revise` 的路由参数(都可选):`--route-skill NAME`(skill 名:小写字母、数字、连字符,≤64;不接受 `plugin:skill`)、`--route-when before|after|instead`(缺省 `before`)、`--route-final`(收尾:只与 `after` 合用,不给 `--route-when` 时隐含 `after`)、`--route-on TAG`(短标签:小写字母、数字、连字符,≤32,供机械比较)。没有 `--route-skill` 时其余路由参数无效;`revise` 在候选已有路由上合并,`--route-clear` 清除整条路由(与其他 `--route-*` 互斥,旧路由记入 `history` 的 `previous`,确认规则同其他修订)。适用条件、目的、不适用仍用 `--trigger` / `--purpose` / `--exclude`;写「所有文字工作」时 `--trigger` 写成「产出面向人的文字成果」,`--exclude` 写代码、配置、命令输出、保持原文等,不要写成全局。
|
|
56
|
+
- 采纳写入的行末带纯 ASCII 标记 `[route skill=… when=… final=1 on=…]`(`final`、`on` 缺省则省略),与项目语言无关;渲染器按**项目文件语言**自动追加两条约束:不适用里加入「skill 自身的执行过程」,正文后加入「该 skill 执行期间不再触发本规则」与「该 skill 不可用时告知用户并按目的自行完成」。没有路由的规则行逐字节不变;`language=en` 的项目不出现中文。不改 Profile schema 与锁格式。
|
|
57
|
+
- 候选记录里的 `route` 对象含 `skill`、`when`、`final`、`on`;旧记录没有该键。`list`、`present`、`pending`、`brief` 的试行条目、`adopt` 预览都带出路由;采纳指纹与展示快照随渲染行一起变化。
|
|
58
|
+
- `routes list [--output markdown]`:只读。列出候选(`pending`、`trial`,以及已批准但尚未写入的 `formal`)与 `OPINION.md` 自定义段里的路由,认不出的行标 `unstructured`(未结构化,只报告)。附**机械检查,仅供参考**(只警告,不阻断):同一 `--route-on` 标签、同一时机路由到不同 skill;重复路由(同 skill、同标签、同时机);全项目多于一条 `--route-final`;超过 6 条;单条超过 500 字节。**不检查 skill 是否存在**(需要 `agenthelm inventory`,下一版提供),也不判断语义重叠与间接循环(输出的 `unchecked` 如实列出)。
|
|
59
|
+
- 验证办法(本版):任务结束提交 lifecycle 的 `use` 事件时,对每条适用的路由规则在现有 `results` 字段自报 `passed`(确实调用并采用)、`not-applicable` 或 `violated`(应调用而未调用)。自报依赖 Agent 如实记录,路由遵从率的阈值没有经过验证;不改 lifecycle。
|
|
39
60
|
|
|
40
61
|
## 待确认项提供者契约
|
|
41
62
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"additionalProperties": false,
|
|
6
6
|
"required": ["schema_version", "id", "version", "templates", "rules", "sources", "overrides", "custom", "derived_from"],
|
|
7
7
|
"properties": {
|
|
8
|
-
"schema_version": {"enum": ["2.0", "2.1"]},
|
|
8
|
+
"schema_version": {"enum": ["2.0", "2.1", "2.2"]},
|
|
9
9
|
"id": {"$ref": "rule.schema.json#/properties/id"},
|
|
10
10
|
"version": {"$ref": "rule.schema.json#/properties/version"},
|
|
11
11
|
"templates": {"type": "array", "uniqueItems": true, "items": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*/[a-z0-9]+(?:[.-][a-z0-9]+)*@(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"}},
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"loading": {"$ref": "#/$defs/loading"}
|
|
24
24
|
},
|
|
25
25
|
"allOf": [
|
|
26
|
-
{"if": {"properties": {"schema_version": {"
|
|
26
|
+
{"if": {"properties": {"schema_version": {"enum": ["2.1", "2.2"]}}}, "then": {"required": ["loading"]}, "else": {"not": {"required": ["loading"]}}},
|
|
27
|
+
{"if": {"properties": {"schema_version": {"const": "2.2"}}}, "then": {"properties": {"loading": {"$ref": "#/$defs/tagLoading"}}}, "else": {"properties": {"loading": {"$ref": "#/$defs/loading"}}}}
|
|
27
28
|
],
|
|
28
29
|
"$defs": {
|
|
29
30
|
"hash": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
|
|
@@ -35,6 +36,22 @@
|
|
|
35
36
|
"bundles": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/bundle"}}
|
|
36
37
|
}
|
|
37
38
|
},
|
|
39
|
+
"tagLoading": {
|
|
40
|
+
"type": "object", "additionalProperties": false, "required": ["always", "tags", "members"],
|
|
41
|
+
"properties": {
|
|
42
|
+
"always": {"type": "array", "uniqueItems": true, "items": {"$ref": "rule.schema.json#/properties/id"}},
|
|
43
|
+
"tags": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/tag"}},
|
|
44
|
+
"members": {"type": "object", "propertyNames": {"$ref": "rule.schema.json#/properties/id"}, "additionalProperties": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"$ref": "#/$defs/tag/properties/id"}}}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"tag": {
|
|
48
|
+
"type": "object", "additionalProperties": false, "required": ["id", "name", "trigger", "exclude"],
|
|
49
|
+
"properties": {
|
|
50
|
+
"id": {"type": "string", "pattern": "^(?!(?:core|none|all)$)[a-z0-9]+(?:-[a-z0-9]+)*$", "maxLength": 32},
|
|
51
|
+
"name": {"$ref": "#/$defs/zhEn"}, "trigger": {"$ref": "#/$defs/zhEn"}, "exclude": {"$ref": "#/$defs/zhEn"}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"zhEn": {"type": "object", "additionalProperties": false, "required": ["zh", "en"], "properties": {"zh": {"type": "string", "pattern": "\\S"}, "en": {"type": "string", "pattern": "\\S"}}},
|
|
38
55
|
"bundle": {
|
|
39
56
|
"type": "object", "additionalProperties": false, "required": ["family", "trigger", "exclude", "routes"],
|
|
40
57
|
"properties": {
|
|
@@ -8,9 +8,31 @@
|
|
|
8
8
|
"id": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$"},
|
|
9
9
|
"version": {"type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"},
|
|
10
10
|
"slot": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$"},
|
|
11
|
-
"title": {"
|
|
11
|
+
"title": {"$ref": "#/$defs/localizedText"},
|
|
12
12
|
"level": {"enum": ["required", "preferred"]},
|
|
13
|
-
"scopes": {"
|
|
14
|
-
"text": {"
|
|
13
|
+
"scopes": {"$ref": "#/$defs/localizedScopes"},
|
|
14
|
+
"text": {"$ref": "#/$defs/localizedText"},
|
|
15
|
+
"trigger": {"$ref": "#/$defs/localizedText"},
|
|
16
|
+
"purpose": {"$ref": "#/$defs/localizedText"},
|
|
17
|
+
"exclude": {"$ref": "#/$defs/localizedText"}
|
|
18
|
+
},
|
|
19
|
+
"$defs": {
|
|
20
|
+
"localizedText": {
|
|
21
|
+
"description": "A plain string is the legacy form and counts as zh; {zh, en} supplies one or both languages.",
|
|
22
|
+
"oneOf": [
|
|
23
|
+
{"type": "string", "pattern": "\\S"},
|
|
24
|
+
{"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
25
|
+
"properties": {"zh": {"type": "string", "pattern": "\\S"}, "en": {"type": "string", "pattern": "\\S"}}}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"localizedScopes": {
|
|
29
|
+
"oneOf": [
|
|
30
|
+
{"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "pattern": "\\S"}},
|
|
31
|
+
{"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
32
|
+
"properties": {
|
|
33
|
+
"zh": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "pattern": "\\S"}},
|
|
34
|
+
"en": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "pattern": "\\S"}}}}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
15
37
|
}
|
|
16
38
|
}
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"family": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$"},
|
|
9
9
|
"variant": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$"},
|
|
10
10
|
"version": {"type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"},
|
|
11
|
-
"name": {"
|
|
12
|
-
"description": {"
|
|
13
|
-
"scopes": {"
|
|
11
|
+
"name": {"$ref": "rule.schema.json#/$defs/localizedText"},
|
|
12
|
+
"description": {"$ref": "rule.schema.json#/$defs/localizedText"},
|
|
13
|
+
"scopes": {"$ref": "rule.schema.json#/$defs/localizedScopes"},
|
|
14
14
|
"rules": {
|
|
15
15
|
"type": "array", "minItems": 1, "uniqueItems": true,
|
|
16
16
|
"items": {"type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*@(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"}
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"loading": {"$ref": "profile.schema.json#/$defs/tagLoading", "description": "可选:本模板规则的标签选择声明;always 与 members 只能引用本模板的规则编号。选择模板时由 profile 预览物化为 Profile 的 loading(schema 2.2)。"}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -132,6 +132,38 @@ Agent 为适用范围与候选含义做判断;scopes 只提供元数据。工
|
|
|
132
132
|
|
|
133
133
|
修订时未提供 `--loading-file` 则沿用原声明;`--remove-loading` 移除声明并恢复完整读取。移除了声明中引用的模板系列时,必须同时提供新的声明文件。
|
|
134
134
|
|
|
135
|
+
### 标签选择(schema 2.2)
|
|
136
|
+
|
|
137
|
+
规则较多且横跨多个场景时,可以改用标签声明:一条规则带多个标签,按需读取标签的并集。设计与决定见 `docs/design/opinion-progressive-loading.md`。声明同样用 `profile --loading-file` 整体写入,`loading` 只含三项,与上面的 `core` / `signals` / `bundles` 互斥:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"always": ["om.chinese-response"],
|
|
142
|
+
"tags": [{"id": "decisions", "name": {"zh": "方案与论证", "en": "Options"},
|
|
143
|
+
"trigger": {"zh": "给出方案或比较时", "en": "When proposing or comparing options"},
|
|
144
|
+
"exclude": {"zh": "纯执行", "en": "Pure execution"}}],
|
|
145
|
+
"members": {"om.calculations": ["decisions"], "om.complete-options": ["decisions"]}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- 标签词表封闭,标签 id 与规则编号只能是 ASCII(标签 id 为小写字母、数字、连字符,不超过 32 字符,不能取 `core`、`none`、`all`);中文只写在 `name`、`trigger`、`exclude` 里,且必须同时给出 zh 与 en。
|
|
150
|
+
- `always` 列出常驻规则;没有任何标签的规则同样常驻;规则同时在 `always` 与标签里时归常驻。悬空规则编号、未知标签、重复项、没有成员的标签都在预览阶段被拒绝。
|
|
151
|
+
- `context core` 输出常驻规则与标签索引;`context select --tag A --tag B` 输出标签并集的规则(不含常驻规则,去重);`context index` 给出逐标签的规则数与字节数;`context check --tag A [--loaded A]` 由声明的标签算出应读取的规则并核对已读取,缺失退出码 1。未知标签、空选择、全部常驻的标签都会报错并列出有效标签。2.2 声明下 `context bundle` 报错并指向 `select`。
|
|
152
|
+
- 自定义段的规则可以在行尾带 ` [tags a b]`(纯 ASCII、字母序;与路由并存时写作 `[route …] [tags …]`),所有标签都在词表内的行按标签按需读取;没有标记、手写、认不出或带词表外标签的行永远常驻。`inbox add` 与 `inbox revise` 用 `--tag`(可重复)指定标签并对照词表校验,`revise --tag-clear` 清空。
|
|
153
|
+
- 回退与 2.1 一致:核对失败、没有声明或 `opinion.loading_mode` 为 `full` 时,`core`、`select`、`index`、`check` 都返回 `fallback`,改为完整读取 `OPINION.md`。使用记账见「候选、灰度与使用记录」的 `loaded_tags` 与 `routing_miss_tags`。
|
|
154
|
+
- 带标签声明的 Profile 使用 `schema_version` 2.2。旧版本工具读它会报字段集合不符并回退为完整读取,`OPINION.md` 仍是完整正文;2.0、2.1 的 Profile、正文与锁字节不变。
|
|
155
|
+
|
|
156
|
+
### 模板声明与预览物化(catalog 1.1.0)
|
|
157
|
+
|
|
158
|
+
公开模板可以带可选的 `loading`,形态与上面的 2.2 声明相同,只能引用本模板的规则编号;它参与模板指纹,只能随模板新版本发布(patch 版本不能改变它)。`scenario/reviewed-project` 与 `scenario/concise-project` 的 1.1.0 声明了常驻集合和四个标签(`decisions`、`files`、`reports`、`maintenance`);其余模板没有声明,物化后规则全部常驻。
|
|
159
|
+
|
|
160
|
+
- `profile` 预览选择带声明的模板时,自动生成 Profile 的 `loading`(schema 2.2),在 `changes.loading_changed` 与 `changes.loading.before/after` 中展示,预览输出的 `loading_source` 标明来源(`template`、`inherited`、`file`、`removed`、`none`)。沿用「预览 → 确认指纹 → 写入」,确认前不生效。
|
|
161
|
+
- 只在新建 Profile 或模板选择发生变化(例如从 1.0.0 升到 1.1.0)时物化;模板不变的修订沿用原声明。原声明恰好等于旧模板物化的结果时,随模板更新;原声明是用户手写的,不自动合并,只在预览的 `loading_suggestion` 里给出建议,需要时用 `--loading-file` 整体写入。
|
|
162
|
+
- 多个模板同时声明时:标签词表按 id 合并,同一 id 的定义必须逐字相同,否则预览报「标签定义冲突」并列出来源;`always` 与 `members` 取并集;没有声明的模板,其规则全部常驻;规则同时在 `always` 与标签里时归常驻。直接选择的原子规则、`overrides` 停用或修订的规则,按规则编号沿用成员关系;停用后标签没有有效规则时,读取侧按「空」处理。
|
|
163
|
+
- `--no-tags` 不物化模板声明,保持完整读取(schema 2.0);`--loading-file`、`--remove-loading` 的行为不变,二者与 `--no-tags` 不能同时用于整体写入。已经选择了带声明模板、又用 `--no-tags` 写入的 Profile,在下次改变模板选择时会再次得到物化预览,仍可再加 `--no-tags`。
|
|
164
|
+
- `updates` 对每个可升级的模板列出各版本的声明摘要(`loading`,没有声明为 `null`);升级预览走 `profile --template <新版本>`,`compose` 仍会因人工修改阻断,需读取并纳入后用 `--accept-current` 确认。
|
|
165
|
+
- `untranslated` 的范围包含标签的 `name`、`trigger`、`exclude`;缺译文只警告,不阻断。
|
|
166
|
+
|
|
135
167
|
读取与核对使用只读的 `context` 命令:
|
|
136
168
|
|
|
137
169
|
```bash
|
|
@@ -149,6 +181,48 @@ python3 plugins/opinion-manager/runtime/opinion_manager.py context check --proje
|
|
|
149
181
|
|
|
150
182
|
判断任务属于哪个场景、声明哪些信号,始终由 Agent 负责;判断不清时一并读取。维护规则本身的任务读取完整正文。
|
|
151
183
|
|
|
184
|
+
## 迁移
|
|
185
|
+
|
|
186
|
+
`migrate` 把用户**现有**的 Profile(2.0 或 2.1)迁移到带标签声明的 2.2,并把 1.0.0 的公开模板与规则升级到 1.1.0。默认只读预览;写入前备份;失败自动还原;可回滚。不迁移则项目保持原样,2.0 与 2.1 的 Profile、正文与锁字节不变。
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
python3 plugins/opinion-manager/runtime/opinion_manager.py migrate --project /path/to/project [--tags] [--skip 模板或规则编号]… [--resolutions-file 冲突处理.json] [--output json|markdown]
|
|
190
|
+
python3 plugins/opinion-manager/runtime/opinion_manager.py migrate --project /path/to/project [--tags] --apply --confirm <预览指纹>
|
|
191
|
+
python3 plugins/opinion-manager/runtime/opinion_manager.py migrate --project /path/to/project --rollback .opinion/backups/<时间戳>-migrate
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**流程。** 1. 预览:零写入(文件树哈希前后相同,失败路径也一样),输出分类表与 `confirmation_sha256`;2. 向用户展示完整预览并取得明确确认;3. `--apply --confirm <指纹>`:指纹覆盖新 Profile、渲染后的 `OPINION.md`、分类结果与收件箱文件指纹,预览之后 Profile、`OPINION.md`、收件箱或 catalog 任何变化都使它失效,必须重新预览;4. 写入前把 `OPINION.md`、`opinion.lock.json`、原 Profile、收件箱文件原样备份到 `.opinion/backups/<UTC 时间戳>-migrate/files/`,并写 `manifest.json`(相对路径、SHA-256、是否随回滚还原、迁移后的状态);5. 复用 `profile` → `compose` → `verify` 的原子写,再读回核对 `OPINION.md` 与 Profile;备份、写入、读回任一步失败,按备份逐字节还原并删除本次产生的备份与新目录,项目与迁移前相同(还原本身失败时保留备份目录并给出 `--rollback` 命令)。
|
|
195
|
+
|
|
196
|
+
**分类(预览逐项列出)。**
|
|
197
|
+
|
|
198
|
+
- Profile 版本与来源模板版本;可升级的模板与规则沿用 `updates` 的预览,默认升级到最新版本,`--skip` 保持某项不升级,升级冲突沿用 `keep-local` / `use-upstream`(`--resolutions-file`),未处理的冲突阻止写入。只升级一部分模板可能让共享规则落在两个版本上,预览会报错,不写入。
|
|
199
|
+
- 2.0:由升级后模板携带的标签声明物化为 2.2。所选模板组合没有可物化的声明(没有选用公开模板、只选了原子规则、模板版本不带标签):状态 `nothing-to-migrate`,保持完整读取。曾用 `--no-tags` 保持完整读取的 2.0,迁移会再次物化声明,预览的 `notes` 会说明;不迁移保持原样,迁移后可用回滚或 `profile --remove-loading` 恢复完整读取。
|
|
200
|
+
- 2.1:默认保持不动(`unchanged`,`context bundle` 继续可用);加 `--tags` 才改写为 2.2,规则束声明整体替换为标签声明(二者互斥,改写后不再有 `bundles`)。2.2:`unchanged`。
|
|
201
|
+
- `OPINION.md` 是否被手工修改(与锁里的正文指纹比较):自定义规则小节内的任何改动、其他位置的纯追加,原样并入新 Profile 的 `custom`(不改写任何字节,常驻),预览给出追加与改动的行数;改写或删除了生成内容(规则正文、元数据)无法并入,状态 `cannot-migrate`,原因 `manual-edit-conflict`;删除了全部自定义规则同样拒绝,不让已删除的行复活。迁移内部使用与 `compose --accept-current` 相同的确认。CRLF 行尾的正文可迁移,迁移后的正文统一为 LF,回滚逐字节还原原文件。
|
|
202
|
+
- `custom` 段逐行归类:`tagged`(已带词表内有效标签,保持原样、按需加载);`suggest`(带“条件”的结构化行,只在预览里列出,由用户决定是否手工在行尾加 ` [tags …]`);`resident`(没有标记、手写、认不出、标记损坏或含词表外标签,保持原样,永远常驻)。迁移不替用户猜标签。
|
|
203
|
+
- 收件箱:缺 `trigger` / `purpose` 的旧候选只列出,不改写、不阻断迁移;收件箱存储格式、已采纳的行都不改动。
|
|
204
|
+
- `loading` 前后对照(`loading.before/after` 摘要与 `changes.loading` 完整声明)、新旧正文差异行数、完整的新 `OPINION.md`(JSON 的 `content`)。
|
|
205
|
+
|
|
206
|
+
**状态与退出码。**
|
|
207
|
+
|
|
208
|
+
- 0:`preview`、`migrated`、`unchanged`、`nothing-to-migrate`、`rolled-back`。空白 `OPINION.md`(不存在、空文件或初始化占位且没有锁)是 `nothing-to-migrate`,不是错误。
|
|
209
|
+
- 2:用法或 I/O 错误(例如 `--confirm` 没有 `--apply`、未知的 `--skip`)。
|
|
210
|
+
- 3:`cannot-migrate`,零写入,输出 `reason` 与 `next`:`no-project`、`no-lock`(没有锁但正文有内容)、`lock-invalid`(锁或 Profile 损坏)、`opinion-missing`、`opinion-unreadable`(符号链接、非普通文件、不可读)、`manual-edit-conflict`、`catalog-conflict`、`draft-failed`、`tag-conflict`、`compose-failed`。
|
|
211
|
+
- 4:`refused`,零写入:`confirm-required`、`stale-confirmation`、`unresolved-conflicts`、`blocked`;回滚时为 `not-a-backup`、`manifest-invalid`、`incomplete-backup`、`backup-damaged`、`state-changed`。
|
|
212
|
+
- 5:`failed`:`apply-failed`(已还原,`restored: true`,`phase` 为 `backup`、`write`、`read-back` 或 `manifest`)、`restore-failed`(自动还原失败,保留备份目录)、`rollback-failed`(已恢复到回滚前)。
|
|
213
|
+
|
|
214
|
+
**回滚。** `--rollback <备份目录>` 只接受本项目 `.opinion/backups/` 下的 `*-migrate` 目录,核对 `manifest.json` 与备份文件的 SHA-256;只在当前 `OPINION.md`、锁与迁移写入的 Profile 都等于迁移后的状态时还原 `OPINION.md`、锁与原 Profile,并删除迁移写入的新 Profile,回滚后与迁移前逐字节相同;迁移之后任一文件又被修改则拒绝(`state-changed`,列出文件),不丢后续修改;当前已等于迁移前返回 `unchanged`。回滚直接执行,没有单独的预览。收件箱文件只留底,迁移不改写它,回滚也不还原它。
|
|
215
|
+
|
|
216
|
+
**不变量(测试逐条断言,见 `tests/test_migrate.py`)。** 预览与失败的应用零写入;用户手工修改的每个字节与 `custom` 的每一行在迁移后仍在 `core` ∪ 全部 `select` 的并集里;没有标记与认不出的行常驻且往返不变;迁移后 `verify` 通过,未选择迁移的 2.0/2.1 字节不变;回滚后 Profile、`OPINION.md`、锁与迁移前逐字节相同;迁移不触碰 `.agents/` 与收件箱的候选内容。重复执行:已是目标状态返回 `unchanged`,不产生新备份。
|
|
217
|
+
|
|
218
|
+
**已知限制。**
|
|
219
|
+
|
|
220
|
+
- 用户在“用户自定义规则”小节之外手工追加的小节(含二级标题),迁移后落在 `custom` 段里(该段内的 `## ` 标题保留原样,常驻读取);`inbox` 按行号读取自定义段时只看到第一个 `## ` 之前的部分。
|
|
221
|
+
- 迁移用 `project.json` 的 `language` 渲染新正文:项目语言与旧锁的语言不一致时,新正文换用项目语言。
|
|
222
|
+
- 备份目录 `.opinion/backups/` 含原 Profile 与正文,随项目私有保存;是否纳入版本控制由用户决定,迁移不修改 `.gitignore`。
|
|
223
|
+
- 只升级一部分模板(`--skip`)可能因共享规则的版本不一致而报 `draft-failed`;这时全部升级,或全部 `--skip`。
|
|
224
|
+
- `migrate` 只迁移用户的 Profile 与正文,不触碰 `agents-init` 的项目入口文件。
|
|
225
|
+
|
|
152
226
|
## 候选、灰度与使用记录
|
|
153
227
|
|
|
154
228
|
`lifecycle` 命令在项目内的私有目录保存候选、证据快照、人工裁决和灰度使用记录。它只记账,不写 `OPINION.md`、规则目录或 Profile;每个项目各自维护状态,互不引用。
|
|
@@ -170,8 +244,10 @@ python3 plugins/opinion-manager/runtime/opinion_manager.py lifecycle event --pro
|
|
|
170
244
|
5. `adopt`:`human_confirmed: true`、当前 `profile_sha256`。先通过 `verify`,随后该 Profile 版本记为灰度。
|
|
171
245
|
6. `use`:`occurrence`、`rules`(当前 Profile 的精确规则引用)、`passed`、`user_changed`、`fixture`。可选字段:
|
|
172
246
|
- `results`:为每条规则给出 `passed`、`not-applicable` 或 `violated`;
|
|
173
|
-
- `loaded_bundles
|
|
174
|
-
- `routing_miss
|
|
247
|
+
- `loaded_bundles`:本次读取的按需规则束(schema 2.1);
|
|
248
|
+
- `routing_miss`:本应读取却没有读取的规则束(schema 2.1);
|
|
249
|
+
- `loaded_tags`:本次读取的标签(schema 2.2,如 `context select --tag` 的取值);
|
|
250
|
+
- `routing_miss_tags`:本应读取却没有读取的标签(schema 2.2);
|
|
175
251
|
- `date`:`YYYY-MM-DD`,用于显示规则最近一次使用。
|
|
176
252
|
7. `formalize`:`human_confirmed: true`、当前 `profile_sha256`。只改变上线标签,不改规则正文。
|
|
177
253
|
|
|
@@ -180,10 +256,11 @@ python3 plugins/opinion-manager/runtime/opinion_manager.py lifecycle event --pro
|
|
|
180
256
|
- `occurrence` 是项目内工作记录的相对路径,按前两级目录归为一个独立场景,同一任务的多个阶段只计一次。默认接受 `tasks`、`cases`、`reviews`、`projects`、`journal` 五个顶层目录,可用 `--occurrence-root` 改写。
|
|
181
257
|
- `fixture: true` 的记录不计入任何成熟度。
|
|
182
258
|
- 候选每新增一次独立真实发生次数 n,推荐信用增加 n/(n+1),达到 1 时标记待推荐,展示后扣 1。出现 `failed` 的候选显示为待处理。这是默认参数,没有经过大量使用验证。
|
|
183
|
-
- `
|
|
259
|
+
- 标签字段只在 schema 2.2 的 Profile 下可用,取值必须是 `loading.tags[].id` 的不重复列表,未声明的标签、重复项、非列表都会被拒绝并列出有效标签;2.2 下写 `loaded_bundles` 或 `routing_miss` 会报错并指向新字段,2.1 下写标签字段同理。2.1 的字段与语义不变。
|
|
260
|
+
- `use` 未通过、用户改动了结果、或存在 `routing_miss` / `routing_miss_tags` 时记为阻断;有阻断的版本不能转正式,须在新版本中解决。
|
|
184
261
|
- 至少两个独立的真实成功使用且无阻断时,`status` 标记 `ready_for_review`。它只表示可以提交复盘,不会自动转正式。
|
|
185
262
|
|
|
186
|
-
`status` 在当前正文通过核验时附带覆盖视图:每条规则的独立成功使用次数、违反次数与最近使用日期,从未使用的规则;Profile
|
|
263
|
+
`status` 在当前正文通过核验时附带覆盖视图:每条规则的独立成功使用次数、违反次数与最近使用日期,从未使用的规则;Profile 声明了分层加载时,还包括每个规则束被读取和实际用到的次数、漏读次数,以及从未用到的规则束。2.2 的标签单独列在 `tags` 中,每项带 `kind: "tag"`、`loaded_in`、`exercised_in`、`routing_misses`(`exercised_in` 为用到该标签任一成员规则的独立成功使用次数),从未用到的标签列在 `unused_tags`;2.1 的 `bundles` 与 `unused_bundles` 输出不变(条目不带 `kind`,视为规则束)。复盘时据此判断「正式」覆盖到了哪些规则。
|
|
187
264
|
|
|
188
265
|
同一 Profile 编号发布新版本后,旧版本的使用记录在其全部规则指纹未变时沿用到新版本,并计入独立成功使用次数;规则被修改或个人修订后,相关记录不再沿用。沿用需要读取旧版本的 Profile 文件并核对指纹,默认位置为项目的 `.opinion/profiles`,可用 `--profiles-root` 指定;找不到或指纹不符时不沿用,并在 `not_carried` 中列出。旧版本的阻断不沿用,但违反记录仍可在覆盖视图中看到。
|
|
189
266
|
|
|
@@ -202,6 +279,14 @@ python3 plugins/opinion-manager/runtime/opinion_manager.py publish \
|
|
|
202
279
|
|
|
203
280
|
公开目录发布还需要 `--public-approved`。使用此标志前必须执行 Skill 中的公开准入检查、展示待公开文件的全部内容并取得用户明确同意。标志本身不能代替用户的授权。公开目录只接收逐文件批准的规则、模板及说明;审批记录、私有来源映射、个人 Profile、锁和运行日志不能随目录复制到公开包。
|
|
204
281
|
|
|
282
|
+
## 双语字段与适用条件
|
|
283
|
+
|
|
284
|
+
规则的 `title`、`text`、`scopes` 与模板的 `name`、`description`、`scopes` 可以写成旧格式(字符串,`scopes` 为字符串数组,视为 zh),也可以写成 `{"zh": …, "en": …}`(`scopes` 为 `{"zh": […], "en": […]}`;至少一种语言,不允许其他语言键)。规则新增可选的 `trigger`(何时适用)、`purpose`(为什么)、`exclude`(何时不适用),同样可本地化。已发布的版本不可修改:旧 1.0.0 文件保持原样,指纹计算不变;给既有规则补译文或字段属于行为变化,不能作为 patch 发布。
|
|
285
|
+
|
|
286
|
+
- **渲染**:`profile` 预览与 `compose` 按项目文件语言(Project Profile 的 `language`,缺省 zh)选取文字;`trigger` / `purpose` / `exclude` 有就写进规则头一行(zh:`;条件:…;目的:…;不适用:…`,en:`; When: …; Purpose: …; Not for: …`),没有则与旧输出逐字节相同。分层加载的切片与规则束索引里的模板名同样按项目语言选取。
|
|
287
|
+
- **untranslated 警告**:项目语言不是 zh 时,预览(`profile`、`compose`、`inbox adopt`)里带 `untranslated`(逐条列出缺该语言译文的公开规则 `ref` 与字段)与 `warnings`。不阻断:缺译文的内容按原文写入,`ref` 点名便于逐条处理;个人修订是用户自己的文字,不计入。zh 项目的输出不带这两个键。
|
|
288
|
+
- **发布守卫**:`tests/test_catalog_bilingual.py` 要求公开 catalog 中高于 1.0.0 的规则与模板带三项字段(规则)和 zh / en 两种文字;1.0.0 存量列入显式白名单,改写内容升版时同步从白名单删除。
|
|
289
|
+
|
|
205
290
|
## 修订、派生与升级
|
|
206
291
|
|
|
207
292
|
只读查看当前变体的可用新版本:
|
|
@@ -7,6 +7,7 @@ import json
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
+
import tags
|
|
10
11
|
import versioned
|
|
11
12
|
from i18n_opinion import _, N_ # noqa: E402
|
|
12
13
|
|
|
@@ -49,7 +50,7 @@ def load(args: argparse.Namespace) -> tuple[dict[str, Any], dict[str, Any] | Non
|
|
|
49
50
|
return profile, lock
|
|
50
51
|
|
|
51
52
|
|
|
52
|
-
def partition(profile: dict[str, Any]) -> dict[str, Any]:
|
|
53
|
+
def partition(profile: dict[str, Any], language: str = "zh") -> dict[str, Any]:
|
|
53
54
|
"""把每条有效规则分到唯一的模板系列;常驻系列优先,未登记的系列按常驻处理。"""
|
|
54
55
|
loading = profile["loading"]
|
|
55
56
|
rules = versioned.effective_rules(profile)
|
|
@@ -72,18 +73,18 @@ def partition(profile: dict[str, Any]) -> dict[str, Any]:
|
|
|
72
73
|
return {
|
|
73
74
|
"rules": rules, "groups": groups, "unlisted": unlisted,
|
|
74
75
|
"refs": {family: ref for ref, family, _ in templates},
|
|
75
|
-
"names": {family: value["name"] for _, family, value in templates},
|
|
76
|
+
"names": {family: versioned.pick(value["name"], language)[0] for _, family, value in templates},
|
|
76
77
|
"always": [family for family in (*loading["core"], *unlisted, DIRECT) if family in groups],
|
|
77
78
|
"bundles": [bundle for bundle in loading["bundles"] if bundle["family"] in groups],
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
|
|
81
|
-
def group_text(profile: dict[str, Any], parts: dict[str, Any], family: str) -> str:
|
|
82
|
-
return "\n\n".join(versioned.render_rule(profile, parts["rules"][identity]) for identity in parts["groups"].get(family, []))
|
|
82
|
+
def group_text(profile: dict[str, Any], parts: dict[str, Any], family: str, language: str = "zh") -> str:
|
|
83
|
+
return "\n\n".join(versioned.render_rule(profile, parts["rules"][identity], language) for identity in parts["groups"].get(family, []))
|
|
83
84
|
|
|
84
85
|
|
|
85
|
-
def core_text(profile: dict[str, Any], lock: dict[str, Any] | None) -> str:
|
|
86
|
-
parts = partition(profile)
|
|
86
|
+
def core_text(profile: dict[str, Any], lock: dict[str, Any] | None, language: str = "zh") -> str:
|
|
87
|
+
parts = partition(profile, language)
|
|
87
88
|
if lock:
|
|
88
89
|
origin = _("正文指纹:`{0}`").format(lock["opinion_sha256"])
|
|
89
90
|
else:
|
|
@@ -92,8 +93,8 @@ def core_text(profile: dict[str, Any], lock: dict[str, Any] | None) -> str:
|
|
|
92
93
|
_("Profile:`{0}@{1}`;{2}。").format(profile["id"], profile["version"], origin),
|
|
93
94
|
_("本输出是完整正文的只读切片,始终适用。场景规则束见文末索引,命中时再读取。")]
|
|
94
95
|
for family in parts["always"]:
|
|
95
|
-
lines.extend(("", group_text(profile, parts, family)))
|
|
96
|
-
lines.extend(versioned.custom_section(profile))
|
|
96
|
+
lines.extend(("", group_text(profile, parts, family, language)))
|
|
97
|
+
lines.extend(versioned.custom_section(profile, language))
|
|
97
98
|
lines.extend(("", _("## 规则束索引"), "", _("任务命中触发条件时用 `context bundle <系列>` 读取对应规则束;判断不清时一并读取。")))
|
|
98
99
|
for bundle in parts["bundles"]:
|
|
99
100
|
family = bundle["family"]
|
|
@@ -109,23 +110,23 @@ def resolve_bundle(parts: dict[str, Any], name: str) -> str:
|
|
|
109
110
|
return family
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
def bundle_text(profile: dict[str, Any], names: list[str]) -> str:
|
|
113
|
+
def bundle_text(profile: dict[str, Any], names: list[str], language: str = "zh") -> str:
|
|
113
114
|
if not names:
|
|
114
115
|
versioned.fail(_("bundle 需要至少一个模板系列或精确模板引用"))
|
|
115
|
-
parts = partition(profile)
|
|
116
|
+
parts = partition(profile, language)
|
|
116
117
|
lines: list[str] = []
|
|
117
118
|
for name in names:
|
|
118
119
|
family = resolve_bundle(parts, name)
|
|
119
|
-
lines.extend((_("# 规则束 `{0}`").format(parts["refs"][family]), "", group_text(profile, parts, family), ""))
|
|
120
|
+
lines.extend((_("# 规则束 `{0}`").format(parts["refs"][family]), "", group_text(profile, parts, family, language), ""))
|
|
120
121
|
return "\n".join(lines).rstrip() + "\n"
|
|
121
122
|
|
|
122
123
|
|
|
123
|
-
def index_view(profile: dict[str, Any], lock: dict[str, Any] | None) -> dict[str, Any]:
|
|
124
|
-
parts = partition(profile)
|
|
124
|
+
def index_view(profile: dict[str, Any], lock: dict[str, Any] | None, language: str = "zh") -> dict[str, Any]:
|
|
125
|
+
parts = partition(profile, language)
|
|
125
126
|
|
|
126
127
|
def entry(family: str) -> dict[str, Any]:
|
|
127
128
|
return {"family": family, "ref": parts["refs"].get(family), "name": parts["names"].get(family),
|
|
128
|
-
"rules": len(parts["groups"][family]), "bytes": len(group_text(profile, parts, family).encode("utf-8"))}
|
|
129
|
+
"rules": len(parts["groups"][family]), "bytes": len(group_text(profile, parts, family, language).encode("utf-8"))}
|
|
129
130
|
|
|
130
131
|
return {
|
|
131
132
|
"ok": True, "profile": f"{profile['id']}@{profile['version']}", "profile_sha256": versioned.digest(profile),
|
|
@@ -134,7 +135,7 @@ def index_view(profile: dict[str, Any], lock: dict[str, Any] | None) -> dict[str
|
|
|
134
135
|
"custom_bytes": len((profile["custom"] or "").encode("utf-8")),
|
|
135
136
|
"bundles": [{**entry(bundle["family"]), "trigger": bundle["trigger"], "exclude": bundle["exclude"], "routes": bundle["routes"]} for bundle in parts["bundles"]],
|
|
136
137
|
"unlisted": parts["unlisted"], "signals": profile["loading"]["signals"],
|
|
137
|
-
"core_bytes": len(core_text(profile, lock).encode("utf-8")), "complete_bytes": len(versioned.render(profile).encode("utf-8")),
|
|
138
|
+
"core_bytes": len(core_text(profile, lock, language).encode("utf-8")), "complete_bytes": len(versioned.render(profile, language).encode("utf-8")),
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
|
|
@@ -159,8 +160,9 @@ def check(profile: dict[str, Any], signals: list[str], loaded: list[str]) -> dic
|
|
|
159
160
|
|
|
160
161
|
def add_command(subparsers: Any) -> None:
|
|
161
162
|
parser = subparsers.add_parser("context", help=_("按已确认的加载声明只读切分正文,并核对交付信号"))
|
|
162
|
-
parser.add_argument("action", choices=("core", "bundle", "index", "check"))
|
|
163
|
+
parser.add_argument("action", choices=("core", "bundle", "select", "index", "check"))
|
|
163
164
|
parser.add_argument("names", nargs="*", help=_("bundle 的模板系列或精确模板引用"))
|
|
165
|
+
parser.add_argument("--tag", action="append", default=[], help=_("标签 id(schema 2.2),select 与 check 使用,可重复,取并集"))
|
|
164
166
|
parser.add_argument("--project", type=Path)
|
|
165
167
|
parser.add_argument("--profile", type=Path, help=_("用候选或已保存的 Profile 预览,不读取项目锁"))
|
|
166
168
|
parser.add_argument("--signal", action="append", default=[], help=_("交付信号,格式为 键=值,可重复"))
|
|
@@ -171,12 +173,17 @@ def add_command(subparsers: Any) -> None:
|
|
|
171
173
|
def execute(args: argparse.Namespace) -> tuple[int, str]:
|
|
172
174
|
try:
|
|
173
175
|
profile, lock = load(args)
|
|
176
|
+
language = lock.get("language", "zh") if lock else (versioned.project_language(versioned.safe_path(args.project)) if args.project else "zh")
|
|
177
|
+
if tags.is_tag_profile(profile):
|
|
178
|
+
return tags.execute(args, profile, lock, language)
|
|
179
|
+
if args.action == "select" or args.tag:
|
|
180
|
+
versioned.fail(_("该 Profile 使用规则束声明(schema 2.1),请用 context bundle;select 与 --tag 只用于标签声明(schema 2.2)"))
|
|
174
181
|
if args.action == "core":
|
|
175
|
-
return EXIT_OK, core_text(profile, lock)
|
|
182
|
+
return EXIT_OK, core_text(profile, lock, language)
|
|
176
183
|
if args.action == "bundle":
|
|
177
|
-
return EXIT_OK, bundle_text(profile, args.names)
|
|
184
|
+
return EXIT_OK, bundle_text(profile, args.names, language)
|
|
178
185
|
if args.action == "index":
|
|
179
|
-
return EXIT_OK, versioned.pretty(index_view(profile, lock))
|
|
186
|
+
return EXIT_OK, versioned.pretty(index_view(profile, lock, language))
|
|
180
187
|
result = check(profile, args.signal, args.loaded)
|
|
181
188
|
return (EXIT_OK if result["ok"] else EXIT_MISSING), versioned.pretty(result)
|
|
182
189
|
except FullReading as exc:
|