@aragon-agent/cli 0.6.53 → 0.6.55

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 (101) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +135 -6
  3. package/dist/agent/controller.d.ts +98 -0
  4. package/dist/agent/controller.js +341 -1
  5. package/dist/agent/redteam-prompt.d.ts +47 -0
  6. package/dist/agent/redteam-prompt.js +161 -0
  7. package/dist/agent/redteam-wiring.d.ts +159 -0
  8. package/dist/agent/redteam-wiring.js +349 -0
  9. package/dist/agent/system-prompt.d.ts +27 -0
  10. package/dist/agent/system-prompt.js +10 -0
  11. package/dist/app/App.d.ts +17 -1
  12. package/dist/app/App.js +266 -26
  13. package/dist/app/use-redteam-mode.d.ts +56 -0
  14. package/dist/app/use-redteam-mode.js +121 -0
  15. package/dist/cli.js +78 -4
  16. package/dist/commands/builtins.js +49 -1
  17. package/dist/commands/catalog.js +5 -0
  18. package/dist/commands/index-build.js +2 -1
  19. package/dist/commands/redteam-command.d.ts +22 -0
  20. package/dist/commands/redteam-command.js +141 -0
  21. package/dist/commands/registry.d.ts +7 -0
  22. package/dist/compaction/compactor.d.ts +26 -0
  23. package/dist/compaction/compactor.js +81 -8
  24. package/dist/compaction/summarize-call.d.ts +22 -0
  25. package/dist/compaction/summarize-call.js +29 -0
  26. package/dist/compaction/wiring.js +22 -3
  27. package/dist/config/app-paths.d.ts +13 -0
  28. package/dist/config/app-paths.js +15 -0
  29. package/dist/config/cli-commands.d.ts +15 -0
  30. package/dist/config/cli-commands.js +32 -1
  31. package/dist/config/env.d.ts +3 -1
  32. package/dist/config/env.js +23 -1
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +19 -1
  35. package/dist/config/redteam-launch.d.ts +77 -0
  36. package/dist/config/redteam-launch.js +58 -0
  37. package/dist/config/store.js +20 -1
  38. package/dist/config/ui-state.d.ts +44 -0
  39. package/dist/config/ui-state.js +38 -0
  40. package/dist/exec/bridge/server.js +9 -2
  41. package/dist/exec/options.js +16 -2
  42. package/dist/governance/prompts/orchestrator-block.js +2 -2
  43. package/dist/host/controller-factory.d.ts +33 -0
  44. package/dist/host/controller-factory.js +14 -0
  45. package/dist/host/follow-up-seed.d.ts +109 -0
  46. package/dist/host/follow-up-seed.js +196 -0
  47. package/dist/host/follow-up.d.ts +73 -0
  48. package/dist/host/follow-up.js +123 -0
  49. package/dist/host/index.d.ts +3 -0
  50. package/dist/host/index.js +3 -0
  51. package/dist/host/memory.d.ts +21 -0
  52. package/dist/host/memory.js +17 -0
  53. package/dist/host/sessions.d.ts +32 -2
  54. package/dist/host/sessions.js +40 -2
  55. package/dist/logging/install.d.ts +1 -0
  56. package/dist/logging/install.js +4 -0
  57. package/dist/logging/logger.d.ts +1 -1
  58. package/dist/memory/block.d.ts +24 -0
  59. package/dist/memory/block.js +54 -0
  60. package/dist/memory/command.d.ts +31 -0
  61. package/dist/memory/command.js +350 -0
  62. package/dist/memory/format.d.ts +51 -0
  63. package/dist/memory/format.js +308 -0
  64. package/dist/memory/paths.d.ts +68 -0
  65. package/dist/memory/paths.js +172 -0
  66. package/dist/memory/plan.d.ts +37 -0
  67. package/dist/memory/plan.js +184 -0
  68. package/dist/memory/resolve.d.ts +45 -0
  69. package/dist/memory/resolve.js +54 -0
  70. package/dist/memory/secrets.d.ts +30 -0
  71. package/dist/memory/secrets.js +73 -0
  72. package/dist/memory/service.d.ts +175 -0
  73. package/dist/memory/service.js +576 -0
  74. package/dist/memory/store.d.ts +133 -0
  75. package/dist/memory/store.js +694 -0
  76. package/dist/memory/tools.d.ts +36 -0
  77. package/dist/memory/tools.js +527 -0
  78. package/dist/memory/transfer.d.ts +53 -0
  79. package/dist/memory/transfer.js +93 -0
  80. package/dist/session/checkpoint.d.ts +33 -0
  81. package/dist/session/checkpoint.js +52 -0
  82. package/dist/session/limits.d.ts +16 -0
  83. package/dist/session/limits.js +16 -0
  84. package/dist/session/persist.d.ts +68 -0
  85. package/dist/session/persist.js +11 -0
  86. package/dist/session/startup-session.d.ts +17 -2
  87. package/dist/session/startup-session.js +15 -2
  88. package/dist/session/store.d.ts +14 -0
  89. package/dist/session/store.js +18 -0
  90. package/dist/session/validate-session.js +129 -0
  91. package/dist/team/runtime.d.ts +11 -0
  92. package/dist/team/runtime.js +6 -0
  93. package/dist/team/subagent.d.ts +21 -0
  94. package/dist/team/subagent.js +7 -0
  95. package/dist/tools/index.d.ts +45 -2
  96. package/dist/tools/index.js +53 -3
  97. package/package.json +3 -3
  98. package/skills/project-indexer/SKILL.md +275 -147
  99. package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
  100. package/skills/project-indexer/templates/config-template.md +12 -0
  101. package/skills/project-indexer/templates/index-template.md +4 -0
@@ -1,12 +1,10 @@
1
1
  ---
2
2
  name: project-indexer
3
- description: Generate and use a project index for quick codebase understanding in new sessions. Scans the workspace, extracts exported symbols, writes .claude-index/index.md plus config, and injects a Google-style Clean Code Guidelines section into CLAUDE.md. Use when the user says "explore the project", "generate index", "regenerate index", "更新索引", "生成索引", or presses Ctrl+I.
4
- version: 1.1.0
3
+ description: Generate and use a project index for quick codebase understanding in new sessions. Use when the user says "explore the project", "generate index", "regenerate index", "更新索引", "生成索引", or presses Ctrl+I.
4
+ version: 1.2.0
5
5
  license: MIT
6
6
  keywords: [productivity, codebase, indexing, navigation, cleancode]
7
- # The read-only tools (read_file, list_dir, glob, grep, ask_user, todo_write)
8
- # are always available inside a skill frame via the tool floor; this ceiling
9
- # adds exactly the two writers the generated files need.
7
+ # Read tools are provided by the tool floor; only these two writers are added.
10
8
  allowed-tools:
11
9
  - write_file
12
10
  - edit_file
@@ -14,150 +12,280 @@ allowed-tools:
14
12
 
15
13
  # Project Indexer
16
14
 
17
- Generate a structured index of any codebase so a new session understands the
18
- project with minimal context usage. The index is a **navigation map**, not a
19
- code copy: enough to see the project globally (type, stack, architecture),
20
- navigate on demand (feature map, file index), and know which symbols exist
21
- without reading every file.
15
+ 为当前工作区生成导航索引,便于新会话了解项目、按需定位功能和导出符号。
16
+ 索引是导航,不复制源码。写入型操作维护 index/config,以及全文相同的
17
+ `CLAUDE.md`、`AGENTS.md` 两份普通文件;必选产物规则独立于可选 Clean Code。
18
+ 此契约适用于当前内置 1.2.0;不修改同名用户/项目技能,不改变技能解析优先级。
22
19
 
23
20
  ## Current request
24
21
 
25
22
  $ARGUMENTS
26
23
 
27
- ## Step 1: Check for an existing index
28
-
29
- - If `.claude-index/index.md` exists and has the key sections (Project
30
- Overview, Feature Map, File Index), go to "Using an existing index".
31
- - If it exists but is empty or malformed, tell the user and regenerate
32
- (first-time flow), preserving `config.md` if intact.
33
- - Otherwise run the first-time flow.
34
-
35
- ## Using an existing index
36
-
37
- 1. Read `.claude-index/index.md` and `CLAUDE.md` (if present).
38
- 2. Summarize in 3-5 bullets: structure, stack, feature areas, key entry
39
- points. Offer to help.
40
- 3. For later questions, navigate via the Feature Map / File Index and read
41
- real source only when detail is needed.
42
-
43
- ## First-time flow
44
-
45
- ### Step 2: Gather configuration (ask_user)
46
-
47
- Ask with `ask_user`, defaults offered in every question:
48
-
49
- 1. **Exclusions** - A) defaults (node_modules, .git, dist, build,
50
- __pycache__, .venv, vendor, coverage, .next, .nuxt, .cache, target, bin,
51
- obj, .idea, .vscode) B) add more C) custom list.
52
- 2. **Priority directories** - A) auto-detect (recommended) B) specify C) all
53
- equally.
54
- 3. **Tech stack** - auto-detect unless the user names one.
55
- 4. **Clean Code Guidelines** (injected into CLAUDE.md) - A) Google strict
56
- (method 60, file 1000 - recommended) B) Google relaxed (method 600)
57
- C) custom D) skip.
58
-
59
- If C: ask **one `ask_user` call per limit** showing default and range -
60
- MAX_FILE_LINES 1000 (200-5000), MAX_METHOD_LINES 60 (20-600),
61
- MAX_FUNCTION_PARAMS 5 (2-10), MAX_CYCLOMATIC 10 (5-25); fall back to the
62
- default on an out-of-range answer and say so in the summary.
63
- MAX_LINE_LENGTH (default 100, Python 80) and MAX_NESTING_DEPTH (4) are never
64
- asked. If the user skips every question, use all defaults.
65
-
66
- Treat the answer as `CleanCodeConfig.preset`: strict | relaxed | custom |
67
- disabled. D (`disabled`) skips the Clean Code composition below, never adds
68
- markers, and persists `Enabled: No`.
69
-
70
- ### Step 3: Scan and analyze
71
-
72
- 1. Traverse the tree with the exclusion rules (`glob`, never one giant read).
73
- 2. Detect project type (frontend/backend/fullstack/library/CLI/monorepo),
74
- languages with percentages, frameworks, entry points.
75
- 3. Group files by feature/domain and extract exported symbols - full support
76
- for JS/TS (.js/.jsx/.ts/.tsx/.mjs) and Python; best-effort for Java,
77
- Kotlin, Go, Rust, C/C++, C#, Ruby, PHP; unknown types are listed without
78
- symbols.
79
- 4. Analyze module-level dependencies (import graph).
80
-
81
- Adaptive sizing: <50 files -> full detail; 50-200 -> full coverage with
82
- concise descriptions; 200+ -> detail the priority directories, summarize the
83
- rest, group similar utilities. Over 1000 files after exclusions: warn and
84
- suggest more exclusions before continuing; sample representative files with
85
- glob/grep rather than reading everything. Keep language/framework findings in
86
- working memory - do NOT write an intermediate JSON file.
87
-
88
- ### Step 4: Write `.claude-index/`
89
-
90
- 1. `config.md` - exclusions, priorities, tech stack, plus an Index Settings
91
- block (Generated date, Project Root, Index Version) and a Clean Code
92
- Settings block (Enabled / Preset / the six limits; when the user picked
93
- skip, write `Enabled: No`, `Preset: disabled` and the strict numbers so a
94
- later "enable cleancode" can flip it back).
95
- 2. `index.md` - follow `templates/index-template.md` in this skill's
96
- directory: Project Overview, Feature Map (per area: entry file, one-line
97
- description, key exports with signatures), Module Dependencies, File Index
98
- (per-directory tables, one line per file).
99
-
100
- ### Step 5: Compose the Clean Code Guidelines (skip when disabled)
101
-
102
- Read `templates/cleancode-template.md` and `templates/cleancode-overrides.md`
103
- from this skill's directory, then:
104
-
105
- 1. Primary languages = every language with >= 10% of post-exclusion source
106
- files; if none clears 10%, use the `Other` row.
107
- 2. Take the **minimum** across all matching rows for each numeric column.
108
- 3. Apply the user preset: strict/relaxed values intersect with the language
109
- minimum (never looser than the baseline); custom numbers are honoured
110
- verbatim with divergence noted.
111
- 4. Substitute every placeholder: `{{MAX_FILE_LINES}}`, `{{MAX_METHOD_LINES}}`,
112
- `{{MAX_FUNCTION_PARAMS}}`, `{{MAX_CYCLOMATIC}}`, `{{MAX_LINE_LENGTH}}`,
113
- `{{MAX_NESTING_DEPTH}}`, `{{PRIMARY_LANGUAGES}}` (comma-joined languages)
114
- and `{{LANGUAGE_HINTS}}` (one `- Language: note` bullet per matching row,
115
- deduped by exact string).
116
- 5. Verify no `{{...}}` placeholder remains. Do not count characters at
117
- runtime.
118
-
119
- ### Step 6: Update CLAUDE.md
120
-
121
- - `## Project Index` section: upsert (replace when present, else append at
122
- end; create the file when missing). Contents: Location
123
- `.claude-index/index.md`, Last Updated (YYYY-MM-DD), Contents line, a
124
- Usage line, and "Regenerate: say 'regenerate index' / '更新索引'".
125
- - `## Clean Code Guidelines` section (unless disabled): wrap the rendered
126
- body in `<!-- project-indexer:cleancode:begin v1.1.0 -->` and
127
- `<!-- project-indexer:cleancode:end -->`. Locate an existing block with
128
- the version-agnostic regex `<!-- project-indexer:cleancode:begin
129
- v\d+\.\d+\.\d+ -->` (NEVER a literal-version match) plus the literal end
130
- marker; fallback: the region from a `## Clean Code Guidelines` heading to
131
- the next `## ` heading or EOF. Replace the found block; if none, insert
132
- after the Project Index section (first-insert only; when both sections
133
- already exist preserve the user's ordering and everything between them).
134
- Write UTF-8; add a trailing newline when missing.
135
-
136
- ### Step 7: Report
137
-
138
- List what was created/updated, the feature-area count, files indexed and
139
- symbols extracted. Offer to start work.
140
-
141
- ## Regeneration ("regenerate index" / "更新索引")
142
-
143
- 1. Read `config.md` and preserve exclusions, priorities, stack.
144
- 2. Clean Code handling: if CLAUDE.md has markers or the heading, ask
145
- A) refresh B) keep C) remove; honour `Enabled: No` from config.md by
146
- skipping silently with one reminder line. When no block exists and
147
- Enabled is Yes/absent, compose and inject (announce before writing).
148
- 3. Confirm the plan (exclusions, priorities, cleancode decision) with the
149
- user, then re-run Steps 3-7.
150
-
151
- Special triggers: "disable cleancode" removes the block and sets
152
- `Enabled: No`; "enable cleancode" re-composes it and sets `Enabled: Yes` -
153
- both without a full rescan.
154
-
155
- ## Edge cases
156
-
157
- - Inaccessible directories: list them under a "Skipped Directories" note and
158
- continue; never fail the whole run for one unreadable path.
159
- - No recognizable source files: generate a minimal index (overview + file
160
- listing) and say so.
161
- - The user pressed Ctrl+I: they already confirmed once - do not re-ask the
162
- global "proceed?" question, but still ask the configuration questions
163
- above (or reuse `.claude-index/config.md` when it exists).
24
+ ## Step 1:先判定意图,再检查索引
25
+
26
+ 工作区根始终是会话 cwd,不提升到 Git 根或父目录。先按下列优先级路由:
27
+
28
+ 1. 明确 enable cleancode / disable cleancode,且未同时要求重建:局部开关。
29
+ 必须已有有效 index 和可安全复用 config,否则说明需先构建/修复,零写入;
30
+ 不扫描、不偷偷构建。若同时要求重建,则执行一次完整重建并应用显式开关。
31
+ 2. 明确构建/生成/更新/重建索引,包括 Ctrl+I 的 Build/Rebuild 机器句子:
32
+ 必须进入写入流程,不能因旧索引存在而退回只读摘要。有完整配置则复用,
33
+ 无配置才首次配置;无效索引重新构建,但完整旧配置仍保留。
34
+ 3. 仅探索/理解项目且已有有效索引:进入下方只读流程。
35
+ 4. 其它无索引或无有效结构的情况:首次构建;完整旧配置仍可复用。
36
+
37
+ 有效 index 包含 Project Overview、Feature Map、File Index。仅 ENOENT 表示缺失;
38
+ 已有 config 不可读、结构损坏或关键字段冲突时停止全部写入,不能用首次模板覆盖。
39
+ 可读完整的旧配置缺新增段或可选字段时,仅补缺失默认值,保留未知内容和有效值。
40
+
41
+ ### 使用已有索引(只读)
42
+
43
+ 先读取所有适用指导,包括已存在的两个文件族和 agent.md,再读
44
+ `.claude-index/index.md`。以 3–5 点概括结构、技术栈、功能区和入口;
45
+ 后续按 Feature Map / File Index 定位源码。不补 AGENTS、不更新模板、不写任何文件。
46
+
47
+ ## Step 2:完整读取、配置和预检(所有写入型操作必经)
48
+
49
+ **第一次写入前完成本节及 Steps 3–5。** 模板、冲突、读取或容量错误均零写入。
50
+ 只使用当前工具;不得假设 bash、cp、Copy-Item、Python、Node、删除工具可用,
51
+ 不得通过这些手段绕过技能权限。正常只产生四个目标文件,不落盘中间 JSON 或备份。
52
+
53
+ ### 目标与完整读取
54
+
55
+ - 用根目录实际条目识别名称忽略大小写等于 CLAUDE.md / AGENTS.md 的两个文件族。
56
+ 不存在用标准大写;唯一变体沿用实际拼写,不重命名;同族有两个独立条目则列出
57
+ 路径并停止。Windows 大小写别名不算两个条目。agent.md 只读、不修改、不镜像。
58
+ - 完整读取指导、config 及需保留的 index。read_file 使用 offset/limit 连续分页,
59
+ 用返回行号核对覆盖;只剥除工具添加的行号,保留文件缩进、空格、空行。
60
+ 200 行预览不是全文。工具无总行数字段:以未截断的短页或后续 EOF 探测确认结束;
61
+ 空文件可能返回带编号空行,越过 EOF 返回 `(empty file)`。
62
+ - 默认工具输出上限为 100,000 字节。遇 `... [truncated]` 或完整性不明,缩小 limit,
63
+ 从原页起点重读;截断不等于 EOF。目录 list_dir 截断也不能证明文件不存在。
64
+ 必须执行缩页重读,必要时读到 limit=1;不能仅跳到后续行或探测 EOF,就把截断页
65
+ 当作完整。若确定是单行过长,仍须用该行 offset、limit=1 重读确认后再报告容量限制。
66
+ limit=1 的单行仍截断、目录条目无法完整确认、上下文装不下完整基线、
67
+ 或不能用一次 write_file 参数输出完整目标时,首次写入前停止并报告路径和限制。
68
+ 不发明字节分页 API,不用摘要/空文本/分段覆盖代替全文。上下文压缩后失去基线,
69
+ 必须重读并重新预检。
70
+ - 不可读、目录占位、二进制、缺页都停止;不能当作不存在。已知链接指向工作区外时
71
+ 拒绝写入;现有工具不保证识别所有链接,不宣称完整链接检测。
72
+
73
+ ### 配置选择
74
+
75
+ 首次配置用 ask_user 提供默认选项:
76
+ 1. 排除目录:默认 node_modules, .git, dist, build, __pycache__, .venv, vendor,
77
+ coverage, .next, .nuxt, .cache, target, bin, obj, .idea, .vscode;或增加、自定义。
78
+ 2. 优先目录:自动检测(默认)、指定、全部同等。
79
+ 3. 技术栈:自动检测,除非用户指定。
80
+ 4. Clean Code:Google strict(默认,method 60/file 1000)、relaxed(method 600)、
81
+ custom、skip。
82
+
83
+ custom 每个限值单独一次 ask_user:MAX_FILE_LINES 1000 (200–5000),
84
+ MAX_METHOD_LINES 60 (20–600),MAX_FUNCTION_PARAMS 5 (2–10),
85
+ MAX_CYCLOMATIC 10 (5–25)。超范围回退默认并说明。
86
+ MAX_LINE_LENGTH 默认 100(Python 80)、MAX_NESTING_DEPTH 4 不询问。
87
+ 全部跳过采用默认。首次 skip 保存 Enabled: No、Preset: disabled 及默认六限值。
88
+
89
+ 重建复用排除、优先目录、技术栈、有效 preset 和六限值。已有 Clean Code 且启用时
90
+ 可问 refresh/keep/remove;已有 Enabled: No 时普通重建默认 disabled 并说明。
91
+ 明确无人值守/不要询问时复用已有配置,无配置采用默认;已有 Enabled: No 则 disabled,
92
+ 其它默认 refresh。显式 keep/remove/enable/disable 优先。Ctrl+I 已确认,
93
+ 不重复全局 proceed;只在允许提问且需要配置时询问。双文件和产物管理没有关闭开关。
94
+
95
+ ### 唯一托管范围(比较、替换和删除必须使用同一边界)
96
+
97
+ 只识别真实 Markdown 结构,忽略反引号/波浪线围栏、缩进代码、引用中的示例标题/markers。
98
+ 标题范围到下一个同级或更高级标题,不只查下一个 `##`。
99
+
100
+ - 三个真实目标标题各至多一个:`## Project Index`、`## Clean Code Guidelines`、
101
+ `## Workspace Artifact Hygiene`。Clean Code 和 artifact-hygiene markers 各零组或一组。
102
+ begin/end 必须成对、顺序正确、不嵌套、不交叉,位于对应唯一标题内、不跨其它同级/
103
+ 更高级标题。无标题 markers、重复标题/markers、孤立 end、坏版本均冲突,写入前停止。
104
+ - 合法 markers 只拥有 begin 至 end(含边界)。同节 marker 前后文字属于用户;
105
+ 比较必须保留这些文字,更新仅替换 marker 区域,不重复标题。专用标题可从比较排除,
106
+ 但绝不能排除用户文字。删除 Clean Code 时仅删 marker 区;仍有用户备注则保留标题,
107
+ 只有纯托管章节才能连标题删除。
108
+ - Clean Code 的旧版无 marker 回退:仅在完整章节结构和限值条目能识别为旧生成模板,
109
+ 或用户已明确授权迁移该具体范围时,才拥有唯一标题至下个同级/更高级标题的区间。
110
+ 仅同名标题不够;无法确认归属就停止,尤其 disable 后留下的备注不能在下次吞掉。
111
+ artifact-hygiene 是新章节,没有自动迁移的无 marker 历史版本;同名无 marker 标题
112
+ 是用户内容冲突,停止,除非已有针对该具体范围的明确迁移授权。
113
+ - Project Index 是历史无 marker 章节,只拥有已知导航字段(Location、Last Updated、
114
+ Contents、Configuration、Usage、Regenerate 及本技能新增的 Guidance Files / Artifacts)。
115
+ 额外项目链接/备注属于用户,保留并参与比较;无法区分固定字段和补充内容时停止。
116
+ 不整章替换、不动其它章节或代码示例。
117
+
118
+ ### 共同正文与冲突
119
+
120
+ 先独立解析两边 Clean Code 来源,再选择用户正文基底。非托管正文仅排除上述确切拥有
121
+ 的范围,不能为了让两边相等而多排除用户备注。规范化仅去文件起始 UTF-8 BOM、
122
+ CRLF/CR 转 LF、文件末尾换行为一个 LF;不 trim 段落、行末空格或开头空行,不摘要。
123
+
124
+ | 观察到的状态 | 共同正文基底 |
125
+ | --- | --- |
126
+ | 两份缺失 | 空文档 |
127
+ | 仅一份存在 | 该份完整正文 |
128
+ | 两份规范化后全文相同 | CLAUDE 全文 |
129
+ | 非托管正文相同,仅托管区不同 | CLAUDE 全文,按本次策略更新托管区 |
130
+ | 一份非托管正文为空,另一份非空 | 含用户正文的一份全文 |
131
+ | 两份非托管正文均非空且不同 | 零写入,报告具体差异和路径 |
132
+
133
+ 空白判断只用于确认没有用户内容,不授权删除另一份的文字。冲突时不任意覆盖或拼接,
134
+ 不生成藏旧规则的备份,不循环问批准。说明用户需先合并非托管正文为一致,或后续明确
135
+ 指定本次以哪份完整正文为准,再重试。
136
+
137
+ 适用的原有规则若明确禁止镜像文件、要求结果只能放在其它目录、或与清理条款直接冲突,
138
+ 在预检时指出条款和来源,零写入;不能保留矛盾规则又追加新规则。描述历史输出路径但
139
+ 未禁止 runs 不构成冲突,不迁移历史产物。
140
+
141
+ ### Clean Code 状态(不影响产物规则)
142
+
143
+ keep/disabled 必须独立合并两边来源:仅一边有则保留其完整受管内容和版本;
144
+ 两边规范化后相同则留一份;不同则预检冲突。即使来源不在选中基底,也必须插入保留。
145
+
146
+ | 选择 | 指导正文 | config |
147
+ | --- | --- | --- |
148
+ | refresh / enable | 依据有效配置统一生成,两边旧托管区可不同 | Enabled: Yes;保留 strict/relaxed/custom 和限值;旧 disabled 恢复 strict 并应用保存限值及语言覆盖 |
149
+ | keep | 保留独立合并结果;两边都没有就不生成 | Enabled、Preset、六限值不变,不从正文反推设置 |
150
+ | remove / disable | 只删受管内容,保留 marker 外用户文字 | Enabled: No;保留有效 preset 和六限值供以后启用 |
151
+ | 首次 skip | 不生成;已有遗留段按 keep 保留 | Enabled: No;无旧配置才用 disabled 和默认限值 |
152
+ | 普通重建且已有 Enabled: No | 不刷新、不删除;按 keep 保留遗留块并说明 | Enabled: No、Preset、限值不变 |
153
+
154
+ ### 配置政策预检
155
+
156
+ `## Workspace Artifact Policy` 是固定契约记录。唯一合法段只定向更新六个已知字段,
157
+ 保持该段未知字段、自由备注、相对顺序以及所有其它未知章节。缺段则补段,不整份
158
+ 重套首次模板,不整段覆盖。字段和值来自 templates/config-template.md,
159
+ Guidance Files 使用本轮实际拼写。
160
+
161
+ 真实标题重复、同字段重复且冲突、版本格式无效或高于 1.0.0 时零写入;不猜值、
162
+ 不降级未来版本。无版本旧段仅在六字段兼容且边界明确时补版本/缺失字段;
163
+ 其它唯一 Results Directory 或可选清理策略按实际规则冲突处理。
164
+ 相同值的重复字段只保留一个,未知内容不动。政策不改变扫描排除/优先目录,
165
+ 包括旧配置明确要求索引 runs 时仍尊重扫描策略。
166
+
167
+ ## Step 3:扫描分析(局部开关跳过)
168
+
169
+ 使用 glob 分段遍历,遵守现有排除;检测项目类型、语言比例、框架、入口;
170
+ 按功能域组织文件,提取导出符号和模块依赖。JS/TS (.js/.jsx/.ts/.tsx/.mjs) 和 Python
171
+ 完整支持,Java/Kotlin/Go/Rust/C/C++/C#/Ruby/PHP 尽力提取,其它类型列文件不猜符号。
172
+ 小于 50 文件完整细节;50–200 完整覆盖、简述;200+ 优先目录详细,其余分组;
173
+ 超过 1000 文件提示可增加排除,glob/grep 选代表文件而非读尽全仓。
174
+ 语言/框架分析留在上下文,**不写中间 JSON**。
175
+
176
+ 源码目录不可访问可记 Skipped Directories 后继续;但指导/config/index/模板不可读
177
+ 不能据此继续写入。无源码则生成最小 overview/feature map/file listing 并说明。
178
+ 不创建空 runs,不用海量实验结果替代代码导航。
179
+
180
+ ## Step 4:读取全部所需模板、合成所有目标(仍不写入)
181
+
182
+ 先读取当前技能目录的全部所需模板:
183
+ - `templates/config-template.md`:新建配置才整体使用;旧配置仅局部更新已知字段。
184
+ - `templates/index-template.md`:扫描型操作生成导航、Feature Map、Module Dependencies、
185
+ File Index、Notes;示例内容不是实际扫描结果,替换模板占位符。
186
+ - `templates/cleancode-template.md` 和 `templates/cleancode-overrides.md`:
187
+ 仅 refresh/enable 需要,keep/disabled 不重生成。
188
+ - **每次写入型操作必读** `templates/artifact-hygiene-template.md`:
189
+ 不受 skip/remove/disabled 影响,保留完整八条规则,无需虚构实验记录。
190
+
191
+ 任一所需模板缺失、不可读、生成占位符未替换、合成不完整时,第一次写入前停止。
192
+ 用户原有示例中的占位符属于用户,不删改;检查的是本轮生成区域。
193
+
194
+ ### index / config
195
+
196
+ 构建时 config 更新 Index Settings 的生成日期、cwd、版本、实际文件/符号数量;
197
+ 保留排除、优先目录、技术栈、未知段/备注和未被本次选择修改的 Clean Code 设置。
198
+ 按上节边界补齐唯一 Workspace Artifact Policy,不写易过期的 Synced: Yes。
199
+ index Notes 写 runs/<run-id>/、runs/<run-id>/tmp/ 和两份实际指导文件导航;
200
+ File Index 只报告实际扫描项,不把尚未创建的 runs 当作存在。
201
+
202
+ 局部 enable/disable 只改 config 的 Clean Code 设置和 Workspace Artifact Policy、
203
+ 两份指导文件;**index 原始字节、日期和统计不变,无扫描**。
204
+ 缺失 Project Index 导航可据旧索引补齐,用真实生成日期,不伪装为重建日期。
205
+
206
+ ### refresh / enable 的 Clean Code 合成
207
+
208
+ 1. 主语言是排除后源码占比 >=10% 的每种语言;没有则用 Other 行。
209
+ 2. 对匹配语言每个数值取最小值。
210
+ 3. strict/relaxed 的已保存限值与语言最小值相交(不能更宽松);custom 原值照用并说明偏离。
211
+ 4. 替换 {{MAX_FILE_LINES}}、{{MAX_METHOD_LINES}}、{{MAX_FUNCTION_PARAMS}}、
212
+ {{MAX_CYCLOMATIC}}、{{MAX_LINE_LENGTH}}、{{MAX_NESTING_DEPTH}}、
213
+ {{PRIMARY_LANGUAGES}}(逗号分隔)、{{LANGUAGE_HINTS}}(每语言一条,精确去重)。
214
+ 5. 确认生成区域无 {{...}}。新块边界是
215
+ `<!-- project-indexer:cleancode:begin v1.2.0 -->` /
216
+ `<!-- project-indexer:cleancode:end -->`;
217
+ 旧 begin 按 `v\d+\.\d+\.\d+` 识别,不用固定旧版本;keep 不改旧版本标签。
218
+
219
+ ## Step 5:合成唯一共同指导正文
220
+
221
+ 从预检选定的完整基底,按同一托管边界更新:
222
+ - Project Index:原位更新 Location、Last Updated、Contents、Usage、Regenerate
223
+ (regenerate index / 更新索引),补两份 Guidance Files 与 Artifacts 导航;
224
+ 保留额外链接/备注。缺失则追加。
225
+ - Clean Code:按已确定状态处理;缺失且需插入时放 Project Index 后;
226
+ 已存在则保持原位置,不重排用户章节。
227
+ - Workspace Artifact Hygiene:原位替换合法 marker 区;缺失追加模板完整章节到末尾。
228
+ 标题只写一次,边界固定
229
+ `<!-- project-indexer:artifact-hygiene:begin v1.0.0 -->` /
230
+ `<!-- project-indexer:artifact-hygiene:end -->`,独立于 Clean Code 版本。
231
+
232
+ 确认 Project Index 和产物章节各一个,Clean Code 受管区零或一个;disable 后留下的
233
+ 用户备注标题不算规则被重新生成。用户正文文字、顺序、段内空白及行末双空格全部保留。
234
+ 合成后单独把保留的非托管正文与最初完整基线逐行、逐字符对照,仅允许前述文件级
235
+ 格式归一化;尤其 Markdown 行尾两个 U+0020 空格代表硬换行,不能因显示不明显而删除。
236
+ 必须复制原行及其尾随空格,不重新录入或格式化列表。用户内容有任何差异时,先在上下文
237
+ 内修正并重新核验,未确认一致不得开始写入;无法可靠保留空白时零写入停止。
238
+ 共同正文统一 UTF-8、LF、无 BOM、文件末尾一个 LF。只合成**一个完整字符串**,
239
+ 两次 write_file 的 content 使用同一字符串,不为 AGENTS 改写、翻译、加专属说明,
240
+ 不写指向另一份的链接替代全文,不把 read_file 的行号写回。
241
+
242
+ ## Step 6:复查基线、顺序写入、完整读回
243
+
244
+ 1. 全部目标已合成且能完整输出后,重新完整读取所有拟改文件,
245
+ 包括原本缺失的目标,核对预检基线。扫描中出现外部修改/新文件则停止;
246
+ 不能用旧快照覆盖。现有工具无 CAS,检查不能消除检查和写入之间的竞争。
247
+ 2. 固定顺序:**config → index → CLAUDE 文件族目标 → AGENTS 文件族目标**;
248
+ 局部操作跳过 index。每个目标写之前再次确认其旧内容/缺失状态未变。
249
+ 对每一个目标执行“read_file 该目标 → 等待读取结果并与基线比较 → 单独 write_file”
250
+ 的循环。已有目标必须从第 1 行连续完整重读到 EOF(可分页),逐段对照完整基线;
251
+ 只抽查首尾、grep 匹配、检查大小或存在性均不算复核,不能沿用最初读取来补足本次缺页。
252
+ 原本缺失的目标也必须重新 read_file,只有本次仍为 ENOENT 才允许新建。
253
+ 上一个文件写完后,必须重新检查下一个目标;最初的根目录列表或全局基线检查
254
+ 不能代替这个检查。尤其 CLAUDE 写成功后,必须重新读取 AGENTS,再决定是否写入。
255
+ 不把该目标的检查和写入放在同一批工具调用中,因为必须先收到并核对读取结果。
256
+ **本次调用的基线不可重置。** 任一目标与预检基线不同(包括原本不存在、现在被
257
+ 外部创建),立即进入“部分完成/失败”,此后本次调用不得再执行任何 write_file
258
+ 或 edit_file。即使新增文字兼容、可以无损合并,也不能接纳为新基底、重新合成
259
+ 两份指导、继续同步或回写已经完成的目标;新文件不是用户授权你重新开始的指令。
260
+ 仅列明变化、已写和未写路径,等待用户下次重新发起调用后才可重新预检。
261
+ 与目标字节已相同可跳过,但仍要读回检查。逐个
262
+ `write_file({path, content})` 并检查结果,绝不并发写。
263
+ 3. 任一失败/权限拒绝/中断立即停止后续写入,列出已写、未写、失败、状态未知的路径;
264
+ 不自动回滚,不宣称完成。四文件不具备事务,强杀可能留下部分结果。
265
+ 4. 按完整读取规则分页读回全部修改文件,两份指导逐页分别对比共同正文,
266
+ config/index 对比各自目标。记录 write_file 返回字节数,但字节数相同不代替全文。
267
+ 另将两份成品中的非托管正文分别与最初用户正文基线逐字符核验(包括每行尾随空格),
268
+ 不能只核验两份互相相等:两份共同丢失用户内容也是失败,必须报告部分完成。
269
+ read_file 不是原始 Buffer 比较;只报告全文读回结果,外部验收另做原始字节比较。
270
+ **进入最终读回后,本次调用只读。** 禁止以润色、补充说明、修正扫描快照措辞等理由
271
+ 再次 write_file 或 edit_file;这会绕过既定写入顺序与目标基线。所有文字须在首次
272
+ 写入前定稿,读回时发现还需更改则报告部分完成,留给下一次调用重新预检。
273
+ 5. 读回不匹配、读不全、外部写后编辑时停止、报告部分完成,**不自动覆盖修复**;
274
+ 不能确定差异是否属于他人。下次调用从磁盘重新读取并完整预检,不复用上轮快照。
275
+
276
+ ## Step 7:收尾与如实报告
277
+
278
+ 先根据 Step 6 的实际结果确定最终状态,再写回复:任一文件失败、读回不一致、读取
279
+ 不完整或状态未知时,首句必须是“部分完成:”或“失败:”,并立即指出原因及路径。
280
+ 即使 index/config 已写成功,也不能写“索引已构建完成”“同步完成”或把错误藏在
281
+ 成功总结后的注意事项里。只有所有必需目标成功且全文读回一致,才能首句宣告完成。
282
+
283
+ 检查本轮写入清单及相关目录(包含本轮创建但 Git 忽略的路径)。
284
+ 正常仅四目标;单纯索引不创建空 runs,无删除工具就避免产生一次性落盘文件。
285
+ 不清理用户历史 note.txt/second.txt 等可疑文件,不运行全局 git clean,不删历史 runs。
286
+ 如已产生无用临时文件但无权删除,列明路径、归属和原因。
287
+
288
+ 报告:创建/更新/跳过/失败/未知的目标、双文件全文读回状态、实际扫描的功能区/
289
+ 文件/符号数、Clean Code 选择、保留实验结果位置及本轮临时文件检查结果。
290
+ 未检查、冲突、容量不足或部分写入必须明确,不声称工作区干净。
291
+ `startIndexBuild().ok` 仅表示提交成功,不能当作文件生成完成。
@@ -0,0 +1,14 @@
1
+ ## Workspace Artifact Hygiene
2
+
3
+ <!-- project-indexer:artifact-hygiene:begin v1.0.0 -->
4
+
5
+ 1. **实验结果归档。** 运行调试、实验、性能比较、模型评估或复现任务产生的日志、指标、图表、截图、报告、导出数据和需要保留的模型输出,统一存放在当前工作区根目录的 `runs/<run-id>/`,不要散落在根目录或业务源码目录。此约定只针对新增任务产物,不修改原有框架配置;工具必须在指定位置运行时,在授权范围内将最终结果归档到 runs,不擅自搬动用户数据。
6
+ 2. **按次隔离。** run-id 使用不含路径分隔符和冒号的时间戳加任务短名,例如 `20261105-153000-parser-debug`。目录已存在时追加 `-02`、`-03` 等序号,禁止覆盖已有实验。只在实际产生结果时创建目录,单纯构建索引不创建空的 runs 目录。
7
+ 3. **临时文件隔离。** 同一任务的一次性脚本、探针、临时日志、下载中间文件和可重建中间产物放在 `runs/<run-id>/tmp/`。正式源码、测试和需长期维护的复现用例放在项目既有源码或测试目录,不作为临时文件清除。
8
+ 4. **保留可复现证据。** 需要保留的结果附简短说明,记录目的、执行命令、必要环境/配置、结论与输出路径,不记录密钥。关闭临时进程、释放文件句柄后再收尾。保留有效结果和必要复现材料,不能为了工作区看起来干净而删除。
9
+ 5. **任务结束前检查。** 每次修改或运行操作结束前,检查本轮涉及目录及本轮创建文件,区分交付内容、需要保留的结果和无用临时内容。有 Git 且允许执行时查看 `git status --short` 与相关 diff;同时检查本轮创建但被忽略的路径,因为 Git 状态不会列出它们。无 Git 时用目录检查和本轮创建清单核验。
10
+ 6. **只清理属于本轮的垃圾。** 只删除已确认由本轮创建且不再需要的临时文件,保留用户原有文件、其他任务产物、未提交修改、正式测试和实验结果。删除前核对具体路径及归属;禁止根据 tmp、test、debug 名称批量删除,禁止无差别执行 `git clean -fdx` 或清空整个 runs 目录。
11
+ 7. **权限边界。** 清理仅使用当前任务已允许的能力;没有删除能力时不要绕过工具限制,明确列出残留路径和原因。索引生成不授予清理任意历史文件的权限;无法确认归属的文件保留并报告。
12
+ 8. **交付说明。** 完成回复简述本轮清理情况和保留结果的位置;未检查、无法清理或仍有不明残留时如实说明,不能声称工作区已干净。干净指本轮没有未说明的无用临时文件,不要求抹掉所有 Git 未提交变更。
13
+
14
+ <!-- project-indexer:artifact-hygiene:end -->
@@ -60,6 +60,18 @@ Detected or specified technology stack:
60
60
  - MAX_LINE_LENGTH: 100
61
61
  - MAX_NESTING_DEPTH: 4
62
62
 
63
+ ## Workspace Artifact Policy
64
+
65
+ 以下字段记录技能的固定输出约定,不是可关闭的配置开关。
66
+ Guidance Files 写入本轮实际选定的大小写拼写。更新旧段时仅更新这六个字段,保留未知字段和备注。
67
+
68
+ - Guidance Files: CLAUDE.md, AGENTS.md
69
+ - Guidance Sync: identical-full-content
70
+ - Artifact Rules Version: 1.0.0
71
+ - Results Directory: runs/<run-id>/
72
+ - Temporary Directory: runs/<run-id>/tmp/
73
+ - Completion Cleanup Check: required
74
+
63
75
  ## Regeneration Notes
64
76
 
65
77
  Notes for future regeneration:
@@ -126,4 +126,8 @@ hooks → api, auth (combines data fetching with auth state)
126
126
 
127
127
  ## Notes
128
128
 
129
+ 新增实验结果归档到 `runs/<run-id>/`,一次性中间文件放在 `runs/<run-id>/tmp/`。
130
+ 完整的产物保留、临时文件归属及任务收尾规则见内容相同的 `CLAUDE.md` 与 `AGENTS.md`。
131
+ 仅将实际存在并扫描过的目录列入 File Index;未创建的 runs 不是已扫描内容,实验输出不应淹没代码导航。
132
+
129
133
  {Any additional notes about the project structure, conventions, or important information}