@kyuki3rain/cupola 0.0.0-stage → 0.1.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/CHANGELOG.md +26 -0
- package/LICENSE +202 -0
- package/README.md +40 -2
- package/dist/adr.js +106 -0
- package/dist/catalog.js +137 -0
- package/dist/check.js +192 -0
- package/dist/cli.js +8 -0
- package/dist/code.js +216 -0
- package/dist/commands/change.js +522 -0
- package/dist/commands/epic.js +311 -0
- package/dist/commands/install.js +109 -0
- package/dist/commands/locks.js +175 -0
- package/dist/commands/procedure.js +92 -0
- package/dist/commands/revision.js +139 -0
- package/dist/commands/run.js +1015 -0
- package/dist/commands/setup.js +382 -0
- package/dist/commands/spec.js +80 -0
- package/dist/commands/status.js +1158 -0
- package/dist/commands/trace.js +397 -0
- package/dist/commands/wait.js +102 -0
- package/dist/commands/work.js +121 -0
- package/dist/commands/workspace.js +126 -0
- package/dist/commands/worktree.js +422 -0
- package/dist/config.js +289 -0
- package/dist/day.js +29 -0
- package/dist/e2e-project.js +62 -0
- package/dist/e2e.js +207 -0
- package/dist/engine/cc-sdd.js +164 -0
- package/dist/epic.js +360 -0
- package/dist/feedback.js +34 -0
- package/dist/frontmatter.js +20 -0
- package/dist/git.js +365 -0
- package/dist/host/github.js +290 -0
- package/dist/host/host.js +1 -0
- package/dist/install.js +182 -0
- package/dist/io.js +46 -0
- package/dist/main.js +771 -0
- package/dist/method/v1.js +56 -0
- package/dist/procedure.js +60 -0
- package/dist/record.js +473 -0
- package/dist/release.js +84 -0
- package/dist/repo.js +13 -0
- package/dist/runbook.js +111 -0
- package/dist/safe-write.js +80 -0
- package/dist/spec.js +171 -0
- package/dist/status.js +190 -0
- package/dist/templates.js +49 -0
- package/dist/trace.js +275 -0
- package/dist/tracker/files.js +156 -0
- package/dist/tracker/github-issues.js +217 -0
- package/dist/tracker/index.js +27 -0
- package/dist/tracker/tracker.js +69 -0
- package/dist/tree.js +42 -0
- package/dist/trust.js +13 -0
- package/dist/version.js +5 -0
- package/dist/work.js +149 -0
- package/dist/workspace.js +299 -0
- package/npm-shrinkwrap.json +2014 -0
- package/package.json +41 -4
- package/skills/cupola-abort/SKILL.md +45 -0
- package/skills/cupola-adr/SKILL.md +41 -0
- package/skills/cupola-ask/SKILL.md +42 -0
- package/skills/cupola-catalog/SKILL.md +41 -0
- package/skills/cupola-catalog-draft/SKILL.md +114 -0
- package/skills/cupola-complete/SKILL.md +87 -0
- package/skills/cupola-decide/SKILL.md +60 -0
- package/skills/cupola-doc/SKILL.md +52 -0
- package/skills/cupola-e2e-setup/SKILL.md +78 -0
- package/skills/cupola-e2e-test/SKILL.md +115 -0
- package/skills/cupola-epic-accept/SKILL.md +162 -0
- package/skills/cupola-epic-create/SKILL.md +120 -0
- package/skills/cupola-epic-revise/SKILL.md +71 -0
- package/skills/cupola-epic-run/SKILL.md +127 -0
- package/skills/cupola-fix/SKILL.md +115 -0
- package/skills/cupola-init/SKILL.md +88 -0
- package/skills/cupola-intake/SKILL.md +78 -0
- package/skills/cupola-operate/SKILL.md +64 -0
- package/skills/cupola-resolve/SKILL.md +86 -0
- package/skills/cupola-review/SKILL.md +132 -0
- package/skills/cupola-spec-design/SKILL.md +164 -0
- package/skills/cupola-spec-impl/SKILL.md +135 -0
- package/skills/cupola-spec-run/SKILL.md +125 -0
- package/skills/cupola-steering/SKILL.md +46 -0
- package/templates/install/.kiro/steering/e2e.md +48 -0
- package/templates/install/.kiro/steering/operations.md +109 -0
- package/templates/install/.kiro/steering/principles.md +25 -0
- package/templates/install/CLAUDE.md +19 -0
- package/templates/install/adr/TEMPLATE.md +38 -0
- package/templates/install/cc-sdd/patches.json +31 -0
- package/templates/method-1/behavior-area.md +43 -0
- package/templates/method-1/behavior-index.md +16 -0
- package/templates/method-1/card.md +41 -0
- package/templates/method-1/case-draft.md +25 -0
- package/templates/method-1/case.md +38 -0
- package/templates/method-1/catalog-spec.md +33 -0
- package/templates/method-1/changes/adr.md +4 -0
- package/templates/method-1/changes/catalog.md +29 -0
- package/templates/method-1/changes/doc.md +5 -0
- package/templates/method-1/changes/e2e.md +7 -0
- package/templates/method-1/changes/epic.md +29 -0
- package/templates/method-1/changes/fix.md +21 -0
- package/templates/method-1/changes/release.md +23 -0
- package/templates/method-1/changes/spec.md +55 -0
- package/templates/method-1/changes/system.md +13 -0
- package/templates/method-1/cupola-issue-draft.md +17 -0
- package/templates/method-1/epic.md +136 -0
- package/templates/method-1/fix-spec.md +34 -0
- package/templates/method-1/fix.md +39 -0
- package/templates/method-1/lock.json +13 -0
- package/templates/method-1/phase-outcome.json +29 -0
- package/templates/method-1/record.json +63 -0
- package/templates/method-1/report.md +27 -0
- package/templates/method-1/runbook.md +39 -0
- package/templates/method-1/runner-result.json +6 -0
- package/templates/method-1/send-back.md +23 -0
- package/templates/methods.json +13 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Cupola follows [Semantic Versioning](https://semver.org/). Before 1.0, a minor version may change
|
|
4
|
+
behavior; a patch version only fixes. Documents Cupola writes record their format as `method`: work in
|
|
5
|
+
flight keeps its method until done, and `cupola update` moves the rest forward.
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
First public release.
|
|
10
|
+
|
|
11
|
+
- Skills and a CLI for the whole flow on top of cc-sdd: cases, epics, specs in three modes (full, fix,
|
|
12
|
+
catalog), gates G1–G5, one repository or several, in components.
|
|
13
|
+
- A user guide (`docs/guide.md`, Japanese `docs/guide.ja.md`).
|
|
14
|
+
- Every document can live in the hub (`documents: "hub"`): other repositories hold only code.
|
|
15
|
+
- `cupola wait` follows an epic past its gates on its own.
|
|
16
|
+
- Only trusted people are acted on: by default the repository's owners, members, and collaborators
|
|
17
|
+
(`trust` in `.cupola/config.json`). An issue someone else opened is not taken as a case; their
|
|
18
|
+
comments are counted, never followed.
|
|
19
|
+
- At G3, a change can be sent back by leaving feedback on it; the run answers it in review.
|
|
20
|
+
- `timezone` in `.cupola/config.json` (an IANA name) sets the day records and documents are dated in;
|
|
21
|
+
`cupola init` writes the machine's zone.
|
|
22
|
+
- Writes stay inside the repository (symlinks, repository names, IDs are checked).
|
|
23
|
+
- `cupola init` denies Claude Code the git commands only a human runs (force pushes, pushes to the
|
|
24
|
+
default branch, changing remotes).
|
|
25
|
+
- cc-sdd is checked against a digest before it is installed; dependencies are pinned by
|
|
26
|
+
`npm-shrinkwrap.json`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025-2026 kyuki3rain
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cupola
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Status: beta.**
|
|
4
|
+
|
|
5
|
+
Cupola is a way of building software with AI agents in which **people decide how the system should
|
|
6
|
+
behave, and AI builds it**. You agree on use cases and examples; the AI writes the tests and the code,
|
|
7
|
+
works through to the next point where a person is needed, and shows you what changed in behavior and
|
|
8
|
+
how it was verified. You don't review code.
|
|
9
|
+
|
|
10
|
+
It runs in [Claude Code](https://claude.com/claude-code) as `cupola-*` skills and a small CLI, on top of
|
|
11
|
+
[cc-sdd](https://github.com/gotalab/cc-sdd).
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx @kyuki3rain/cupola init # in your repository
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then, in Claude Code: `cupola-init`.
|
|
18
|
+
|
|
19
|
+
- **A few gates, nothing in between.** People agree on an epic, answer the rare decision card, accept
|
|
20
|
+
changes, release, and judge whether the problem is gone. The AI never stops to ask in the middle.
|
|
21
|
+
- **A behavior catalog.** What the system promises, one line per behavior, traced to the tests that
|
|
22
|
+
check it and their latest results.
|
|
23
|
+
- **Any shape of system.** One repository, a monorepo, or several repositories, in components.
|
|
24
|
+
- **Nothing to keep in your head.** `cupola status <work>` always names whose turn it is and the one
|
|
25
|
+
thing to do next.
|
|
26
|
+
|
|
27
|
+
Read the **[guide](docs/guide.md)** to set up a project and take a first problem to its release.
|
|
28
|
+
|
|
29
|
+
## 日本語
|
|
30
|
+
|
|
31
|
+
> **ベータ版です。**
|
|
32
|
+
|
|
33
|
+
Cupola は、AI エージェントと一緒にソフトウェアを作るための進め方です。**システムがどう振る舞うべきかは人が決め、作るのは AI です。** 人はユースケースと例について合意します。AI はテストとコードを書き、人が必要になるところまで進みます。そして、振る舞いの何が変わったか、どう確かめたかを見せます。人はコードをレビューしません。
|
|
34
|
+
|
|
35
|
+
[Claude Code](https://claude.com/claude-code) の上で、`cupola-*` スキルと小さな CLI として動きます。土台は [cc-sdd](https://github.com/gotalab/cc-sdd) です。
|
|
36
|
+
|
|
37
|
+
使い方は **[ガイド](docs/guide.ja.md)** を見てください。
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
[Apache-2.0](LICENSE)
|
package/dist/adr.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { parseFrontMatter } from "./frontmatter.js";
|
|
6
|
+
/**
|
|
7
|
+
* Decision records: `<paths.adr>/<id>.md`, by default `.cupola/adr/`. Their index is derived from
|
|
8
|
+
* their front matter whenever it is read (`cupola adr list`), never stored.
|
|
9
|
+
*/
|
|
10
|
+
const Adr = z.strictObject({
|
|
11
|
+
kind: z.literal("adr"),
|
|
12
|
+
method: z.number().int(),
|
|
13
|
+
id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "an imperative slug in kebab case"),
|
|
14
|
+
date: z.union([z.string().regex(/^\d{4}-\d{2}-\d{2}$/), z.date()]),
|
|
15
|
+
summary: z.string().min(1),
|
|
16
|
+
"applies-to": z.array(z.string()).min(1),
|
|
17
|
+
from: z.string().min(1),
|
|
18
|
+
supersedes: z.union([z.string(), z.array(z.string())]).optional(),
|
|
19
|
+
});
|
|
20
|
+
async function readAdrs(root, adrDir) {
|
|
21
|
+
const dir = join(root, adrDir);
|
|
22
|
+
const adrs = [];
|
|
23
|
+
const problems = [];
|
|
24
|
+
if (!existsSync(dir))
|
|
25
|
+
return { adrs, problems };
|
|
26
|
+
for (const f of (await readdir(dir)).sort()) {
|
|
27
|
+
if (!f.endsWith(".md") || f === "README.md" || f === "TEMPLATE.md")
|
|
28
|
+
continue;
|
|
29
|
+
const file = `${adrDir}/${f}`;
|
|
30
|
+
const parsed = Adr.safeParse(parseFrontMatter(await readFile(join(dir, f), "utf8")).data);
|
|
31
|
+
if (!parsed.success) {
|
|
32
|
+
for (const i of parsed.error.issues)
|
|
33
|
+
problems.push({
|
|
34
|
+
file,
|
|
35
|
+
message: `front matter ${i.path.join(".") || "(root)"}: ${i.message}`,
|
|
36
|
+
});
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const date = parsed.data.date instanceof Date
|
|
40
|
+
? parsed.data.date.toISOString().slice(0, 10)
|
|
41
|
+
: parsed.data.date;
|
|
42
|
+
if (parsed.data.id !== f.slice(0, -3))
|
|
43
|
+
problems.push({ file, message: `id is ${parsed.data.id}, but the file is ${f}` });
|
|
44
|
+
const s = parsed.data.supersedes;
|
|
45
|
+
adrs.push({
|
|
46
|
+
...parsed.data,
|
|
47
|
+
date,
|
|
48
|
+
supersedes: s === undefined ? [] : Array.isArray(s) ? s : [s],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const ids = new Set(adrs.map((a) => a.id));
|
|
52
|
+
for (const a of adrs) {
|
|
53
|
+
for (const sup of a.supersedes)
|
|
54
|
+
if (!ids.has(sup))
|
|
55
|
+
problems.push({
|
|
56
|
+
file: `${adrDir}/${a.id}.md`,
|
|
57
|
+
message: `supersedes ${sup}, which does not exist`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return { adrs, problems };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The index, derived from the records whenever it is read (never stored):
|
|
64
|
+
* newest first. With `appliesTo`, only the ADRs whose `applies-to` holds one of
|
|
65
|
+
* the values or a dotted child of it (`operations` matches `operations.lifetime`).
|
|
66
|
+
*/
|
|
67
|
+
export async function listAdrs(root, adrDir, appliesTo = []) {
|
|
68
|
+
const { adrs, problems } = await readAdrs(root, adrDir);
|
|
69
|
+
const by = new Map(adrs.flatMap((a) => a.supersedes.map((sup) => [sup, a.id])));
|
|
70
|
+
const matches = (a) => appliesTo.length === 0 ||
|
|
71
|
+
a["applies-to"].some((x) => appliesTo.some((w) => x === w || x.startsWith(`${w}.`)));
|
|
72
|
+
const entries = adrs
|
|
73
|
+
.filter(matches)
|
|
74
|
+
.sort((a, b) => b.date.localeCompare(a.date) || a.id.localeCompare(b.id))
|
|
75
|
+
.map((a) => {
|
|
76
|
+
const sup = by.get(a.id);
|
|
77
|
+
return {
|
|
78
|
+
id: a.id,
|
|
79
|
+
date: a.date,
|
|
80
|
+
"applies-to": a["applies-to"],
|
|
81
|
+
summary: a.summary.replace(/\s+/g, " "),
|
|
82
|
+
file: `${adrDir}/${a.id}.md`,
|
|
83
|
+
...(sup ? { supersededBy: sup } : {}),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return { adrs: entries, problems };
|
|
87
|
+
}
|
|
88
|
+
/** The text form: current ADRs, then superseded ones. */
|
|
89
|
+
export function renderAdrList(adrs) {
|
|
90
|
+
const current = adrs
|
|
91
|
+
.filter((a) => !a.supersededBy)
|
|
92
|
+
.map((a) => `${a.id} — ${a.date} — ${a["applies-to"].join(", ")} — ${a.summary}`);
|
|
93
|
+
const superseded = adrs
|
|
94
|
+
.filter((a) => a.supersededBy)
|
|
95
|
+
.map((a) => `${a.id} — superseded by ${a.supersededBy}`);
|
|
96
|
+
const lines = current.length > 0 ? current : ["No ADRs."];
|
|
97
|
+
return superseded.length > 0
|
|
98
|
+
? [...lines, "", "Superseded:", ...superseded].join("\n")
|
|
99
|
+
: lines.join("\n");
|
|
100
|
+
}
|
|
101
|
+
/** For `cupola check`: every ADR's front matter, its id, and what it supersedes. */
|
|
102
|
+
export async function checkAdrs(root, adrDir) {
|
|
103
|
+
if (!existsSync(join(root, adrDir)))
|
|
104
|
+
return [];
|
|
105
|
+
return (await readAdrs(root, adrDir)).problems;
|
|
106
|
+
}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { resolveComponents } from "./config.js";
|
|
5
|
+
import { parseFrontMatter } from "./frontmatter.js";
|
|
6
|
+
/** The catalog level of the whole system, in the hub; no component takes the name. */
|
|
7
|
+
export const SYSTEM = "system";
|
|
8
|
+
export const ENTRY_ID = /^[a-z0-9-]+\.[a-z0-9-]+$/;
|
|
9
|
+
const PRECISE = "<!-- precise layer -->";
|
|
10
|
+
/**
|
|
11
|
+
* The behavior directories of a repository, one per component it holds:
|
|
12
|
+
* `<paths.behavior>/<component>/`, and in the hub `<paths.behavior>/system/`
|
|
13
|
+
* for the system level. Components in other repositories are
|
|
14
|
+
* not here.
|
|
15
|
+
*/
|
|
16
|
+
export function behaviorDirs(config,
|
|
17
|
+
/** The repository the catalog is read in: the hub, or a component's. */
|
|
18
|
+
repo = config.hub) {
|
|
19
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
20
|
+
const behavior = config.paths.behavior;
|
|
21
|
+
const own = resolveComponents(config).filter((c) => same(c.repo, repo));
|
|
22
|
+
return [...(same(repo, config.hub) ? [SYSTEM] : []), ...own.map((c) => c.name)].map((name) => ({
|
|
23
|
+
dir: `${behavior}/${name}`,
|
|
24
|
+
components: [name],
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
const RETIRED = /^-\s+`([a-z0-9-]+\.[a-z0-9-]+)`\s*(?:→|->|—|\(|$)/;
|
|
28
|
+
const FIELD = /^-\s+(origin|verified|mark):\s*(.*)$/;
|
|
29
|
+
/**
|
|
30
|
+
* Parses an area file. After the precise-layer marker, an entry
|
|
31
|
+
* is a heading whose first token is an ID; it runs to the next heading. Its
|
|
32
|
+
* statement is its first paragraph, and its fields are unindented `- key:`
|
|
33
|
+
* bullets. Retired IDs are `` - `<id>` → … `` bullets outside entries. Fenced
|
|
34
|
+
* code is skipped, and headings themselves are never parsed.
|
|
35
|
+
*/
|
|
36
|
+
export function parseArea(path, dir, raw) {
|
|
37
|
+
const text = raw.replace(/\r\n?/g, "\n");
|
|
38
|
+
const { data, body } = parseFrontMatter(text, path);
|
|
39
|
+
const offset = text.slice(0, text.length - body.length).split("\n").length - 1;
|
|
40
|
+
const lines = body.split("\n");
|
|
41
|
+
const start = lines.findIndex((l) => l.trim() === PRECISE);
|
|
42
|
+
const entries = [];
|
|
43
|
+
const retired = [];
|
|
44
|
+
let current;
|
|
45
|
+
let statementOpen = false;
|
|
46
|
+
let fence;
|
|
47
|
+
for (let i = start + 1; start >= 0 && i < lines.length; i++) {
|
|
48
|
+
const line = lines[i] ?? "";
|
|
49
|
+
const fenceMark = /^(```+|~~~+)/.exec(line.trim())?.[1];
|
|
50
|
+
if (fence !== undefined || fenceMark) {
|
|
51
|
+
if (fence === undefined)
|
|
52
|
+
fence = fenceMark;
|
|
53
|
+
else if (fenceMark?.startsWith(fence))
|
|
54
|
+
fence = undefined;
|
|
55
|
+
if (current && statementOpen)
|
|
56
|
+
current.statement = `${current.statement}\n${line}`.trim();
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const heading = /^#{1,6}\s+(\S+)/.exec(line);
|
|
60
|
+
if (heading) {
|
|
61
|
+
const id = heading[1] ?? "";
|
|
62
|
+
current = ENTRY_ID.test(id) ? { id, statement: "", line: offset + i + 1 } : undefined;
|
|
63
|
+
if (current)
|
|
64
|
+
entries.push(current);
|
|
65
|
+
statementOpen = current !== undefined;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!current) {
|
|
69
|
+
const r = RETIRED.exec(line);
|
|
70
|
+
if (r)
|
|
71
|
+
retired.push({ id: r[1] ?? "", line: offset + i + 1 });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const field = FIELD.exec(line);
|
|
75
|
+
if (field) {
|
|
76
|
+
statementOpen = false;
|
|
77
|
+
current[field[1]] = (field[2] ?? "").trim();
|
|
78
|
+
}
|
|
79
|
+
else if (line.trim() === "") {
|
|
80
|
+
if (current.statement !== "")
|
|
81
|
+
statementOpen = false;
|
|
82
|
+
}
|
|
83
|
+
else if (statementOpen) {
|
|
84
|
+
current.statement =
|
|
85
|
+
current.statement === "" ? line.trim() : `${current.statement} ${line.trim()}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
path,
|
|
90
|
+
dir,
|
|
91
|
+
area: String(data.area ?? ""),
|
|
92
|
+
component: String(data.component ?? ""),
|
|
93
|
+
summary: String(data.summary ?? ""),
|
|
94
|
+
kind: data.kind,
|
|
95
|
+
method: data.method,
|
|
96
|
+
precise: start >= 0,
|
|
97
|
+
entries,
|
|
98
|
+
retired,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Every area file of the repository. */
|
|
102
|
+
export async function loadCatalog(root, config, repo = config.hub) {
|
|
103
|
+
const areas = [];
|
|
104
|
+
for (const { dir } of behaviorDirs(config, repo)) {
|
|
105
|
+
const full = join(root, dir);
|
|
106
|
+
if (!existsSync(full))
|
|
107
|
+
continue;
|
|
108
|
+
for (const file of (await readdir(full)).sort()) {
|
|
109
|
+
if (!file.endsWith(".md") || file === "README.md")
|
|
110
|
+
continue;
|
|
111
|
+
const path = join(dir, file);
|
|
112
|
+
areas.push(parseArea(path, dir, await readFile(join(root, path), "utf8")));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return areas;
|
|
116
|
+
}
|
|
117
|
+
/** The generated index of one behavior directory. */
|
|
118
|
+
export function renderIndex(areas) {
|
|
119
|
+
const rows = areas
|
|
120
|
+
.slice()
|
|
121
|
+
.sort((a, b) => a.area.localeCompare(b.area))
|
|
122
|
+
.map((a) => `| [${a.area}](${a.area}.md) | ${a.component} | ${a.summary.replaceAll("|", "\\|")} |`);
|
|
123
|
+
return `---
|
|
124
|
+
kind: behavior-index
|
|
125
|
+
method: 1
|
|
126
|
+
generated: cupola trace --index
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
# Behavior catalog
|
|
130
|
+
|
|
131
|
+
How the system behaves now. Read this index, then only the areas you need.
|
|
132
|
+
|
|
133
|
+
| Area | Component | What users do there |
|
|
134
|
+
|------|-----------|---------------------|
|
|
135
|
+
${rows.join("\n")}
|
|
136
|
+
`;
|
|
137
|
+
}
|