devlog-tracker 0.22.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.
- package/LICENSE +201 -0
- package/README.md +234 -0
- package/bin/devlog-tracker.js +51 -0
- package/cli/init.js +55 -0
- package/cli/init.test.js +37 -0
- package/cli/merge-hooks.js +60 -0
- package/cli/merge-hooks.test.js +187 -0
- package/cli/platforms/codex.js +13 -0
- package/cli/platforms/cursor.js +13 -0
- package/cli/status.js +14 -0
- package/cli/status.test.js +33 -0
- package/cli/vendor.js +37 -0
- package/cli/vendor.test.js +84 -0
- package/codex/hooks/on-pre-tool.sh +19 -0
- package/codex/hooks/on-session-end.sh +31 -0
- package/codex/hooks/on-session-start.sh +37 -0
- package/codex/hooks/on-stop.sh +18 -0
- package/codex/hooks/on-user-prompt-submit.sh +15 -0
- package/codex/hooks/project-dir.sh +13 -0
- package/codex/hooks/test-adapters.sh +98 -0
- package/codex/hooks.json +54 -0
- package/commands/checkpoint.md +17 -0
- package/commands/clean.md +50 -0
- package/commands/compact.md +24 -0
- package/commands/continue.md +30 -0
- package/commands/keep.md +100 -0
- package/commands/lessons-drift.md +19 -0
- package/commands/lessons-off.md +16 -0
- package/commands/lessons-on.md +20 -0
- package/commands/lessons.md +20 -0
- package/commands/overview.md +32 -0
- package/commands/pause.md +20 -0
- package/commands/resume.md +18 -0
- package/commands/segment-watch.md +21 -0
- package/commands/span.md +13 -0
- package/commands/start.md +19 -0
- package/commands/status.md +14 -0
- package/cursor/hooks/on-pre-tool.sh +24 -0
- package/cursor/hooks/on-session-end.sh +11 -0
- package/cursor/hooks/on-session-start.sh +15 -0
- package/cursor/hooks/on-stop.sh +44 -0
- package/cursor/hooks/on-submit-prompt.sh +28 -0
- package/cursor/hooks/on-tool-failure.sh +16 -0
- package/cursor/hooks/project-dir.sh +10 -0
- package/cursor/hooks/test-adapters.sh +201 -0
- package/cursor/hooks.json +26 -0
- package/hooks/scripts/await-open.sh +23 -0
- package/hooks/scripts/checkpoint-set.sh +44 -0
- package/hooks/scripts/clean-devlog.sh +69 -0
- package/hooks/scripts/close-open-round.sh +186 -0
- package/hooks/scripts/compact-devlog.sh +72 -0
- package/hooks/scripts/detect-pending-question.sh +31 -0
- package/hooks/scripts/devlog-lock.sh +38 -0
- package/hooks/scripts/devlog-md.sh +222 -0
- package/hooks/scripts/devlog-path.sh +70 -0
- package/hooks/scripts/enforce-devlog.sh +629 -0
- package/hooks/scripts/files-snapshot.sh +70 -0
- package/hooks/scripts/json-field.sh +76 -0
- package/hooks/scripts/keep-move.sh +155 -0
- package/hooks/scripts/kept-list.sh +40 -0
- package/hooks/scripts/lessons-append.sh +93 -0
- package/hooks/scripts/lessons-drift-set.sh +42 -0
- package/hooks/scripts/lessons-off.sh +15 -0
- package/hooks/scripts/lessons-on.sh +21 -0
- package/hooks/scripts/lessons-read.sh +60 -0
- package/hooks/scripts/on-session-end.sh +14 -0
- package/hooks/scripts/on-stop-failure.sh +18 -0
- package/hooks/scripts/on-tool-failure.sh +25 -0
- package/hooks/scripts/pause-devlog.sh +13 -0
- package/hooks/scripts/redact-prompt.sh +19 -0
- package/hooks/scripts/resume-devlog.sh +41 -0
- package/hooks/scripts/round-start.sh +333 -0
- package/hooks/scripts/run-tests.sh +26 -0
- package/hooks/scripts/segment-watch-set.sh +47 -0
- package/hooks/scripts/segment-watch.sh +197 -0
- package/hooks/scripts/session-start-devlog.sh +157 -0
- package/hooks/scripts/span-close.sh +9 -0
- package/hooks/scripts/span-open.sh +21 -0
- package/hooks/scripts/start-devlog.sh +24 -0
- package/hooks/scripts/status-devlog.sh +43 -0
- package/hooks/scripts/tests/test-await-open.sh +112 -0
- package/hooks/scripts/tests/test-branch-scoped-integration.sh +108 -0
- package/hooks/scripts/tests/test-checkpoint-set.sh +36 -0
- package/hooks/scripts/tests/test-clean-devlog.sh +160 -0
- package/hooks/scripts/tests/test-cli-init-e2e.sh +37 -0
- package/hooks/scripts/tests/test-close-open-round.sh +325 -0
- package/hooks/scripts/tests/test-compact-devlog.sh +62 -0
- package/hooks/scripts/tests/test-devlog-lock.sh +37 -0
- package/hooks/scripts/tests/test-devlog-md.sh +530 -0
- package/hooks/scripts/tests/test-devlog-path.sh +118 -0
- package/hooks/scripts/tests/test-enforce-devlog-files.sh +233 -0
- package/hooks/scripts/tests/test-enforce-devlog-handoff-order.sh +223 -0
- package/hooks/scripts/tests/test-enforce-devlog-workspace.sh +333 -0
- package/hooks/scripts/tests/test-enforce-devlog.sh +1290 -0
- package/hooks/scripts/tests/test-files-snapshot.sh +142 -0
- package/hooks/scripts/tests/test-json-field.sh +57 -0
- package/hooks/scripts/tests/test-keep-move.sh +127 -0
- package/hooks/scripts/tests/test-kept-list.sh +80 -0
- package/hooks/scripts/tests/test-lessons-append.sh +138 -0
- package/hooks/scripts/tests/test-lessons-drift-set.sh +36 -0
- package/hooks/scripts/tests/test-lessons-on-off.sh +75 -0
- package/hooks/scripts/tests/test-lessons-read.sh +97 -0
- package/hooks/scripts/tests/test-on-interrupt.sh +186 -0
- package/hooks/scripts/tests/test-redact-prompt.sh +27 -0
- package/hooks/scripts/tests/test-resume-devlog.sh +35 -0
- package/hooks/scripts/tests/test-round-start.sh +825 -0
- package/hooks/scripts/tests/test-segment-watch-set.sh +75 -0
- package/hooks/scripts/tests/test-segment-watch.sh +468 -0
- package/hooks/scripts/tests/test-session-start-devlog.sh +508 -0
- package/hooks/scripts/tests/test-start-pause-devlog.sh +84 -0
- package/hooks/scripts/tests/test-status-span.sh +50 -0
- package/hooks/scripts/tests/test-workspace-snapshot.sh +130 -0
- package/hooks/scripts/workspace-snapshot.sh +69 -0
- package/package.json +37 -0
- package/skills/devlog-tracker/SKILL.md +411 -0
- package/skills/devlog-tracker/references/checkpoint-mode.md +42 -0
- package/skills/devlog-tracker/references/lessons-mode.md +32 -0
- package/skills/devlog-tracker/references/reply-fold.md +129 -0
- package/skills/devlog-tracker/references/round-segments.md +55 -0
- package/skills/devlog-tracker/references/span-mode.md +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing
|
|
141
|
+
the origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [<your-github-handle>]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# devlog-tracker
|
|
2
|
+
|
|
3
|
+
**版本** 0.22.0
|
|
4
|
+
|
|
5
|
+
在專案中維護一份 `.devlog/devlog.md`,把每一輪對話的請求、決策與結果寫成永久紀錄。對話一 `/clear` 或換 session 就沒了;這份檔案取代那個缺口,讓工作可以中斷再接。沒下過 `/devlog-tracker:start` 時,裝著也不會動任何檔案。
|
|
6
|
+
|
|
7
|
+
## 這是什麼
|
|
8
|
+
|
|
9
|
+
把「這輪做了什麼、決定了什麼、下一步是什麼」寫進專案內的 `devlog.md`。Stop hook 保證每輪都寫完才放行;沒明確 `/devlog-tracker:start` 前不會建立或改動 `.devlog/`。
|
|
10
|
+
|
|
11
|
+
`devlog.md` 只管**跨 session 的交接連續性**(決策軌跡、目前卡點、完成條件、下一步),並作為 **L1**(人觸發 continue/開 session 注入後,agent 只靠 SSOT 接手,且必須把本輪狀態**寫回**本檔)的主入口。不是整個專案的單一真相來源:
|
|
12
|
+
|
|
13
|
+
- 程式碼/檔案狀態的真相仍是 git
|
|
14
|
+
- 完整逐字過程的真相是對話 transcript(`/clear` 後不存在)
|
|
15
|
+
- 設計決策的真相是 `docs/design/*.md`
|
|
16
|
+
|
|
17
|
+
這份檔案只是取代「終端機一 clear 就沒了」的缺口,讓工作可以隨時中斷、隨時接續。L2(無人喚醒)與 L3(跨機共享 `.devlog/`)不在範圍;細節見 [`docs/design/devlog-as-ssot-assessment.md`](docs/design/devlog-as-ssot-assessment.md)。
|
|
18
|
+
|
|
19
|
+
每輪收尾固定寫 `Summary`/`Reply`(對使用者說過的話)/`Handoff`(含未完成時的 `完成條件`)/`Status`。接手=核對工作區 → 做下一步 → **寫回**;讀而不寫算交接失敗。
|
|
20
|
+
|
|
21
|
+
## 安裝
|
|
22
|
+
|
|
23
|
+
作為 Claude Code plugin 安裝(會自動更新):
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
/plugin marketplace add gogogohuang/devlog-tracker
|
|
27
|
+
/plugin install devlog-tracker@devlog-tracker
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### npx(Cursor/Codex 用)
|
|
31
|
+
|
|
32
|
+
Claude Code 請用上面的 `/plugin marketplace add` 安裝方式;這個 CLI 不會設定 Claude Code。
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx devlog-tracker init
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
沒帶 `--codex`/`--cursor` 時會互動式問要裝哪個平台;在沒有 TTY 的環境(例如 CI)且沒帶旗標時,`init` 不會詢問,直接安裝所有支援的平台(codex + cursor)。也可以直接指定:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx devlog-tracker init --codex --cursor
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
會把 `hooks/scripts/`、`codex/hooks/`、`cursor/hooks/`、`skills/`、`commands/`
|
|
45
|
+
複製進專案的 `.devlog-tracker/`,並把對應平台的 `hooks.json` 合併進專案(不覆蓋
|
|
46
|
+
其他工具已設定的 hook)。重新執行 `npx devlog-tracker init` 可以升級到套件目前的
|
|
47
|
+
版本;`npx devlog-tracker status` 可以查目前裝的版本是否落後。
|
|
48
|
+
|
|
49
|
+
`init` 會把這台機器專屬的絕對路徑寫進 `.codex/hooks.json`、`.cursor/hooks.json` 與
|
|
50
|
+
`.devlog-tracker/env.sh`。如果你把這些檔案 commit 進 git,每位隊友都要在自己的機器上
|
|
51
|
+
跑一次 `npx devlog-tracker init`(路徑每台機器不同);或者改成把 `.devlog-tracker/` 與
|
|
52
|
+
產生出來的 hooks.json 加進 `.gitignore`。
|
|
53
|
+
|
|
54
|
+
### Cursor(選用)
|
|
55
|
+
|
|
56
|
+
Claude Code 仍是主要安裝方式。若要在 Cursor workspace 使用,先設定
|
|
57
|
+
`DEVLOG_TRACKER_ROOT` 為本 plugin 的絕對路徑,再把 `cursor/hooks.json` 的
|
|
58
|
+
`hooks` 合併進專案 `.cursor/hooks.json`。也可以把整個 `cursor/hooks/` 與
|
|
59
|
+
`hooks/scripts/` vendoring 到專案,並調整 command 路徑;兩者的相對目錄必須維持可用。
|
|
60
|
+
|
|
61
|
+
Cursor cloud agent 不執行 `sessionStart`,因此不會自動注入接手摘要;其他已設定的
|
|
62
|
+
hook 仍依 Cursor 支援的事件執行。
|
|
63
|
+
|
|
64
|
+
Cursor 沒有 `/devlog-tracker:*` slash 指令面;hooks 裝好後,請用與 Claude commands
|
|
65
|
+
相同的腳本(`commands/*.md` 會優先讀 `CLAUDE_PLUGIN_ROOT`,否則讀
|
|
66
|
+
`DEVLOG_TRACKER_ROOT`):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
export DEVLOG_TRACKER_ROOT=/absolute/path/to/devlog-tracker
|
|
70
|
+
export CLAUDE_PROJECT_DIR="$(pwd)"
|
|
71
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/start-devlog.sh"
|
|
72
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/status-devlog.sh"
|
|
73
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/segment-watch-set.sh" 600
|
|
74
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/checkpoint-set.sh" 20
|
|
75
|
+
# pause / span-open / span-close / compact / keep-move / clean / resume:見 commands/*.md
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Codex(選用)
|
|
79
|
+
|
|
80
|
+
Claude Code 仍是主要安裝方式。若要在 Codex CLI 使用,先設定
|
|
81
|
+
`DEVLOG_TRACKER_ROOT` 為本 plugin 的絕對路徑,再把 `codex/hooks.json` 的
|
|
82
|
+
`hooks` 合併進專案(或 `~/.codex/`)的 `hooks.json`。也可以把整個 `codex/hooks/` 與
|
|
83
|
+
`hooks/scripts/` vendoring 到專案,並調整 command 路徑;兩者的相對目錄必須維持可用。
|
|
84
|
+
|
|
85
|
+
Codex 目前沒有對應「使用者中斷」(Claude Code 的 `PostToolUseFailure`/
|
|
86
|
+
`is_interrupt`)與「這輪異常結束」(`StopFailure`)的事件,這兩種細節狀態在
|
|
87
|
+
Codex 上不會被標記成 `INTERRUPTED`;核心強制記錄機制(`Stop` 事件擋住未寫完的
|
|
88
|
+
輪次)不受影響。
|
|
89
|
+
|
|
90
|
+
Codex 沒有 `/devlog-tracker:*` slash 指令面;hooks 裝好後,請用與 Claude commands
|
|
91
|
+
相同的腳本(`commands/*.md` 會優先讀 `CLAUDE_PLUGIN_ROOT`,否則讀
|
|
92
|
+
`DEVLOG_TRACKER_ROOT`):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
export DEVLOG_TRACKER_ROOT=/absolute/path/to/devlog-tracker
|
|
96
|
+
export CLAUDE_PROJECT_DIR="$(pwd)"
|
|
97
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/start-devlog.sh"
|
|
98
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/status-devlog.sh"
|
|
99
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/segment-watch-set.sh" 600
|
|
100
|
+
bash "$DEVLOG_TRACKER_ROOT/hooks/scripts/checkpoint-set.sh" 20
|
|
101
|
+
# pause / span-open / span-close / compact / keep-move / clean / resume:見 commands/*.md
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 快速開始
|
|
105
|
+
|
|
106
|
+
在專案裡下一次:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
/devlog-tracker:start
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
之後正常跟 Claude 對話即可,每一輪結束前都會被強制檢查、補上 `.devlog/devlog.md` 的紀錄。`/clear` 之後 context 是空的;要接著做上一題,下 `/devlog-tracker:continue`。暫停、歸檔、具名搬走、狀態與 span 見下方指令表(完整 namespace,plugin 名稱是 `devlog-tracker`)。
|
|
113
|
+
|
|
114
|
+
## 指令
|
|
115
|
+
|
|
116
|
+
| 指令 | 做什麼 |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `/devlog-tracker:start` | 跑腳本建立 `.devlog/.enabled`(缺的 state 檔會補上,已有門檻不重置)。讀檔對進度,不自動開工。`.devlog/` 含 prompt,會建議加進 `.gitignore`,要你同意才改。 |
|
|
119
|
+
| `/devlog-tracker:continue` | 讀 `.devlog/devlog.md`,核對最後一輪 Handoff「工作區」後再依下一步接著做。`/clear` 之後要接續用這個。細節見 [`docs/design/continue.md`](docs/design/continue.md)。 |
|
|
120
|
+
| `/devlog-tracker:pause` | 暫停強制記錄,歷史檔不動,之後可再 `start`。 |
|
|
121
|
+
| `/devlog-tracker:compact` | 腳本把較舊的 `DONE` 輪次搬到 `devlog.archive.md`(Checkpoint 與未完成輪留在主檔)。 |
|
|
122
|
+
| `/devlog-tracker:keep` | 掃全檔分主題,一次列出建議,確認後把各段各自搬走成 `devlog.<name>.md`(並在主檔留一個 `## Kept 索引` 指標行,含一句主題描述);也可抽出一段或合併成全部歷史一檔。不是 compact。細節見 [`docs/design/keep.md`](docs/design/keep.md)。 |
|
|
123
|
+
| `/devlog-tracker:overview` | 讀完所有已 keep 的 `devlog.<name>.md`,整合成跨主題總覽,並列出看起來該進 `CLAUDE.md` 的規範候選。純讀取,不核對工作區、不等確認、不寫檔。細節見 [`docs/design/keep.md`](docs/design/keep.md) Kept index。 |
|
|
124
|
+
| `/devlog-tracker:resume <name>` | 讀具名保存檔的最後一輪與 Handoff,核對「工作區」後提出接續;新工作仍寫回主 `devlog.md`。 |
|
|
125
|
+
| `/devlog-tracker:clean` | 無條件清空 `devlog.md`(含專案摘要與所有 Round 歷史),不搬移、不備份、不可復原;執行前一定會先問,要明確回覆「清空」才動手。只留目前開著的那一輪,重編成 `## Round 1`。 |
|
|
126
|
+
| `/devlog-tracker:status` | 查看強制記錄開關、Span、Checkpoint、Segment Watch、Lessons Mode 工作區漂移計數與最後一輪 Status。 |
|
|
127
|
+
| `/devlog-tracker:span` | 開啟或關閉自動續接長任務使用的 Span Mode(不要手寫 `.span-open` JSON)。 |
|
|
128
|
+
| `/devlog-tracker:segment-watch <時間長度>` | 調整 Segment Watch 的沉默門檻(預設 10 分鐘)。專案還沒 `/devlog-tracker:start` 時回報 `NOT_STARTED`,不會建立任何檔案。 |
|
|
129
|
+
| `/devlog-tracker:checkpoint <輪數>` | 調整 Checkpoint Mode 的沉默門檻(預設 20 輪)。專案還沒 start 時回報 `NOT_STARTED`。 |
|
|
130
|
+
| `/devlog-tracker:lessons-on` | 開啟預設關閉的 Lessons Mode(隸屬主開關,沒 `start` 過會拒絕)。細節見 [`docs/design/lessons-mode.md`](docs/design/lessons-mode.md)。 |
|
|
131
|
+
| `/devlog-tracker:lessons-off` | 關閉 Lessons Mode,不動任何已寫的 `devlog.lessons.*.md` 或索引。 |
|
|
132
|
+
| `/devlog-tracker:lessons [<topic>]` | 沒給 topic:印 `## Lessons 索引`。給 topic:印該主題檔全文。純讀取,不核對工作區、不等確認。 |
|
|
133
|
+
| `/devlog-tracker:lessons-drift <次數>` | 調整 Lessons Mode「工作區漂移重複發生」機制性提醒的門檻(預設 3 次)。隸屬 Lessons Mode,沒開會回報 `LESSONS_NOT_ENABLED`。 |
|
|
134
|
+
|
|
135
|
+
## 強制記錄開著之後
|
|
136
|
+
|
|
137
|
+
```mermaid
|
|
138
|
+
sequenceDiagram
|
|
139
|
+
participant U as 使用者
|
|
140
|
+
participant H as Hooks
|
|
141
|
+
participant C as Claude
|
|
142
|
+
participant D as .devlog/devlog.md
|
|
143
|
+
|
|
144
|
+
U->>H: 送出訊息
|
|
145
|
+
H->>D: 先寫 Round skeleton(User Input + IN_PROGRESS)
|
|
146
|
+
C->>D: 補 Summary / Reply / Handoff,改 Status
|
|
147
|
+
C->>H: 這一輪要結束
|
|
148
|
+
alt 沒寫完、標題是空的,或 Status 不合法
|
|
149
|
+
H-->>C: 擋住,要求補寫
|
|
150
|
+
else 寫完了
|
|
151
|
+
H-->>C: 放行
|
|
152
|
+
end
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
每一輪固定:
|
|
156
|
+
|
|
157
|
+
- **`User Input`** — 送出原文優先(hook 寫入;Claude 不要改寫),常見 token 會遮罩
|
|
158
|
+
- **`Summary`** — 給人掃的結論
|
|
159
|
+
- **`Reply`** — 這輪對使用者說過/答應過的話
|
|
160
|
+
- **`Handoff`** — 給下一輪接手(決策/檔案/工作區/現況/完成條件/下一步)
|
|
161
|
+
- **`Status`** — `DONE` / `IN_PROGRESS` / `BLOCKED` / `INTERRUPTED` 四選一
|
|
162
|
+
|
|
163
|
+
其中「工作區」是收尾時的 git 快照,進行中/卡住必寫;`DONE` 若「檔案」有內容(宣稱動過/commit 過檔案)也必寫。「完成條件」在進行中/卡住必寫。
|
|
164
|
+
|
|
165
|
+
Stop hook 會做這些事:
|
|
166
|
+
|
|
167
|
+
1. 確認 `Summary`/`Reply`/`Handoff` 標題底下有內容、Status 是上述四值之一;Handoff 小節順序為 決策 → 檔案 → 工作區 → 現況 → 完成條件 → 下一步
|
|
168
|
+
2. 進行中/卡住時有「完成條件」與「下一步」;「下一步」不是純黑名單空話(例如整節只寫「繼續完成」;字串比對,非語意評分,細節見 [`docs/design/next-step-blacklist.md`](docs/design/next-step-blacklist.md));進行中另做輕量可執行檢查;卡住時「現況」或「下一步」須含缺件句式
|
|
169
|
+
3. 機器核對「工作區」是否跟收尾當下的 git 狀態逐字相符(進行中/卡住一律核對,`DONE` 只在「檔案」非空時核對),避免「已 commit 完成」卻其實沒 commit 這類宣稱跟實際不符
|
|
170
|
+
|
|
171
|
+
`#### 檔案` 非空時同樣機器核對:commit 區塊要跟該次 commit 的實際內容逐字相符,未 commit 的區塊只要求宣稱的路徑真的存在變更(不要求涵蓋全部,避免把跨輪殘留算成這輪漏列)。
|
|
172
|
+
|
|
173
|
+
細節見 [`docs/design/summary-handoff.md`](docs/design/summary-handoff.md)、[`docs/design/devlog-as-ssot-assessment.md`](docs/design/devlog-as-ssot-assessment.md)、[`docs/design/files-verify.md`](docs/design/files-verify.md) 和 SKILL.md。
|
|
174
|
+
|
|
175
|
+
## Hook 會自動做的事
|
|
176
|
+
|
|
177
|
+
正常規則是「一則使用者訊息 = 一輪,結束前一定要寫完 Summary/Reply/Handoff/Status」。下面四個機制各自放寬這條規則的不同一塊,彼此正交、可以同時存在:
|
|
178
|
+
|
|
179
|
+
| 機制 | 放寬的是 | 解決的問題 |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| **Span Mode** | 「每次自動喚醒算不算一輪」 | `/loop`、Workflow 這類被自己排程反覆喚醒、不是使用者手動打字觸發的長任務,每個自動 tick 都強制寫完整 Round,會逼出大量沒意義的紀錄,甚至卡住整條自動化流程 |
|
|
182
|
+
| **Checkpoint Mode** | 「有沒有跨輪的摘要路標」 | 一般互動對話每輪都正常寫,但輪數一多,翻閱的人要逐輪爬完才知道整體進度 |
|
|
183
|
+
| **Reply Fold** | 「一問一答算不算兩輪」 | Claude 用純文字提問、下一則訊息其實是在回答時,預設邏輯(每個 `UserPromptSubmit` 開新 Round)會把這組問答硬拆成兩個不相關的 Round |
|
|
184
|
+
| **Segment Watch** | 「一輪內部要不要留階段性痕跡」 | 一輪做很久(先探索、再決策、再實作、再驗證),憋到最後才寫一次,中途 crash 會把整個過程全部遺失 |
|
|
185
|
+
|
|
186
|
+
以下是各機制實際觸發時的行為:
|
|
187
|
+
|
|
188
|
+
#### 自動接續
|
|
189
|
+
|
|
190
|
+
`SessionStart` hook 在開新 session、resume、`/compact`、`/fork` 時,注入最後一個 Checkpoint(若有)、`## Kept 索引`(若有,不是具名檔內容)加上最近兩輪的 Summary / Handoff / Status,不是整份檔。`/clear` 是真的清空,不注入;要接續請 `/devlog-tracker:continue`(先核對「工作區」再做下一步)。細節見 [`docs/design/continue.md`](docs/design/continue.md)。
|
|
191
|
+
|
|
192
|
+
#### 同輪工作區漂移偵測
|
|
193
|
+
|
|
194
|
+
同一條對話送出下一則訊息時,`UserPromptSubmit` 會拿上一輪 Handoff 的「工作區」跟目前 git 狀態比對;不符就注入提示,並讓 `PreToolUse` 擋住非 devlog 工具,直到這一輪補上含實際快照的 `### 段落`(唯讀的 `git status`/`diff`/`log`/`show`/`rev-parse` 不受影響,方便自行核對)。Span 安靜 tick、task-notification 與 `DONE` 不擋。細節見 [`docs/design/continue.md`](docs/design/continue.md) 與 [`docs/design/segment-watch.md`](docs/design/segment-watch.md)。
|
|
195
|
+
|
|
196
|
+
#### 意外中斷
|
|
197
|
+
|
|
198
|
+
非 usage 的 API 錯誤、SessionEnd、殘留的 `.round-open` 會把開著的 Round 標成 `INTERRUPTED`。usage 用光不算中斷。中途取消(例如 Esc)通常是在**下一則訊息**或**下次 SessionStart(startup / resume / clear / fork)**才補上;`PostToolUseFailure` 的 `is_interrupt` 若有觸發,只是 best-effort,不能當成一定會立刻蓋章。`Status` 下面會多一行 `[reason: ...]` 內部代號方便之後 debug(例如 `dangling:next_prompt`);中斷當下如果是卡在等 `AskUserQuestion` 的回答,Summary/Handoff 會直接說明,不會寫成「意外」。細節見 [`docs/design/recording-moments.md`](docs/design/recording-moments.md)。
|
|
199
|
+
|
|
200
|
+
#### 段落記錄
|
|
201
|
+
|
|
202
|
+
長輪不要憋到最後,邊做邊寫 `### 段落`。同一輪連續約 10 分鐘沒改 `.round-current.md`,`PreToolUse` hook 會擋住下一個工具;先 Read 再 Edit/StrReplace 追加一段(不要 Write 覆寫整檔)。門檻可用 `/devlog-tracker:segment-watch <時間長度>` 調整。Claude Code subagent/dynamic workflow(PreToolUse 帶 `agent_id`)不套用父輪這道閥。細節見 [`docs/design/segment-watch.md`](docs/design/segment-watch.md)。
|
|
203
|
+
|
|
204
|
+
#### Checkpoint Mode
|
|
205
|
+
|
|
206
|
+
累積約 20 輪沒寫跨輪摘要,`Stop` hook 會要求補一段 `## Checkpoint`(門檻可調)。細節見 [`docs/design/checkpoint-mode.md`](docs/design/checkpoint-mode.md)。
|
|
207
|
+
|
|
208
|
+
#### Span Mode
|
|
209
|
+
|
|
210
|
+
`/loop`、Workflow 這類自動續接的長任務,不必每個 tick 都寫完整 Round,用 tick 計數當安全閥;崩潰最多漏記固定數量的 tick,不是整段。細節見 [`docs/design/span-mode.md`](docs/design/span-mode.md)。
|
|
211
|
+
|
|
212
|
+
#### Reply Fold
|
|
213
|
+
|
|
214
|
+
Claude 用純文字結尾提出問題、下一則訊息才拿到答案時,不用開新 Round——提問前先手動記一段問題原文再跑 `await-open.sh` 標記,下一則訊息(答案)就會自動折進同一個 Round 當一段 `### 段落`,不是拆成兩個不相關的 Round。連續多輪一問一答(例如 grilling)時,中途每題只記問題段落,不必每題重寫 Summary/Reply/Handoff/Status,等整場問答真正結束才收尾一次。`AskUserQuestion` 在同一 turn 內問答,不用 fold,但仍要用 `### 段落(AskUserQuestion)` 記下問題與答案。背景 task-notification(子 agent 完成通知)也會自動走同一套折疊機制,不留原始 XML,只記精簡摘要。細節見 [`docs/design/reply-fold.md`](docs/design/reply-fold.md)。
|
|
215
|
+
|
|
216
|
+
#### 分支各自的 devlog 檔
|
|
217
|
+
|
|
218
|
+
同一個工作目錄裡切換分支時,主檔會依目前 checkout 的分支自動分開:`main`/`master` 繼續用 `.devlog/devlog.md`,其他分支各自用 `.devlog/devlog.<branch>.md`(斜線轉成 `-`)。另開一個 `git worktree`(不同目錄)本來就有自己獨立的 `.devlog/`,不受這個機制影響。第一次在某分支偵測到還沒有專屬檔案、且 `devlog.md` 已有內容時,會把它改名(非複製)成該分支的檔案。細節見 [`docs/design/branch-scoped-devlog.md`](docs/design/branch-scoped-devlog.md)。
|
|
219
|
+
|
|
220
|
+
#### Lessons Mode(預設關閉,不自動)
|
|
221
|
+
|
|
222
|
+
開著時,Status 從 `BLOCKED` 解開、明顯繞路,或工作區漂移累積達門檻(預設 3 次,`/devlog-tracker:lessons-drift <次數>` 可調)才考慮記一筆開發歷程教訓,per-topic 存成 `devlog.lessons.<topic>.md`,`devlog.md` 只留標題索引。三種訊號都完全不 hook 強制寫入本身、不是知識庫(架構決策仍在 `docs/design/*.md`)。細節見 [`docs/design/lessons-mode.md`](docs/design/lessons-mode.md)。
|
|
223
|
+
|
|
224
|
+
## 測試
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
bash hooks/scripts/run-tests.sh
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
含 Cursor adapter。
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
Apache-2.0
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
async function main(argv) {
|
|
6
|
+
const [command, ...rest] = argv;
|
|
7
|
+
const pkg = require('../package.json');
|
|
8
|
+
|
|
9
|
+
if (command === '--version' || command === '-v') {
|
|
10
|
+
console.log(pkg.version);
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
if (!command || command === '--help' || command === '-h') {
|
|
14
|
+
console.log('Usage: devlog-tracker <init|status> [--codex] [--cursor]');
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
if (command === 'init') {
|
|
18
|
+
const { run } = require('../cli/init');
|
|
19
|
+
const { vendorRoot, platforms } = await run(rest, {
|
|
20
|
+
repoRoot: path.join(__dirname, '..'),
|
|
21
|
+
targetDir: process.cwd(),
|
|
22
|
+
version: pkg.version,
|
|
23
|
+
});
|
|
24
|
+
console.log(`devlog-tracker installed to ${vendorRoot} for: ${platforms.join(', ')}`);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
if (command === 'status') {
|
|
28
|
+
const { status } = require('../cli/status');
|
|
29
|
+
const result = status({ targetDir: process.cwd(), currentVersion: pkg.version });
|
|
30
|
+
if (!result.installed) {
|
|
31
|
+
console.log('devlog-tracker is not installed in this project. Run `npx devlog-tracker init`.');
|
|
32
|
+
} else if (result.upToDate) {
|
|
33
|
+
console.log(`devlog-tracker ${result.vendoredVersion} is up to date.`);
|
|
34
|
+
} else {
|
|
35
|
+
console.log(
|
|
36
|
+
`devlog-tracker ${result.vendoredVersion} is installed; ${pkg.version} is available. Run \`npx devlog-tracker init\` to upgrade.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
console.error(`Unknown command: ${command}`);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
main(process.argv.slice(2)).then(
|
|
46
|
+
(code) => { process.exitCode = code; },
|
|
47
|
+
(err) => {
|
|
48
|
+
console.error(err instanceof Error ? err.message : err);
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
}
|
|
51
|
+
);
|
package/cli/init.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const readline = require('readline');
|
|
3
|
+
const { vendor } = require('./vendor');
|
|
4
|
+
const codex = require('./platforms/codex');
|
|
5
|
+
const cursor = require('./platforms/cursor');
|
|
6
|
+
|
|
7
|
+
const PLATFORMS = { codex, cursor };
|
|
8
|
+
|
|
9
|
+
function parseArgs(argv) {
|
|
10
|
+
const platforms = [];
|
|
11
|
+
for (const arg of argv) {
|
|
12
|
+
if (arg === '--codex') platforms.push('codex');
|
|
13
|
+
else if (arg === '--cursor') platforms.push('cursor');
|
|
14
|
+
else if (arg.startsWith('-')) {
|
|
15
|
+
throw new Error(`Unknown option: ${arg} (supported: --codex, --cursor)`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { platforms };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function promptPlatforms() {
|
|
22
|
+
if (!process.stdin.isTTY) return Promise.resolve(Object.keys(PLATFORMS));
|
|
23
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
rl.question('要裝哪個平台?(codex/cursor,逗號分隔,留空=全部): ', (answer) => {
|
|
26
|
+
rl.close();
|
|
27
|
+
const trimmed = answer.trim();
|
|
28
|
+
if (!trimmed) return resolve(Object.keys(PLATFORMS));
|
|
29
|
+
resolve(
|
|
30
|
+
trimmed
|
|
31
|
+
.split(',')
|
|
32
|
+
.map((s) => s.trim())
|
|
33
|
+
.filter((s) => PLATFORMS[s])
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function run(argv, { repoRoot, targetDir, version }) {
|
|
40
|
+
const { platforms } = parseArgs(argv);
|
|
41
|
+
const selected = platforms.length > 0 ? platforms : await promptPlatforms();
|
|
42
|
+
const vendorRoot = vendor({ repoRoot, targetDir, version });
|
|
43
|
+
for (const name of selected) {
|
|
44
|
+
try {
|
|
45
|
+
PLATFORMS[name].install({ repoRoot, targetDir, vendorRoot });
|
|
46
|
+
} catch (err) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Installed files to ${vendorRoot} but failed to configure ${name}: ${String(err.message).replace(/\.$/, '')}. Fix the issue and re-run \`devlog-tracker init\` (safe to re-run).`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { vendorRoot, platforms: selected };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { run, parseArgs, PLATFORMS };
|
package/cli/init.test.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { parseArgs, run } = require('./init');
|
|
8
|
+
|
|
9
|
+
test('parseArgs accepts --codex and --cursor', () => {
|
|
10
|
+
assert.deepEqual(parseArgs(['--codex']), { platforms: ['codex'] });
|
|
11
|
+
assert.deepEqual(parseArgs(['--codex', '--cursor']), { platforms: ['codex', 'cursor'] });
|
|
12
|
+
assert.deepEqual(parseArgs([]), { platforms: [] });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('parseArgs throws a clear error for unknown options', () => {
|
|
16
|
+
assert.throws(
|
|
17
|
+
() => parseArgs(['--claude']),
|
|
18
|
+
{ message: 'Unknown option: --claude (supported: --codex, --cursor)' }
|
|
19
|
+
);
|
|
20
|
+
assert.throws(() => parseArgs(['--codex', '-x']), /Unknown option: -x/);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('run wraps platform install failures with vendoring context', async () => {
|
|
24
|
+
const repoRoot = path.join(__dirname, '..');
|
|
25
|
+
const targetDir = fs.mkdtempSync(path.join(os.tmpdir(), 'devlog-tracker-init-'));
|
|
26
|
+
fs.mkdirSync(path.join(targetDir, '.codex'), { recursive: true });
|
|
27
|
+
fs.writeFileSync(path.join(targetDir, '.codex', 'hooks.json'), '{ not json');
|
|
28
|
+
await assert.rejects(
|
|
29
|
+
() => run(['--codex'], { repoRoot, targetDir, version: '0.0.0' }),
|
|
30
|
+
(err) => {
|
|
31
|
+
assert.match(err.message, /Installed files to .*\.devlog-tracker but failed to configure codex: /);
|
|
32
|
+
assert.match(err.message, /Cannot parse existing/);
|
|
33
|
+
assert.match(err.message, /re-run `devlog-tracker init` \(safe to re-run\)/);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const MARKER = '.devlog-tracker/';
|
|
6
|
+
|
|
7
|
+
function isPlainObject(v) {
|
|
8
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function readExisting(targetPath) {
|
|
12
|
+
if (!fs.existsSync(targetPath)) return {};
|
|
13
|
+
const text = fs.readFileSync(targetPath, 'utf8');
|
|
14
|
+
if (text.trim() === '') return {};
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = JSON.parse(text);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Cannot parse existing ${targetPath}: ${err.message}. Fix or move the file, then re-run \`devlog-tracker init\` (safe to re-run).`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (parsed === null) return {};
|
|
24
|
+
if (!isPlainObject(parsed)) {
|
|
25
|
+
throw new Error(`Existing ${targetPath} must contain a JSON object at the top level; fix or move the file, then re-run \`devlog-tracker init\` (safe to re-run).`);
|
|
26
|
+
}
|
|
27
|
+
if ('hooks' in parsed && parsed.hooks !== null && !isPlainObject(parsed.hooks)) {
|
|
28
|
+
throw new Error(`Existing ${targetPath}: "hooks" must be a JSON object; fix or move the file, then re-run \`devlog-tracker init\` (safe to re-run).`);
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mergeHooksTemplate({ templatePath, targetPath, vendorRoot }) {
|
|
34
|
+
const escapedRoot = JSON.stringify(vendorRoot).slice(1, -1);
|
|
35
|
+
const rawTemplate = fs.readFileSync(templatePath, 'utf8').split('${DEVLOG_TRACKER_ROOT}').join(escapedRoot);
|
|
36
|
+
const template = JSON.parse(rawTemplate);
|
|
37
|
+
|
|
38
|
+
const existing = readExisting(targetPath);
|
|
39
|
+
if (!existing.hooks) existing.hooks = {};
|
|
40
|
+
|
|
41
|
+
for (const key of Object.keys(template)) {
|
|
42
|
+
if (key === 'hooks') continue;
|
|
43
|
+
if (!(key in existing)) existing[key] = template[key];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const event of Object.keys(template.hooks)) {
|
|
47
|
+
const templateEntries = template.hooks[event];
|
|
48
|
+
const currentEntries = existing.hooks[event] === undefined || existing.hooks[event] === null ? [] : existing.hooks[event];
|
|
49
|
+
if (!Array.isArray(currentEntries)) {
|
|
50
|
+
throw new Error(`Existing ${targetPath}: hooks.${event} must be an array; fix or move the file, then re-run \`devlog-tracker init\` (safe to re-run).`);
|
|
51
|
+
}
|
|
52
|
+
const kept = currentEntries.filter((entry) => !JSON.stringify(entry).includes(MARKER));
|
|
53
|
+
existing.hooks[event] = kept.concat(templateEntries);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
57
|
+
fs.writeFileSync(targetPath, `${JSON.stringify(existing, null, 2)}\n`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { mergeHooksTemplate, MARKER };
|