@purix/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/cli/commands/auth.d.ts +3 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +130 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/backup.d.ts +3 -0
- package/dist/cli/commands/backup.d.ts.map +1 -0
- package/dist/cli/commands/backup.js +54 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +35 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/connect.d.ts +16 -0
- package/dist/cli/commands/connect.d.ts.map +1 -0
- package/dist/cli/commands/connect.js +45 -0
- package/dist/cli/commands/connect.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +3 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +58 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/index.d.ts +3 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +35 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/lang.d.ts +3 -0
- package/dist/cli/commands/lang.d.ts.map +1 -0
- package/dist/cli/commands/lang.js +187 -0
- package/dist/cli/commands/lang.js.map +1 -0
- package/dist/cli/commands/lifecycle.d.ts +3 -0
- package/dist/cli/commands/lifecycle.d.ts.map +1 -0
- package/dist/cli/commands/lifecycle.js +782 -0
- package/dist/cli/commands/lifecycle.js.map +1 -0
- package/dist/cli/commands/mcp.d.ts +3 -0
- package/dist/cli/commands/mcp.d.ts.map +1 -0
- package/dist/cli/commands/mcp.js +75 -0
- package/dist/cli/commands/mcp.js.map +1 -0
- package/dist/cli/commands/mcp_serve.d.ts +3 -0
- package/dist/cli/commands/mcp_serve.d.ts.map +1 -0
- package/dist/cli/commands/mcp_serve.js +16 -0
- package/dist/cli/commands/mcp_serve.js.map +1 -0
- package/dist/cli/commands/memory.d.ts +3 -0
- package/dist/cli/commands/memory.d.ts.map +1 -0
- package/dist/cli/commands/memory.js +12 -0
- package/dist/cli/commands/memory.js.map +1 -0
- package/dist/cli/commands/migrations.d.ts +3 -0
- package/dist/cli/commands/migrations.d.ts.map +1 -0
- package/dist/cli/commands/migrations.js +98 -0
- package/dist/cli/commands/migrations.js.map +1 -0
- package/dist/cli/commands/observability.d.ts +3 -0
- package/dist/cli/commands/observability.d.ts.map +1 -0
- package/dist/cli/commands/observability.js +141 -0
- package/dist/cli/commands/observability.js.map +1 -0
- package/dist/cli/commands/provider.d.ts +3 -0
- package/dist/cli/commands/provider.d.ts.map +1 -0
- package/dist/cli/commands/provider.js +82 -0
- package/dist/cli/commands/provider.js.map +1 -0
- package/dist/cli/commands/security.d.ts +3 -0
- package/dist/cli/commands/security.d.ts.map +1 -0
- package/dist/cli/commands/security.js +27 -0
- package/dist/cli/commands/security.js.map +1 -0
- package/dist/cli/commands/tier.d.ts +3 -0
- package/dist/cli/commands/tier.d.ts.map +1 -0
- package/dist/cli/commands/tier.js +27 -0
- package/dist/cli/commands/tier.js.map +1 -0
- package/dist/cli/commands/tools.d.ts +3 -0
- package/dist/cli/commands/tools.d.ts.map +1 -0
- package/dist/cli/commands/tools.js +18 -0
- package/dist/cli/commands/tools.js.map +1 -0
- package/dist/cli/output.d.ts +5 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +22 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/savings_output.d.ts +9 -0
- package/dist/cli/savings_output.d.ts.map +1 -0
- package/dist/cli/savings_output.js +62 -0
- package/dist/cli/savings_output.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +155 -0
- package/dist/cli.js.map +1 -0
- package/dist/telemetry/log.d.ts +4 -0
- package/dist/telemetry/log.d.ts.map +1 -0
- package/dist/telemetry/log.js +92 -0
- package/dist/telemetry/log.js.map +1 -0
- package/package.json +47 -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
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
original version of the Work and any modifications or additions to
|
|
50
|
+
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
|
|
57
|
+
systems, and issue tracking systems that are managed by, or on behalf
|
|
58
|
+
of, the Licensor for the purpose of discussing and improving the
|
|
59
|
+
Work, but excluding communication that is conspicuously marked or
|
|
60
|
+
otherwise designated in writing by the copyright owner as
|
|
61
|
+
"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
|
|
142
|
+
the 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 [yyyy] [name of copyright owner]
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/auth.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkBzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAqHpD"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as readline from "node:readline/promises";
|
|
2
|
+
import { apiClient, ApiUnreachableError, ApiRequestError } from "@purix/core/security/api_client";
|
|
3
|
+
import { saveSession, clearSession, loadSession } from "@purix/core/security/session";
|
|
4
|
+
import { refreshEntitlements, clearEntitlementsCache } from "@purix/core/licensing/tier";
|
|
5
|
+
import { getProjectId } from "@purix/core/state/project_id";
|
|
6
|
+
import { getMachineId } from "@purix/core/state/machine_id";
|
|
7
|
+
import { getSavingsSummary } from "@purix/core/llm/budget";
|
|
8
|
+
async function prompt(question) {
|
|
9
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
10
|
+
try {
|
|
11
|
+
return (await rl.question(question)).trim();
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
rl.close();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function registerAuthCommands(program) {
|
|
18
|
+
program
|
|
19
|
+
.command("login")
|
|
20
|
+
.description("Log in to sync savings history and unlock your web dashboard")
|
|
21
|
+
.action(async () => {
|
|
22
|
+
const existing = loadSession();
|
|
23
|
+
if (existing) {
|
|
24
|
+
console.log(`Already logged in as ${existing.email}. Run "purix logout" first to switch accounts.`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const email = await prompt("Email: ");
|
|
28
|
+
if (!email.includes("@")) {
|
|
29
|
+
console.error("That doesn't look like an email address.");
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
await apiClient.requestCode(email);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
// Part 3: "if email delivery fails, return a real error to the
|
|
38
|
+
// CLI, never a silent 'check your email'" — surfaced verbatim
|
|
39
|
+
// here, not swallowed into a generic message.
|
|
40
|
+
console.error(`Couldn't send a login code: ${err instanceof Error ? err.message : err}`);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log(`A 6-digit code was sent to ${email}.`);
|
|
45
|
+
const code = await prompt("Code: ");
|
|
46
|
+
let token;
|
|
47
|
+
try {
|
|
48
|
+
const result = await apiClient.verifyCode(email, code);
|
|
49
|
+
token = result.token;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error(`Login failed: ${err instanceof Error ? err.message : err}`);
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
saveSession(token, email);
|
|
57
|
+
console.log(`✅ Logged in as ${email}.`);
|
|
58
|
+
// Part 4: "On first successful login, call /sync/savings with the
|
|
59
|
+
// full local ledger history across every project this machine has
|
|
60
|
+
// data for." Honest limitation, not silently glossed over: nothing
|
|
61
|
+
// in this codebase maintains a registry of every project directory
|
|
62
|
+
// Purix has ever been run in — each project's .purix/ is
|
|
63
|
+
// independent and unaware of siblings — so "every project" isn't
|
|
64
|
+
// achievable from a single `purix login` invocation without adding
|
|
65
|
+
// that registry. What this DOES do is sync the current project
|
|
66
|
+
// (the one login was run from); the architecture doc's "periodic /
|
|
67
|
+
// per-run" sync trigger picks up every other project incrementally
|
|
68
|
+
// as the user works in them, so the end state converges to "every
|
|
69
|
+
// project synced" over time rather than instantly at login.
|
|
70
|
+
try {
|
|
71
|
+
const summary = getSavingsSummary(3650); // ~10 years — effectively "all time" for this project
|
|
72
|
+
if (summary.callCount > 0) {
|
|
73
|
+
await apiClient.syncSavings([
|
|
74
|
+
{
|
|
75
|
+
projectId: getProjectId(),
|
|
76
|
+
machineId: getMachineId(),
|
|
77
|
+
windowStart: new Date(0).toISOString(),
|
|
78
|
+
totalSavingsUsd: summary.totalSavingsUsd,
|
|
79
|
+
callCount: summary.callCount,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
// Part 3: "a network blip mid-purix login shouldn't fail the
|
|
86
|
+
// login itself, log and retry the sync on next invocation
|
|
87
|
+
// instead of blocking session issuance on it." Login has already
|
|
88
|
+
// succeeded above; this failure is logged, not fatal.
|
|
89
|
+
console.warn(` (savings sync didn't complete — will retry on a future run: ${err instanceof Error ? err.message : err})`);
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await refreshEntitlements();
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (!(err instanceof ApiUnreachableError)) {
|
|
96
|
+
console.warn(` (couldn't fetch entitlements yet: ${err instanceof Error ? err.message : err})`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
program
|
|
101
|
+
.command("logout")
|
|
102
|
+
.description("Log out and clear the local session")
|
|
103
|
+
.action(async () => {
|
|
104
|
+
if (!loadSession()) {
|
|
105
|
+
console.log("Not logged in.");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
await apiClient.logout();
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
// Best-effort server-side invalidation — local logout must
|
|
113
|
+
// succeed even offline, or a user with no connectivity could
|
|
114
|
+
// never log out of a machine.
|
|
115
|
+
if (!(err instanceof ApiUnreachableError)) {
|
|
116
|
+
console.warn(` (server logout didn't complete: ${err instanceof Error ? err.message : err})`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
clearSession();
|
|
120
|
+
// This must happen immediately, not on the next TTL expiry — see
|
|
121
|
+
// the design note in tier.ts / the offline-grace interaction this
|
|
122
|
+
// exists to close: without it, logging out, then losing
|
|
123
|
+
// connectivity, then running a Pro-gated command would read the
|
|
124
|
+
// stale cached tier under the 72-hour grace window and let a
|
|
125
|
+
// logged-out session through as Pro for up to three days.
|
|
126
|
+
clearEntitlementsCache();
|
|
127
|
+
console.log("✅ Logged out.");
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/cli/commands/auth.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,KAAK,UAAU,MAAM,CAAC,QAAgB;IACpC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe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AkE;QAClE,wDAAwD;QACxD,gEAAgE;QAChE,6DAA6D;QAC7D,0DAA0D;QAC1D,sBAAsB,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/backup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QA8CtD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { confirmGated } from "@purix/core/cli-io/gated-confirm";
|
|
2
|
+
import { exportManifestData, importManifestData } from "@purix/core/manifest/store";
|
|
3
|
+
import { reconcilePendingOperations } from "@purix/core/state/reconcile";
|
|
4
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
export function registerBackupCommands(program) {
|
|
6
|
+
program
|
|
7
|
+
.command("backup <outFile>")
|
|
8
|
+
.description("Export the manifest + pending operations to a JSON file")
|
|
9
|
+
.action(async (outFile) => {
|
|
10
|
+
try {
|
|
11
|
+
const data = exportManifestData();
|
|
12
|
+
await writeFile(outFile, JSON.stringify(data, null, 2), "utf-8");
|
|
13
|
+
console.log(`✅ Backed up ${data.manifest.length} component(s) to ${outFile}.`);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(`\n🛑 Failed to write backup: ${err instanceof Error ? err.message : err}`);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
program
|
|
21
|
+
.command("restore <inFile>")
|
|
22
|
+
.description("Restore the manifest from a backup file — DESTRUCTIVE, replaces current state")
|
|
23
|
+
.action(async (inFile) => {
|
|
24
|
+
try {
|
|
25
|
+
const proceed = await confirmGated(`This will WIPE and replace the current manifest with the contents of ${inFile}. Continue?`, "restore", null);
|
|
26
|
+
if (!proceed)
|
|
27
|
+
return;
|
|
28
|
+
const raw = JSON.parse(await readFile(inFile, "utf-8"));
|
|
29
|
+
importManifestData(raw);
|
|
30
|
+
console.log(`✅ Restored ${raw.manifest.length} component(s) from ${inFile}.`);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error(`\n🛑 Failed to restore backup: ${err instanceof Error ? err.message : err}`);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// reconcile (§7.3 safety net, standalone)
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
program
|
|
41
|
+
.command("reconcile")
|
|
42
|
+
.description("Force a reconciliation pass for crash-interrupted operations")
|
|
43
|
+
.action(async () => {
|
|
44
|
+
try {
|
|
45
|
+
await reconcilePendingOperations();
|
|
46
|
+
console.log("Reconciliation check complete.");
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.error(`\n🛑 Reconciliation failed: ${err instanceof Error ? err.message : err}`);
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=backup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.js","sourceRoot":"","sources":["../../../src/cli/commands/backup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAuB,MAAM,4BAA4B,CAAC;AACzG,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,OAAO;SACJ,OAAO,CAAC,kBAAkB,CAAC;SAC3B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AAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YAC5F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,8EAA8E;IAC9E,0CAA0C;IAC1C,8EAA8E;IAC9E,OAAO;SACJ,OAAO,CAAC,WAAW,CAAC;SACpB,WAAW,CAAC,8DAA8D,CAAC;SAC3E,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC;YACH,MAAM,0BAA0B,EAAE,CAAC;YACnC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YACzF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QAkCtD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { config } from "@purix/core/state/config";
|
|
2
|
+
export function registerConfigCommands(program) {
|
|
3
|
+
const configCmd = program.command("config").description("Read or change local Purix configuration for this project");
|
|
4
|
+
configCmd
|
|
5
|
+
.command("set <key> <value>")
|
|
6
|
+
.description("Set a config value (e.g. `purix config set show-savings off`)")
|
|
7
|
+
.action((key, value) => {
|
|
8
|
+
// Coerce obviously-numeric/boolean-looking values so, e.g.,
|
|
9
|
+
// `purix config set milestone-threshold 100` is stored as a number,
|
|
10
|
+
// not the literal string "100" — matters for the milestone-upsell
|
|
11
|
+
// comparison in lifecycle.ts.
|
|
12
|
+
let coerced = value;
|
|
13
|
+
if (value === "true" || value === "false")
|
|
14
|
+
coerced = value === "true";
|
|
15
|
+
else if (value !== "" && !Number.isNaN(Number(value)))
|
|
16
|
+
coerced = Number(value);
|
|
17
|
+
config.set(key, coerced);
|
|
18
|
+
console.log(`✅ ${key} = ${coerced}`);
|
|
19
|
+
});
|
|
20
|
+
configCmd
|
|
21
|
+
.command("get <key>")
|
|
22
|
+
.description("Show a config value")
|
|
23
|
+
.action((key) => {
|
|
24
|
+
const value = config.get(key);
|
|
25
|
+
console.log(value === undefined ? `(not set)` : String(value));
|
|
26
|
+
});
|
|
27
|
+
configCmd
|
|
28
|
+
.command("delete <key>")
|
|
29
|
+
.description("Remove a config override, reverting to the default")
|
|
30
|
+
.action((key) => {
|
|
31
|
+
config.delete(key);
|
|
32
|
+
console.log(`✅ ${key} reset to default.`);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/cli/commands/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,2DAA2D,CAAC,CAAC;IAErH,SAAS;SACN,OAAO,CAAC,mBAAmB,CAAC;SAC5B,WAAW,CAAC,+DAA+D,CAAC;SAC5E,MAAM,CAAC,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;QACrC,4DAA4D;QAC5D,oEAAoE;QACpE,kEAAkE;QAClE,8BAA8B;QAC9B,IAAI,OAAO,GAA8B,KAAK,CAAC;QAC/C,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO;YAAE,OAAO,GAAG,KAAK,KAAK,MAAM,CAAC;aACjE,IAAI,KAAK,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAE/E,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,MAAM,OAAO,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEL,SAAS;SACN,OAAO,CAAC,WAAW,CAAC;SACpB,WAAW,CAAC,qBAAqB,CAAC;SAClC,MAAM,CAAC,CAAC,GAAW,EAAE,EAAE;QACtB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEL,SAAS;SACN,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,oDAAoD,CAAC;SACjE,MAAM,CAAC,CAAC,GAAW,EAAE,EAAE;QACtB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,oBAAoB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type AgentInput, type InstallResult } from "add-mcp";
|
|
3
|
+
/**
|
|
4
|
+
* Writes (or merges into) `agentType`'s MCP config so it launches Purix's
|
|
5
|
+
* MCP server via `purix mcp-serve`, tagging actions from this agent with
|
|
6
|
+
* `agentId` in the audit trail (PURIX_MCP_AGENT_ID).
|
|
7
|
+
*
|
|
8
|
+
* Project-scoped when the agent supports it (falls back to that agent's
|
|
9
|
+
* global config otherwise) — this mirrors add-mcp's own local-vs-global
|
|
10
|
+
* resolution, not a Purix-specific rule.
|
|
11
|
+
*/
|
|
12
|
+
export declare function connectAgent(agentType: AgentInput, cwd: string, agentId: string): {
|
|
13
|
+
result: InstallResult;
|
|
14
|
+
};
|
|
15
|
+
export declare function registerConnectCommand(program: Command): void;
|
|
16
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/connect.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,CAgB3B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QA+BtD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { agents, detectProjectAgents, upsertServer, } from "add-mcp";
|
|
2
|
+
/**
|
|
3
|
+
* Writes (or merges into) `agentType`'s MCP config so it launches Purix's
|
|
4
|
+
* MCP server via `purix mcp-serve`, tagging actions from this agent with
|
|
5
|
+
* `agentId` in the audit trail (PURIX_MCP_AGENT_ID).
|
|
6
|
+
*
|
|
7
|
+
* Project-scoped when the agent supports it (falls back to that agent's
|
|
8
|
+
* global config otherwise) — this mirrors add-mcp's own local-vs-global
|
|
9
|
+
* resolution, not a Purix-specific rule.
|
|
10
|
+
*/
|
|
11
|
+
export function connectAgent(agentType, cwd, agentId) {
|
|
12
|
+
const known = agents[agentType];
|
|
13
|
+
const local = known?.localConfigPath !== undefined;
|
|
14
|
+
const result = upsertServer(agentType, "purix", {
|
|
15
|
+
command: "purix",
|
|
16
|
+
args: ["mcp-serve"],
|
|
17
|
+
env: { PURIX_MCP_AGENT_ID: agentId },
|
|
18
|
+
}, { local, cwd });
|
|
19
|
+
return { result };
|
|
20
|
+
}
|
|
21
|
+
export function registerConnectCommand(program) {
|
|
22
|
+
program
|
|
23
|
+
.command("connect [agent]")
|
|
24
|
+
.description("Register Purix's MCP server with a coding agent (Claude Code, Cursor, Codex, etc.) — auto-detects the agent(s) in this project if none is given")
|
|
25
|
+
.option("--agent-id <id>", "Identity recorded in the audit trail for actions from this agent (defaults to the agent type)")
|
|
26
|
+
.action((agent, options) => {
|
|
27
|
+
const cwd = process.cwd();
|
|
28
|
+
const targets = agent ? [agent] : detectProjectAgents(cwd);
|
|
29
|
+
if (targets.length === 0) {
|
|
30
|
+
console.log("No supported coding agent detected in this project. Pass one explicitly, e.g. `purix connect claude-code`.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const target of targets) {
|
|
34
|
+
const agentId = options.agentId ?? target;
|
|
35
|
+
const { result } = connectAgent(target, cwd, agentId);
|
|
36
|
+
if (result.success) {
|
|
37
|
+
console.log(`✅ Connected purix to ${target} — wrote ${result.path}`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log(`❌ Failed to connect purix to ${target}: ${result.error ?? "unknown error"}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../src/cli/commands/connect.ts"],"names":[],"mappings":"AASA,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,YAAY,GAGb,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAqB,EACrB,GAAW,EACX,OAAe;IAEf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CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,KAAK,MAAM,CAAC,KAAK,IAAI,eAAe,EAAE,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0D1D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// packages/cli/src/cli/commands/dev.ts
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { writeFileSync, mkdirSync, existsSync } from "node:fs";
|
|
4
|
+
import { resolve, join } from "node:path";
|
|
5
|
+
export function registerDevCommands(program) {
|
|
6
|
+
const dev = program.command("dev").description("Internal development tools");
|
|
7
|
+
dev
|
|
8
|
+
.command("scaffold-language")
|
|
9
|
+
.argument("<id>", "language id")
|
|
10
|
+
.option("--bin <name>", "toolchain binary name")
|
|
11
|
+
.option("--ext <pattern>", "file extension pattern")
|
|
12
|
+
.option("--manifest <filename>", "manifest filename")
|
|
13
|
+
.action((id, options) => {
|
|
14
|
+
const baseDir = process.cwd();
|
|
15
|
+
const providersDir = resolve(baseDir, "packages/core/src/language/providers");
|
|
16
|
+
const fixturesDir = resolve(baseDir, "packages/core/src/language/conformance/fixtures", id);
|
|
17
|
+
if (!existsSync(providersDir)) {
|
|
18
|
+
console.error("Providers directory not found");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// Generate Provider
|
|
22
|
+
const providerTemplate = `// Generated for ${id}
|
|
23
|
+
import type { LanguageProvider } from "../provider";
|
|
24
|
+
import { runIsolatedOrNotInstalled, resolveToolchainCache, parseLockfileFingerprint } from "../provider-kit";
|
|
25
|
+
|
|
26
|
+
export const ${id}Provider: LanguageProvider = {
|
|
27
|
+
id: "${id}",
|
|
28
|
+
minSupportedVersion: "0.1.0",
|
|
29
|
+
detect(baseDir: string = process.cwd()): boolean { return false; },
|
|
30
|
+
verify(filePaths: string[], baseDir: string = process.cwd()) { throw new Error("Not implemented for ${id}"); },
|
|
31
|
+
runTests(componentId: string, testFiles: string[], baseDir: string = process.cwd()) { throw new Error("Not implemented for ${id}"); },
|
|
32
|
+
checkIdiom(filePaths: string[], baseDir: string = process.cwd()) { throw new Error("Not implemented for ${id}"); },
|
|
33
|
+
async auditDependencies(baseDir: string = process.cwd()) { throw new Error("Not implemented for ${id}"); },
|
|
34
|
+
async getFingerprint(baseDir: string = process.cwd()) { return {}; }
|
|
35
|
+
};
|
|
36
|
+
`;
|
|
37
|
+
writeFileSync(join(providersDir, `${id}.ts`), providerTemplate);
|
|
38
|
+
// Generate Pack
|
|
39
|
+
const packTemplate = `// Generated for ${id}
|
|
40
|
+
import type { LanguagePack } from "../pack";
|
|
41
|
+
export const ${id}Pack: LanguagePack = {
|
|
42
|
+
languageId: "${id}",
|
|
43
|
+
minSupportedVersion: "0.1.0",
|
|
44
|
+
isFullyInstalled(baseDir: string = process.cwd()) { return false; }
|
|
45
|
+
};
|
|
46
|
+
`;
|
|
47
|
+
writeFileSync(join(providersDir, `${id}.pack.ts`), packTemplate);
|
|
48
|
+
// Generate Fixtures
|
|
49
|
+
mkdirSync(fixturesDir, { recursive: true });
|
|
50
|
+
writeFileSync(join(fixturesDir, "readme.md"), `Fixtures for ${id}`);
|
|
51
|
+
console.log(`Generated scaffolding for ${id}`);
|
|
52
|
+
console.log(`Manual steps remaining:`);
|
|
53
|
+
console.log(`1. Register ${id}Provider and ${id}Pack in registry.ts`);
|
|
54
|
+
console.log(`2. Implement all methods in ${id}.ts`);
|
|
55
|
+
console.log(`3. Populate fixtures in ${fixturesDir}`);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=dev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