@cmnwlth/cli 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/LICENSE +202 -0
- package/dist/index.d.ts +442 -0
- package/dist/index.js +1081 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 Kristof Feys
|
|
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.
|
|
202
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { NewNoteInput } from '@cmnwlth/core';
|
|
2
|
+
|
|
3
|
+
/** Per-source counts of what seeding mined from the repo. */
|
|
4
|
+
interface InitBySource {
|
|
5
|
+
adr: number;
|
|
6
|
+
git: number;
|
|
7
|
+
config: number;
|
|
8
|
+
}
|
|
9
|
+
/** Flags that shape an `init` run, parsed from the CLI. */
|
|
10
|
+
interface InitOptions {
|
|
11
|
+
/** Explicit brain directory to create/use instead of {@link defaultBrainDir}. */
|
|
12
|
+
brain?: string;
|
|
13
|
+
/** Skip the confirmation prompt and seed non-interactively. */
|
|
14
|
+
yes?: boolean;
|
|
15
|
+
/** Re-run seeding even if this project already resolves to a brain (skip JOIN). */
|
|
16
|
+
reseed?: boolean;
|
|
17
|
+
/** Gather + stage seed candidates. Defaults to `true`; `false` creates the brain but skips staging. */
|
|
18
|
+
seed?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Injected side effects so {@link runInit} is deterministic and unit-testable without
|
|
22
|
+
* touching the filesystem, spawning `commonwealth-curate`, or prompting a human.
|
|
23
|
+
*/
|
|
24
|
+
interface InitDeps {
|
|
25
|
+
/** Mine cold-start candidates from the repo (usually `@cmnwlth/seed`'s `gatherCandidates`). */
|
|
26
|
+
gather(repoDir: string): Promise<{
|
|
27
|
+
candidates: NewNoteInput[];
|
|
28
|
+
bySource: InitBySource;
|
|
29
|
+
}>;
|
|
30
|
+
/** Resolve the brain this project already belongs to, or `null` if none. */
|
|
31
|
+
resolveBrain(cwd: string): Promise<string | null>;
|
|
32
|
+
/** Scaffold a fresh brain at `dir` with the given human-readable name. */
|
|
33
|
+
createBrain(dir: string, name: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Record that `repoDir` maps to `brainDir` in the global brain registry (ADR-0011). The
|
|
36
|
+
* registry is the default source of truth; the per-project `.commonwealth/brain` marker
|
|
37
|
+
* remains an optional manual override (`core.setBrainMarker`), not written here.
|
|
38
|
+
*/
|
|
39
|
+
registerBrain(repoDir: string, brainDir: string): Promise<void>;
|
|
40
|
+
/** Stage candidates into the brain's review queue; returns how many were captured. */
|
|
41
|
+
stage(brainDir: string, candidates: NewNoteInput[]): Promise<{
|
|
42
|
+
captured: number;
|
|
43
|
+
}>;
|
|
44
|
+
/** Ask the user a yes/no question; resolves to their answer. */
|
|
45
|
+
confirm(message: string): Promise<boolean>;
|
|
46
|
+
/** Emit a human-facing line (diagnostics stream, never stdout data). */
|
|
47
|
+
log(message: string): void;
|
|
48
|
+
}
|
|
49
|
+
/** What an {@link runInit} run did, for the CLI to summarize and tests to assert on. */
|
|
50
|
+
interface InitResult {
|
|
51
|
+
/** `new` = brain created + seeded; `join` = mounted existing brain; `skipped` = created but seeding declined. */
|
|
52
|
+
mode: "new" | "join" | "skipped";
|
|
53
|
+
/** The brain directory this project is now pinned to. */
|
|
54
|
+
brainDir: string;
|
|
55
|
+
/** How many candidate notes were staged into the review queue. */
|
|
56
|
+
staged: number;
|
|
57
|
+
/** How many candidates seeding gathered (0 in JOIN mode). */
|
|
58
|
+
gathered: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Walk up from `startDir` looking for a `.git` directory; return the repo root, or fall
|
|
62
|
+
* back to `startDir` when no `.git` ancestor exists (e.g. a not-yet-initialized project).
|
|
63
|
+
*
|
|
64
|
+
* @param startDir Directory to start the upward search from.
|
|
65
|
+
* @returns The nearest ancestor containing `.git`, else `startDir`.
|
|
66
|
+
*/
|
|
67
|
+
declare function findRepoRoot(startDir: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Compute the default brain directory for a project. The brain is a SEPARATE repo living
|
|
70
|
+
* under `~/.commonwealth/brains/<basename>-<hash>`, never nested inside the project itself.
|
|
71
|
+
* The short hash of the FULL resolved path disambiguates same-named projects in different
|
|
72
|
+
* locations (`~/work/app` vs `~/personal/app`), which would otherwise collapse to one brain
|
|
73
|
+
* and silently share it (#103). Deterministic, so re-running `init` maps to the same brain.
|
|
74
|
+
*
|
|
75
|
+
* @param repoRoot The project's repo root.
|
|
76
|
+
* @returns An absolute path for the project's default brain.
|
|
77
|
+
*/
|
|
78
|
+
declare function defaultBrainDir(repoRoot: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Orchestrate `commonwealth init`. Deterministic and side-effect-free except through `deps`.
|
|
81
|
+
*
|
|
82
|
+
* Flow: resolve the repo root and any existing brain. If one exists and we're not
|
|
83
|
+
* reseeding, JOIN it (register the mapping, done). Otherwise create a new brain, register
|
|
84
|
+
* the project → brain mapping, gather seed candidates, preview them, and — guarded behind
|
|
85
|
+
* confirmation unless `--yes` — stage them into the review queue. Brain creation and the
|
|
86
|
+
* registry mapping are idempotent and always run; every content write (staging) is gated
|
|
87
|
+
* by `confirm`.
|
|
88
|
+
*
|
|
89
|
+
* @param cwd The directory `commonwealth init` was invoked from.
|
|
90
|
+
* @param opts Parsed CLI flags.
|
|
91
|
+
* @param deps Injected side effects.
|
|
92
|
+
* @returns A structured summary of what happened.
|
|
93
|
+
*/
|
|
94
|
+
declare function runInit(cwd: string, opts: InitOptions, deps: InitDeps): Promise<InitResult>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A minimal interactive prompter over a terminal. {@link createReadlinePrompter} wires this to
|
|
98
|
+
* `node:readline/promises`; the wizard depends only on this interface so tests can drive it with a
|
|
99
|
+
* scripted fake and never touch a real TTY.
|
|
100
|
+
*/
|
|
101
|
+
interface Prompter {
|
|
102
|
+
/** Ask for free text; show `message [def]: `; empty input returns `def`. */
|
|
103
|
+
text(message: string, def: string): Promise<string>;
|
|
104
|
+
/** Ask a yes/no question defaulting to `def`; empty input returns `def`. */
|
|
105
|
+
confirm(message: string, def: boolean): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Numbered multi-select over the given items. Prints each with a `[x]`/`[ ]` marker reflecting
|
|
108
|
+
* `defaultSelected`, then accepts `all` / `none` / a comma-or-space list of 1-based indices;
|
|
109
|
+
* empty input keeps the defaults. Returns the chosen items' `value`s (in item order).
|
|
110
|
+
*/
|
|
111
|
+
select(message: string, items: {
|
|
112
|
+
label: string;
|
|
113
|
+
value: string;
|
|
114
|
+
}[], defaultSelected: boolean[]): Promise<string[]>;
|
|
115
|
+
/** Release the underlying readline interface (idempotent). */
|
|
116
|
+
close(): void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* True only when BOTH stdin and stdout are TTYs — the precondition for interactive prompting.
|
|
120
|
+
* Non-TTY (piped/CI) callers must fall back to defaults + flags and never block on stdin.
|
|
121
|
+
*/
|
|
122
|
+
declare function isInteractive(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Parse a yes/no answer. Recognizes `y`/`yes`/`n`/`no` case-insensitively (trimmed); empty input
|
|
125
|
+
* returns `def`; anything else also falls back to `def` (a lenient default-accept). Pure, so it is
|
|
126
|
+
* unit-testable without a TTY.
|
|
127
|
+
*
|
|
128
|
+
* @param input Raw line the user typed.
|
|
129
|
+
* @param def The default applied to empty (or unrecognized) input.
|
|
130
|
+
* @returns The resolved boolean answer.
|
|
131
|
+
*/
|
|
132
|
+
declare function parseConfirm(input: string, def: boolean): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Resolve a free-text answer against its default: empty (trimmed) input returns `def`, otherwise
|
|
135
|
+
* the trimmed input. Pure counterpart to {@link Prompter.text} for unit tests.
|
|
136
|
+
*
|
|
137
|
+
* @param input Raw line the user typed.
|
|
138
|
+
* @param def The default applied to empty input.
|
|
139
|
+
* @returns The resolved text answer.
|
|
140
|
+
*/
|
|
141
|
+
declare function parseText(input: string, def: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* Resolve a multi-select answer against a list of candidate values. Pure counterpart to
|
|
144
|
+
* {@link Prompter.select} so tests never touch a TTY. Rules:
|
|
145
|
+
* - empty (trimmed) input keeps `defaultSelected` (values whose flag is true, in order);
|
|
146
|
+
* - `all` selects every value; `none` selects nothing;
|
|
147
|
+
* - otherwise the input is split on commas/whitespace and each token parsed as a 1-based index;
|
|
148
|
+
* out-of-range or non-numeric tokens are ignored, duplicates collapse, and the result is
|
|
149
|
+
* returned in `values` order.
|
|
150
|
+
*
|
|
151
|
+
* @param input Raw line the user typed.
|
|
152
|
+
* @param values The candidate values, in display order.
|
|
153
|
+
* @param defaultSelected Per-value default flags (same length/order as `values`).
|
|
154
|
+
* @returns The chosen values, in `values` order.
|
|
155
|
+
*/
|
|
156
|
+
declare function parseSelection(input: string, values: string[], defaultSelected: boolean[]): string[];
|
|
157
|
+
/**
|
|
158
|
+
* A real {@link Prompter} backed by `node:readline/promises` over stdin/stdout. Only construct this
|
|
159
|
+
* after {@link isInteractive} returns true; on a non-TTY it would block waiting for input.
|
|
160
|
+
*
|
|
161
|
+
* @returns A prompter whose `close()` ends the readline interface.
|
|
162
|
+
*/
|
|
163
|
+
declare function createReadlinePrompter(): Prompter;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Flags that shape a full `commonwealth init` orchestration. The step gates (`seed`, `mcp`,
|
|
167
|
+
* `daemon`, `build`, `scope`) default to `true` when omitted; pass `false` to skip that step. This
|
|
168
|
+
* is a type alias (not an interface) so it stays free of empty-interface lint noise.
|
|
169
|
+
*/
|
|
170
|
+
type OnboardOptions = {
|
|
171
|
+
/** Explicit brain directory to create/use instead of the project default. */
|
|
172
|
+
brain?: string;
|
|
173
|
+
/** Skip the whole-plan confirmation and run non-interactively. */
|
|
174
|
+
yes?: boolean;
|
|
175
|
+
/** Re-run seeding even if this project already resolves to a brain. */
|
|
176
|
+
reseed?: boolean;
|
|
177
|
+
/** Gather + stage seed candidates. Default: true. `false` skips staging. */
|
|
178
|
+
seed?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Install the Commonwealth plugin (global MCP + session hooks) via the repo marketplace.
|
|
181
|
+
* Default: true. The plugin resolves the brain per repo dynamically, so no brain dir is
|
|
182
|
+
* pinned. `mcp` is a backward-compatible alias for this gate.
|
|
183
|
+
*/
|
|
184
|
+
plugin?: boolean;
|
|
185
|
+
/** Backward-compatible alias for {@link OnboardOptions.plugin}. */
|
|
186
|
+
mcp?: boolean;
|
|
187
|
+
/** Start the sync daemon for the brain. Default: true. */
|
|
188
|
+
daemon?: boolean;
|
|
189
|
+
/** Build/bundle the workspace if dist artifacts are missing. Default: true. */
|
|
190
|
+
build?: boolean;
|
|
191
|
+
/** Add the repo root to the capture allowlist (`scope allow`). Default: true. */
|
|
192
|
+
scope?: boolean;
|
|
193
|
+
/** Enable auto-ADR capture for the brain. Default: false. */
|
|
194
|
+
autoAdr?: boolean;
|
|
195
|
+
/** Add this URL as the brain's git `origin` remote. Default: undefined (skip). */
|
|
196
|
+
remote?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Folders to sync into this brain: each is added to the capture allowlist and wired to the
|
|
199
|
+
* brain via the global user registry (plus a convenience symlink). Default: `[cwd]` (#61).
|
|
200
|
+
*/
|
|
201
|
+
syncFolders?: string[];
|
|
202
|
+
/**
|
|
203
|
+
* Repos to mine (seed) into the brain now. Default: {@link OnboardOptions.syncFolders} when
|
|
204
|
+
* seeding is enabled, else `[]`.
|
|
205
|
+
*/
|
|
206
|
+
seedRepos?: string[];
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Injected side effects so {@link runOnboard} is deterministic and unit-testable without
|
|
210
|
+
* building the workspace, delegating to `runInit`, spawning `claude`, or starting a daemon.
|
|
211
|
+
*/
|
|
212
|
+
interface OnboardDeps {
|
|
213
|
+
/** Build the workspace when dist artifacts are missing; a no-op (with a note) otherwise. */
|
|
214
|
+
ensureBuilt(): Promise<{
|
|
215
|
+
built: boolean;
|
|
216
|
+
skipped?: string;
|
|
217
|
+
}>;
|
|
218
|
+
/** Create/seed/join the brain (delegates to `runInit` with real init deps). */
|
|
219
|
+
init(cwd: string, initOpts: InitOptions): Promise<InitResult>;
|
|
220
|
+
/** Idempotently add `folder` to the capture allowlist (`scope allow`; de-dupes). */
|
|
221
|
+
configureScope(folder: string): Promise<{
|
|
222
|
+
added: boolean;
|
|
223
|
+
skipped?: string;
|
|
224
|
+
}>;
|
|
225
|
+
/**
|
|
226
|
+
* Register `folder → brainDir` in the global user registry (the default brain-wiring source
|
|
227
|
+
* of truth) and drop a convenience `~/.commonwealth/brains/<name>` symlink. Idempotent;
|
|
228
|
+
* never throws. `mapped` reflects the registry write, `linked` the symlink; `skipped` carries
|
|
229
|
+
* a reason when the symlink could not be created (the mapping still counts).
|
|
230
|
+
*/
|
|
231
|
+
registerBrain(folder: string, brainDir: string): Promise<{
|
|
232
|
+
mapped: boolean;
|
|
233
|
+
linked: boolean;
|
|
234
|
+
skipped?: string;
|
|
235
|
+
}>;
|
|
236
|
+
/** Mine `repoDir` and stage the candidates into `brainDir`'s review queue. */
|
|
237
|
+
seedFrom(brainDir: string, repoDir: string): Promise<{
|
|
238
|
+
staged: number;
|
|
239
|
+
skipped?: string;
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Ensure the per-user scope config file exists (creating an empty one if missing) and return
|
|
243
|
+
* its resolved path. Called near the end of onboarding regardless of scope choices.
|
|
244
|
+
*/
|
|
245
|
+
ensureUserConfig(): Promise<{
|
|
246
|
+
path: string;
|
|
247
|
+
}>;
|
|
248
|
+
/** Enable/disable auto-ADR capture for `brainDir`. */
|
|
249
|
+
setAutoAdr(brainDir: string, on: boolean): Promise<{
|
|
250
|
+
set: boolean;
|
|
251
|
+
skipped?: string;
|
|
252
|
+
}>;
|
|
253
|
+
/** Add `url` as the brain's git `origin` remote unless one already exists. */
|
|
254
|
+
setRemote(brainDir: string, url: string): Promise<{
|
|
255
|
+
set: boolean;
|
|
256
|
+
skipped?: string;
|
|
257
|
+
}>;
|
|
258
|
+
/**
|
|
259
|
+
* Idempotently install the Commonwealth plugin (global MCP + session hooks) via the repo
|
|
260
|
+
* marketplace with the `claude` CLI. No brain dir is needed — the plugin + its SessionStart
|
|
261
|
+
* hook resolve the brain per repo dynamically (ADR-0012). Never throws. `installed` is true
|
|
262
|
+
* when the plugin is present after the step; `skipped` carries a reason when it is not.
|
|
263
|
+
*/
|
|
264
|
+
installPlugin(): Promise<{
|
|
265
|
+
installed: boolean;
|
|
266
|
+
skipped?: string;
|
|
267
|
+
}>;
|
|
268
|
+
/** Start the sync daemon for `brainDir`, or report it already running. */
|
|
269
|
+
startDaemon(brainDir: string): Promise<{
|
|
270
|
+
started: boolean;
|
|
271
|
+
alreadyRunning?: boolean;
|
|
272
|
+
skipped?: string;
|
|
273
|
+
}>;
|
|
274
|
+
/** Ask the user a yes/no question; resolves to their answer. */
|
|
275
|
+
confirm(message: string): Promise<boolean>;
|
|
276
|
+
/** Emit a human-facing line (diagnostics stream, never stdout data). */
|
|
277
|
+
log(message: string): void;
|
|
278
|
+
}
|
|
279
|
+
/** What a {@link runOnboard} run did, for the CLI to summarize and tests to assert on. */
|
|
280
|
+
interface OnboardResult {
|
|
281
|
+
/** The brain directory this project is now pinned to. */
|
|
282
|
+
brainDir: string;
|
|
283
|
+
/** Delegated `runInit` mode: `new` / `join` / `skipped`. */
|
|
284
|
+
mode: InitResult["mode"];
|
|
285
|
+
/** Whether {@link OnboardDeps.ensureBuilt} actually built anything. */
|
|
286
|
+
built: boolean;
|
|
287
|
+
/** How many candidate notes were staged into the review queue (summed across seeded repos). */
|
|
288
|
+
staged: number;
|
|
289
|
+
/** How many folders were added to the capture allowlist. */
|
|
290
|
+
scopedFolders: number;
|
|
291
|
+
/** How many folders were wired into a brain via the global registry. */
|
|
292
|
+
mappedFolders: number;
|
|
293
|
+
/** How many repos were seeded (mined) into the brain. */
|
|
294
|
+
seededRepos: number;
|
|
295
|
+
/** Resolved path of the per-user scope config file (always ensured to exist). */
|
|
296
|
+
scopeConfigPath: string;
|
|
297
|
+
/** Short allowlist status string (e.g. `added`, `skipped`). */
|
|
298
|
+
scope: string;
|
|
299
|
+
/** Short auto-ADR status string (e.g. `enabled`, `skipped`). */
|
|
300
|
+
autoAdr: string;
|
|
301
|
+
/** Short brain-remote status string (e.g. `set`, `origin exists`, `skipped`). */
|
|
302
|
+
remote: string;
|
|
303
|
+
/** Short plugin-install status string (e.g. `installed`, `skipped`). */
|
|
304
|
+
plugin: string;
|
|
305
|
+
/** Short daemon status string (e.g. `started`, `already running`, `skipped`). */
|
|
306
|
+
daemon: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Orchestrate the full `commonwealth init`: build the workspace (if needed), create/seed/join
|
|
310
|
+
* the brain, install the Commonwealth plugin (global MCP + session hooks), and start the sync
|
|
311
|
+
* daemon — a single idempotent command. Deterministic and side-effect-free except through `deps`.
|
|
312
|
+
*
|
|
313
|
+
* Flow: build a plan and log it; unless `--yes`, confirm the whole plan (a decline does NOTHING
|
|
314
|
+
* and returns early); then run each enabled step in order — ensureBuilt, init, installPlugin,
|
|
315
|
+
* startDaemon — and log a done summary. Each step is individually gated by its option and every
|
|
316
|
+
* step is idempotent, so re-running is safe.
|
|
317
|
+
*
|
|
318
|
+
* @param cwd The directory `commonwealth init` was invoked from.
|
|
319
|
+
* @param opts Parsed CLI flags (step gates default to enabled).
|
|
320
|
+
* @param deps Injected side effects.
|
|
321
|
+
* @returns A structured summary of what happened.
|
|
322
|
+
*/
|
|
323
|
+
declare function runOnboard(cwd: string, opts: OnboardOptions, deps: OnboardDeps): Promise<OnboardResult>;
|
|
324
|
+
/** The answers a wizard collects, ready to be turned into {@link OnboardOptions}. */
|
|
325
|
+
interface WizardAnswers {
|
|
326
|
+
brain: string;
|
|
327
|
+
scope: boolean;
|
|
328
|
+
seed: boolean;
|
|
329
|
+
plugin: boolean;
|
|
330
|
+
daemon: boolean;
|
|
331
|
+
autoAdr: boolean;
|
|
332
|
+
remote: string;
|
|
333
|
+
}
|
|
334
|
+
/** Defaults the wizard seeds its prompts with (Enter accepts each). */
|
|
335
|
+
interface WizardDefaults {
|
|
336
|
+
brain: string;
|
|
337
|
+
/**
|
|
338
|
+
* The invocation dir — the fallback sync/seed target when no sibling repos are found, and the
|
|
339
|
+
* base whose parent is offered as the default scan directory. Deliberately NOT the git root:
|
|
340
|
+
* that can climb above `cwd` and over-scope (#61).
|
|
341
|
+
*/
|
|
342
|
+
projectDir: string;
|
|
343
|
+
scope: boolean;
|
|
344
|
+
seed: boolean;
|
|
345
|
+
plugin: boolean;
|
|
346
|
+
daemon: boolean;
|
|
347
|
+
autoAdr: boolean;
|
|
348
|
+
}
|
|
349
|
+
/** What {@link runWizard} produces: the assembled options, or an abort signal. */
|
|
350
|
+
type WizardOutcome = {
|
|
351
|
+
proceed: true;
|
|
352
|
+
opts: OnboardOptions;
|
|
353
|
+
} | {
|
|
354
|
+
proceed: false;
|
|
355
|
+
opts: null;
|
|
356
|
+
};
|
|
357
|
+
/** Injectable side effects for {@link runWizard} (defaults to the real discovery). */
|
|
358
|
+
interface WizardDeps {
|
|
359
|
+
/** Scan `baseDir` for git repositories (defaults to {@link findGitRepos}). */
|
|
360
|
+
scan(baseDir: string): Promise<string[]>;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Drive the interactive wizard: ask each choice with a sensible default (Enter accepts), then a
|
|
364
|
+
* final `Proceed?` confirm. Pure orchestration over a {@link Prompter} + {@link WizardDeps}, so
|
|
365
|
+
* tests script answers with a fake and never touch a real TTY or filesystem. A declined
|
|
366
|
+
* `Proceed?` returns `{ proceed: false }` and the caller must perform ZERO side effects.
|
|
367
|
+
*
|
|
368
|
+
* After the brain prompt it asks which directory to scan for projects, discovers the git repos
|
|
369
|
+
* beneath it, and lets the user multi-select which folders to SYNC into the brain and which repos
|
|
370
|
+
* to SEED now (seed defaults to the sync selection). When nothing is found it falls back to the
|
|
371
|
+
* repo root for both.
|
|
372
|
+
*
|
|
373
|
+
* The returned `opts` carry `yes: true` because the wizard has already confirmed — the caller must
|
|
374
|
+
* NOT prompt again inside {@link runOnboard}.
|
|
375
|
+
*
|
|
376
|
+
* @param defaults Per-prompt defaults (usually derived from environment probing).
|
|
377
|
+
* @param prompter The interactive prompter.
|
|
378
|
+
* @param deps Injectable discovery (defaults to scanning the real filesystem).
|
|
379
|
+
* @returns A {@link WizardOutcome}: the options to run, or an abort.
|
|
380
|
+
*/
|
|
381
|
+
declare function runWizard(defaults: WizardDefaults, prompter: Prompter, deps?: WizardDeps): Promise<WizardOutcome>;
|
|
382
|
+
|
|
383
|
+
/** Options for {@link defaultInitDeps}, mostly to make wiring testable/overridable. */
|
|
384
|
+
interface DefaultInitDepsOptions {
|
|
385
|
+
/** Absolute path to `commonwealth-curate`'s built entry (its `capture` subcommand is spawned). */
|
|
386
|
+
curateEntry?: string;
|
|
387
|
+
/** When true, `confirm` always resolves `true` (from `--yes`). */
|
|
388
|
+
assumeYes?: boolean;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Wire the real {@link InitDeps}: seed for gathering, core for brain/marker resolution, a
|
|
392
|
+
* spawned `commonwealth-curate capture` for staging, a readline prompt for confirmation, and
|
|
393
|
+
* stderr for logging. Pure orchestration lives in {@link runInit}; this is the only place
|
|
394
|
+
* that performs real I/O.
|
|
395
|
+
*
|
|
396
|
+
* @param opts Optional overrides ({@link DefaultInitDepsOptions}).
|
|
397
|
+
* @returns A fully-wired {@link InitDeps}.
|
|
398
|
+
*/
|
|
399
|
+
declare function defaultInitDeps(opts?: DefaultInitDepsOptions): InitDeps;
|
|
400
|
+
/** Options for {@link defaultOnboardDeps}, mostly to make wiring testable/overridable. */
|
|
401
|
+
interface DefaultOnboardDepsOptions {
|
|
402
|
+
/** Repo root to resolve dist paths from; defaults to the nearest `.git` ancestor of cwd. */
|
|
403
|
+
repoRoot?: string;
|
|
404
|
+
/** Absolute path to `commonwealth-curate`'s built entry, forwarded to {@link defaultInitDeps}. */
|
|
405
|
+
curateEntry?: string;
|
|
406
|
+
}
|
|
407
|
+
declare function defaultOnboardDeps(opts?: DefaultOnboardDepsOptions): OnboardDeps;
|
|
408
|
+
|
|
409
|
+
/** Options for {@link findGitRepos}. */
|
|
410
|
+
interface FindGitReposOptions {
|
|
411
|
+
/** How many directory levels below `baseDir` to descend (default 2). `0` = only `baseDir`. */
|
|
412
|
+
maxDepth?: number;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Discover git repositories under `baseDir`: every directory that directly contains a `.git`
|
|
416
|
+
* entry (a file or directory), scanning up to `maxDepth` levels deep. Skips `node_modules` and
|
|
417
|
+
* any dot-directory (e.g. `.git`, `.cache`) so it never descends into vendored or hidden trees.
|
|
418
|
+
*
|
|
419
|
+
* Never throws: an unreadable directory is simply skipped. Results are absolute, de-duped, and
|
|
420
|
+
* sorted lexicographically for deterministic output.
|
|
421
|
+
*
|
|
422
|
+
* @param baseDir Directory to scan from.
|
|
423
|
+
* @param opts Optional depth cap ({@link FindGitReposOptions}).
|
|
424
|
+
* @returns Absolute paths of directories that are git repos, sorted and de-duped.
|
|
425
|
+
*/
|
|
426
|
+
declare function findGitRepos(baseDir: string, opts?: FindGitReposOptions): Promise<string[]>;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* `commonwealth` CLI entry. Parses argv, dispatches `init` to the full {@link runOnboard}
|
|
430
|
+
* orchestration, prints the plan + a one-line summary to stderr, and resolves the exit code.
|
|
431
|
+
* Diagnostics go to stderr; there is no stdout data contract for `init`. Unknown commands and
|
|
432
|
+
* `--help` print usage.
|
|
433
|
+
*
|
|
434
|
+
* `parseArgs` has no native boolean negation, so `--no-seed`/`--no-mcp`/`--no-daemon`/`--no-build`
|
|
435
|
+
* are stripped from argv here and turned into `false` gates before parsing the rest.
|
|
436
|
+
*
|
|
437
|
+
* @param argv Arguments after `node <script>` (i.e. `process.argv.slice(2)`).
|
|
438
|
+
* @returns Exit code: 0 on success, 2 on usage error.
|
|
439
|
+
*/
|
|
440
|
+
declare function run(argv: string[]): Promise<number>;
|
|
441
|
+
|
|
442
|
+
export { type FindGitReposOptions, type InitBySource, type InitDeps, type InitOptions, type InitResult, type OnboardDeps, type OnboardOptions, type OnboardResult, type Prompter, type WizardAnswers, type WizardDefaults, type WizardDeps, type WizardOutcome, createReadlinePrompter, defaultBrainDir, defaultInitDeps, defaultOnboardDeps, findGitRepos, findRepoRoot, isInteractive, parseConfirm, parseSelection, parseText, run, runInit, runOnboard, runWizard };
|