@ligeti/step-beads 0.0.0-stage → 2.2.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 +190 -2
- package/dist/add-dependency.d.ts +25 -0
- package/dist/add-dependency.d.ts.map +1 -0
- package/dist/add-dependency.js +52 -0
- package/dist/add-dependency.js.map +1 -0
- package/dist/bd.d.ts +4 -0
- package/dist/bd.d.ts.map +1 -0
- package/dist/bd.js +146 -0
- package/dist/bd.js.map +1 -0
- package/dist/close.d.ts +44 -0
- package/dist/close.d.ts.map +1 -0
- package/dist/close.js +39 -0
- package/dist/close.js.map +1 -0
- package/dist/comment.d.ts +33 -0
- package/dist/comment.d.ts.map +1 -0
- package/dist/comment.js +33 -0
- package/dist/comment.js.map +1 -0
- package/dist/create.d.ts +88 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +93 -0
- package/dist/create.js.map +1 -0
- package/dist/environment.d.ts +17 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +28 -0
- package/dist/environment.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/list-human.d.ts +40 -0
- package/dist/list-human.d.ts.map +1 -0
- package/dist/list-human.js +35 -0
- package/dist/list-human.js.map +1 -0
- package/dist/list.d.ts +55 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +77 -0
- package/dist/list.js.map +1 -0
- package/dist/remove-label.d.ts +42 -0
- package/dist/remove-label.d.ts.map +1 -0
- package/dist/remove-label.js +32 -0
- package/dist/remove-label.js.map +1 -0
- package/dist/settings.d.ts +13 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +21 -0
- package/dist/settings.js.map +1 -0
- package/dist/show.d.ts +69 -0
- package/dist/show.d.ts.map +1 -0
- package/dist/show.js +35 -0
- package/dist/show.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +116 -0
- package/dist/types.js.map +1 -0
- package/dist/update.d.ts +89 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +56 -0
- package/dist/update.js.map +1 -0
- package/package.json +26 -3
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 purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the 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
|
|
95
|
+
Derivative 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 the
|
|
141
|
+
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 Viktor "Bika" Nagy
|
|
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
CHANGED
|
@@ -1,3 +1,191 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ligeti/step-beads
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drives the [beads](https://github.com/gastownhall/beads) issue tracker's `bd` CLI, as ten steps:
|
|
4
|
+
`beads.list`, `beads.list-human`, `beads.show`, `beads.close`, `beads.update`,
|
|
5
|
+
`beads.remove-label`, `beads.comment`, `beads.create`, `beads.add-dependency` and
|
|
6
|
+
`beads.environment`.
|
|
7
|
+
|
|
8
|
+
Requires `bd` `>= 1.3.0` on `PATH` (or pointed at by `LIGETI_BEADS_BIN`). The floor is real: this
|
|
9
|
+
package uses the server-side `list --external-ref` filter and comma-separated `human list --status`,
|
|
10
|
+
both 1.3.0 features.
|
|
11
|
+
|
|
12
|
+
## Vocabulary
|
|
13
|
+
|
|
14
|
+
These words are binding on this package. The project-wide vocabulary is
|
|
15
|
+
[`docs/glossary.md`](../../docs/glossary.md); a word that reaches no further than this package is
|
|
16
|
+
defined here instead, per [ADR-0006](../../adr/0006-ubiquitous-language-is-an-enforced-artifact.md).
|
|
17
|
+
|
|
18
|
+
| Term | Definition | It is NOT |
|
|
19
|
+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| **Bead** | One tracked issue, as this package returns it: bd's `--json` wire object normalised to camelCase and narrowed to the ~20 fields we curate (`src/types.ts`). | Not bd's raw wire object — that has ~50 snake_case fields, and `parseBead` drops the ones we do not model. Not a Ligeti **run**, **step** or **resource**. |
|
|
21
|
+
| **Bead id** | A bd issue id (`tst-c7a` shape), validated by `BeadId` to be argv-safe. | Not an arbitrary string. A leading `-` is rejected because bd's flag parser, like git's, scans every argv position for option-shaped values. |
|
|
22
|
+
| **Status** | A bead's lifecycle value. bd ships seven (`open`, `in_progress`, `blocked`, `deferred`, `closed`, `pinned`, `hooked`) but they are user-extensible via `bd config set status.custom`, so `Bead.status` is a plain string. | Not a closed enum. `BeadStatus` exists only for callers that want to validate against the built-in set, and must not be used to parse bd's output. Not a "state" — see the project glossary's banned words. |
|
|
23
|
+
| **External ref** | An identifier linking a bead to an issue in another system, paired with `sourceSystem`. | Not the bead id. |
|
|
24
|
+
| **Human list** | The subset of beads labelled `human` — those needing a person's input — retrieved by `bd human list`, not by a label filter on `bd list`. | Not a status. A bead can be `open` and not `human`, or `human` and `blocked`. |
|
|
25
|
+
| **Key** | A caller-chosen string that names one bead for the purpose of retrying `beads.create`, stored on the bead as the label `ligeti-key:<key>`. Unique per parent. | Not the bead id, which bd assigns. Not an idempotency key bd knows about: bd has no such concept, so the label is the whole mechanism. |
|
|
26
|
+
| **Repo path** | The directory holding the bd database, passed as every step's `repoPath` input and given to `bd -C`. | Not a git worktree, though it is often the same directory. This package never creates or removes it. |
|
|
27
|
+
|
|
28
|
+
### `bead` vs `issue`
|
|
29
|
+
|
|
30
|
+
The two are the same concept, which makes this a synonym pair of exactly the kind
|
|
31
|
+
[ADR-0006](../../adr/0006-ubiquitous-language-is-an-enforced-artifact.md) calls a defect. The rule
|
|
32
|
+
for this package:
|
|
33
|
+
|
|
34
|
+
> **`bead` is the canonical word in identifiers** — the type is `Bead`, the output field is
|
|
35
|
+
> `beads`, the steps are `beads.*`. `issue` is permitted only in prose describing bd's own CLI and
|
|
36
|
+
> documentation, which is where the word comes from.
|
|
37
|
+
|
|
38
|
+
The step `description` strings currently say "issues" (they are user-facing text describing bd), so
|
|
39
|
+
the two words coexist deliberately rather than by accident. A new identifier named `*Issue*` is a
|
|
40
|
+
defect; a sentence explaining what `bd list` does may say "issue".
|
|
41
|
+
|
|
42
|
+
## Steps
|
|
43
|
+
|
|
44
|
+
All ten take `repoPath` and retry up to 3 times, 2 seconds apart.
|
|
45
|
+
|
|
46
|
+
| Step | Purpose | Key inputs |
|
|
47
|
+
| ---------------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `beads.list` | Lists beads, filtered server-side. | `status[]`, `labels[]`, `labelsAny[]`, `issueType`, `parent`, `externalRef`, `ready`, `limit` (default `0` = unlimited) |
|
|
49
|
+
| `beads.list-human` | Lists the beads labelled `human`. | `status[]`, `externalRef` |
|
|
50
|
+
| `beads.show` | Fetches one bead's full detail. | `id`, `includeComments` (default `false`) |
|
|
51
|
+
| `beads.close` | Closes one or more beads. | `ids[]` (min 1), `reason`, `actor`, `force` |
|
|
52
|
+
| `beads.update` | Sets one bead's status and/or assignee. | `id`, `status`, `assignee` (`""` unassigns), `actor`, `force` |
|
|
53
|
+
| `beads.remove-label` | Removes one label from one or more beads. | `ids[]` (min 1), `label`, `actor` |
|
|
54
|
+
| `beads.comment` | Adds a comment to one bead. | `id`, `text` (non-empty), `actor` |
|
|
55
|
+
| `beads.create` | Finds or creates the bead carrying a key. | `key`, `type`, `title`, `description`, `parent`, `labels[]`, `externalRef`, `priority` (0-4), `actor` |
|
|
56
|
+
| `beads.add-dependency` | Makes one bead blocked by another. | `id`, `blockedBy`, `actor` |
|
|
57
|
+
| `beads.environment` | Reports bd's version and custom types. | none beyond `repoPath` |
|
|
58
|
+
|
|
59
|
+
`beads.list`'s `ready` input (default `false`) switches the listing to `bd list --ready`: bd's own
|
|
60
|
+
blocker-aware "ready work" query, returning open beads with no active blocker and excluding
|
|
61
|
+
`in_progress`/`blocked`/`deferred`/`hooked`. Because `--ready` already implies its own status set,
|
|
62
|
+
`beads.list` rejects `ready: true` combined with a non-empty `status` filter rather than leaving
|
|
63
|
+
that combination for bd to resolve one way or another. bd itself refuses `--ready` together with
|
|
64
|
+
`--external-ref`, so `ready: true` with an `externalRef` lists bd's ready work and matches the
|
|
65
|
+
`externalRef` exactly in the step.
|
|
66
|
+
|
|
67
|
+
`beads.list`, `beads.list-human`, `beads.close` and `beads.remove-label` all output
|
|
68
|
+
`{ beads: Bead[] }`; `beads.show` outputs `{ bead: Bead }` and throws if the id does not exist,
|
|
69
|
+
surfacing bd's own not-found error; `beads.comment` outputs `{ comment: Comment }` (`id`, `issueId`,
|
|
70
|
+
`author`, `text`, `createdAt`).
|
|
71
|
+
|
|
72
|
+
Closing an already-closed bead succeeds as a no-op, which is what makes `beads.close` safe to
|
|
73
|
+
retry. `beads.remove-label` is the same shape of idempotent: it runs `bd update --remove-label`
|
|
74
|
+
(not `bd label remove`, whose own `--json` payload is `{issue_id, label, status}` rather than a
|
|
75
|
+
bead — `bd update` returns the full updated bead(s) in one call, matching this package's other
|
|
76
|
+
steps' output convention), and removing a label a bead no longer carries succeeds as a no-op.
|
|
77
|
+
|
|
78
|
+
`beads.update` outputs `{ bead: Bead }` and needs at least one of `status` and `assignee`. It sets
|
|
79
|
+
values instead of adding them, so repeating it is harmless. It rejects `status: "closed"`: `bd
|
|
80
|
+
update --status=closed` skips the checks `bd close` makes (the assignee, open blockers, open
|
|
81
|
+
children) and drops the close reason, so closing goes through `beads.close`. It throws when bd
|
|
82
|
+
answers with an issue other than `id`. bd refuses to change the assignee of a bead that is
|
|
83
|
+
`in_progress` for another actor, and that includes clearing it; `force` (default `false`) passes
|
|
84
|
+
`--force`, which overrides that refusal and, with it, bd's other update guards. A caller releases a
|
|
85
|
+
claim it did not make by setting `force`, and claims with it left off.
|
|
86
|
+
|
|
87
|
+
`beads.comment` has no such no-op to fall back into: every successful `bd comments add` appends a
|
|
88
|
+
new, distinct comment, so a retry or a workflow recovery after an unacknowledged success can
|
|
89
|
+
duplicate the comment. A `maxAttempts` cap would not remove that risk -- DBOS re-executes an
|
|
90
|
+
unrecorded step on recovery regardless of the step's own retry config -- so `beads.comment` is
|
|
91
|
+
retried the same as this package's other steps (`retry: { maxAttempts: 3, intervalSeconds: 2 }`).
|
|
92
|
+
The duplication is accepted: a duplicated comment is harmless, while a transient `bd` error (e.g.
|
|
93
|
+
"database is locked") turning into a fatal, unretried failure is not.
|
|
94
|
+
|
|
95
|
+
`beads.create` outputs `{ bead: Bead, created: boolean }`. It looks for a bead labelled
|
|
96
|
+
`ligeti-key:<key>` (`bd list -l ... --all`, so closed beads count, narrowed by `--parent` when
|
|
97
|
+
`parent` is given) and returns it with `created: false`; only when none exists does it run `bd
|
|
98
|
+
create`, so a retry or a workflow recovery returns the bead the first run made. When more than one bead carries the key (two racing calls can do that), it
|
|
99
|
+
returns the oldest by `created_at`, ties broken by id, and logs a warning naming the key and the
|
|
100
|
+
duplicate ids. A key is unique per parent, and the top level counts as a scope of its
|
|
101
|
+
own: a lookup without `parent` passes `--no-parent`, so a child carrying the same key does not
|
|
102
|
+
match it. A `labels` entry starting with `ligeti-key:` is rejected, because that prefix belongs to
|
|
103
|
+
the key. `bd create` is always given `--no-inherit-labels`: a bead's labels are the key label plus `labels`,
|
|
104
|
+
never the parent's. The `type` may be a custom type; bd refuses an unknown one and the step throws.
|
|
105
|
+
Two concurrent runs with the same key can both miss the lookup and both create; a workflow that
|
|
106
|
+
needs more serialises them itself.
|
|
107
|
+
|
|
108
|
+
`beads.add-dependency` outputs `{ id, blockedBy, added }` and adds a `blocks` edge from `id` to
|
|
109
|
+
`blockedBy`. It reads `bd dep list` first and returns `added: false` without writing when the edge
|
|
110
|
+
exists, which is what makes it safe to retry. `added: false` also follows a retry after an earlier
|
|
111
|
+
attempt added the edge, so a caller must not branch side effects on it. `bd dep add` refuses a
|
|
112
|
+
missing id that has this database's prefix but accepts one with a foreign prefix, so the step runs
|
|
113
|
+
`bd show` on `blockedBy` first and bd's error propagates if it is not a bead. A bead blocked by
|
|
114
|
+
itself is rejected by the input schema.
|
|
115
|
+
|
|
116
|
+
`beads.environment` is read-only and outputs `{ bdVersion, customTypes }` from `bd version` and
|
|
117
|
+
`bd types`; `customTypes` is empty when the database configures none (`bd config set types.custom`).
|
|
118
|
+
|
|
119
|
+
Concurrent writers (several children of one run, for example `beads.close` beside an agent's
|
|
120
|
+
`bd comments add`) are safe on bd's default embedded Dolt store: bd 1.3.0 takes a file lock only
|
|
121
|
+
during `bd init`, and its Dolt driver serialises the rest. Seventy-two simultaneous
|
|
122
|
+
`bd comments add` and `bd update --add-label` processes against one repository all exited 0 and
|
|
123
|
+
lost no write. This package neither locks nor serialises them, and a transient failure is still
|
|
124
|
+
re-run by the steps' `retry`. The embedded backend's own error text says it supports one writer at a
|
|
125
|
+
time, so if a bd upgrade starts refusing overlapping writers, run bd in server mode
|
|
126
|
+
(`bd init --server`).
|
|
127
|
+
|
|
128
|
+
## Environment variables
|
|
129
|
+
|
|
130
|
+
| Variable | Required | Default | Purpose |
|
|
131
|
+
| ------------------ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
132
|
+
| `LIGETI_BEADS_BIN` | no | `bd` | The `bd` binary to invoke. A test and ops seam: tests point it at a stand-in script, and a deployment can pin a specific build without touching `PATH`. |
|
|
133
|
+
|
|
134
|
+
Parsed by `src/settings.ts` through Zod, with an injectable `env`, per
|
|
135
|
+
[ADR-0003](../../adr/0003-configuration-is-a-settings-module.md).
|
|
136
|
+
|
|
137
|
+
### Seven variables are stripped from bd's environment
|
|
138
|
+
|
|
139
|
+
`BD_BACKEND` and `BD_DATABASE_BACKEND` are deleted from every child environment. `bd` hard-refuses
|
|
140
|
+
to start if either is set, so a worker process carrying one for unrelated reasons would otherwise
|
|
141
|
+
break every beads step with a confusing bd-level error.
|
|
142
|
+
|
|
143
|
+
`LIGETI_CALLBACK_KEY`, `LIGETI_ATTEST_KEY`, `LIGETI_DATABASE_URL`, `GITLAB_TOKEN` and
|
|
144
|
+
`GITLAB_ACCESS_TOKEN` are also deleted: this package runs inside a worker process, whose own
|
|
145
|
+
environment carries those per-app credentials and, when `steps/gitlab-mr`/`steps/gitlab-issue`/
|
|
146
|
+
`steps/gitlab-registry` are configured, a GitLab access token -- and `bd` needs none of them. Every other `bd` variable
|
|
147
|
+
(`BEADS_DIR`, `BEADS_ACTOR`, …) is passed through untouched.
|
|
148
|
+
|
|
149
|
+
This is a denylist, where the rest of the codebase builds child environments from an allow-list
|
|
150
|
+
([ADR-0004](../../adr/0004-child-processes-take-argv-and-an-explicit-environment.md)). It is
|
|
151
|
+
deliberate: `bd` reads its own configuration from the ambient environment, so an allow-list would
|
|
152
|
+
have to enumerate bd's entire variable surface and would silently break whenever bd added one.
|
|
153
|
+
|
|
154
|
+
## Argv safety
|
|
155
|
+
|
|
156
|
+
Every value that reaches `bd`'s argv is validated first, because bd's flag parser scans all argv
|
|
157
|
+
positions for option-shaped strings — a "positional" value beginning with `-` can still be read as
|
|
158
|
+
a flag:
|
|
159
|
+
|
|
160
|
+
- Ids, filter tokens and statuses must not begin with `-`.
|
|
161
|
+
- Statuses and labels must not contain `,`. `beads.list` comma-joins statuses into one `-s` flag,
|
|
162
|
+
and `--label`/`--label-any` are cobra `StringSlice` flags that split on commas themselves, so an
|
|
163
|
+
embedded comma would smuggle in a filter value the caller never asked for. `--type` is exempt: it
|
|
164
|
+
is a plain string with no comma splitting.
|
|
165
|
+
- A `beads.create` key matches `[A-Za-z0-9][A-Za-z0-9._:/-]*` (at most 200 characters): it becomes
|
|
166
|
+
part of a label, so it carries no comma and no whitespace. `beads.create` and
|
|
167
|
+
`beads.add-dependency` hand every free-form value to bd as one `--flag=value` argument, so a
|
|
168
|
+
title, description or id that begins with `-` stays inert.
|
|
169
|
+
- `beads.comment`'s free-text `text` input is not similarly charset-restricted (a comment is
|
|
170
|
+
prose, not a filter token), so it is instead placed after a literal `--` argv terminator, the same
|
|
171
|
+
guard `beads.close` uses for its ids: it tells bd's own flag parser that everything after it is
|
|
172
|
+
positional, so a comment beginning with `-` can't be misread as a flag.
|
|
173
|
+
|
|
174
|
+
Commands are always invoked as an argv array, never through a shell.
|
|
175
|
+
|
|
176
|
+
## Notes on bd's output
|
|
177
|
+
|
|
178
|
+
- `revision` is modelled as a **string**, not a number. bd emits a large (observed: 19-digit, and
|
|
179
|
+
sometimes negative) int64 serialised as a JSON string; parsing it as a JavaScript number would
|
|
180
|
+
silently lose precision.
|
|
181
|
+
- `bd list --json` on a large database comfortably exceeds `execFile`'s 1 MiB default buffer, so
|
|
182
|
+
this package raises it to 32 MiB.
|
|
183
|
+
- Fields bd emits that we do not model are dropped silently. The curation is deliberate, not
|
|
184
|
+
defensive — a bead missing a field `Bead` requires throws an error naming it.
|
|
185
|
+
|
|
186
|
+
## Tests
|
|
187
|
+
|
|
188
|
+
Unit tests drive a fake `bd` (`test/fixtures/fake-bd.mjs`). Integration tests
|
|
189
|
+
(`*.bd.int.test.ts`) drive the **real** `bd` binary against a temporary database, per
|
|
190
|
+
[ADR-0007](../../adr/0007-test-doubles-are-real-processes.md) — so they need `bd` installed, and
|
|
191
|
+
`bd init` git-commits its initial files, which is why CI configures a git identity.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "@ligeti/sdk";
|
|
2
|
+
export declare const BeadsAddDependencyInput: z.ZodObject<{
|
|
3
|
+
repoPath: z.ZodString;
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
blockedBy: z.ZodString;
|
|
6
|
+
actor: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type BeadsAddDependencyInput = z.infer<typeof BeadsAddDependencyInput>;
|
|
9
|
+
export declare const BeadsAddDependencyOutput: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
blockedBy: z.ZodString;
|
|
12
|
+
added: z.ZodBoolean;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type BeadsAddDependencyOutput = z.infer<typeof BeadsAddDependencyOutput>;
|
|
15
|
+
export declare const beadsAddDependency: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
|
|
16
|
+
repoPath: z.ZodString;
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
blockedBy: z.ZodString;
|
|
19
|
+
actor: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
blockedBy: z.ZodString;
|
|
23
|
+
added: z.ZodBoolean;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
//# sourceMappingURL=add-dependency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-dependency.d.ts","sourceRoot":"","sources":["../src/add-dependency.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAM5C,eAAO,MAAM,uBAAuB;;;;;iBAUhC,CAAC;AACL,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE9E,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEhF,eAAO,MAAM,kBAAkB;;;;;;;;;kBAwC7B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ABOUTME: beads.add-dependency, the step that makes one bead blocked by another in a bd (beads) database
|
|
2
|
+
// ABOUTME: via `bd dep add` -- a no-op when the blocking edge already exists, which the output reports.
|
|
3
|
+
import { defineStep, z } from "@ligeti/sdk";
|
|
4
|
+
import pkg from "../package.json" with { type: "json" };
|
|
5
|
+
import { BEADS_ENV_VARS } from "./settings.js";
|
|
6
|
+
import { bdBeads, bdJson } from "./bd.js";
|
|
7
|
+
import { BeadId } from "./types.js";
|
|
8
|
+
export const BeadsAddDependencyInput = z
|
|
9
|
+
.object({
|
|
10
|
+
repoPath: z.string().min(1),
|
|
11
|
+
id: BeadId,
|
|
12
|
+
blockedBy: BeadId,
|
|
13
|
+
actor: z.string().min(1).optional(),
|
|
14
|
+
})
|
|
15
|
+
.refine((input) => input.id !== input.blockedBy, {
|
|
16
|
+
message: "a bead cannot be blocked by itself",
|
|
17
|
+
path: ["blockedBy"],
|
|
18
|
+
});
|
|
19
|
+
export const BeadsAddDependencyOutput = z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
blockedBy: z.string(),
|
|
22
|
+
added: z.boolean(),
|
|
23
|
+
});
|
|
24
|
+
export const beadsAddDependency = defineStep({
|
|
25
|
+
name: "beads.add-dependency",
|
|
26
|
+
envVars: BEADS_ENV_VARS,
|
|
27
|
+
description: "Makes one bead blocked by another in a bd (beads) database; a no-op if it already is.",
|
|
28
|
+
package: { name: pkg.name, version: pkg.version },
|
|
29
|
+
input: BeadsAddDependencyInput,
|
|
30
|
+
output: BeadsAddDependencyOutput,
|
|
31
|
+
retry: { maxAttempts: 3, intervalSeconds: 2 },
|
|
32
|
+
async run(sctx, input) {
|
|
33
|
+
const blockers = await bdJson(input.repoPath, ["dep", "list", input.id, "--type", "blocks", "--readonly"], sctx.signal);
|
|
34
|
+
if (!Array.isArray(blockers)) {
|
|
35
|
+
throw new Error(`beads.add-dependency: bd dep list did not return an array for "${input.id}"`);
|
|
36
|
+
}
|
|
37
|
+
const alreadyBlocked = blockers.some((blocker) => typeof blocker === "object" &&
|
|
38
|
+
blocker !== null &&
|
|
39
|
+
blocker.id === input.blockedBy);
|
|
40
|
+
if (alreadyBlocked) {
|
|
41
|
+
return { id: input.id, blockedBy: input.blockedBy, added: false };
|
|
42
|
+
}
|
|
43
|
+
await bdBeads(input.repoPath, ["show", "--id", input.blockedBy, "--readonly"], sctx.signal);
|
|
44
|
+
const args = ["dep", "add", input.id, `--blocked-by=${input.blockedBy}`, "--type=blocks"];
|
|
45
|
+
if (input.actor !== undefined) {
|
|
46
|
+
args.push("--actor", input.actor);
|
|
47
|
+
}
|
|
48
|
+
await bdJson(input.repoPath, args, sctx.signal);
|
|
49
|
+
return { id: input.id, blockedBy: input.blockedBy, added: true };
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=add-dependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-dependency.js","sourceRoot":"","sources":["../src/add-dependency.ts"],"names":[],"mappings":"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"}
|
package/dist/bd.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Bead } from "./types.js";
|
|
2
|
+
export declare function bdJson(repoPath: string, args: string[], signal?: AbortSignal): Promise<unknown>;
|
|
3
|
+
export declare function bdBeads(repoPath: string, args: string[], signal?: AbortSignal): Promise<Bead[]>;
|
|
4
|
+
//# sourceMappingURL=bd.d.ts.map
|
package/dist/bd.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bd.d.ts","sourceRoot":"","sources":["../src/bd.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,IAAI,EAAa,MAAM,YAAY,CAAC;AAqHlD,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CA6BlB;AAED,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,EAAE,CAAC,CASjB"}
|
package/dist/bd.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// ABOUTME: Thin async wrappers around the `bd` (beads) CLI. Always invoked via argv arrays (never
|
|
2
|
+
// ABOUTME: a shell string), always pinned to a repo with `-C <repoPath>`, always `--json`.
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { loadBeadsSettings } from "./settings.js";
|
|
6
|
+
import { parseBead } from "./types.js";
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
const MAX_BUFFER = 32 * 1024 * 1024;
|
|
9
|
+
const BD_HOSTILE_VARS = ["BD_BACKEND", "BD_DATABASE_BACKEND"];
|
|
10
|
+
const WORKER_SECRET_VARS = [
|
|
11
|
+
"LIGETI_CALLBACK_KEY",
|
|
12
|
+
"LIGETI_ATTEST_KEY",
|
|
13
|
+
"LIGETI_DATABASE_URL",
|
|
14
|
+
"GITLAB_TOKEN",
|
|
15
|
+
"GITLAB_ACCESS_TOKEN",
|
|
16
|
+
];
|
|
17
|
+
function childEnv() {
|
|
18
|
+
const env = { ...process.env };
|
|
19
|
+
const strip = [...BD_HOSTILE_VARS, ...WORKER_SECRET_VARS];
|
|
20
|
+
const out = {};
|
|
21
|
+
for (const [key, value] of Object.entries(env)) {
|
|
22
|
+
if (!strip.includes(key)) {
|
|
23
|
+
out[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function isBdError(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && "error" in value;
|
|
30
|
+
}
|
|
31
|
+
function isEnvelope(value) {
|
|
32
|
+
return (typeof value === "object" && value !== null && "schema_version" in value && "data" in value);
|
|
33
|
+
}
|
|
34
|
+
function unwrapEnvelope(value) {
|
|
35
|
+
return isEnvelope(value) ? value.data : value;
|
|
36
|
+
}
|
|
37
|
+
function stringifyUnknown(value) {
|
|
38
|
+
if (typeof value === "string") {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
42
|
+
return String(value);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function describeBdError(err) {
|
|
52
|
+
const parts = [stringifyUnknown(err.error)];
|
|
53
|
+
if (err.code !== undefined) {
|
|
54
|
+
parts.push(`code=${stringifyUnknown(err.code)}`);
|
|
55
|
+
}
|
|
56
|
+
if (err.hint !== undefined) {
|
|
57
|
+
parts.push(`hint: ${stringifyUnknown(err.hint)}`);
|
|
58
|
+
}
|
|
59
|
+
return parts.join(" ");
|
|
60
|
+
}
|
|
61
|
+
function execErrorStreams(err) {
|
|
62
|
+
const record = typeof err === "object" && err !== null ? err : {};
|
|
63
|
+
const stdout = typeof record.stdout === "string" ? record.stdout : "";
|
|
64
|
+
const stderr = typeof record.stderr === "string" ? record.stderr : "";
|
|
65
|
+
return { stdout, stderr };
|
|
66
|
+
}
|
|
67
|
+
function truncate(text, max = 500) {
|
|
68
|
+
const trimmed = text.trim();
|
|
69
|
+
return trimmed.length > max ? `${trimmed.slice(0, max)}...` : trimmed;
|
|
70
|
+
}
|
|
71
|
+
function describeErrorFromStdout(stdout) {
|
|
72
|
+
const trimmed = stdout.trim();
|
|
73
|
+
if (trimmed.length === 0) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
let parsed;
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(trimmed);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const unwrapped = unwrapEnvelope(parsed);
|
|
84
|
+
return isBdError(unwrapped) ? describeBdError(unwrapped) : undefined;
|
|
85
|
+
}
|
|
86
|
+
function describeExecError(err) {
|
|
87
|
+
const { stdout, stderr } = execErrorStreams(err);
|
|
88
|
+
const fromStdout = describeErrorFromStdout(stdout);
|
|
89
|
+
const base = fromStdout ??
|
|
90
|
+
(stderr.trim().length > 0
|
|
91
|
+
? stderr.trim()
|
|
92
|
+
: err instanceof Error
|
|
93
|
+
? err.message
|
|
94
|
+
: stringifyUnknown(err));
|
|
95
|
+
if (/unknown flag/i.test(base)) {
|
|
96
|
+
return `${base} (this package requires bd >= 1.3.0; check your installed bd's version with \`bd version\`)`;
|
|
97
|
+
}
|
|
98
|
+
return base;
|
|
99
|
+
}
|
|
100
|
+
function withJsonBeforeTerminator(args) {
|
|
101
|
+
const terminatorIndex = args.indexOf("--");
|
|
102
|
+
return terminatorIndex === -1
|
|
103
|
+
? [...args, "--json"]
|
|
104
|
+
: [...args.slice(0, terminatorIndex), "--json", ...args.slice(terminatorIndex)];
|
|
105
|
+
}
|
|
106
|
+
export async function bdJson(repoPath, args, signal) {
|
|
107
|
+
const argv = ["-C", repoPath, ...withJsonBeforeTerminator(args)];
|
|
108
|
+
const { bdBin } = loadBeadsSettings();
|
|
109
|
+
let stdout;
|
|
110
|
+
// QUIRK(beads): embedded mode is single-writer, so concurrent writers can hit "database is locked" and need server mode https://github.com/steveyegge/beads/blob/main/README.md
|
|
111
|
+
try {
|
|
112
|
+
({ stdout } = await execFileAsync(bdBin, argv, {
|
|
113
|
+
signal,
|
|
114
|
+
maxBuffer: MAX_BUFFER,
|
|
115
|
+
env: childEnv(),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
throw new Error(`bd ${args[0] ?? ""} failed: ${describeExecError(err)}`, { cause: err });
|
|
120
|
+
}
|
|
121
|
+
let parsed;
|
|
122
|
+
try {
|
|
123
|
+
parsed = JSON.parse(stdout);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
throw new Error(`bd ${args[0] ?? ""} returned unparseable output: ${truncate(stdout)}`, {
|
|
127
|
+
cause: err,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const unwrapped = unwrapEnvelope(parsed);
|
|
131
|
+
if (isBdError(unwrapped)) {
|
|
132
|
+
throw new Error(`bd ${args[0] ?? ""} failed: ${describeBdError(unwrapped)}`);
|
|
133
|
+
}
|
|
134
|
+
return unwrapped;
|
|
135
|
+
}
|
|
136
|
+
export async function bdBeads(repoPath, args, signal) {
|
|
137
|
+
const payload = await bdJson(repoPath, args, signal);
|
|
138
|
+
if (payload === null || payload === undefined) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
if (!Array.isArray(payload)) {
|
|
142
|
+
throw new Error(`bd ${args[0] ?? ""} did not return an array of issues`);
|
|
143
|
+
}
|
|
144
|
+
return payload.map((item) => parseBead(item));
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=bd.js.map
|