harnesstap 1.2.0 → 1.3.1
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/README.md +28 -15
- package/dist/apply-2GRNKR5H.js +67 -0
- package/dist/apply-2GRNKR5H.js.map +1 -0
- package/dist/approve-KQNCNH2R.js +181 -0
- package/dist/approve-KQNCNH2R.js.map +1 -0
- package/dist/audit-SLYOZCMI.js +434 -0
- package/dist/audit-SLYOZCMI.js.map +1 -0
- package/dist/auth-3IEVICFT.js +220 -0
- package/dist/auth-3IEVICFT.js.map +1 -0
- package/dist/bin.js +166 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-2EIJYDNI.js +10945 -0
- package/dist/chunk-2EIJYDNI.js.map +1 -0
- package/dist/chunk-2H7UOFLK.js +11 -0
- package/dist/chunk-2H7UOFLK.js.map +1 -0
- package/dist/chunk-37E5M4JX.js +34 -0
- package/dist/chunk-37E5M4JX.js.map +1 -0
- package/dist/chunk-3FIWOI3H.js +98 -0
- package/dist/chunk-3FIWOI3H.js.map +1 -0
- package/dist/chunk-3IWTJCPA.js +6448 -0
- package/dist/chunk-3IWTJCPA.js.map +1 -0
- package/dist/chunk-3IZ7SEGT.js +346 -0
- package/dist/chunk-3IZ7SEGT.js.map +1 -0
- package/dist/chunk-3RBYT7QN.js +540 -0
- package/dist/chunk-3RBYT7QN.js.map +1 -0
- package/dist/chunk-4KNQZDZC.js +115 -0
- package/dist/chunk-4KNQZDZC.js.map +1 -0
- package/dist/chunk-5F3LNDZG.js +9 -0
- package/dist/chunk-5F3LNDZG.js.map +1 -0
- package/dist/chunk-63U7QWNY.js +364 -0
- package/dist/chunk-63U7QWNY.js.map +1 -0
- package/dist/chunk-6BY4BV5G.js +998 -0
- package/dist/chunk-6BY4BV5G.js.map +1 -0
- package/dist/chunk-7L2K4N25.js +610 -0
- package/dist/chunk-7L2K4N25.js.map +1 -0
- package/dist/chunk-7LWH5SWH.js +18 -0
- package/dist/chunk-7LWH5SWH.js.map +1 -0
- package/dist/chunk-BIBUCC2E.js +696 -0
- package/dist/chunk-BIBUCC2E.js.map +1 -0
- package/dist/chunk-BSOBXLYI.js +172 -0
- package/dist/chunk-BSOBXLYI.js.map +1 -0
- package/dist/chunk-C4QBVVEH.js +32 -0
- package/dist/chunk-C4QBVVEH.js.map +1 -0
- package/dist/chunk-CHQGE2HF.js +283 -0
- package/dist/chunk-CHQGE2HF.js.map +1 -0
- package/dist/chunk-DV74UZJI.js +87 -0
- package/dist/chunk-DV74UZJI.js.map +1 -0
- package/dist/chunk-DWVAR4BP.js +656 -0
- package/dist/chunk-DWVAR4BP.js.map +1 -0
- package/dist/chunk-DXKAKKLP.js +302 -0
- package/dist/chunk-DXKAKKLP.js.map +1 -0
- package/dist/chunk-EIWXS4RM.js +235 -0
- package/dist/chunk-EIWXS4RM.js.map +1 -0
- package/dist/chunk-EWBCFAF3.js +681 -0
- package/dist/chunk-EWBCFAF3.js.map +1 -0
- package/dist/chunk-F2L4VNQK.js +1759 -0
- package/dist/chunk-F2L4VNQK.js.map +1 -0
- package/dist/chunk-G26HZZDJ.js +1359 -0
- package/dist/chunk-G26HZZDJ.js.map +1 -0
- package/dist/chunk-GQKKX7OE.js +818 -0
- package/dist/chunk-GQKKX7OE.js.map +1 -0
- package/dist/chunk-GRJY22U6.js +691 -0
- package/dist/chunk-GRJY22U6.js.map +1 -0
- package/dist/chunk-H6DVP2SI.js +682 -0
- package/dist/chunk-H6DVP2SI.js.map +1 -0
- package/dist/chunk-HVVPTCKR.js +1173 -0
- package/dist/chunk-HVVPTCKR.js.map +1 -0
- package/dist/chunk-I6XFZLTJ.js +9 -0
- package/dist/chunk-I6XFZLTJ.js.map +1 -0
- package/dist/chunk-IBOABSIA.js +17 -0
- package/dist/chunk-IBOABSIA.js.map +1 -0
- package/dist/chunk-IK524ZDW.js +691 -0
- package/dist/chunk-IK524ZDW.js.map +1 -0
- package/dist/chunk-IRU7NBOT.js +141 -0
- package/dist/chunk-IRU7NBOT.js.map +1 -0
- package/dist/chunk-J4CKQXQ6.js +806 -0
- package/dist/chunk-J4CKQXQ6.js.map +1 -0
- package/dist/chunk-JKGSJGCC.js +311 -0
- package/dist/chunk-JKGSJGCC.js.map +1 -0
- package/dist/chunk-JQOKQKQT.js +158 -0
- package/dist/chunk-JQOKQKQT.js.map +1 -0
- package/dist/chunk-JRFUTIEH.js +426 -0
- package/dist/chunk-JRFUTIEH.js.map +1 -0
- package/dist/chunk-K2BPYEH5.js +491 -0
- package/dist/chunk-K2BPYEH5.js.map +1 -0
- package/dist/chunk-KCQC7YBK.js +7795 -0
- package/dist/chunk-KCQC7YBK.js.map +1 -0
- package/dist/chunk-KDAV2GUT.js +1357 -0
- package/dist/chunk-KDAV2GUT.js.map +1 -0
- package/dist/chunk-KDDXZBMC.js +583 -0
- package/dist/chunk-KDDXZBMC.js.map +1 -0
- package/dist/chunk-KMWHZSEG.js +41 -0
- package/dist/chunk-KMWHZSEG.js.map +1 -0
- package/dist/chunk-KRI4R7EM.js +25 -0
- package/dist/chunk-KRI4R7EM.js.map +1 -0
- package/dist/chunk-LNJ3WZZX.js +186 -0
- package/dist/chunk-LNJ3WZZX.js.map +1 -0
- package/dist/chunk-MWXA4PFE.js +103 -0
- package/dist/chunk-MWXA4PFE.js.map +1 -0
- package/dist/chunk-MY62SSKC.js +183 -0
- package/dist/chunk-MY62SSKC.js.map +1 -0
- package/dist/chunk-NAGAJ5UM.js +145 -0
- package/dist/chunk-NAGAJ5UM.js.map +1 -0
- package/dist/chunk-NJ7WRKIQ.js +532 -0
- package/dist/chunk-NJ7WRKIQ.js.map +1 -0
- package/dist/chunk-OS6NUIBJ.js +38 -0
- package/dist/chunk-OS6NUIBJ.js.map +1 -0
- package/dist/chunk-PXU2OS26.js +238 -0
- package/dist/chunk-PXU2OS26.js.map +1 -0
- package/dist/chunk-QO4LBDVI.js +496 -0
- package/dist/chunk-QO4LBDVI.js.map +1 -0
- package/dist/chunk-QRZPQNLX.js +65 -0
- package/dist/chunk-QRZPQNLX.js.map +1 -0
- package/dist/chunk-SNVAMWB7.js +40 -0
- package/dist/chunk-SNVAMWB7.js.map +1 -0
- package/dist/chunk-SPRVUATR.js +430 -0
- package/dist/chunk-SPRVUATR.js.map +1 -0
- package/dist/chunk-SY7G5QEI.js +35 -0
- package/dist/chunk-SY7G5QEI.js.map +1 -0
- package/dist/chunk-SZNBUIDR.js +6438 -0
- package/dist/chunk-SZNBUIDR.js.map +1 -0
- package/dist/chunk-TQ2NA4Z4.js +24 -0
- package/dist/chunk-TQ2NA4Z4.js.map +1 -0
- package/dist/chunk-TYULB6ZY.js +2959 -0
- package/dist/chunk-TYULB6ZY.js.map +1 -0
- package/dist/chunk-UJYFTXHV.js +296 -0
- package/dist/chunk-UJYFTXHV.js.map +1 -0
- package/dist/chunk-VC6OKCJF.js +184 -0
- package/dist/chunk-VC6OKCJF.js.map +1 -0
- package/dist/chunk-VL2NWCZV.js +118 -0
- package/dist/chunk-VL2NWCZV.js.map +1 -0
- package/dist/chunk-VL7BGD47.js +514 -0
- package/dist/chunk-VL7BGD47.js.map +1 -0
- package/dist/chunk-VQVUJYYY.js +244 -0
- package/dist/chunk-VQVUJYYY.js.map +1 -0
- package/dist/chunk-VZQG2JDV.js +9 -0
- package/dist/chunk-VZQG2JDV.js.map +1 -0
- package/dist/chunk-XFZQVYIN.js +115 -0
- package/dist/chunk-XFZQVYIN.js.map +1 -0
- package/dist/chunk-XGTTOO4R.js +84 -0
- package/dist/chunk-XGTTOO4R.js.map +1 -0
- package/dist/chunk-XQFT4PEP.js +60 -0
- package/dist/chunk-XQFT4PEP.js.map +1 -0
- package/dist/chunk-YDD3ES2K.js +571 -0
- package/dist/chunk-YDD3ES2K.js.map +1 -0
- package/dist/chunk-ZY2MZ2KQ.js +1140 -0
- package/dist/chunk-ZY2MZ2KQ.js.map +1 -0
- package/dist/compile-57EEIUMB.js +161 -0
- package/dist/compile-57EEIUMB.js.map +1 -0
- package/dist/config-4EJ3D7QJ.js +438 -0
- package/dist/config-4EJ3D7QJ.js.map +1 -0
- package/dist/doctor-EEV6P5CH.js +111 -0
- package/dist/doctor-EEV6P5CH.js.map +1 -0
- package/dist/environment-WFEG4DAT.js +2745 -0
- package/dist/environment-WFEG4DAT.js.map +1 -0
- package/dist/github-BSMQD72A.js +114 -0
- package/dist/github-BSMQD72A.js.map +1 -0
- package/dist/harness-VX3PNVQW.js +746 -0
- package/dist/harness-VX3PNVQW.js.map +1 -0
- package/dist/help-AW2HKX63.js +2079 -0
- package/dist/help-AW2HKX63.js.map +1 -0
- package/dist/help-BVFOZD7E.js +1892 -0
- package/dist/help-BVFOZD7E.js.map +1 -0
- package/dist/index.d.ts +164 -1
- package/dist/index.js +50 -59246
- package/dist/index.js.map +1 -1
- package/dist/init-SPN2GEZ4.js +873 -0
- package/dist/init-SPN2GEZ4.js.map +1 -0
- package/dist/lock-K2LLUU7H.js +455 -0
- package/dist/lock-K2LLUU7H.js.map +1 -0
- package/dist/marketplace-VEKSWGX3.js +495 -0
- package/dist/marketplace-VEKSWGX3.js.map +1 -0
- package/dist/mcp-T6DKIKSF.js +202 -0
- package/dist/mcp-T6DKIKSF.js.map +1 -0
- package/dist/migrate-OO37WSB2.js +1043 -0
- package/dist/migrate-OO37WSB2.js.map +1 -0
- package/dist/open-3V3QK5RK.js +32 -0
- package/dist/open-3V3QK5RK.js.map +1 -0
- package/dist/pack-V32UPC7W.js +99 -0
- package/dist/pack-V32UPC7W.js.map +1 -0
- package/dist/plugin-KOBNQ7GT.js +64 -0
- package/dist/plugin-KOBNQ7GT.js.map +1 -0
- package/dist/plugin-from-project-X3VO3MB6.js +16 -0
- package/dist/plugin-from-project-X3VO3MB6.js.map +1 -0
- package/dist/policy-F5MKZNOC.js +105 -0
- package/dist/policy-F5MKZNOC.js.map +1 -0
- package/dist/profile-H4PMH4XT.js +1886 -0
- package/dist/profile-H4PMH4XT.js.map +1 -0
- package/dist/project-QVNEJJGH.js +1392 -0
- package/dist/project-QVNEJJGH.js.map +1 -0
- package/dist/resource-GL4RLSGI.js +555 -0
- package/dist/resource-GL4RLSGI.js.map +1 -0
- package/dist/version-PBHZK44K.js +17 -0
- package/dist/version-PBHZK44K.js.map +1 -0
- package/package.json +21 -14
- package/schemas/ap-package.v1.json +36 -0
- package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
- package/schemas/fixtures/confidence.ap.json +13 -0
- package/schemas/fixtures/context7.ap.json +13 -0
- package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
- package/schemas/fixtures/superpowers.ap.json +13 -0
- package/schemas/fixtures/third-party-skills.ap.json +13 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {
|
|
2
|
+
printDeviceLoginInstructions
|
|
3
|
+
} from "./chunk-C4QBVVEH.js";
|
|
4
|
+
import {
|
|
5
|
+
extractCloudUserId,
|
|
6
|
+
identifyFromCloudWhoami,
|
|
7
|
+
isTelemetryEnabled,
|
|
8
|
+
shortReason,
|
|
9
|
+
trackCloudConnectFailed,
|
|
10
|
+
trackCloudConnectStarted,
|
|
11
|
+
trackCloudConnected
|
|
12
|
+
} from "./chunk-K2BPYEH5.js";
|
|
13
|
+
import {
|
|
14
|
+
configureCommandGroup
|
|
15
|
+
} from "./chunk-G26HZZDJ.js";
|
|
16
|
+
import {
|
|
17
|
+
parseOutputFormat,
|
|
18
|
+
printJson
|
|
19
|
+
} from "./chunk-TQ2NA4Z4.js";
|
|
20
|
+
import {
|
|
21
|
+
fail
|
|
22
|
+
} from "./chunk-DXKAKKLP.js";
|
|
23
|
+
import {
|
|
24
|
+
ui
|
|
25
|
+
} from "./chunk-YDD3ES2K.js";
|
|
26
|
+
import {
|
|
27
|
+
createCloudClient,
|
|
28
|
+
createPersistingCloudClient,
|
|
29
|
+
deviceVerificationUri,
|
|
30
|
+
getCloudAccount,
|
|
31
|
+
pollDeviceToken,
|
|
32
|
+
removeCloudAccount,
|
|
33
|
+
requestDeviceCode,
|
|
34
|
+
resolveCloudBaseUrl,
|
|
35
|
+
saveCloudAccount,
|
|
36
|
+
setDefaultCloudAccount,
|
|
37
|
+
updateCloudAccount
|
|
38
|
+
} from "./chunk-ZY2MZ2KQ.js";
|
|
39
|
+
import "./chunk-VQVUJYYY.js";
|
|
40
|
+
import {
|
|
41
|
+
CLI_ERRORS,
|
|
42
|
+
CLI_HINTS
|
|
43
|
+
} from "./chunk-DWVAR4BP.js";
|
|
44
|
+
|
|
45
|
+
// src/cli/commands/auth.ts
|
|
46
|
+
async function handleCloudLoginCommand(accountName, opts = {}) {
|
|
47
|
+
const name = accountName ?? "default";
|
|
48
|
+
const baseUrl = resolveCloudBaseUrl(opts.baseUrl);
|
|
49
|
+
trackCloudConnectStarted();
|
|
50
|
+
try {
|
|
51
|
+
const device = await requestDeviceCode(baseUrl);
|
|
52
|
+
const waiting = printDeviceLoginInstructions({
|
|
53
|
+
verificationUri: deviceVerificationUri(baseUrl),
|
|
54
|
+
userCode: device.user_code
|
|
55
|
+
});
|
|
56
|
+
const pollIntervalSeconds = device.interval ?? 5;
|
|
57
|
+
const maxPolls = Math.ceil((device.expires_in ?? 600) / pollIntervalSeconds);
|
|
58
|
+
let token;
|
|
59
|
+
try {
|
|
60
|
+
token = await pollDeviceToken(baseUrl, device.device_code, {
|
|
61
|
+
interval: pollIntervalSeconds,
|
|
62
|
+
maxPolls
|
|
63
|
+
});
|
|
64
|
+
} finally {
|
|
65
|
+
waiting.stop();
|
|
66
|
+
}
|
|
67
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
68
|
+
const account = {
|
|
69
|
+
cloudBaseUrl: baseUrl,
|
|
70
|
+
accessToken: token.access_token,
|
|
71
|
+
refreshToken: token.refresh_token,
|
|
72
|
+
accessTokenExpiresAt: token.expires_in ? now + token.expires_in : void 0,
|
|
73
|
+
refreshTokenExpiresAt: void 0,
|
|
74
|
+
orgId: token.orgId,
|
|
75
|
+
orgSlug: token.orgSlug,
|
|
76
|
+
scopes: token.scopes ?? []
|
|
77
|
+
};
|
|
78
|
+
await saveCloudAccount(name, account);
|
|
79
|
+
await setDefaultCloudAccount(name);
|
|
80
|
+
trackCloudConnected({ orgId: token.orgId });
|
|
81
|
+
ui.success(`Saved cloud account: ${name}`);
|
|
82
|
+
void persistCloudIdentity(name, baseUrl, token, now);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
trackCloudConnectFailed(shortReason(err), "cloud_login_failed");
|
|
85
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function persistCloudIdentity(accountName, baseUrl, token, now) {
|
|
89
|
+
if (!isTelemetryEnabled()) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const client = createCloudClient({
|
|
94
|
+
baseUrl,
|
|
95
|
+
token: {
|
|
96
|
+
access_token: token.access_token,
|
|
97
|
+
refresh_token: token.refresh_token,
|
|
98
|
+
expires_at: token.expires_in ? now + token.expires_in : void 0
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const whoami = await client.whoami();
|
|
102
|
+
const userId = extractCloudUserId(whoami);
|
|
103
|
+
if (userId) {
|
|
104
|
+
await updateCloudAccount(accountName, { userId });
|
|
105
|
+
}
|
|
106
|
+
identifyFromCloudWhoami({
|
|
107
|
+
orgId: token.orgId,
|
|
108
|
+
userId,
|
|
109
|
+
whoami
|
|
110
|
+
});
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function handleCloudWhoamiCommand(opts = {}) {
|
|
115
|
+
const format = parseOutputFormat(opts.format);
|
|
116
|
+
const created = await createPersistingCloudClient(opts.account);
|
|
117
|
+
if (!created) {
|
|
118
|
+
if (format === "json") {
|
|
119
|
+
printJson({});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
ui.warn("Not authenticated to cloud.");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const info = await created.client.whoami();
|
|
127
|
+
if (format === "json") {
|
|
128
|
+
printJson(info);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
ui.info(JSON.stringify(info));
|
|
132
|
+
} catch (err) {
|
|
133
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function handleCloudOrgsCommand(opts = {}) {
|
|
137
|
+
const format = parseOutputFormat(opts.format);
|
|
138
|
+
const created = await createPersistingCloudClient(opts.account);
|
|
139
|
+
if (!created) {
|
|
140
|
+
fail(CLI_ERRORS.notAuthenticated, { hint: CLI_HINTS.authLogin });
|
|
141
|
+
if (format === "json") {
|
|
142
|
+
printJson([]);
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const orgs = await created.client.listOrgs();
|
|
148
|
+
if (opts.switch) {
|
|
149
|
+
const target = orgs.find((o) => String(o["slug"]) === opts.switch || String(o["id"]) === opts.switch);
|
|
150
|
+
if (!target) {
|
|
151
|
+
process.exitCode = 1;
|
|
152
|
+
fail(`Organization not found: ${opts.switch}`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
await updateCloudAccount(created.accountName, { orgId: String(target["id"]), orgSlug: String(target["slug"]) });
|
|
156
|
+
ui.success(`Switched to org: ${String(target["slug"])}`);
|
|
157
|
+
if (format === "json") {
|
|
158
|
+
printJson(target);
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (format === "json") {
|
|
163
|
+
printJson(orgs);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
for (const o of orgs) {
|
|
167
|
+
ui.info(`${String(o["slug"])} ${String(o["name"])}`);
|
|
168
|
+
}
|
|
169
|
+
} catch (err) {
|
|
170
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function handleCloudLogoutCommand(opts = {}) {
|
|
174
|
+
const { accountName, account } = await getCloudAccount(opts.account);
|
|
175
|
+
if (!accountName) {
|
|
176
|
+
ui.warn("No cloud account configured.");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
if (account?.refreshToken) {
|
|
181
|
+
try {
|
|
182
|
+
const client = createCloudClient({
|
|
183
|
+
baseUrl: account.cloudBaseUrl,
|
|
184
|
+
token: {
|
|
185
|
+
access_token: account.accessToken || "",
|
|
186
|
+
refresh_token: account.refreshToken,
|
|
187
|
+
expires_at: typeof account.accessTokenExpiresAt === "number" ? account.accessTokenExpiresAt : void 0
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
await client.revokeRefreshToken();
|
|
191
|
+
} catch (_) {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
await removeCloudAccount(accountName);
|
|
195
|
+
ui.success(`Logged out: ${accountName}`);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function registerAuthCommands(root) {
|
|
201
|
+
const authCmd = configureCommandGroup(
|
|
202
|
+
root.command("auth").alias("a").description("Authenticate with HarnessTap Cloud and manage cloud accounts")
|
|
203
|
+
);
|
|
204
|
+
authCmd.command("login [account]").option("--base-url <url>", "Cloud base URL").description("Log into HarnessTap Cloud via device authentication").action(async (account, opts) => {
|
|
205
|
+
await handleCloudLoginCommand(account, opts);
|
|
206
|
+
});
|
|
207
|
+
authCmd.command("status").option("--account <name>", "Account name").option("--format <mode>", "Output format: human or json", "human").description("Show authenticated user and account context").action(async (opts) => {
|
|
208
|
+
await handleCloudWhoamiCommand(opts);
|
|
209
|
+
});
|
|
210
|
+
authCmd.command("orgs").option("--account <name>", "Account name").option("--switch <org_slug>", "Switch to the given organization slug").option("--format <mode>", "Output format: human or json", "human").description("List organizations and optionally switch").action(async (opts) => {
|
|
211
|
+
await handleCloudOrgsCommand(opts);
|
|
212
|
+
});
|
|
213
|
+
authCmd.command("logout").option("--account <name>", "Account name").description("Log out and remove local cloud account").action(async (opts) => {
|
|
214
|
+
await handleCloudLogoutCommand(opts);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
registerAuthCommands
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=auth-3IEVICFT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/auth.ts"],"sourcesContent":["import type { Command } from \"commander\";\nimport {\n getCloudAccount,\n removeCloudAccount,\n saveCloudAccount,\n setDefaultCloudAccount,\n updateCloudAccount,\n} from \"../../config/cloud-accounts.js\";\nimport { resolveCloudBaseUrl } from \"../../config/catalog.js\";\nimport { createPersistingCloudClient } from \"../../services/cloud-account-auth.js\";\nimport {\n createCloudClient,\n deviceVerificationUri,\n pollDeviceToken,\n requestDeviceCode,\n} from \"../../services/cloud-client.js\";\nimport { ui } from \"../../ui/index.js\";\nimport {\n extractCloudUserId,\n identifyFromCloudWhoami,\n isTelemetryEnabled,\n shortReason,\n trackCloudConnectFailed,\n trackCloudConnectStarted,\n trackCloudConnected,\n} from \"../../telemetry/index.js\";\nimport { printDeviceLoginInstructions } from \"../../services/device-login-prompt.js\";\nimport { parseOutputFormat, printJson } from \"../../utils/output-format.js\";\nimport { configureCommandGroup } from \"../help.js\";\nimport { CLI_ERRORS, CLI_HINTS } from \"../messages.js\";\nimport { fail } from \"../shared.js\";\n\nasync function handleCloudLoginCommand(\n accountName: string | undefined,\n opts: { baseUrl?: string } = {},\n): Promise<void> {\n const name = accountName ?? \"default\";\n const baseUrl = resolveCloudBaseUrl(opts.baseUrl);\n trackCloudConnectStarted();\n try {\n const device = await requestDeviceCode(baseUrl);\n const waiting = printDeviceLoginInstructions({\n verificationUri: deviceVerificationUri(baseUrl),\n userCode: device.user_code,\n });\n const pollIntervalSeconds = device.interval ?? 5;\n const maxPolls = Math.ceil((device.expires_in ?? 600) / pollIntervalSeconds);\n let token: Awaited<ReturnType<typeof pollDeviceToken>>;\n try {\n token = await pollDeviceToken(baseUrl, device.device_code, {\n interval: pollIntervalSeconds,\n maxPolls,\n });\n } finally {\n waiting.stop();\n }\n const now = Math.floor(Date.now() / 1000);\n const account = {\n cloudBaseUrl: baseUrl,\n accessToken: token.access_token,\n refreshToken: token.refresh_token,\n accessTokenExpiresAt: token.expires_in ? now + token.expires_in : undefined,\n refreshTokenExpiresAt: undefined,\n orgId: token.orgId,\n orgSlug: token.orgSlug,\n scopes: token.scopes ?? [],\n };\n await saveCloudAccount(name, account);\n await setDefaultCloudAccount(name);\n trackCloudConnected({ orgId: token.orgId });\n ui.success(`Saved cloud account: ${name}`);\n void persistCloudIdentity(name, baseUrl, token, now);\n } catch (err) {\n trackCloudConnectFailed(shortReason(err), \"cloud_login_failed\");\n fail(err instanceof Error ? err.message : String(err));\n }\n}\n\nasync function persistCloudIdentity(\n accountName: string,\n baseUrl: string,\n token: {\n access_token: string;\n refresh_token?: string;\n expires_in?: number;\n orgId?: string;\n },\n now: number,\n): Promise<void> {\n if (!isTelemetryEnabled()) {\n return;\n }\n try {\n const client = createCloudClient({\n baseUrl,\n token: {\n access_token: token.access_token,\n refresh_token: token.refresh_token,\n expires_at: token.expires_in ? now + token.expires_in : undefined,\n },\n });\n const whoami = await client.whoami();\n const userId = extractCloudUserId(whoami);\n if (userId) {\n await updateCloudAccount(accountName, { userId });\n }\n identifyFromCloudWhoami({\n orgId: token.orgId,\n userId,\n whoami,\n });\n } catch {\n // Identify is best-effort and must not fail login.\n }\n}\n\nasync function handleCloudWhoamiCommand(\n opts: { account?: string; format?: string } = {},\n): Promise<void> {\n const format = parseOutputFormat(opts.format);\n const created = await createPersistingCloudClient(opts.account);\n if (!created) {\n if (format === \"json\") {\n printJson({});\n return;\n }\n ui.warn(\"Not authenticated to cloud.\");\n return;\n }\n try {\n const info = await created.client.whoami();\n if (format === \"json\") {\n printJson(info);\n return;\n }\n ui.info(JSON.stringify(info));\n } catch (err) {\n fail(err instanceof Error ? err.message : String(err));\n }\n}\n\nasync function handleCloudOrgsCommand(\n opts: { account?: string; switch?: string; format?: string } = {},\n): Promise<void> {\n const format = parseOutputFormat(opts.format);\n const created = await createPersistingCloudClient(opts.account);\n if (!created) {\n fail(CLI_ERRORS.notAuthenticated, { hint: CLI_HINTS.authLogin });\n if (format === \"json\") {\n printJson([]);\n }\n return;\n }\n try {\n const orgs = await created.client.listOrgs();\n if (opts.switch) {\n const target = (orgs as Record<string, unknown>[]).find((o) => String((o as Record<string, unknown>)[\"slug\"]) === opts.switch || String((o as Record<string, unknown>)[\"id\"]) === opts.switch);\n if (!target) {\n process.exitCode = 1;\n fail(`Organization not found: ${opts.switch}`);\n return;\n }\n await updateCloudAccount(created.accountName, { orgId: String((target as Record<string, unknown>)[\"id\"]), orgSlug: String((target as Record<string, unknown>)[\"slug\"]) });\n ui.success(`Switched to org: ${String((target as Record<string, unknown>)[\"slug\"])}`);\n if (format === \"json\") {\n printJson(target);\n }\n return;\n }\n if (format === \"json\") {\n printJson(orgs);\n return;\n }\n for (const o of orgs as Record<string, unknown>[]) {\n ui.info(`${String(o[\"slug\"])} ${String(o[\"name\"])}`);\n }\n } catch (err) {\n fail(err instanceof Error ? err.message : String(err));\n }\n}\n\nasync function handleCloudLogoutCommand(opts: { account?: string } = {}): Promise<void> {\n const { accountName, account } = await getCloudAccount(opts.account);\n if (!accountName) {\n ui.warn(\"No cloud account configured.\");\n return;\n }\n try {\n if (account?.refreshToken) {\n try {\n const client = createCloudClient({\n baseUrl: account.cloudBaseUrl,\n token: {\n access_token: account.accessToken as string || \"\",\n refresh_token: account.refreshToken as string,\n expires_at: typeof account.accessTokenExpiresAt === \"number\"\n ? (account.accessTokenExpiresAt as number)\n : undefined,\n },\n });\n await client.revokeRefreshToken();\n } catch (_) {\n // ignore revoke errors\n }\n }\n await removeCloudAccount(accountName);\n ui.success(`Logged out: ${accountName}`);\n } catch (err) {\n fail(err instanceof Error ? err.message : String(err));\n }\n}\n\nexport function registerAuthCommands(root: Command): void {\n const authCmd = configureCommandGroup(\n root\n .command(\"auth\")\n .alias(\"a\")\n .description(\"Authenticate with HarnessTap Cloud and manage cloud accounts\"),\n );\n\n authCmd\n .command(\"login [account]\")\n .option(\"--base-url <url>\", \"Cloud base URL\")\n .description(\"Log into HarnessTap Cloud via device authentication\")\n .action(async (account: string | undefined, opts: { baseUrl?: string }) => {\n await handleCloudLoginCommand(account, opts);\n });\n\n authCmd\n .command(\"status\")\n .option(\"--account <name>\", \"Account name\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"Show authenticated user and account context\")\n .action(async (opts: { account?: string; format?: string }) => {\n await handleCloudWhoamiCommand(opts);\n });\n\n authCmd\n .command(\"orgs\")\n .option(\"--account <name>\", \"Account name\")\n .option(\"--switch <org_slug>\", \"Switch to the given organization slug\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"List organizations and optionally switch\")\n .action(async (opts: { account?: string; switch?: string; format?: string }) => {\n await handleCloudOrgsCommand(opts);\n });\n\n authCmd\n .command(\"logout\")\n .option(\"--account <name>\", \"Account name\")\n .description(\"Log out and remove local cloud account\")\n .action(async (opts: { account?: string }) => {\n await handleCloudLogoutCommand(opts);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAe,wBACb,aACA,OAA6B,CAAC,GACf;AACf,QAAM,OAAO,eAAe;AAC5B,QAAM,UAAU,oBAAoB,KAAK,OAAO;AAChD,2BAAyB;AACzB,MAAI;AACF,UAAM,SAAS,MAAM,kBAAkB,OAAO;AAC9C,UAAM,UAAU,6BAA6B;AAAA,MAC3C,iBAAiB,sBAAsB,OAAO;AAAA,MAC9C,UAAU,OAAO;AAAA,IACnB,CAAC;AACD,UAAM,sBAAsB,OAAO,YAAY;AAC/C,UAAM,WAAW,KAAK,MAAM,OAAO,cAAc,OAAO,mBAAmB;AAC3E,QAAI;AACJ,QAAI;AACF,cAAQ,MAAM,gBAAgB,SAAS,OAAO,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UACG,QAAQ,iBAAiB,EACzB,OAAO,oBAAoB,gBAAgB,EAC3C,YAAY,qDAAqD,EACjE,OAAO,OAAO,SAA6B,SAA+B;AACzE,UAAM,wBAAwB,SAAS,IAAI;AAAA,EAC7C,CAAC;AAEH,UACG,QAAQ,QAAQ,EAChB,OAAO,oBAAoB,cAAc,EACzC,OAAO,mBAAmB,gCAAgC,OAAO,EACjE,YAAY,6CAA6C,EACzD,OAAO,OAAO,SAAgD;AAC7D,UAAM,yBAAyB,IAAI;AAAA,EACrC,CAAC;AAEH,UACG,QAAQ,MAAM,EACd,OAAO,oBAAoB,cAAc,EACzC,OAAO,uBAAuB,uCAAuC,EACrE,OAAO,mBAAmB,gCAAgC,OAAO,EACjE,YAAY,0CAA0C,EACtD,OAAO,OAAO,SAAiE;AAC9E,UAAM,uBAAuB,IAAI;AAAA,EACnC,CAAC;AAEH,UACG,QAAQ,QAAQ,EAChB,OAAO,oBAAoB,cAAc,EACzC,YAAY,wCAAwC,EACpD,OAAO,OAAO,SAA+B;AAC5C,UAAM,yBAAyB,IAAI;AAAA,EACrC,CAAC;AACL;","names":[]}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
NATIVE_MODULE_MISMATCH_MESSAGE
|
|
4
|
+
} from "./chunk-SNVAMWB7.js";
|
|
5
|
+
import "./chunk-2H7UOFLK.js";
|
|
6
|
+
|
|
7
|
+
// src/db/native-module.ts
|
|
8
|
+
function shouldShowNativeModuleDetails() {
|
|
9
|
+
if (process.env.HARNESSTAP_DEBUG === "1") {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return process.argv.includes("-v") || process.argv.includes("--verbose");
|
|
13
|
+
}
|
|
14
|
+
function isNativeModuleMismatch(error) {
|
|
15
|
+
if (!error || typeof error !== "object") {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const err = error;
|
|
19
|
+
const code = typeof err.code === "string" ? err.code : "";
|
|
20
|
+
const message = typeof err.message === "string" ? err.message : String(error);
|
|
21
|
+
if (code === "ERR_DLOPEN_FAILED") {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return message.includes("NODE_MODULE_VERSION") || message.includes("ERR_DLOPEN");
|
|
25
|
+
}
|
|
26
|
+
function reportNativeModuleMismatch(cause) {
|
|
27
|
+
if (shouldShowNativeModuleDetails() && cause !== void 0) {
|
|
28
|
+
console.error(cause);
|
|
29
|
+
}
|
|
30
|
+
console.error(NATIVE_MODULE_MISMATCH_MESSAGE);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/node-version.ts
|
|
35
|
+
var MIN_SUPPORTED_NODE_MAJOR = 22;
|
|
36
|
+
var MIN_SUPPORTED_NODE_MINOR = 12;
|
|
37
|
+
function parseNodeVersion(raw) {
|
|
38
|
+
const [majorPart, minorPart] = raw.split(".");
|
|
39
|
+
return {
|
|
40
|
+
major: Number.parseInt(majorPart ?? "0", 10) || 0,
|
|
41
|
+
minor: Number.parseInt(minorPart ?? "0", 10) || 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function isSupportedNodeVersion(raw) {
|
|
45
|
+
const { major, minor } = parseNodeVersion(raw);
|
|
46
|
+
if (major > MIN_SUPPORTED_NODE_MAJOR) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (major === MIN_SUPPORTED_NODE_MAJOR && minor >= MIN_SUPPORTED_NODE_MINOR) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function nodeVersionRefusalMessage(raw) {
|
|
55
|
+
return `HarnessTap needs Node.js ${MIN_SUPPORTED_NODE_MAJOR}.${MIN_SUPPORTED_NODE_MINOR} or newer. You have v${raw}. Install Node 22 or 24 from https://nodejs.org`;
|
|
56
|
+
}
|
|
57
|
+
function isBunRuntime(versions = process.versions) {
|
|
58
|
+
return typeof versions.bun === "string" && versions.bun.length > 0;
|
|
59
|
+
}
|
|
60
|
+
function assertSupportedRuntime(versions = process.versions) {
|
|
61
|
+
if (isBunRuntime(versions)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (isSupportedNodeVersion(versions.node)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
console.error(nodeVersionRefusalMessage(versions.node));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/cli/root-flags.ts
|
|
72
|
+
var ROOT_VERSION_FLAGS = /* @__PURE__ */ new Set(["-V", "--version", "--harnesstap-version"]);
|
|
73
|
+
var ROOT_PASSTHROUGH_FLAGS = /* @__PURE__ */ new Set([
|
|
74
|
+
"-v",
|
|
75
|
+
"--verbose",
|
|
76
|
+
"--no-color",
|
|
77
|
+
"--no-interactive"
|
|
78
|
+
]);
|
|
79
|
+
function argvTokens(argv) {
|
|
80
|
+
return argv.slice(2);
|
|
81
|
+
}
|
|
82
|
+
function isRootVersionRequest(argv) {
|
|
83
|
+
const args = argvTokens(argv);
|
|
84
|
+
let sawVersion = false;
|
|
85
|
+
for (const arg of args) {
|
|
86
|
+
if (arg === "--") {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (ROOT_VERSION_FLAGS.has(arg)) {
|
|
90
|
+
sawVersion = true;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (ROOT_PASSTHROUGH_FLAGS.has(arg)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (arg.startsWith("-")) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return sawVersion;
|
|
102
|
+
}
|
|
103
|
+
function isRootHelpRequest(argv) {
|
|
104
|
+
const args = argvTokens(argv);
|
|
105
|
+
if (args.length === 0) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
let sawHelp = false;
|
|
109
|
+
for (const arg of args) {
|
|
110
|
+
if (arg === "--") {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (arg === "-h" || arg === "--help") {
|
|
114
|
+
sawHelp = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (ROOT_PASSTHROUGH_FLAGS.has(arg)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (arg.startsWith("-")) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return sawHelp;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/bin.ts
|
|
129
|
+
assertSupportedRuntime();
|
|
130
|
+
async function runCliEntry() {
|
|
131
|
+
if (isRootVersionRequest(process.argv)) {
|
|
132
|
+
const { PACKAGE_VERSION } = await import("./version-PBHZK44K.js");
|
|
133
|
+
console.log(PACKAGE_VERSION);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (isRootHelpRequest(process.argv)) {
|
|
137
|
+
const { printRootHelp } = await import("./help-BVFOZD7E.js");
|
|
138
|
+
printRootHelp(process.argv);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const cliEntry = new URL("./index.js", import.meta.url).href;
|
|
142
|
+
let cli;
|
|
143
|
+
try {
|
|
144
|
+
cli = await import(cliEntry);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (isNativeModuleMismatch(error)) {
|
|
147
|
+
reportNativeModuleMismatch(error);
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
await cli.runHarnesstapCli();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (isNativeModuleMismatch(error)) {
|
|
155
|
+
reportNativeModuleMismatch(error);
|
|
156
|
+
}
|
|
157
|
+
if (cli.isPromptCancellationError(error)) {
|
|
158
|
+
process.exitCode = 0;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
process.exitCode = error && typeof error === "object" && "exitCode" in error ? Number(error.exitCode) || 1 : 1;
|
|
162
|
+
cli.renderCliError(error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
void runCliEntry();
|
|
166
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/db/native-module.ts","../src/node-version.ts","../src/cli/root-flags.ts","../src/bin.ts"],"sourcesContent":["import { NATIVE_MODULE_MISMATCH_MESSAGE } from \"../copy/cli.js\";\n\nexport { NATIVE_MODULE_MISMATCH_MESSAGE };\n\nfunction shouldShowNativeModuleDetails(): boolean {\n if (process.env.HARNESSTAP_DEBUG === \"1\") {\n return true;\n }\n return process.argv.includes(\"-v\") || process.argv.includes(\"--verbose\");\n}\n\nexport function isNativeModuleMismatch(error: unknown): boolean {\n if (!error || typeof error !== \"object\") {\n return false;\n }\n const err = error as { code?: unknown; message?: unknown };\n const code = typeof err.code === \"string\" ? err.code : \"\";\n const message = typeof err.message === \"string\" ? err.message : String(error);\n if (code === \"ERR_DLOPEN_FAILED\") {\n return true;\n }\n return message.includes(\"NODE_MODULE_VERSION\") || message.includes(\"ERR_DLOPEN\");\n}\n\nexport function reportNativeModuleMismatch(cause?: unknown): never {\n if (shouldShowNativeModuleDetails() && cause !== undefined) {\n console.error(cause);\n }\n console.error(NATIVE_MODULE_MISMATCH_MESSAGE);\n process.exit(1);\n}\n\n/** Run a native sqlite load; print the DS-6 one-liner on ABI mismatch. */\nexport function withNativeModuleGuard<T>(load: () => T): T {\n try {\n return load();\n } catch (error) {\n if (isNativeModuleMismatch(error)) {\n reportNativeModuleMismatch(error);\n }\n throw error;\n }\n}\n","export const MIN_SUPPORTED_NODE_MAJOR = 22;\nexport const MIN_SUPPORTED_NODE_MINOR = 12;\n\nexport function parseNodeVersion(raw: string): { major: number; minor: number } {\n const [majorPart, minorPart] = raw.split(\".\");\n return {\n major: Number.parseInt(majorPart ?? \"0\", 10) || 0,\n minor: Number.parseInt(minorPart ?? \"0\", 10) || 0,\n };\n}\n\nexport function isSupportedNodeVersion(raw: string): boolean {\n const { major, minor } = parseNodeVersion(raw);\n if (major > MIN_SUPPORTED_NODE_MAJOR) {\n return true;\n }\n if (major === MIN_SUPPORTED_NODE_MAJOR && minor >= MIN_SUPPORTED_NODE_MINOR) {\n return true;\n }\n return false;\n}\n\nexport function nodeVersionRefusalMessage(raw: string): string {\n return (\n `HarnessTap needs Node.js ${MIN_SUPPORTED_NODE_MAJOR}.${MIN_SUPPORTED_NODE_MINOR} or newer. ` +\n `You have v${raw}. Install Node 22 or 24 from https://nodejs.org`\n );\n}\n\nexport function isBunRuntime(\n versions: NodeJS.ProcessVersions = process.versions,\n): boolean {\n return typeof versions.bun === \"string\" && versions.bun.length > 0;\n}\n\nexport function assertSupportedRuntime(\n versions: NodeJS.ProcessVersions = process.versions,\n): void {\n if (isBunRuntime(versions)) {\n return;\n }\n if (isSupportedNodeVersion(versions.node)) {\n return;\n }\n console.error(nodeVersionRefusalMessage(versions.node));\n process.exit(1);\n}\n","const ROOT_VERSION_FLAGS = new Set([\"-V\", \"--version\", \"--harnesstap-version\"]);\nconst ROOT_PASSTHROUGH_FLAGS = new Set([\n \"-v\",\n \"--verbose\",\n \"--no-color\",\n \"--no-interactive\",\n]);\n\nfunction argvTokens(argv: string[]): string[] {\n return argv.slice(2);\n}\n\nexport function isRootVersionRequest(argv: string[]): boolean {\n const args = argvTokens(argv);\n let sawVersion = false;\n for (const arg of args) {\n if (arg === \"--\") {\n return false;\n }\n if (ROOT_VERSION_FLAGS.has(arg)) {\n sawVersion = true;\n continue;\n }\n if (ROOT_PASSTHROUGH_FLAGS.has(arg)) {\n continue;\n }\n if (arg.startsWith(\"-\")) {\n continue;\n }\n return false;\n }\n return sawVersion;\n}\n\nexport function isRootHelpRequest(argv: string[]): boolean {\n const args = argvTokens(argv);\n if (args.length === 0) {\n return true;\n }\n let sawHelp = false;\n for (const arg of args) {\n if (arg === \"--\") {\n return false;\n }\n if (arg === \"-h\" || arg === \"--help\") {\n sawHelp = true;\n continue;\n }\n if (ROOT_PASSTHROUGH_FLAGS.has(arg)) {\n continue;\n }\n if (arg.startsWith(\"-\")) {\n continue;\n }\n return false;\n }\n return sawHelp;\n}\n\nexport function positionalArgvTokens(argv: string[]): string[] {\n const tokens: string[] = [];\n const args = argvTokens(argv);\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg) {\n continue;\n }\n if (arg === \"--\") {\n tokens.push(...args.slice(i + 1));\n break;\n }\n if (arg.startsWith(\"-\")) {\n continue;\n }\n tokens.push(arg);\n }\n return tokens;\n}\n","import { isNativeModuleMismatch, reportNativeModuleMismatch } from \"./db/native-module.js\";\nimport { assertSupportedRuntime } from \"./node-version.js\";\nimport { isRootHelpRequest, isRootVersionRequest } from \"./cli/root-flags.js\";\n\nassertSupportedRuntime();\n\nasync function runCliEntry(): Promise<void> {\n if (isRootVersionRequest(process.argv)) {\n const { PACKAGE_VERSION } = await import(\"./version.js\");\n console.log(PACKAGE_VERSION);\n return;\n }\n if (isRootHelpRequest(process.argv)) {\n const { printRootHelp } = await import(\"./cli/help.js\");\n printRootHelp(process.argv);\n return;\n }\n\n const cliEntry = new URL(\"./index.js\", import.meta.url).href;\n let cli: typeof import(\"./index.js\");\n try {\n cli = await import(cliEntry);\n } catch (error: unknown) {\n if (isNativeModuleMismatch(error)) {\n reportNativeModuleMismatch(error);\n }\n throw error;\n }\n try {\n await cli.runHarnesstapCli();\n } catch (error: unknown) {\n if (isNativeModuleMismatch(error)) {\n reportNativeModuleMismatch(error);\n }\n if (cli.isPromptCancellationError(error)) {\n process.exitCode = 0;\n return;\n }\n process.exitCode =\n error && typeof error === \"object\" && \"exitCode\" in error\n ? Number((error as { exitCode?: unknown }).exitCode) || 1\n : 1;\n cli.renderCliError(error);\n }\n}\n\nvoid runCliEntry();\n"],"mappings":";;;;;;;AAIA,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