@chengzhao-dev/dsh-cpp-workflow 0.7.7 → 0.7.8

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 (71) hide show
  1. package/README.en.md +6 -6
  2. package/README.md +8 -8
  3. package/lib/client.js +7 -3
  4. package/lib/comment-policy.js +7 -3
  5. package/lib/index.js +2 -1
  6. package/lib/workspace.js +17 -3
  7. package/package.json +1 -1
  8. package/skills/building-cpp/SKILL.md +4 -4
  9. package/skills/building-cpp/assets/config/.vscode/settings.json +11 -0
  10. package/skills/building-cpp/assets/templates/projects/common/running-build.sh +13 -6
  11. package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +1 -5
  12. package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +1 -5
  13. package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +0 -7
  14. package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +1 -5
  15. package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +1 -5
  16. package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +0 -7
  17. package/skills/building-cpp/references/01-build-script.md +8 -23
  18. package/skills/building-cpp/references/02-environment.md +5 -4
  19. package/skills/building-cpp/scripts/checking-environment.mjs +45 -13
  20. package/skills/building-cpp/steps/01-build.md +5 -4
  21. package/skills/building-cpp/steps/02-tooling.md +4 -4
  22. package/skills/building-cpp/steps/03-check.md +6 -6
  23. package/skills/building-cpp/steps/04-vscode.md +3 -3
  24. package/skills/developing-cpp/SKILL.md +3 -4
  25. package/skills/developing-cpp/references/comments/01-comment-rules.md +6 -6
  26. package/skills/developing-cpp/references/comments/02-style.md +18 -6
  27. package/skills/developing-cpp/references/comments/examples/01-declaration-class.md +2 -2
  28. package/skills/developing-cpp/references/comments/examples/04-declaration-file.md +5 -3
  29. package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +1 -1
  30. package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +5 -5
  31. package/skills/developing-cpp/references/design/01-project-design.md +1 -1
  32. package/skills/developing-cpp/references/exceptions/01-exception-rules.md +1 -1
  33. package/skills/developing-cpp/references/index.md +11 -10
  34. package/skills/developing-cpp/references/language/glossary/01-language-terms.md +2 -2
  35. package/skills/developing-cpp/references/language/language-basics/02-initialization.md +2 -2
  36. package/skills/developing-cpp/references/language/language-basics/05-expressions.md +2 -2
  37. package/skills/developing-cpp/references/language/language-basics/06-functions.md +4 -3
  38. package/skills/developing-cpp/references/language/language-basics/07-classes.md +1 -1
  39. package/skills/developing-cpp/references/language/performance/02-complexity.md +2 -3
  40. package/skills/developing-cpp/references/language/performance/03-memory.md +1 -1
  41. package/skills/developing-cpp/references/language/performance/05-pitfalls.md +1 -1
  42. package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +1 -1
  43. package/skills/developing-cpp/references/language/standard-library/06-format.md +1 -31
  44. package/skills/developing-cpp/references/language/standard-library/11-format-ecosystem.md +32 -0
  45. package/skills/developing-cpp/references/language/value-types/02-signed.md +2 -2
  46. package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +3 -2
  47. package/skills/developing-cpp/references/language/value-types/04-enum.md +4 -4
  48. package/skills/developing-cpp/references/layout/02-file-template.md +8 -7
  49. package/skills/developing-cpp/references/layout/03-declaration-order.md +6 -5
  50. package/skills/developing-cpp/references/naming/01-identifier-names.md +2 -2
  51. package/skills/developing-cpp/references/naming/glossary/04-square.md +1 -1
  52. package/skills/developing-cpp/references/style/01-google-cpp-style.md +7 -7
  53. package/skills/developing-cpp/scripts/checking-comments.mjs +10 -8
  54. package/skills/developing-cpp/scripts/checking-declaration-order.mjs +77 -10
  55. package/skills/developing-cpp/steps/03-declaration.md +4 -4
  56. package/skills/developing-cpp/steps/04-implementation.md +3 -3
  57. package/skills/engineering/SKILL.md +2 -1
  58. package/skills/engineering/references/cmake/modules/01-functions.md +8 -8
  59. package/skills/engineering/references/cmake/standards/index.md +6 -6
  60. package/skills/engineering/references/cmake/targets/01-target-rules.md +1 -11
  61. package/skills/engineering/references/formatting/01-encoding.md +2 -2
  62. package/skills/engineering/references/formatting/02-clang-format.md +3 -3
  63. package/skills/engineering/references/formatting/04-clangd.md +2 -2
  64. package/skills/engineering/references/formatting/examples/04-config-comments.md +43 -0
  65. package/skills/engineering/references/index.md +2 -1
  66. package/skills/engineering/scripts/checking-encoding.mjs +2 -1
  67. package/skills/engineering/steps/01-targets.md +1 -1
  68. package/skills/engineering/steps/02-modules.md +2 -8
  69. package/skills/shared/operations.md +1 -1
  70. package/skills/shared/rule-priority.md +1 -1
  71. package/templates/cpp-workflow-project/SKILL.md +2 -1
package/README.en.md CHANGED
@@ -19,7 +19,7 @@ The exception material follows the C++ Core Guidelines' Error handling section a
19
19
  Fixed-version npm install:
20
20
 
21
21
  ```bash
22
- dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
22
+ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.8
23
23
  ```
24
24
 
25
25
  This page follows each release; run `npm view @chengzhao-dev/dsh-cpp-workflow version` if you need to confirm the current version on the registry.
@@ -27,7 +27,7 @@ This page follows each release; run `npm view @chengzhao-dev/dsh-cpp-workflow ve
27
27
  GitHub tag installs use the tag with the same version number:
28
28
 
29
29
  ```bash
30
- dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
30
+ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.8
31
31
  ```
32
32
 
33
33
  Replace `--profile` with the profile you actually run. The desktop app always runs the `desktop` profile, and that profile is owned by the app; if the command-line `add` is rejected, add the plugin in the app settings and use the same pinned npm version. A Git tag install uses the prebuilt `lib/` committed in the repository and runs no build on the target machine; the package has no install script that needs approval.
@@ -36,11 +36,11 @@ Replace `--profile` with the profile you actually run. The desktop app always ru
36
36
 
37
37
  The plugin page's "C++ Workflow" card is the only entry point and manages the comment symbol and file-header tags: the symbol is `///` or `/** ... */`, `@file` is always the file name, and every file-header, type, and declaration tag is on by default except the fixed `//` body symbol; empty values are skipped. `@param` is required for every parameter; `@return` may be omitted when the condition is self-evident; `@throws` only when the function throws; `@pre`, `@post`, `@retval`, `@tparam`, `@note`, and `@see` are on by default and can be switched off individually. The preview follows the switches, saving takes effect on the next skill read, and existing sources are never rewritten. The plugin page no longer duplicates navigation.
38
38
 
39
- If the page still reports that it is not connected to a configuration form after an upgrade, the window is still running the previous client bundle: restart DeepSeek Harness or select "Reload page" on the plugin page. The page retries the connection while open and switches to the editable form as soon as the host serves it; reinstalling is unnecessary. After a successful save, the status line shows the written `~/.dsh/profiles/<profile>/cordis.patch.yml`. Discard changes, Restore defaults and Save are separate: discard returns to the last value read from the host, restore fills the draft, and only Save writes it.
39
+ If the page still reports that it is not connected to a configuration form after an upgrade, the window is still running the previous client bundle: restart DeepSeek Harness or select "Reload page" on the plugin page. The page does not poll or retry; restart the host or select "Reload page" while the form is read-only. Reinstalling is unnecessary. After a successful save, the status line shows the written `~/.dsh/profiles/<profile>/cordis.patch.yml`. Discard changes, Restore defaults and Save are separate: discard returns to the last value read from the host, restore fills the draft, and only Save writes it.
40
40
 
41
41
  ## Workspace gate
42
42
 
43
- Only one condition must hold before any of the three skills appears: walking up from the current directory to the Git root, the path contains `.agents/skills/cpp-workflow-project/SKILL.md`.
43
+ Only one condition must hold before any of the three skills appears: walking up from the current directory to the Git root, the path contains `.agents/skills/cpp-workflow-project/SKILL.md` (a repository may instead name that directory `cpp_workflow_project`; both are accepted).
44
44
 
45
45
  The project skill marker is the repository's opt-in declaration. The plugin no longer requires a first-party `CMakeLists.txt` or C++ source file in the same repository: a docs-only repository, a repository that only copied the template, or a repository with no source files yet still matches; with an empty environment axis, the four source steps still work but build setup stops. Without the marker the list is empty, even when the repository contains CMake or `.cpp` files. Scan limits and boundary cases are in [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md).
46
46
 
@@ -48,7 +48,7 @@ The packaged skills use rank 550. A project `.agents/skills` skill uses rank 200
48
48
 
49
49
  ## Project conventions
50
50
 
51
- Copy [templates/cpp-workflow-project](templates/cpp-workflow-project) into the target repository's `.agents/skills/` directory, keeping the `cpp-workflow-project` directory name. Add only files that do not exist; do not overwrite existing source, `CMakeLists.txt`, or `.clang-*` files. The project skill records project-specific facts; the template's "common workflow conventions" carry the shared workflow, editor, and completion rules, so the project skill does not repeat them:
51
+ Copy [templates/cpp-workflow-project](templates/cpp-workflow-project) into the target repository's `.agents/skills/` directory, keeping the `cpp-workflow-project` directory name (the plugin also accepts the underscore form `cpp_workflow_project`, so a repository that renamed it still passes the gate). Add only files that do not exist; do not overwrite existing source, `CMakeLists.txt`, or `.clang-*` files. The project skill records project-specific facts; the template's "common workflow conventions" carry the shared workflow, editor, and completion rules, so the project skill does not repeat them:
52
52
 
53
53
  - project and component names, source root;
54
54
  - library/program boundary and public header location;
@@ -96,7 +96,7 @@ npm ci
96
96
  npm test # main pre-commit gate: build, structural/encoding/workflow checks, and unit tests
97
97
  npm run test:matrix # real build matrix: 4 templates x 5 standards
98
98
  npm run pack:check # inspect the npm package contents
99
- npm run ci # replay the Ubuntu CI job: install, test, package check
99
+ npm run ci # local replay: install, test, package check (no matrix; the Ubuntu CI job also runs test:matrix)
100
100
  npm run ci:full # ci plus the standard matrix; needs a POSIX host
101
101
  ```
102
102
 
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  npm 安装固定版本:
20
20
 
21
21
  ```bash
22
- dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
22
+ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.8
23
23
  ```
24
24
 
25
25
  本页版本号随发布更新;安装前可用 `npm view @chengzhao-dev/dsh-cpp-workflow version` 确认 registry 上的最新版本。
@@ -27,28 +27,28 @@ dsh plugin --profile <profile> add npm:@chengzhao-dev/dsh-cpp-workflow@0.7.6
27
27
  GitHub 标签安装使用同一版本号的标签,地址中的版本与标签同号:
28
28
 
29
29
  ```bash
30
- dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
30
+ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.8
31
31
  ```
32
32
 
33
33
  `--profile` 换成你实际运行的那个 profile。桌面应用固定跑 `desktop` profile,且该 profile 由应用独占管理;命令行 `add` 被拒绝时,在应用设置里添加插件,地址填同一个 npm 版本。Git 标签安装使用仓库内已构建的 `lib/`,不在目标机器上重新构建;包内也不含需要授权执行的安装脚本。
34
34
 
35
35
  ### 设置
36
36
 
37
- 插件页的「C++ 工程流程」是唯一入口:注释符号可选 `///` 或 `/** ... */`,页面按注释符号、文件头、类型、函数声明与只读预览分块。`@file` 固定为文件名;除它和函数体 `//` 外,文件头、类型与函数声明标签的开关出厂全开,空值跳过。函数参数要求 `@param`,返回值要求 `@return`(成立条件自明时可省),会抛才要求 `@throws`;`@pre`、`@post`、`@retval` 与类型块的 `@tparam`、`@note`、`@see` 也出厂开启,需要时可逐项关掉。函数体固定用 `//`。预览随改动即时更新,保存后下一次读取技能即生效,已有源码不会被改写。插件页不再重复列一份导航。
37
+ 插件页的「C++ 工程流程」是唯一入口:注释符号可选 `///` 或 `/** ... */`,页面按注释符号、文件头、类型、函数声明与只读预览分块。标签开关、`@param` / `@return` / `@throws` 的要求、预览生效时机与导航行为见 [docs/plugin-flow.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-flow.md)。
38
38
 
39
- 升级插件后如果这一页暂时只显示出厂值,说明当前窗口还挂着旧的前端产物:重启 DeepSeek Harness,或在插件页点“重新载入页面”即可编辑,不需要重装插件。页面会在打开后自动重试连接,拿到表单就切换为可编辑;保存成功后,状态行会显示写入的 `~/.dsh/profiles/<profile>/cordis.patch.yml`。保存、撤销修改与恢复默认值分三个按钮:撤销只回到最近一次读到的值,恢复默认值只填草稿,点保存才写盘。
39
+ 升级插件后如果这一页暂时只显示出厂值,说明当前窗口还挂着旧的前端产物:重启 DeepSeek Harness,或在插件页点“重新载入页面”即可编辑,不需要重装插件。页面不会轮询重试;表单仍只读时重启宿主或点“重新载入页面”。保存成功后,状态行会显示写入的 `~/.dsh/profiles/<profile>/cordis.patch.yml`。保存、撤销修改与恢复默认值分三个按钮:撤销只回到最近一次读到的值,恢复默认值只填草稿,点保存才写盘。
40
40
 
41
41
  ## 工作区门禁
42
42
 
43
- 会话满足一个条件,技能就会出现:从当前目录向上、停在 git 根,沿途有 `.agents/skills/cpp-workflow-project/SKILL.md`。
43
+ 会话满足一个条件,技能就会出现:从当前目录向上、停在 git 根,沿途有 `.agents/skills/cpp-workflow-project/SKILL.md`(新仓库可把目录名写成下划线 `cpp_workflow_project`,两种都认)。
44
44
 
45
45
  项目技能标记就是仓库选择加入本工作流的声明。插件不再要求同一仓库里已经有第一方 `CMakeLists.txt` 或 C++ 源文件:纯文档仓库、只复制了模板、还没有任何源文件的仓库也会出现;环境轴为空时,源码四步仍能做,但定构建会停。没有标记就返回空列表,即使仓库里有 CMake 或 `.cpp`。扫描上限和边界情形见 [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md)。
46
46
 
47
- 插件技能 rank 550。项目自己的 `.agents/skills` 技能 rank 200、用户级技能 rank 500,两者都会以同名覆盖插件;不要在项目或用户目录里复制 `developing-cpp`、`engineering` 或 `building-cpp`。
47
+ 插件技能与项目 `.agents/skills`、用户级技能的同名覆盖顺序见 [docs/plugin-boundaries.md](https://github.com/chengzhao-dev/dsh-cpp-workflow/blob/main/docs/plugin-boundaries.md#覆盖关系);不要在项目或用户目录里复制 `developing-cpp`、`engineering` 或 `building-cpp`。
48
48
 
49
49
  ## 项目级约定
50
50
 
51
- 把 [templates/cpp-workflow-project](templates/cpp-workflow-project) 整个复制到目标仓库的 `.agents/skills/` 下,目录名保持 `cpp-workflow-project`;只补还不存在的文件,不覆盖已有的源码、`CMakeLists.txt` 或 `.clang-*`。项目技能写本工程特有的事实;通用工作流、编辑器与完成判据由模板的「通用工作流约定」承担,不在项目技能里重复:
51
+ 把 [templates/cpp-workflow-project](templates/cpp-workflow-project) 整个复制到目标仓库的 `.agents/skills/` 下,目录名保持 `cpp-workflow-project`(插件同时接受下划线目录名 `cpp_workflow_project`,改了名的仓库也能通过门禁);只补还不存在的文件,不覆盖已有的源码、`CMakeLists.txt` 或 `.clang-*`。项目技能写本工程特有的事实;通用工作流、编辑器与完成判据由模板的「通用工作流约定」承担,不在项目技能里重复:
52
52
 
53
53
  - 工程名、组件名和源码根;
54
54
  - 库与程序的边界、公共头位置;
@@ -96,7 +96,7 @@ npm ci
96
96
  npm test # 提交前主门:构建、结构/编码/工作流检查与单元测试
97
97
  npm run test:matrix # 四套模板 × 五档标准的真实构建矩阵
98
98
  npm run pack:check # 核对 npm 包内容
99
- npm run ci # 复现 Ubuntu CI:安装、测试、打包检查(不含标准矩阵)
99
+ npm run ci # 本地复现:安装、测试、打包检查(不含标准矩阵;Ubuntu CI 另跑 test:matrix)
100
100
  npm run ci:full # 在 ci 之上再跑标准矩阵,需 POSIX 宿主
101
101
  ```
102
102
 
package/lib/client.js CHANGED
@@ -9,7 +9,7 @@ window.__ModuleLoader__.load({
9
9
  * 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
10
10
  *
11
11
  * 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
12
- * 写法在 `skills/developing-cpp/references/comments/01-rules.md`。设置页保存的值由宿主
12
+ * 写法在 `skills/developing-cpp/references/comments/01-comment-rules.md`。设置页保存的值由宿主
13
13
  * 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
14
14
  *
15
15
  * 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
@@ -151,8 +151,10 @@ function previewParts(raw, sampleName) {
151
151
  header[briefIndex] = header[briefIndex].replace(/@brief$/, `@brief ${SAMPLE_BRIEF}`);
152
152
  }
153
153
  const contract = [];
154
- if (config.param)
154
+ if (config.param) {
155
155
  contract.push('@param row 目标行号。');
156
+ contract.push('@param column 目标列号。');
157
+ }
156
158
  if (config.returns)
157
159
  contract.push('@return 放置成功时为 true。');
158
160
  if (config.throws)
@@ -230,7 +232,9 @@ function snapshotText(raw) {
230
232
  off.push(TAG_LABEL[tag]);
231
233
  }
232
234
  const style = config.commentStyle === 'block' ? '/** ... */' : '///';
233
- const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'}。`;
235
+ const args = checkerArgs(config);
236
+ const argLine = args.length > 0 ? args.join(' ') : '无';
237
+ const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'};检查器参数:${argLine}。`;
234
238
  return `## 当前注释配置(profile)\n\n${line}`;
235
239
  }
236
240
 
@@ -2,7 +2,7 @@
2
2
  * 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
3
3
  *
4
4
  * 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
5
- * 写法在 `skills/developing-cpp/references/comments/01-rules.md`。设置页保存的值由宿主
5
+ * 写法在 `skills/developing-cpp/references/comments/01-comment-rules.md`。设置页保存的值由宿主
6
6
  * 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
7
7
  *
8
8
  * 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
@@ -144,8 +144,10 @@ export function previewParts(raw, sampleName) {
144
144
  header[briefIndex] = header[briefIndex].replace(/@brief$/, `@brief ${SAMPLE_BRIEF}`);
145
145
  }
146
146
  const contract = [];
147
- if (config.param)
147
+ if (config.param) {
148
148
  contract.push('@param row 目标行号。');
149
+ contract.push('@param column 目标列号。');
150
+ }
149
151
  if (config.returns)
150
152
  contract.push('@return 放置成功时为 true。');
151
153
  if (config.throws)
@@ -223,6 +225,8 @@ export function snapshotText(raw) {
223
225
  off.push(TAG_LABEL[tag]);
224
226
  }
225
227
  const style = config.commentStyle === 'block' ? '/** ... */' : '///';
226
- const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'}。`;
228
+ const args = checkerArgs(config);
229
+ const argLine = args.length > 0 ? args.join(' ') : '无';
230
+ const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};未填值 ${unset.join('、') || '无'};关闭 ${off.join('、') || '无'};检查器参数:${argLine}。`;
227
231
  return `## 当前注释配置(profile)\n\n${line}`;
228
232
  }
package/lib/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // 示例与资产都由安装后的包内解析。
6
6
  //
7
7
  // 门禁只认显式启用的工作区:会话 cwd 到 git 根的路径上必须有
8
- // `.agents/skills/cpp-workflow-project/SKILL.md`,否则 `list()` 返回空。
8
+ // `.agents/skills/cpp-workflow-project/SKILL.md`(或下划线目录 `cpp_workflow_project`),
9
+ // 否则 `list()` 返回空。
9
10
  // C++ 或 CMake 证据刻意不参与:刚复制的模板还没有源码,空工程也可以停在
10
11
  // 构建步骤;检出之外的 C++ 示例看不到这些技能名,标记查找也不进兄弟目录。
11
12
  //
package/lib/workspace.js CHANGED
@@ -5,7 +5,12 @@
5
5
  // git 根是仓库边界:标记查找不进兄弟目录,也不向根之上继续。
6
6
  import { access } from 'node:fs/promises';
7
7
  import path from 'node:path';
8
- export const PROJECT_SKILL = path.join('.agents', 'skills', 'cpp-workflow-project', 'SKILL.md');
8
+ /** 项目技能目录名,按优先顺序排列;下划线与连字符两种写法等价,连字符是模板与文档的默认写法。 */
9
+ export const PROJECT_SKILL_DIRS = ['cpp_workflow_project', 'cpp-workflow-project'];
10
+ /** 首选标记文件;查找时按 `PROJECT_SKILL_MARKERS` 逐个尝试。 */
11
+ export const PROJECT_SKILL = path.join('.agents', 'skills', PROJECT_SKILL_DIRS[0], 'SKILL.md');
12
+ /** 所有可接受的标记文件,顺序同 `PROJECT_SKILL_DIRS`。 */
13
+ export const PROJECT_SKILL_MARKERS = PROJECT_SKILL_DIRS.map((name) => path.join('.agents', 'skills', name, 'SKILL.md'));
9
14
  export const MAX_ASCENT = 64;
10
15
  async function exists(target) {
11
16
  try {
@@ -16,6 +21,15 @@ async function exists(target) {
16
21
  return false;
17
22
  }
18
23
  }
24
+ /** 在一层目录里按优先顺序找项目技能标记,返回第一个存在的。 */
25
+ async function findMarker(root) {
26
+ for (const marker of PROJECT_SKILL_MARKERS) {
27
+ const file = path.join(root, marker);
28
+ if (await exists(file))
29
+ return file;
30
+ }
31
+ return undefined;
32
+ }
19
33
  /** 最近的上级 git 检出;worktree 的 `.git` 文件也算。 */
20
34
  export async function findGitRoot(cwd) {
21
35
  if (typeof cwd !== 'string' || cwd.trim() === '')
@@ -64,8 +78,8 @@ export async function findProjectSkill(cwd, gitRoot) {
64
78
  }
65
79
  }
66
80
  for (let depth = 0; depth < MAX_ASCENT; depth += 1) {
67
- const file = path.join(cursor, PROJECT_SKILL);
68
- if (await exists(file))
81
+ const file = await findMarker(cursor);
82
+ if (file !== undefined)
69
83
  return { file, root: cursor };
70
84
  if (cursor === gitRoot)
71
85
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chengzhao-dev/dsh-cpp-workflow",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "写 C++ 源码、配 CMake、用 Clang 构建;头文件用 /// Doxygen 文档注释,函数体用 // 分段说明,文件头标签可在设置里改。",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -14,10 +14,10 @@ metadata:
14
14
  - **负责**:环境四轴与构建入口;工具配置的复制、落地与检查(规则条文归 `engineering`);编码、声明校验、活动校验、项目入口命令的次序。
15
15
  - **不负责**:`CMakeLists.txt` 与 `cmake/` 下的 target、属性、标准与模块开 `engineering`,本技能只读它们来配置和检查,不在这一步改 target 图;函数体、类型、命名、异常与源码注释开 `developing-cpp`。
16
16
  - **交接**:一次改动同时碰到源码和构建文件时,先开 `developing-cpp` 定行为、边界与实现;需要新增或移动源文件、改库与程序的边界、补测试 target 时,转 `engineering` 把文件写进 CMake;最后回到本技能定工具配置并通过检查。只改函数体、命名、异常或注释且入口命令可运行时,定实现后只开本技能的通过检查。
17
- - **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。三个环境轴为空、`standard` 非法或组合非法时停在定构建,不猜 WSL、Clang 或构建目录;`standard` 缺失或为空时按默认 `c++23` 继续并提示声明升级;`windows` + `native` 直接拒绝,提示「本版本不能在 Windows 原生壳里构建」,不给补 PowerShell 的路线。
17
+ - **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。声明非法时停在定构建,不猜 WSL、Clang 或构建目录;判定规则与取值见 `../building-cpp/references/02-environment.md`「合法组合」。
18
18
  - **分因**:编译失败时先看诊断指向哪一层。函数体问题回 `developing-cpp` 的定实现;找不到头、链接失败、target 不存在或标准不对转 `engineering` 的对应步骤;没有编译数据库、format/tidy 不在 PATH 或配置不生效留在本技能的定工具配置。
19
19
  - **编码**:源码与构建文件用 UTF-8 无 BOM、检出 LF,`.bat` / `.cmd` 用 CRLF,`.clang-format` 写 `LineEnding: LF`;MSVC 不是受支持的环境轴;`/utf-8` 配方只留在资产注释里,当前构建仍用 clang/gcc。完整规则见 `../engineering/references/formatting/01-encoding.md`,机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准。
20
- - **编辑器**:工程根已有 `.vscode/` 时按 `steps/04-vscode.md` 接线;从当前目录向上到 git 根都没有 `.vscode/` 时不打开、也不新建。配置、构建、运行和调试都从 CMake Tools 进入,构建仍以 `running-build.sh` 为准。
20
+ - **编辑器**:工程根已有 `.vscode/` 时按 `steps/04-vscode.md` 接线;从当前目录向上到工程根(含 `CMakeLists.txt` 的目录)都没有 `.vscode/` 时不打开、也不新建,外层仓库根或书根的 `.vscode/` 不算工程配置。配置、构建、运行和调试都从 CMake Tools 进入,构建仍以 `running-build.sh` 为准。
21
21
 
22
22
  ## 三种操作
23
23
 
@@ -61,7 +61,7 @@ metadata:
61
61
 
62
62
  加载预算见 [budget.md](../shared/budget.md);building-cpp 的步骤固定 4 份。
63
63
 
64
- 项目技能列出了检查命令时只跑那一条,没有时跑本技能自己的 `scripts/checking-environment.mjs` 与 `../engineering/scripts/checking-encoding.mjs`;退出码为 0 后停在这一步,不再继续走没有失败的步骤。入口脚本只做配置、构建、CTest 与最小运行;`clang-format` 与 `clang-tidy` 的手动检查留在定工具配置,不塞进入口脚本。`environment.json` 的三个环境轴与 `standard` 是唯一来源,缺项就停。
64
+ 项目技能列出了检查命令时先跑那一条;没有时跑本技能自己的 `scripts/checking-environment.mjs` 与 `../engineering/scripts/checking-encoding.mjs`。这些命令只覆盖各自那一段,完成判据还要求入口命令、CTest 与格式化检查,按 `steps/03-check.md` 的顺序跑完再停在这一步。入口脚本只做配置、构建、CTest 与最小运行;`clang-format` 与 `clang-tidy` 的手动检查留在定工具配置,不塞进入口脚本。`environment.json` 的三个环境轴是唯一来源;取值与合法性见 `references/02-environment.md`「合法组合」,脚本行为见 `scripts/checking-environment.mjs`。
65
65
 
66
66
  ## 四类改动
67
67
 
@@ -77,7 +77,7 @@ metadata:
77
77
  ## 完成判据
78
78
 
79
79
  - [ ] 项目 `environment.json` 的三个环境轴齐全且是合法组合,`standard` 在 `c++11`–`c++23` 内;新工程默认 `c++23`,没有靠猜。
80
- - [ ] 配置命令固定 Ninja 和单一编译器,`build/<compiler>/compile_commands.json` 存在,根 `build/compile_commands.json` 指向当前编译器。
80
+ - [ ] 配置命令固定 Ninja 和单一编译器,`build/<compiler>/compile_commands.json` 存在;项目技能没有声明单一构建目录时,根 `build/compile_commands.json` 还要指向当前编译器。
81
81
  - [ ] target 契约已经成立:程序 target(模板默认 `app`,本书 `terminal`)、库 target、公共 include、标准与输出目录都已由 `engineering` 写好;本技能没有偷偷改 CMake 来绕过失败。
82
82
  - [ ] `clang-format --dry-run --Werror` 与 `clang-tidy` 在项目源码上零告警;只扫描项目源码和项目头。
83
83
  - [ ] CTest 全绿,程序从该编译器的构建目录启动;有测试时注册用 `gtest_discover_tests` 或项目既有机制,运行带 `--output-on-failure --no-tests=error`,失败时报告的是具体角色和原因。
@@ -9,9 +9,13 @@
9
9
  // VSCode 的配置、构建、运行和调试入口都留在 CMake Tools。
10
10
  // 不另建 launch.json / tasks.json,避免出现第二套构建或启动路径。
11
11
  "cmake.buildDirectory": "${workspaceFolder}/build/clang",
12
+ // 构建固定用 Ninja,与工程入口脚本一致;换生成器要同步脚本。
12
13
  "cmake.generator": "Ninja",
14
+ // 打开工程时不自动配置,配置时机由入口脚本决定。
13
15
  "cmake.configureOnOpen": false,
16
+ // 运行前先构建,避免跑到旧产物。
14
17
  "cmake.buildBeforeRun": true,
18
+ // 生成 compile_commands.json,供 clangd 与 clang-tidy 读取。
15
19
  "cmake.exportCompileCommandsFile": true,
16
20
  // CMake Tools 的快速调试默认使用 C/C++ 扩展的 cppdbg 适配器;
17
21
  // 这里只把它的调试后端改成 LLDB。GCC 模式改成 gdb + /usr/bin/gdb。
@@ -26,22 +30,29 @@
26
30
  // cpptools 只作为 CMake 的调试后端,不再提供 IntelliSense;
27
31
  // 补全、跳转、诊断和格式化都由读取 compile_commands.json 的 clangd 负责。
28
32
  "C_Cpp.intelliSenseEngine": "disabled",
33
+ // 保存即格式化;实际排版交给 clangd,不在构建脚本里跑 clang-format -i。
29
34
  "editor.formatOnSave": true,
35
+ // C/C++ 的默认格式化器都交给 clangd。
30
36
  "[cpp]": {
31
37
  "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
32
38
  },
33
39
  "[c]": {
34
40
  "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
35
41
  },
42
+ // 项目头文件统一按 C++ 解析,避免被当成 C。
36
43
  "files.associations": {
37
44
  "*.h": "cpp"
38
45
  },
46
+ // 文件统一按 UTF-8 保存,与 .editorconfig 的 charset 一致。
39
47
  "files.encoding": "utf8",
48
+ // 行尾统一 LF,与 .gitattributes 和 .clang-format 的 LineEnding 一致。
40
49
  "files.eol": "\n",
50
+ // 构建产物与本地缓存不显示在资源管理器里。
41
51
  "files.exclude": {
42
52
  "**/build": true,
43
53
  "**/.cache": true
44
54
  },
55
+ // 同一批目录也不进入搜索结果。
45
56
  "search.exclude": {
46
57
  "**/build": true,
47
58
  "**/.cache": true
@@ -3,8 +3,9 @@
3
3
  # 配置、构建、测试并运行当前 C++11–C++23 工程(默认 C++23)。
4
4
  #
5
5
  # 用法:./running-build.sh [clang|gcc];省略时用 clang。
6
- # 程序名与构建目录可用 APP_NAME、BUILD_DIR 覆盖;默认 app 与 build/<compiler>。
7
- # 编译数据库:build/<compiler>/compile_commands.json。
6
+ # 程序名、构建目录与构建根可用 APP_NAME、BUILD_DIR、BUILD_ROOT 覆盖;默认 app、build/<compiler> 与 build。
7
+ # 单一构建目录时把 BUILD_ROOT 设为与 BUILD_DIR 相同,脚本不再补 build/compile_commands.json 链接。
8
+ # 编译数据库:默认 build/<compiler>/compile_commands.json,随 BUILD_DIR 走。
8
9
  # 适用于 Linux、macOS 和 Windows + WSL,不支持 Windows 原生壳。
9
10
 
10
11
  set -euo pipefail
@@ -60,15 +61,21 @@ main() {
60
61
  cmake --build "${BUILD_DIR}"
61
62
 
62
63
  header "编译数据库"
63
- rm -f "${BUILD_ROOT}/compile_commands.json"
64
- ln -s "${COMPILER}/compile_commands.json" \
65
- "${BUILD_ROOT}/compile_commands.json"
64
+ if [ "${BUILD_DIR}" != "${BUILD_ROOT}" ]; then
65
+ rm -f "${BUILD_ROOT}/compile_commands.json"
66
+ target="${BUILD_DIR}/compile_commands.json"
67
+ case "${target}" in
68
+ "${BUILD_ROOT}"/*) relative="${target#"${BUILD_ROOT}/"}" ;;
69
+ *) relative="${target}" ;;
70
+ esac
71
+ ln -s "${relative}" "${BUILD_ROOT}/compile_commands.json"
72
+ fi
66
73
 
67
74
  header "测试"
68
75
  if [ -d tests ]; then
69
76
  ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=error
70
77
  else
71
- ctest --test-dir "${BUILD_DIR}" --output-on-failure
78
+ ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=ignore
72
79
  fi
73
80
 
74
81
  header "运行 ${APP_NAME}"
@@ -4,8 +4,6 @@ project({{PROJECT_NAME}} VERSION 0.1.0 LANGUAGES CXX)
4
4
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
5
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
6
6
 
7
- enable_testing()
8
-
9
7
  add_executable(app
10
8
  src/main.cpp
11
9
  src/greeting.cpp
@@ -17,6 +15,4 @@ set_target_properties(app PROPERTIES
17
15
  CXX_STANDARD_REQUIRED ON
18
16
  CXX_EXTENSIONS OFF
19
17
  )
20
- target_compile_options(app PRIVATE -Wall -Wextra -Werror)
21
-
22
- add_test(NAME app_smoke COMMAND app)
18
+ # 警告与 -Werror 由工程按需要打开(set_target_warnings),模板不默认加在 target 上。
@@ -5,8 +5,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
5
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
6
6
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
7
7
 
8
- enable_testing()
9
-
10
8
  add_subdirectory(greeting)
11
9
 
12
10
  add_executable(app src/main.cpp)
@@ -16,12 +14,10 @@ set_target_properties(app PROPERTIES
16
14
  CXX_STANDARD_REQUIRED ON
17
15
  CXX_EXTENSIONS OFF
18
16
  )
19
- target_compile_options(app PRIVATE -Wall -Wextra -Werror)
17
+ # 警告与 -Werror 由工程按需要打开(set_target_warnings),模板不默认加在 target 上。
20
18
  target_link_libraries(app PRIVATE greeting)
21
19
  if(APPLE)
22
20
  set_target_properties(app PROPERTIES BUILD_RPATH "@loader_path/../lib")
23
21
  else()
24
22
  set_target_properties(app PROPERTIES BUILD_RPATH "$ORIGIN/../lib")
25
23
  endif()
26
-
27
- add_test(NAME app_smoke COMMAND app)
@@ -6,10 +6,3 @@ set_target_properties(greeting PROPERTIES
6
6
  CXX_STANDARD_REQUIRED ON
7
7
  CXX_EXTENSIONS OFF
8
8
  )
9
- target_compile_options(greeting PRIVATE
10
- -Wall
11
- -Wextra
12
- -Werror
13
- -Wold-style-cast
14
- -Wshadow
15
- )
@@ -4,8 +4,6 @@ project({{PROJECT_NAME}} VERSION 0.1.0 LANGUAGES CXX)
4
4
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
5
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
6
6
 
7
- enable_testing()
8
-
9
7
  add_executable(app src/main.cpp)
10
8
  target_compile_features(app PRIVATE cxx_std_23)
11
9
  set_target_properties(app PROPERTIES
@@ -13,6 +11,4 @@ set_target_properties(app PROPERTIES
13
11
  CXX_STANDARD_REQUIRED ON
14
12
  CXX_EXTENSIONS OFF
15
13
  )
16
- target_compile_options(app PRIVATE -Wall -Wextra -Werror)
17
-
18
- add_test(NAME app_smoke COMMAND app)
14
+ # 警告与 -Werror 由工程按需要打开(set_target_warnings),模板不默认加在 target 上。
@@ -5,8 +5,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
5
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
6
6
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
7
7
 
8
- enable_testing()
9
-
10
8
  add_subdirectory(greeting)
11
9
 
12
10
  add_executable(app src/main.cpp)
@@ -16,7 +14,5 @@ set_target_properties(app PROPERTIES
16
14
  CXX_STANDARD_REQUIRED ON
17
15
  CXX_EXTENSIONS OFF
18
16
  )
19
- target_compile_options(app PRIVATE -Wall -Wextra -Werror)
17
+ # 警告与 -Werror 由工程按需要打开(set_target_warnings),模板不默认加在 target 上。
20
18
  target_link_libraries(app PRIVATE greeting)
21
-
22
- add_test(NAME app_smoke COMMAND app)
@@ -6,10 +6,3 @@ set_target_properties(greeting PROPERTIES
6
6
  CXX_STANDARD_REQUIRED ON
7
7
  CXX_EXTENSIONS OFF
8
8
  )
9
- target_compile_options(greeting PRIVATE
10
- -Wall
11
- -Wextra
12
- -Werror
13
- -Wold-style-cast
14
- -Wshadow
15
- )
@@ -1,4 +1,4 @@
1
- <!-- 读取时机:写构建脚本时;读完能回答:构建脚本;预算:一次只开这一份(88 行),不自动串联。 -->
1
+ <!-- 读取时机:写构建脚本时;读完能回答:构建脚本;预算:一次只开这一份(73 行),不自动串联。 -->
2
2
  # 构建脚本
3
3
 
4
4
  `assets/templates/projects/common/running-build.sh` 是 POSIX build-host 脚本,适用于 Linux、macOS 和 Windows + WSL。`host=windows` + `build_host=native` 不是本版本支持的组合:声明校验会直接拒绝,脚本也不会在原生 Windows 壳里运行。脚本只做配置、构建、CTest 与运行;格式化与静态检查在编辑时手动跑,不混进构建入口。
@@ -7,13 +7,7 @@
7
7
 
8
8
  不在 `running-build.sh` 里跑。构建脚本只做配置、构建、CTest 与运行;格式化是编辑时动作,不能让构建顺手改动源码。检查放在编辑器保存时或 CI 的独立步骤里。
9
9
 
10
- 检查(按工程实际源码根替换 `src/`、`include/`、`app/`、`tests/`):
11
-
12
- ```bash
13
- clang-format --dry-run --Werror src/*.cpp include/*.h
14
- ```
15
-
16
- 需要修复时单独运行 `clang-format -i`,再回看 diff。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按 `../../developing-cpp/references/comments/01-comment-rules.md` 的规则和 `checking-comments.mjs` 检查。
10
+ 检查命令与顺序以 `../steps/03-check.md` 第 4 步为唯一出处:那里列出 `clang-format` 与 `clang-tidy` 的完整调用,本文件不再重复。需要修复时单独运行 `clang-format -i`,再回看 diff。`clang-format` 只排版,不会把行尾注释搬到上一行;数据成员注释位置按 `../../developing-cpp/references/comments/01-comment-rules.md` 的规则和 `checking-comments.mjs` 检查。
17
11
 
18
12
  ## 用法
19
13
 
@@ -24,18 +18,18 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
24
18
 
25
19
  - 参数是编译器名,只接受 `clang` / `gcc`;省略时默认 `clang`。
26
20
  - 脚本以自身所在目录为工程根;把它放在工程根,从其他目录调用时会先 `cd` 到脚本目录。
27
- - 构建目录由参数决定:`build/clang` 或 `build/gcc`;不要用环境变量临时改目录。
21
+ - 构建目录默认 `build/clang` 或 `build/gcc`;脚本头声明的 `BUILD_DIR`、`BUILD_ROOT`、`APP_NAME` 只覆盖这一次运行,默认值不变。单一构建目录时把 `BUILD_ROOT` 设为与 `BUILD_DIR` 相同,脚本就不再补 `build/compile_commands.json` 链接;构建目录的取值以 `02-environment.md`「构建目录」的「单一目录」行为准。
28
22
  - 脚本不安装依赖、不下载工具、不改 PATH;缺工具时让命令失败,由 `building-cpp` 的通过检查分诊。
29
23
 
30
24
  ## 结构
31
25
 
32
26
  1. **shebang + 文件头**:标题一行、`#` 一行,再用「用法」「依赖」「构建目录」等行说明参数与支持的 build host;段落用单行注释,不画 `#===` 横幅。
33
- 2. **严格模式与目录**:`set -euo pipefail`;`cd "$(dirname "$0")"`;`readonly BUILD_DIR`、`readonly APP_NAME="app"`。
27
+ 2. **严格模式与目录**:`set -euo pipefail`;`cd "$(dirname "$0")"`;`APP_NAME`、`BUILD_ROOT` 取环境变量默认值,`BUILD_DIR` 由编译器名推导;`COMPILER` 与 `CXX` 用 `readonly`。
34
28
  3. **输出辅助**:`header()` 打印阶段名,`err()` 打印到 stderr;`trap ERR` 打印失败命令。
35
29
  4. **configure**:每次运行都重新 configure,不复用缓存;传 `-G Ninja`、`-DCMAKE_BUILD_TYPE=Debug`、`-DCMAKE_C_COMPILER`、`-DCMAKE_CXX_COMPILER`、`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`。C 与 C++ 使用同一套编译器;没有 C 语言的工程会忽略 C 编译器设置。
36
30
  5. **build**:`cmake --build "$BUILD_DIR"`。
37
- 6. **编译数据库链接**:先 `rm -f build/compile_commands.json`,再 `ln -s "${COMPILER}/compile_commands.json" build/compile_commands.json`;不用 `ln -n`,它在 BSD/macOS 上不可移植。
38
- 7. **test**:有 `tests/` 目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure --no-tests=error`,防止测试 discovery 失败后 0 条也算通过;没有测试目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure`,0 条不算失败。
31
+ 6. **编译数据库链接**:`BUILD_DIR` 与 `BUILD_ROOT` 相同时数据库就在该目录,不建链接;否则先 `rm -f "${BUILD_ROOT}/compile_commands.json"`,再用 `realpath --relative-to="${BUILD_ROOT}" "${BUILD_DIR}/compile_commands.json"` 求相对路径后 `ln -s` 到 `${BUILD_ROOT}/compile_commands.json`;不用 `ln -n`,它在 BSD/macOS 上不可移植。
32
+ 7. **test**:有 `tests/` 目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure --no-tests=error`,防止测试 discovery 失败后 0 条也算通过;没有测试目录时 `ctest --test-dir "$BUILD_DIR" --output-on-failure --no-tests=ignore`,0 条不算失败;不写 `--no-tests=ignore` 时 ctest 会把 0 条当失败(退出码 8)。
39
33
  8. **run**:`(cd "$BUILD_DIR/bin" && "./$APP_NAME")`;共享库的运行时路径由定构建的 CMake RPATH 负责,不在脚本里设全局 `LD_LIBRARY_PATH`。
40
34
 
41
35
  最后一行是 `main "$@"`;函数定义在 `main()` 之前,`set` / `readonly` 在最前。
@@ -50,16 +44,7 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
50
44
  - 失败时保留原始命令输出;不要在脚本里 `2>/dev/null` 吞掉诊断。
51
45
  - 脚本自身用 `bash -n` 检查语法;文件权限保持可执行。
52
46
 
53
- ## 构建模式的错误合同
54
-
55
- 工程需要 Release 时另建构建目录;模式只改变诊断详略,不改变失败方式:
56
-
57
- - 返回值:两种模式的返回值相同,调用方不按 `NDEBUG` 分支。
58
- - 自定义异常:两种模式都抛;Debug 的 `what()` 可以带 `file:line`,Release 只留值。
59
- - `Check`:两种模式都在条件不成立时打印诊断并终止。
60
- - `DebugCheck`:只在 Debug 生效,`NDEBUG` 后展开为空,参数不能带副作用。
61
-
62
- 不要写成 Debug 抛异常、Release 返回 false 的模式分支;这会把调用方逼成两套逻辑。规则详见 `../../developing-cpp/references/exceptions/01-exception-rules.md`。
47
+ Debug 与 Release 的返回值、异常与 `Check` / `DebugCheck` 合同见 `../../developing-cpp/references/exceptions/01-exception-rules.md`;构建脚本只换诊断详略,不改失败方式。
63
48
 
64
49
  ## 失败分诊
65
50
 
@@ -76,7 +61,7 @@ clang-format --dry-run --Werror src/*.cpp include/*.h
76
61
 
77
62
  - `bash -n running-build.sh` 通过。
78
63
  - 在声明的 build host 上,`./running-build.sh clang` 与 `./running-build.sh gcc` 都能从 configure 走到 run。
79
- - 从工程根直接 `./build/clang/bin/app` 能启动(共享库场景由 RPATH 保证)。
64
+ - 从工程根直接 `./build/clang/bin/<入口 target>` 能启动(模板默认 `app`,本书是 `terminal`;共享库场景由 RPATH 保证)。
80
65
  - 切换编译器后 `build/compile_commands.json` 指向新数据库。
81
66
  - 调用者的 `LD_LIBRARY_PATH` 在脚本结束后不变。
82
67
  - Windows 原生:声明校验已拒绝该组合;不要伪造 PowerShell 脚本,也不要绕过声明。
@@ -1,7 +1,7 @@
1
- <!-- 读取时机:配环境或检查工具时;读完能回答:环境组合;预算:一次只开这一份(115 行),不自动串联。 -->
1
+ <!-- 读取时机:配环境或检查工具时;读完能回答:环境组合;预算:一次只开这一份(116 行),不自动串联。 -->
2
2
  # 环境组合
3
3
 
4
- 环境是**声明**,不是探测结果。项目技能 `cpp-workflow-project` 的 `environment.json` 写清楚三个环境轴和一个语言标准;构建规则、工具配置和检查都按这个声明执行。声明为空或组合非法时,先修声明,不要靠猜。
4
+ 环境是**声明**,不是探测结果。项目技能 `cpp-workflow-project`(目录名也接受 `cpp_workflow_project`)的 `environment.json` 写清楚三个环境轴和一个语言标准;构建规则、工具配置和检查都按这个声明执行。声明为空或组合非法时,先修声明,不要靠猜。
5
5
 
6
6
  ## 四个轴
7
7
 
@@ -72,6 +72,7 @@
72
72
  | clang | `build/clang/` | `build/clang/compile_commands.json` |
73
73
  | gcc | `build/gcc/` | `build/gcc/compile_commands.json` |
74
74
  | 当前 | `build/` | `build/compile_commands.json` → 上面之一的符号链接 |
75
+ | 单一目录 | 项目声明的目录(如 `games/tictactoe/build/`) | `<build-dir>/compile_commands.json`,不建符号链接 |
75
76
 
76
77
  一次 configure 只用一个编译器;切换编译器时用另一个目录,不要在同一目录里改 `CMAKE_CXX_COMPILER` 后复用缓存。项目技能声明单一构建目录时以项目为准(本书 `games/tictactoe/build/`),此时不建 `build/clang` 与 `build/gcc`,编译数据库仍在 `<build-dir>/compile_commands.json`。
77
78
 
@@ -79,8 +80,8 @@
79
80
 
80
81
  `<skill-dir>/scripts/checking-environment.mjs` 做两件事:
81
82
 
82
- 1. **静态**(默认):读 `environment.json`,检查三个环境轴、`standard` 和组合。轴为空或组合非法时以退出码 2 结束,不查找任何可执行文件。
83
- 2. **活动**(`--live`):先做声明校验,再核对当前进程是否在声明的 build host 上,然后查 PATH、角色和版本。声明本身不合法时仍以退出码 2 结束;声明合法但活动核对失败时以退出码 3 结束。
83
+ 1. **静态**(默认):读声明文件,检查三个环境轴、`standard` 和组合。轴为空或组合非法时以退出码 2 结束,不查找任何可执行文件。默认路径是 `.agents/skills/cpp-workflow-project/environment.json`(向上到 git 根);其他位置用 `--environment <file>` 指定。
84
+ 2. **活动**(`--live`):先做声明校验,再核对当前进程是否在声明的 build host 上,然后查 PATH、角色和版本,并用 `-std=<standard> -fsyntax-only` 空编译确认编译器接受该标准。声明本身不合法时仍以退出码 2 结束;声明合法但活动核对失败时以退出码 3 结束。
84
85
 
85
86
  ```bash
86
87
  node "<skill-dir>/scripts/checking-environment.mjs" --project . --json