dsh-ai-collab 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,6 +91,16 @@
91
91
  1. **用户级一次性转发**(推荐,项目内零冗余):`~\.claude\CLAUDE.md` 写"若存在 ./AGENTS.md 则遵循";Gemini 在 `~\.gemini\settings.json` 设 `"contextFileName": "AGENTS.md"`。
92
92
  2. **临时落地**:`& .ai\llm.cmd entries -Publish` 生成 4 个转发文件,用完 `& .ai\llm.cmd entries -Remove` 收回。
93
93
  - 转发母版常驻 `.ai\entries\`;改规则只改本文件,`entries -Publish -Force` 会同步。
94
+ ## 8. 纪律清单(自动生成,勿手改)
95
+
96
+ > 全局纪律由 `$DSH_HOME\AGENTS.md` 注入(对所有会话生效);项目纪律的“启用”表示正文已内联在本节,
97
+ > 真正进入当前项目的提示词;“停用”只保留清单行,不生效。
98
+ > 管理入口:DSH 工具 `ai_discipline`(list / add / enable / disable / remove / global-*);
99
+ > 改动后由 `ai-ensure` 重渲染本节。
100
+
101
+ {{DISCIPLINE_TABLE}}
102
+
103
+ {{DISCIPLINE_RULES}}
94
104
  <!-- dsh-ai-collab:generated:end -->
95
105
 
96
106
  <!-- dsh-ai-collab:user:start -->
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ - Disciplines: global modules + project rules.
6
+ - New `ai_discipline` tool: `list/add/enable/disable/remove` for
7
+ `.ai/disciplines/disciplines.json` + `.ai/disciplines/rules/<id>.md`;
8
+ `global-list/global-migrate/global-add/global-enable/global-disable/global-remove`
9
+ for `$DSH_HOME/disciplines/`.
10
+ - `global-migrate` splits an existing `$DSH_HOME/AGENTS.md` into `g0.md … gN.md` + a registry,
11
+ then rewrites `AGENTS.md` as a marker line plus the original text (byte-for-byte, backup
12
+ first). Toggling a module re-renders the injected file, so a disabled section really stops
13
+ being injected.
14
+ - Project rules render into a new **§8** of `AGENTS.md`: a table of global `G*` and project
15
+ `P-*` rows, plus the inline body of every enabled rule. `ai_check` reports drift
16
+ (`on-rule` / `off-rule` / registry unreadable).
17
+ - Cross-session handoff: new `ai_handoff` tool (`read` / `write` / `inherit`) and
18
+ `.ai/SESSION_BOOT.md`, regenerated by `ai_log`, `ai_init` and `autoInit`. It carries the status
19
+ snapshot, the most recent records, the discipline list, and an inheritance prompt for a new
20
+ session. `read` returns the file text itself (generating the file first if it is missing).
21
+ - Concurrency and file protection: `lib/atomic.js` (temp file + `fsync` + rename, retry on
22
+ `EPERM`/`EBUSY`/`EACCES`) and `lib/lock.js` (cross-process lock with stale detection).
23
+ `ai_log` holds `.ai/.log.lock` across the append and status update; `status.json` gains a
24
+ `rev`; `TASKS.md` and `SESSION_BOOT.md` are written atomically. `template/.ai/llm.ps1` gets
25
+ `Write-TextAtomic` + `Enter-ProjectLock`/`Exit-ProjectLock` for `add`, `tasks`, `board` and
26
+ `archive` (archive aborts if the log grew during the copy). `install.ps1` writes `AGENTS.md`
27
+ atomically and backs it up to `.ai/backups/` (last 10) before any change.
28
+ - Tests: 25 (tool contract, config, task rendering, AGENTS.md preservation, atomic/lock,
29
+ discipline registry and §8 drift, handoff).
30
+ - Verified on a real workspace: project rule add/disable/enable/remove, global module
31
+ disable/enable (bytes 5900 → 5671 → 5900), 12 concurrent writers → 12 records with `rev=12`,
32
+ 6 concurrent `llm.ps1 add` calls without loss.
33
+ - Docs: README gains a "What's new in 0.5.0" summary and the discipline/concurrency sections;
34
+ `docs/DETAIL.md` and the visual introduction page are refreshed for 0.5.0.
35
+
3
36
  ## 0.4.4
4
37
 
5
38
  - Docs/legal: add `docs/DISCLAIMER.md` (AS IS, limitation of liability, backup guidance)
package/README.md CHANGED
@@ -11,7 +11,28 @@ The point: any AI tool working in the repo (DSH, Claude Code, Cursor, Copilot, C
11
11
 
12
12
  > **Visual introduction (中文):** <https://ZhuYw3927.github.io/dsh-ai-collab/>
13
13
 
14
- > Status: **0.4.4, experimental**. Published on npm as [`dsh-ai-collab`](https://www.npmjs.com/package/dsh-ai-collab) and listed in the community plugin market — see [Known limitations](#known-limitations).
14
+ > Status: **0.5.0, experimental**. Published on npm as [`dsh-ai-collab`](https://www.npmjs.com/package/dsh-ai-collab) and listed in the community plugin market — see [Known limitations](#known-limitations).
15
+
16
+ ## What's new in 0.5.0
17
+
18
+ - **Disciplines are now first-class.** `AGENTS.md` gains a generated **§8 discipline list**: global
19
+ modules (`G0…`) plus project rules (`P-*`), each marked enabled/disabled with its source file.
20
+ Enabled project rules are inlined, so they actually constrain the session; disabled ones stay as
21
+ a visible row only.
22
+ - **`ai_discipline`** manages both levels from a DSH tool: `list/add/enable/disable/remove` for the
23
+ project (`.ai/disciplines/`), `global-list/global-migrate/global-add/global-enable/global-disable/global-remove`
24
+ for `$DSH_HOME/disciplines/`. Toggling a global module re-renders `$DSH_HOME/AGENTS.md` from the
25
+ enabled modules only — a disabled section really disappears from the prompt.
26
+ - **`ai_handoff` + `.ai/SESSION_BOOT.md`**: a new session reads one file to load the status
27
+ snapshot, the recent records, the discipline list and an inheritance prompt, instead of guessing
28
+ from a long log. Regenerated by `ai_log`, `ai_init` and `autoInit`; `read` returns the file text.
29
+ - **Concurrency and file protection**: cross-process locks (`lib/lock.js`) plus atomic writes
30
+ (`lib/atomic.js` — temp file, `fsync`, rename, retry on `EPERM`/`EBUSY`/`EACCES`).
31
+ `status.json` carries an incrementing `rev`; `TASKS.md` and `SESSION_BOOT.md` are written
32
+ atomically; `llm.ps1` mirrors both mechanisms; `AGENTS.md` rewrites are backed up to
33
+ `.ai/backups/` (last 10). `ai_check` also fails on §8 drift.
34
+ - Verified by 25 tests (atomic/lock, discipline registry, §8 drift, handoff) and by a real burst:
35
+ 12 concurrent writers → 12 records, one unique id each, `rev=12`.
15
36
 
16
37
  ## Requirements
17
38
 
@@ -80,10 +101,12 @@ index generated by `scripts/make-market-index.mjs`.
80
101
  | Tool | Does |
81
102
  |---|---|
82
103
  | `ai_status` | Reads `.ai/status.json` + the last N log records (start a session here) |
83
- | `ai_log` | Appends one record to `.ai/log.jsonl`; rejects invalid enums, requires `issue` for `blocked`/`failed`; refreshes `status.json` **and the sibling board** |
84
- | `ai_check` | Validates every record: required fields, enums, timezone, monotonic `ts`, unique `id` |
104
+ | `ai_log` | Appends one record to `.ai/log.jsonl`; rejects invalid enums, requires `issue` for `blocked`/`failed`; refreshes `status.json`, the sibling board, `TASKS.md` and `.ai/SESSION_BOOT.md` |
105
+ | `ai_check` | Validates every record: required fields, enums, timezone, monotonic `ts`, unique `id`; audits the §8 discipline list for drift |
85
106
  | `ai_board` | Read-only roll-up of sibling projects' `.ai/status.json` |
86
107
  | `ai_init` | Ensures the workspace: scaffold if missing, refresh stale `.ai/`/`AGENTS.md`, refresh stale board (idempotent) |
108
+ | `ai_discipline` | Lists, adds, enables, disables and removes project disciplines; migrates/toggles the global discipline modules in `$DSH_HOME` |
109
+ | `ai_handoff` | Reads or rewrites the cross-session handoff packet (`.ai/SESSION_BOOT.md`) and returns an inheritance prompt |
87
110
 
88
111
  ## What `ai_init` creates
89
112
 
@@ -93,7 +116,9 @@ index generated by `scripts/make-market-index.mjs`.
93
116
  └─ .ai\
94
117
  ├─ llm.ps1, llm.cmd ← CLI: status / tail / add / check / entries / archive / board / doctor
95
118
  ├─ log.jsonl ← append-only, UTF-8 no BOM, LF
96
- ├─ status.json ← current state (overwritten)
119
+ ├─ status.json ← current state (overwritten, `rev` increments)
120
+ ├─ SESSION_BOOT.md ← cross-session handoff packet (regenerated on demand)
121
+ ├─ disciplines\ ← project discipline registry + rules\*.md
97
122
  ├─ LOG_FORMAT.md, SECURITY.md, schema\log.schema.json
98
123
  ├─ changelog\ ← version-level docs + patch engine
99
124
  ├─ entries\ ← forwarding-file masters (publish on demand)
@@ -130,7 +155,7 @@ Get-Content "$DSH_HOME\logs\ai-collab-tools.log" -Tail 3 # tools=ai_status,…
130
155
  ```
131
156
 
132
157
  - A fresh boot line means `apply()` ran in this process.
133
- - A `tools=` line means all five tools registered; `spec` shows where `@deepseek-ai/dsh-tools` was loaded from.
158
+ - A `tools=` line means all seven tools registered; `spec` shows where `@deepseek-ai/dsh-tools` was loaded from.
134
159
  - `load-failed` / `register-failed` lines carry the exact resolution errors.
135
160
 
136
161
  The plugin is mounted from outside `app.asar` (a `link:`/absolute path), so the bare `@deepseek-ai/dsh-tools` specifier is not resolvable; it is loaded from the host's real `app.asar` path instead (see `asarRoots()` in `index.js`). `DSH_HOME` is read from the host environment and may be absent when the app is launched from Explorer — the plugin then falls back to `~/.dsh` (`home=homedir`).
@@ -152,7 +177,33 @@ The plugin is mounted from outside `app.asar` (a `link:`/absolute path), so the
152
177
  - A file **without** the zone markers is treated as project-owned and is never rewritten; the rendered reference goes to `.ai/AGENTS.generated.md`. This includes legacy single-line-marker files, which are frozen.
153
178
  - Explicit migration only:
154
179
  - `-ForceAgents` — rebuild the generated zone and move the whole old file into the user zone (nothing deleted);
155
- - `-ResetAgents` — discard old content and write the template (destructive, explicit).
180
+ - `-ResetAgents` — discard old content and write the template (destructive, explicit; the old file is backed up to `.ai/backups/` first).
181
+
182
+ ## Disciplines: global modules and project rules
183
+
184
+ ### Global (`$DSH_HOME`)
185
+
186
+ - `$DSH_HOME/AGENTS.md` stays the file DSH injects into every session. `ai_discipline` with
187
+ `action:"global-migrate"` splits it into `$DSH_HOME/disciplines/g0.md … gN.md` plus
188
+ `$DSH_HOME/disciplines/disciplines.json`, then rewrites `AGENTS.md` as **one marker line + the
189
+ original text, byte-for-byte**. Nothing is deleted; a timestamped copy is written first.
190
+ - `global-list` / `global-enable` / `global-disable` / `global-add` / `global-remove` manage the
191
+ modules. Every change re-renders `AGENTS.md` from the enabled modules only.
192
+ - Disabling a global module is real: the text disappears from the injected file. It cannot be
193
+ overridden per project, because DSH injects the global file unconditionally.
194
+
195
+ ### Project (`.ai/disciplines/`)
196
+
197
+ - Registry: `.ai/disciplines/disciplines.json`; rule bodies: `.ai/disciplines/rules/<id>.md`.
198
+ - `ai_discipline action:"add" | "enable" | "disable" | "remove"` edits the registry and re-renders
199
+ the workspace. Section **§8** of `AGENTS.md` (generated zone) lists every global module (G0…,
200
+ read-only) and every project rule (P-…). The body of each **enabled** project rule is inlined
201
+ into §8, so it is part of the prompt of the project; a disabled rule keeps only its table row.
202
+ - `ai_check` audits §8 against the registry and reports drift: an enabled rule whose body is
203
+ missing, a disabled rule still inlined, or a registry that cannot be read.
204
+ - Raw format is intentionally plain: any human can edit the registry or the rule files; the next
205
+ `ai-ensure` / `install.ps1` render will pick them up.
206
+
156
207
  ## Safety
157
208
 
158
209
  - The log is **append-only**; corrections are new records (`action:"correction"`), never edits.
@@ -162,6 +213,24 @@ The plugin is mounted from outside `app.asar` (a `link:`/absolute path), so the
162
213
  - **Task lists are rendered inside the plugin** (`lib/tasks.js`); the plugin never executes a
163
214
  workspace-provided `.ai/llm.ps1`, so cloning a hostile repository and logging cannot run its code.
164
215
 
216
+ ## Concurrency and file protection
217
+
218
+ - `lib/atomic.js` writes to a same-directory temp file, `fsync`s and renames (retries on
219
+ `EPERM`/`EBUSY`/`EACCES`), so a reader never sees a half-written `status.json`, `TASKS.md` or
220
+ `SESSION_BOOT.md`.
221
+ - `lib/lock.js` is a cross-process lock (`openSync(path, 'wx')`), stale after 30 s, 15 s timeout.
222
+ `ai_log` holds `.ai/.log.lock` across the append **and** the status update; `status.json`
223
+ carries a `rev` that increments on each write.
224
+ - `TASKS.md` refresh holds `.ai/.tasks.lock`; `SESSION_BOOT.md` is written atomically.
225
+ - `template/.ai/llm.ps1` mirrors this in PowerShell: `Write-TextAtomic` (temp + `File.Replace`),
226
+ `Enter-ProjectLock` / `Exit-ProjectLock` around `add`, `tasks`, `board` and `archive`; `archive`
227
+ aborts if the log grew while it was copying.
228
+ - `install.ps1` writes `AGENTS.md` atomically and backs it up to
229
+ `.ai/backups/AGENTS.<stamp>.md` (last 10) before any change.
230
+ - Boundaries: this is **cooperative** locking between this plugin and `.ai/llm.cmd`, not an
231
+ OS-level guarantee. Editors that ignore the lock can still race. `initScript` is trusted
232
+ configuration — never point it at untrusted code.
233
+
165
234
  ## Uninstall
166
235
 
167
236
  1. Remove `dsh-ai-collab` from `dsh.profile.bundles` (or set `enabled: false` on its row) and restart.
@@ -170,16 +239,21 @@ The plugin is mounted from outside `app.asar` (a `link:`/absolute path), so the
170
239
 
171
240
  ## Global discipline (user level)
172
241
 
173
- The bundle ships tools and workspace scaffolding, not a user-level instruction file. To get
174
- the mandatory "step 0" behaviour in every session, copy
175
- [`AGENTS.global.template.md`](AGENTS.global.template.md) to `$DSH_HOME/AGENTS.md`
176
- (or merge it into your existing one). It contains only cross-project discipline — no project facts.
242
+ The bundle ships tools and workspace scaffolding, not a user-level instruction file. Two ways to
243
+ get the mandatory "step 0" behaviour in every session:
244
+
245
+ - **Fresh machine**: copy [`AGENTS.global.template.md`](AGENTS.global.template.md) to
246
+ `$DSH_HOME/AGENTS.md`.
247
+ - **Existing `AGENTS.md`**: call `ai_discipline` with `action:"global-migrate"`. It backs up the
248
+ file, splits it into `$DSH_HOME/disciplines/gN.md` + `disciplines.json`, and rewrites
249
+ `AGENTS.md` as a single marker plus the original text (byte-for-byte). Then use
250
+ `global-disable` / `global-enable` to switch individual sections off or on.
177
251
 
178
252
  ## Development
179
253
 
180
254
  ```powershell
181
255
  npm run check # node --check index.js + lib/*.js
182
- npm test # 19 tests: tool contract, config, task rendering, AGENTS.md preservation
256
+ npm test # 25 tests: tool contract, config, task rendering, AGENTS.md preservation, atomic/lock/discipline/handoff
183
257
  npm pack --dry-run
184
258
  ```
185
259
 
@@ -191,6 +265,13 @@ npm pack --dry-run
191
265
  return `unsupported-platform` instead of failing silently.
192
266
  - Config values are normalised in-process (no schemastery `Config` yet); invalid values produce warnings in `$DSH_HOME/logs/ai-collab-config.log`.
193
267
  - A legacy `AGENTS.md` without zone markers is frozen by design; migrate explicitly with `-ForceAgents` or `-ResetAgents`.
268
+ - Global discipline toggles rewrite `$DSH_HOME/AGENTS.md`. They only work after `global-migrate`
269
+ has produced the marker + `disciplines/` directory; `global-enable` of a missing module is
270
+ rejected. A global module cannot be disabled for one project only — DSH injects the file
271
+ unconditionally.
272
+ - Section §8 of a project `AGENTS.md` is refreshed by `ai-ensure` / `install.ps1`; a rule added
273
+ while no render runs appears after the next `ai_init`, `ai_discipline` change, or session start.
274
+ - The locking is cooperative (plugin + `.ai/llm.cmd`); external editors are not blocked.
194
275
  - The forwarding files for Claude Code / Gemini CLI are only masters under `.ai/entries/`; publish them with `.ai\llm.cmd entries -Publish` when a tool needs auto-discovery.
195
276
  - Publishing is not automated yet — see `PUBLISH.md`.
196
277
 
package/docs/DETAIL.md CHANGED
@@ -14,18 +14,31 @@ files that any tool can read: `AGENTS.md` for facts, `.ai/log.jsonl` for history
14
14
 
15
15
  | Capability | Detail |
16
16
  |---|---|
17
- | Five tools | `ai_status`, `ai_log`, `ai_check`, `ai_board`, `ai_init` |
17
+ | Seven tools | `ai_status`, `ai_log`, `ai_check`, `ai_board`, `ai_init`, `ai_discipline`, `ai_handoff` |
18
18
  | Auto-adoption | On `session/created` (`autoInit: true`) run `ai-ensure` in non-temp directories: scaffold when missing, upgrade when the template changed, refresh the board when stale |
19
- | Zoned `AGENTS.md` | A `generated` zone (routing, permissions, commands) replaced on upgrade, and a `user` zone (project facts, sampling data, analysis methods, decisions) preserved byte-for-byte |
20
- | Protected files | An `AGENTS.md` without zone markers is treated as project-owned and never rewritten; the rendered reference goes to `.ai/AGENTS.generated.md` |
19
+ | Zoned `AGENTS.md` | A `generated` zone (routing, permissions, commands, §8 discipline list) replaced on upgrade, and a `user` zone (project facts, sampling data, analysis methods, decisions) preserved byte-for-byte |
20
+ | Disciplines | Global modules in `$DSH_HOME/disciplines/` (migrate/toggle via `ai_discipline`) and project rules in `.ai/disciplines/`; enabled project rules are inlined into §8, disabled ones only listed |
21
+ | Handoff | `.ai/SESSION_BOOT.md` carries status, recent records, disciplines and an inheritance prompt; regenerated by `ai_log` / `ai_init` / `autoInit` |
22
+ | Protected files | An `AGENTS.md` without zone markers is treated as project-owned and never rewritten; the rendered reference goes to `.ai/AGENTS.generated.md`; rewrites are atomic and backed up |
21
23
  | Task list | When `.ai/tasks-enabled` exists, `ai_log` and `ai-ensure` refresh `TASKS.md` at the workspace root |
22
24
  | Cross-project board | When a sibling `.ai/board.md` exists, the board is refreshed after a record is written |
25
+ | Concurrency | `lib/lock.js` cross-process lock + `lib/atomic.js` temp/fsync/rename; `status.json` has a `rev`; PowerShell `llm.ps1` mirrors both |
26
+
27
+ ## What's new in 0.5.0
28
+
29
+ | Change | Effect |
30
+ |---|---|
31
+ | Discipline list | `AGENTS.md` §8 lists global modules (`G*`) and project rules (`P-*`); enabled project rules are inlined, disabled ones only listed |
32
+ | `ai_discipline` | Manages project rules (`.ai/disciplines/`) and global modules (`$DSH_HOME/disciplines/`), including `global-migrate` and per-module toggles that really re-render the injected file |
33
+ | `ai_handoff` | `.ai/SESSION_BOOT.md` carries status, recent records, disciplines and an inheritance prompt; `read` returns the text |
34
+ | Concurrency | Cross-process lock + atomic writes for log, status (`rev`), `TASKS.md`, `SESSION_BOOT.md` and `AGENTS.md` (with backups); `llm.ps1` mirrors the protocol |
35
+ | Drift audit | `ai_check` reports §8 drift (enabled rule not inlined, disabled rule still inlined, registry unreadable) |
23
36
 
24
37
  ## Install
25
38
 
26
39
  - **Plugin Manager (recommended):** Plugins → Add plugin → select this package directory.
27
40
  - **CLI:** `dsh plugin --profile <profile> add <package path or npm name>`
28
- - Restart DSH once; every session in the profile then exposes the five tools.
41
+ - Restart DSH once; every session in the profile then exposes the seven tools.
29
42
 
30
43
  ## Configuration
31
44
 
@@ -47,7 +60,9 @@ Values are normalised and invalid values are reported as warnings in
47
60
  └─ .ai/
48
61
  ├─ llm.ps1 / llm.cmd status / tail / add / check / board / doctor / tasks
49
62
  ├─ log.jsonl append-only, UTF-8 without BOM, LF
50
- ├─ status.json current-state snapshot (overwritten)
63
+ ├─ status.json current-state snapshot (overwritten, `rev` increments)
64
+ ├─ SESSION_BOOT.md cross-session handoff packet
65
+ ├─ disciplines/ project discipline registry + rules/
51
66
  ├─ LOG_FORMAT.md / SECURITY.md / schema/log.schema.json
52
67
  ├─ changelog/ version-level notes and patches
53
68
  ├─ entries/ forwarding masters for Claude Code / Gemini CLI
@@ -68,6 +83,9 @@ A record is one JSON object per line:
68
83
  - Adoption writes only into the workspace, never into system or temp directories.
69
84
  - The plugin performs no network requests and stores no credentials.
70
85
  - Task rendering runs inside the plugin; it never executes a workspace-provided script.
86
+ - Writes are atomic (temp + `fsync` + rename) and record/status updates take `.ai/.log.lock`;
87
+ PowerShell `llm.ps1` uses the same lock protocol. This is cooperative, not an OS guarantee.
88
+ - `install.ps1` backs up `AGENTS.md` to `.ai/backups/` (last 10) before changing it.
71
89
 
72
90
  ## Compatibility
73
91
 
@@ -83,6 +101,9 @@ A record is one JSON object per line:
83
101
  - The bundle declares no display icon fallback for hosts older than the locale/meta support.
84
102
  - A legacy `AGENTS.md` without zone markers is frozen by design; migrate explicitly with
85
103
  `install.ps1 -ForceAgents` (moves old content into the user zone) or `-ResetAgents`.
104
+ - Global discipline toggles require a prior `ai_discipline global-migrate`; they rewrite
105
+ `$DSH_HOME/AGENTS.md`, and a global module cannot be disabled for a single project.
106
+ - §8 of a project `AGENTS.md` refreshes on the next `ai-ensure` / `install.ps1` render.
86
107
 
87
108
  ## License
88
109
 
package/docs/index.html CHANGED
@@ -484,7 +484,7 @@
484
484
  <svg class="logo" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="8" fill="#0d6b5b"/><path d="M9 11h14M9 16h9M9 21h11" stroke="#8fe7d1" stroke-width="2.6" stroke-linecap="round"/></svg>
485
485
  <span>dsh-ai-collab</span>
486
486
  </a>
487
- <span class="ver">v0.4.4</span>
487
+ <span class="ver">v0.5.0</span>
488
488
  <nav class="top-nav" aria-label="页面导航">
489
489
  <a href="#problem">问题</a>
490
490
  <a href="#model">机制</a>
@@ -561,13 +561,14 @@
561
561
  <li><a href="#records"><span class="n">04</span>记录:本地留存与追溯</a></li>
562
562
  <li><a href="#zones"><span class="n">05</span>分区:模板与事实各管各的</a></li>
563
563
  <li><a href="#discipline"><span class="n">06</span>纪律:随会话加载</a></li>
564
- <li><a href="#start"><span class="n">07</span>上手:三条命令</a></li>
565
- <li><a href="#status"><span class="n">08</span>边界与发布状态</a></li>
566
- <li><a href="#summary"><span class="n">09</span>结语</a></li>
564
+ <li><a href="#handoff"><span class="n">07</span>交接:接棒提示词与并发</a></li>
565
+ <li><a href="#start"><span class="n">08</span>上手:三条命令</a></li>
566
+ <li><a href="#status"><span class="n">09</span>边界与发布状态</a></li>
567
+ <li><a href="#summary"><span class="n">10</span>结语</a></li>
567
568
  </ol>
568
569
  </nav>
569
570
  <div class="side-card">
570
- <div class="sc-row"><span class="pulse" aria-hidden="true"></span>已发布 · 0.4.4</div>
571
+ <div class="sc-row"><span class="pulse" aria-hidden="true"></span>已发布 · 0.5.0</div>
571
572
  <p>npm 已上架,社区市场已收录;脚手架当前支持 Windows。</p>
572
573
  <button class="print-btn" type="button" id="printBtn" onclick="window.print()">打印 / 保存为 PDF</button>
573
574
  </div>
@@ -845,7 +846,7 @@
845
846
  <section class="sec" id="discipline">
846
847
  <p class="kicker"><span class="bar" aria-hidden="true"></span>06 · 全局纪律</p>
847
848
  <h2>全局纪律,随每个会话加载</h2>
848
- <p class="lead">插件附带用户级纪律模板 <code>AGENTS.global.template.md</code>:复制到 <code>$DSH_HOME/AGENTS.md</code>(已有全局文件则合并),DSH 会在每个会话注入它——不依赖模型记性,也不依赖项目是否已经接入。它是可加载的:改一次文件,之后每个会话都带着同一套纪律开始。</p>
849
+ <p class="lead">纪律现在由插件管理,不再靠手抄。全局纪律驻留在 <code>$DSH_HOME/AGENTS.md</code>,DSH 在每个会话无条件注入;<code>ai_discipline global-migrate</code> 把它拆成 8 个可独立开关的模块(<code>g0.md</code>…<code>g7.md</code>),之后 <code>global-disable g7</code> 这样一条调用就能让某节纪律从提示词里真正消失。</p>
849
850
 
850
851
  <div class="loadmap" aria-label="纪律加载链路">
851
852
  <div><span class="lm-k">01 · 安装</span><b>$DSH_HOME/AGENTS.md</b><span>跨项目纪律,一份文件</span></div>
@@ -856,6 +857,7 @@
856
857
 
857
858
  <div class="callout">
858
859
  <p><strong>全局文件只放跨项目纪律,没有任何项目事实。</strong>项目事实留在 <code>&lt;项目根&gt;/AGENTS.md</code>。编辑全局文件对下一次请求立即生效,无需重启;插件代码升级才需要重启 DSH。</p>
860
+ <p><strong>能做什么、不能做什么:</strong>可以全局停用某一节纪律,也可以给单个项目追加更严的规则;但<strong>不能只对某个项目卸载全局纪律</strong>——DSH 注入全局文件是无条件的,项目级只能「加」不能「减」。</p>
859
861
  </div>
860
862
 
861
863
  <div class="rules">
@@ -905,14 +907,72 @@
905
907
  </div>
906
908
 
907
909
  <div class="code-wrap">
908
- <pre class="code powershell"><code><span class="c"># 首次:把模板复制到 DSH 用户目录(已有全局文件则合并,不要直接覆盖)</span>
909
- Copy-Item <span class="s">"&lt;包目录&gt;\AGENTS.global.template.md"</span> <span class="s">"$env:DSH_HOME\AGENTS.md"</span></code></pre>
910
+ <pre class="code powershell"><code><span class="c"># 首次:把已有的全局 AGENTS.md 拆成可开关的模块(先备份,原文逐字节保留)</span>
911
+ ai_discipline action:global-migrate
912
+
913
+ <span class="c"># 日常:全局模块开关,改完立即重渲染 $DSH_HOME/AGENTS.md</span>
914
+ ai_discipline action:global-list
915
+ ai_discipline action:global-disable id:g7
916
+ ai_discipline action:global-enable id:g7
917
+
918
+ <span class="c"># 项目级:只对这个项目追加更严的规则,正文会内联进 AGENTS.md §8</span>
919
+ ai_discipline action:add id:no-force-push title:<span class="s">"禁止强推主干"</span> `
920
+ body:<span class="s">"推送前先确认远端状态;禁止 git push --force 到 main。"</span>
921
+ ai_discipline action:disable id:no-force-push <span class="c"># 只保留表行,不再约束</span></code></pre>
922
+ </div>
923
+
924
+ <div class="callout">
925
+ <p><strong>§8 是自检点。</strong>项目 <code>AGENTS.md</code> 的 generated 区里有一张纪律清单:全局行 <code>G0…G7</code> 只做索引(正文在全局文件里),项目行 <code>P-*</code> 的正文按「启用」内联。规则文件是纯 Markdown,人和工具都能改;<code>ai_check</code> 会报告漂移——启用了却没内联、停用了却还内联、注册表读不出来。</p>
910
926
  </div>
911
927
  </section>
912
928
 
913
929
  <!-- 07 -->
930
+ <section class="sec" id="handoff">
931
+ <p class="kicker"><span class="bar" aria-hidden="true"></span>07 · 交接与并发</p>
932
+ <h2>新会话先读一份「接棒提示词」</h2>
933
+ <p class="lead">原始日志是事件流,不适合当成开场白。插件维护一份 <code>.ai/SESSION_BOOT.md</code>:当前状态、最近记录、纪律清单、必读顺序,以及「读完请输出继承摘要」的指令。<code>ai_log</code>、<code>ai_init</code> 与自动接入都会重写它,<code>ai_handoff</code> 负责读取、重建和生成可粘贴的继承提示。</p>
934
+
935
+ <div class="loadmap" aria-label="交接链路">
936
+ <div><span class="lm-k">01 · 读取</span><b>SESSION_BOOT.md</b><span>接棒提示词与必读顺序</span></div>
937
+ <div><span class="lm-k">02 · 加载</span><b>status.json + log.jsonl</b><span>状态快照与最近流水</span></div>
938
+ <div><span class="lm-k">03 · 汇报</span><b>继承摘要</b><span>5–8 行,事实全部来自文件</span></div>
939
+ <div><span class="lm-k">04 · 开干</span><b>本轮任务</b><span>接着已有进度,不重新摸一遍</span></div>
940
+ </div>
941
+
942
+ <div class="code-wrap">
943
+ <pre class="code powershell"><code><span class="c"># 新会话开场:读接棒提示词(文件缺失时先生成再返回原文)</span>
944
+ ai_handoff action:read
945
+
946
+ <span class="c"># 或者直接要一段可粘贴给新会话的继承指令</span>
947
+ ai_handoff action:inherit
948
+
949
+ <span class="c"># 收工写记录时会自动重建 SESSION_BOOT.md</span>
950
+ &amp; .ai\llm.cmd add -Tool deepseek-harness -Action fix -Status ok -Summary <span class="s">"…"</span></code></pre>
951
+ </div>
952
+
953
+ <h3 class="subhead">多会话同时写,不会写坏文件</h3>
954
+ <div class="table-wrap">
955
+ <table>
956
+ <thead><tr><th>风险</th><th>做法</th><th>结果</th></tr></thead>
957
+ <tbody>
958
+ <tr><td>两个会话同时写日志</td><td><code>.ai/.log.lock</code> 跨进程锁,append 与状态更新在同一临界区</td><td>12 个进程并发写入 → 12 条记录、id 全唯一、<code>rev=12</code></td></tr>
959
+ <tr><td>写到一半被读到</td><td>临时文件 + <code>fsync</code> + rename 原子替换(对占用/权限错误退避重试)</td><td>读者只会看到旧版或新版,没有半截文件</td></tr>
960
+ <tr><td><code>TASKS.md</code> 被并行覆盖</td><td><code>.ai/.tasks.lock</code> 内整份重渲染</td><td>清单始终与日志一致</td></tr>
961
+ <tr><td><code>AGENTS.md</code> 改坏</td><td>原子写 + 写前备份到 <code>.ai/backups/</code>(保留最近 10 份)</td><td>可回滚;<code>-ResetAgents</code> 也有备份</td></tr>
962
+ <tr><td>状态快照丢更新</td><td><code>status.json</code> 增加自增 <code>rev</code>,写入在锁内完成</td><td><code>rev</code> 可作为「有没有丢写」的快速判断</td></tr>
963
+ <tr><td>纪律与实际渲染不一致</td><td><code>ai_check</code> 审计 §8 漂移</td><td>启用未内联 / 停用仍内联 / 注册表损坏都会报错</td></tr>
964
+ </tbody>
965
+ </table>
966
+ </div>
967
+
968
+ <div class="callout">
969
+ <p><strong>边界要说清:</strong>这是插件与 <code>.ai/llm.cmd</code> 之间的<strong>协作锁</strong>,不是操作系统级保证。用编辑器或别的脚本直接改这些文件,仍然可以绕过锁;<code>initScript</code> 是可信配置,不要指向不可信代码。</p>
970
+ </div>
971
+ </section>
972
+
973
+ <!-- 08 -->
914
974
  <section class="sec" id="start">
915
- <p class="kicker"><span class="bar" aria-hidden="true"></span>07 · 快速开始</p>
975
+ <p class="kicker"><span class="bar" aria-hidden="true"></span>08 · 快速开始</p>
916
976
  <h2>三条命令,开始交接</h2>
917
977
  <p class="lead">安装一次,之后每个会话只重复三个动作:读状态、干活、写记录。</p>
918
978
 
@@ -942,7 +1002,7 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
942
1002
  autoInit: true</code></pre>
943
1003
  </div>
944
1004
  </div>
945
- <p class="note">安装后重启 DSH;profile 内所有会话都会出现 5 个工具。首次进入某个项目时,先调用 <code>ai_init</code>(或把 <code>autoInit</code> 设为 <code>true</code>)生成 <code>.ai/</code> 与 <code>AGENTS.md</code>,之后按下面的动作循环。若包只进了依赖、未进 <code>dsh.profile.bundles</code>,需要手动补一行。</p>
1005
+ <p class="note">安装后重启 DSH;profile 内所有会话都会出现 7 个工具。首次进入某个项目时,先调用 <code>ai_init</code>(或把 <code>autoInit</code> 设为 <code>true</code>)生成 <code>.ai/</code> 与 <code>AGENTS.md</code>,之后按下面的动作循环。若包只进了依赖、未进 <code>dsh.profile.bundles</code>,需要手动补一行。</p>
946
1006
 
947
1007
  <div class="code-wrap">
948
1008
  <pre class="code powershell"><code><span class="c"># 开工:同步并读状态(约 10 秒)</span>
@@ -956,12 +1016,14 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
956
1016
  &amp; .ai\llm.cmd check</code></pre>
957
1017
  </div>
958
1018
 
959
- <div class="tools-chips" aria-label="五个原生工具">
1019
+ <div class="tools-chips" aria-label="七个原生工具">
960
1020
  <div class="toolchip"><b>ai_status</b><span>读状态与最近记录</span></div>
961
1021
  <div class="toolchip"><b>ai_log</b><span>追加一条记录</span></div>
962
1022
  <div class="toolchip"><b>ai_check</b><span>校验日志与状态</span></div>
963
1023
  <div class="toolchip"><b>ai_board</b><span>跨项目只读看板</span></div>
964
1024
  <div class="toolchip"><b>ai_init</b><span>幂等接入工作区</span></div>
1025
+ <div class="toolchip"><b>ai_discipline</b><span>纪律清单与开关</span></div>
1026
+ <div class="toolchip"><b>ai_handoff</b><span>跨会话交接摘要</span></div>
965
1027
  </div>
966
1028
 
967
1029
  <h3 class="subhead">常用命令</h3>
@@ -994,17 +1056,17 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
994
1056
  </div>
995
1057
  </section>
996
1058
 
997
- <!-- 08 -->
1059
+ <!-- 09 -->
998
1060
  <section class="sec" id="status">
999
- <p class="kicker"><span class="bar" aria-hidden="true"></span>08 · 边界与状态</p>
1061
+ <p class="kicker"><span class="bar" aria-hidden="true"></span>09 · 边界与状态</p>
1000
1062
  <h2>已发布,边界清晰</h2>
1001
- <p class="lead">0.4.4 已上 npm 并被社区插件市场收录;脚手架目前仅支持 Windows,只读工具与任务渲染本身与平台无关。</p>
1063
+ <p class="lead">0.5.0 已上 npm 并被社区插件市场收录;脚手架目前仅支持 Windows,只读工具与任务渲染本身与平台无关。</p>
1002
1064
 
1003
1065
  <div class="release">
1004
1066
  <div class="rel">
1005
1067
  <div class="rel-top"><span>npm</span><span class="badge-ok">已发布</span></div>
1006
- <b>dsh-ai-collab@0.4.4</b>
1007
- <span>2026-11-20 上架,可直接安装</span>
1068
+ <b>dsh-ai-collab@0.5.0</b>
1069
+ <span>2026-11-23 上架,可直接安装</span>
1008
1070
  </div>
1009
1071
  <div class="rel">
1010
1072
  <div class="rel-top"><span>GitHub</span><span class="badge-ok">已就绪</span></div>
@@ -1023,6 +1085,26 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
1023
1085
  </div>
1024
1086
  </div>
1025
1087
 
1088
+ <h3 class="subhead">0.5.0 更新摘要</h3>
1089
+ <div class="rules">
1090
+ <div class="rule">
1091
+ <span class="rule-n">新</span>
1092
+ <div><h3>纪律清单与开关</h3><p><code>AGENTS.md</code> 新增 generated 区 §8:全局 <code>G0…G7</code> 索引 + 项目 <code>P-*</code> 规则(启用内联)。新工具 <code>ai_discipline</code> 负责项目增删启停,以及全局模块的迁移与开关。</p></div>
1093
+ </div>
1094
+ <div class="rule">
1095
+ <span class="rule-n">新</span>
1096
+ <div><h3>跨会话交接</h3><p><code>.ai/SESSION_BOOT.md</code> + <code>ai_handoff</code>:接棒提示词、必读顺序、继承摘要要求;<code>ai_log</code> / <code>ai_init</code> / 自动接入时自动重建。</p></div>
1097
+ </div>
1098
+ <div class="rule">
1099
+ <span class="rule-n">固</span>
1100
+ <div><h3>并发与文件保护</h3><p>跨进程锁 + 原子写覆盖日志、状态(<code>rev</code>)、<code>TASKS.md</code>、<code>SESSION_BOOT.md</code> 与 <code>AGENTS.md</code>;<code>llm.ps1</code> 同步实现;<code>ai_check</code> 增加 §8 漂移审计。</p></div>
1101
+ </div>
1102
+ <div class="rule">
1103
+ <span class="rule-n">测</span>
1104
+ <div><h3>验证</h3><p>25 个测试全通过;12 进程并发写 12 条无丢失、<code>rev=12</code>;6 个 PowerShell <code>add</code> 并发无丢失;纪律增删启停与全局模块停用/恢复均实测。</p></div>
1105
+ </div>
1106
+ </div>
1107
+
1026
1108
  <h3 class="subhead">兼容性</h3>
1027
1109
  <div class="table-wrap">
1028
1110
  <table>
@@ -1042,16 +1124,18 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
1042
1124
  <li><span class="lm">2</span><span><strong>尚未导出 Config schema。</strong>配置在进程内归一化,非法值写入 <code>ai-collab-config.log</code>,不会静默沿用。</span></li>
1043
1125
  <li><span class="lm">3</span><span><strong>旧 AGENTS.md 被冻结。</strong>无分区标记的文件不会自动升级,需显式 <code>-ForceAgents</code> 或 <code>-ResetAgents</code>。</span></li>
1044
1126
  <li><span class="lm">4</span><span><strong>看板依赖目录布局。</strong>仅当兄弟项目共享父级 <code>.ai\board.md</code> 时生成跨项目看板。</span></li>
1045
- <li><span class="lm">5</span><span><strong>生效时机不同。</strong>插件代码改动需重启 DSH;全局 <code>AGENTS.md</code> 编辑对下一次请求立即生效。</span></li>
1127
+ <li><span class="lm">5</span><span><strong>生效时机不同。</strong>插件代码改动需重启 DSH;全局 <code>AGENTS.md</code> 编辑对下一次请求立即生效;项目 §8 纪律清单在下次 <code>ai-ensure</code> 渲染时刷新。</span></li>
1128
+ <li><span class="lm">6</span><span><strong>全局纪律只能整体开关。</strong>停用/启用会重渲染 <code>$DSH_HOME/AGENTS.md</code>,且必须先 <code>global-migrate</code>;不能只对某个项目停用某节全局纪律。</span></li>
1129
+ <li><span class="lm">7</span><span><strong>锁是协作式的。</strong>插件与 <code>.ai/llm.cmd</code> 遵守同一套锁协议;外部编辑器直接改文件仍可能绕过。单个项目日志建议不超过 2 MB 并及时 <code>archive</code>。</span></li>
1046
1130
  </ul>
1047
1131
 
1048
1132
  <p class="roadmap"><b>下一步:</b>跨平台 Node 脚手架 · 导出 Config schema。市场详情页:<a href="https://awesome-dsh-plugin.com/p/ZhuYw3927/dsh-ai-collab/" target="_blank" rel="noopener">awesome-dsh-plugin.com/p/ZhuYw3927/dsh-ai-collab</a></p>
1049
1133
  </section>
1050
1134
 
1051
- <!-- 09 -->
1135
+ <!-- 10 -->
1052
1136
  <section class="sec" id="summary">
1053
1137
  <div class="closing">
1054
- <p class="kicker"><span class="bar" aria-hidden="true"></span>09 · 结语</p>
1138
+ <p class="kicker"><span class="bar" aria-hidden="true"></span>10 · 结语</p>
1055
1139
  <h2>它不发明新的工作流,只是让「交底、记账、校验」留在仓库里。</h2>
1056
1140
  <p>于是工具可以换、会话可以断、维护者可以更替,而项目的进度与判断依据不会丢。这就是 dsh-ai-collab 的全部野心:把一次性的会话成本,变成可继承的项目资产。</p>
1057
1141
  <div class="closing-chips">
@@ -1065,7 +1149,7 @@ dsh plugin --profile &lt;profile&gt; add "&lt;包绝对路径&gt;"</code></pre>
1065
1149
 
1066
1150
  <footer class="site-footer">
1067
1151
  <div class="foot-inner">
1068
- <div>本文基于项目 <code>AGENTS.md</code>、<code>dsh-ai-collab.md</code>、插件 README 与发布记录整理 · 2026-11-20 · 对应版本 0.4.4</div>
1152
+ <div>本文基于项目 <code>AGENTS.md</code>、<code>dsh-ai-collab.md</code>、插件 README 与发布记录整理 · 2026-11-23 · 对应版本 0.5.0</div>
1069
1153
  <div class="foot-links">
1070
1154
  <a href="https://www.npmjs.com/package/dsh-ai-collab" target="_blank" rel="noopener">npm</a>
1071
1155
  <a href="https://github.com/ZhuYw3927/dsh-ai-collab" target="_blank" rel="noopener">GitHub</a>