@artis-lab/cli 0.12.0 → 0.14.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/README.md +40 -11
- package/package.json +4 -1
- package/src/bin.js +5 -10
- package/src/index.js +15 -9
- package/src/lib/app.d.ts +3 -0
- package/src/lib/app.js +9 -0
- package/src/lib/args.d.ts +1 -0
- package/src/lib/args.js +5 -3
- package/src/lib/chunk-43WVFZLO.js +104 -0
- package/src/lib/chunk-46DMRA3V.js +141 -0
- package/src/lib/chunk-CCCATRMP.js +591 -0
- package/src/lib/{chunk-OBEJTKCR.js → chunk-CT5TD6L2.js} +9 -5
- package/src/lib/{chunk-KY47KP5E.js → chunk-JYMG2Y6C.js} +1 -1
- package/src/lib/chunk-KJV7R7DE.js +82 -0
- package/src/lib/{chunk-YXGHBN47.js → chunk-PG7WDW5F.js} +599 -305
- package/src/lib/chunk-Q5KBGVKT.js +155 -0
- package/src/lib/{chunk-YAZGW7Y4.js → chunk-QZFIUZXT.js} +256 -83
- package/src/lib/cli.d.ts +44 -23
- package/src/lib/cli.js +15 -9
- package/src/lib/config.d.ts +31 -1
- package/src/lib/config.js +11 -3
- package/src/lib/files.js +1 -1
- package/src/lib/next-actions.d.ts +13 -0
- package/src/lib/next-actions.js +16 -0
- package/src/lib/oauth.d.ts +45 -0
- package/src/lib/oauth.js +18 -0
- package/src/lib/revision-bases.js +2 -2
- package/src/lib/skill-install.d.ts +1 -1
- package/src/lib/skill-install.js +2 -2
- package/src/lib/verify.d.ts +27 -10
- package/src/lib/verify.js +3 -3
- package/src/lib/chunk-QNS7GLAA.js +0 -63
- package/src/lib/chunk-U3ZF6SRR.js +0 -25
- /package/src/lib/{chunk-QDQQASRY.js → chunk-MEPQKMK5.js} +0 -0
|
@@ -1,43 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OAuthError,
|
|
3
|
+
pollDeviceToken,
|
|
4
|
+
refreshTokens,
|
|
5
|
+
revokeToken,
|
|
6
|
+
startDeviceAuthorization
|
|
7
|
+
} from "./chunk-43WVFZLO.js";
|
|
8
|
+
import {
|
|
9
|
+
getRememberedBase,
|
|
10
|
+
rememberBase
|
|
11
|
+
} from "./chunk-JYMG2Y6C.js";
|
|
1
12
|
import {
|
|
2
13
|
installSkillFromCli
|
|
3
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-CT5TD6L2.js";
|
|
4
15
|
import {
|
|
5
16
|
VerifyUnavailableError,
|
|
6
|
-
composeSlidesFiles,
|
|
7
17
|
formatVerifyReport,
|
|
8
|
-
|
|
18
|
+
verifyFiles,
|
|
9
19
|
verifyTypes
|
|
10
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-QZFIUZXT.js";
|
|
11
21
|
import {
|
|
12
22
|
artisCliVersion
|
|
13
23
|
} from "./chunk-IZYFOV2K.js";
|
|
24
|
+
import {
|
|
25
|
+
feedbackActions,
|
|
26
|
+
publishedActions,
|
|
27
|
+
renderNextActions,
|
|
28
|
+
renderResult
|
|
29
|
+
} from "./chunk-Q5KBGVKT.js";
|
|
14
30
|
import {
|
|
15
31
|
hasFlag,
|
|
16
|
-
parseFlagValue
|
|
17
|
-
|
|
32
|
+
parseFlagValue,
|
|
33
|
+
valueFlags
|
|
34
|
+
} from "./chunk-KJV7R7DE.js";
|
|
35
|
+
import {
|
|
36
|
+
ARTIS_DEFAULT_HOST,
|
|
37
|
+
findProfileForHost,
|
|
38
|
+
getConfigPath,
|
|
39
|
+
normalizeHost,
|
|
40
|
+
readCliConfig,
|
|
41
|
+
resolveOrigin,
|
|
42
|
+
saveDefaultProfile,
|
|
43
|
+
updateProfileTokens,
|
|
44
|
+
withConfigLock
|
|
45
|
+
} from "./chunk-46DMRA3V.js";
|
|
18
46
|
import {
|
|
19
47
|
changedFiles,
|
|
20
48
|
readFilesDir,
|
|
21
49
|
writeFilesDir
|
|
22
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-MEPQKMK5.js";
|
|
23
51
|
import {
|
|
24
52
|
CliError,
|
|
25
53
|
exitCodeForResponse,
|
|
26
54
|
exitCodes,
|
|
27
55
|
usageError
|
|
28
56
|
} from "./chunk-H32QAUSA.js";
|
|
29
|
-
import {
|
|
30
|
-
getRememberedBase,
|
|
31
|
-
rememberBase
|
|
32
|
-
} from "./chunk-KY47KP5E.js";
|
|
33
|
-
import {
|
|
34
|
-
ARTIS_DEFAULT_HOST,
|
|
35
|
-
findProfileForHost,
|
|
36
|
-
getConfigPath,
|
|
37
|
-
normalizeHost,
|
|
38
|
-
readCliConfig,
|
|
39
|
-
saveDefaultProfile
|
|
40
|
-
} from "./chunk-QNS7GLAA.js";
|
|
41
57
|
|
|
42
58
|
// packages/cli/src/lib/cli.ts
|
|
43
59
|
import { spawn } from "node:child_process";
|
|
@@ -87,7 +103,10 @@ function buildRequest(baseUrl, key, input = {}) {
|
|
|
87
103
|
const search = query.toString();
|
|
88
104
|
const headers = {};
|
|
89
105
|
let body;
|
|
90
|
-
if (typeof
|
|
106
|
+
if (typeof Blob !== "undefined" && input.body instanceof Blob) {
|
|
107
|
+
headers["content-type"] = "application/octet-stream";
|
|
108
|
+
body = input.body;
|
|
109
|
+
} else if (typeof input.body === "string" || input.body instanceof Uint8Array) {
|
|
91
110
|
const bytes = typeof input.body === "string" ? new TextEncoder().encode(input.body) : input.body;
|
|
92
111
|
headers["content-type"] = htmlUploadContentType;
|
|
93
112
|
headers["content-length"] = String(bytes.byteLength);
|
|
@@ -106,6 +125,11 @@ function buildRequest(baseUrl, key, input = {}) {
|
|
|
106
125
|
};
|
|
107
126
|
}
|
|
108
127
|
async function readBody(response) {
|
|
128
|
+
if (/^application\/octet-stream\b/i.test(
|
|
129
|
+
response.headers.get("content-type") ?? ""
|
|
130
|
+
)) {
|
|
131
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
132
|
+
}
|
|
109
133
|
const text = await response.text();
|
|
110
134
|
if (!text) {
|
|
111
135
|
return void 0;
|
|
@@ -135,6 +159,9 @@ function createApiClient(options) {
|
|
|
135
159
|
input
|
|
136
160
|
);
|
|
137
161
|
const headers = init.headers;
|
|
162
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
163
|
+
headers[name.toLowerCase()] ??= value;
|
|
164
|
+
}
|
|
138
165
|
if (options.auth && options.auth !== "cookie") {
|
|
139
166
|
headers["authorization"] = `Bearer ${options.auth.bearer}`;
|
|
140
167
|
}
|
|
@@ -212,9 +239,8 @@ var storageLimits = {
|
|
|
212
239
|
var encoder = new TextEncoder();
|
|
213
240
|
var storageOnlyCodes = /* @__PURE__ */ new Set([
|
|
214
241
|
"version_conflict",
|
|
215
|
-
"
|
|
242
|
+
"capability_not_declared",
|
|
216
243
|
"rules_changed",
|
|
217
|
-
"revision_stale",
|
|
218
244
|
"quota_exceeded",
|
|
219
245
|
"too_large",
|
|
220
246
|
"invalid_path",
|
|
@@ -311,6 +337,8 @@ var commands = [
|
|
|
311
337
|
"annotate",
|
|
312
338
|
"annotation",
|
|
313
339
|
"artifact",
|
|
340
|
+
"asset",
|
|
341
|
+
"capabilities",
|
|
314
342
|
"data",
|
|
315
343
|
"guidelines",
|
|
316
344
|
"help",
|
|
@@ -327,60 +355,6 @@ var commands = [
|
|
|
327
355
|
];
|
|
328
356
|
var cliVisibilityOptions = ["public", "unlisted", "private"];
|
|
329
357
|
var cliAnnotationStatusOptions = ["open", "resolved"];
|
|
330
|
-
var valueFlags = /* @__PURE__ */ new Set([
|
|
331
|
-
"--after",
|
|
332
|
-
"--api-key",
|
|
333
|
-
"--as-role",
|
|
334
|
-
"--depth",
|
|
335
|
-
"--idempotency-key",
|
|
336
|
-
"--if-match",
|
|
337
|
-
"--ops",
|
|
338
|
-
"--order",
|
|
339
|
-
"--patch",
|
|
340
|
-
"--value",
|
|
341
|
-
"--author",
|
|
342
|
-
"--comment",
|
|
343
|
-
"--css",
|
|
344
|
-
"--cursor",
|
|
345
|
-
"--description",
|
|
346
|
-
"--dir",
|
|
347
|
-
"--email",
|
|
348
|
-
"--harness",
|
|
349
|
-
"--host",
|
|
350
|
-
// Removed (ADR 0015); still a value flag so its value is not read as a
|
|
351
|
-
// positional before rejectRemovedKindFlag() refuses it.
|
|
352
|
-
"--kind",
|
|
353
|
-
"--limit",
|
|
354
|
-
"--output",
|
|
355
|
-
"--pin-label",
|
|
356
|
-
"--quote",
|
|
357
|
-
"--quote-prefix",
|
|
358
|
-
"--quote-suffix",
|
|
359
|
-
"--query",
|
|
360
|
-
"--rect",
|
|
361
|
-
"--requested-change",
|
|
362
|
-
// Removed; still a value flag so its value is not read as a positional
|
|
363
|
-
// before rejectRemovedResolveFlag() refuses it.
|
|
364
|
-
"--resolve",
|
|
365
|
-
"--revision",
|
|
366
|
-
"--role",
|
|
367
|
-
"--root",
|
|
368
|
-
"--since",
|
|
369
|
-
"--status",
|
|
370
|
-
"--base",
|
|
371
|
-
"--capabilities",
|
|
372
|
-
"--contract",
|
|
373
|
-
"--summary",
|
|
374
|
-
"--tag",
|
|
375
|
-
"--text-end",
|
|
376
|
-
"--text-start",
|
|
377
|
-
"--timeout",
|
|
378
|
-
"--title",
|
|
379
|
-
"--type",
|
|
380
|
-
"--types",
|
|
381
|
-
"--url",
|
|
382
|
-
"--visibility"
|
|
383
|
-
]);
|
|
384
358
|
function getPositionals(args) {
|
|
385
359
|
const positionals = [];
|
|
386
360
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -408,7 +382,7 @@ function parseVisibility(value) {
|
|
|
408
382
|
`Invalid visibility "${value}". Expected one of: ${cliVisibilityOptions.join(", ")}`
|
|
409
383
|
);
|
|
410
384
|
}
|
|
411
|
-
async function parseCapabilitiesFlag(value) {
|
|
385
|
+
async function parseCapabilitiesFlag(value, flag = "--capabilities") {
|
|
412
386
|
if (value === void 0) {
|
|
413
387
|
return void 0;
|
|
414
388
|
}
|
|
@@ -418,7 +392,7 @@ async function parseCapabilitiesFlag(value) {
|
|
|
418
392
|
source = await readFile(value, "utf8");
|
|
419
393
|
} catch {
|
|
420
394
|
throw usageError(
|
|
421
|
-
|
|
395
|
+
`${flag} must be a JSON object or a path to a JSON file; could not read "${value}".`
|
|
422
396
|
);
|
|
423
397
|
}
|
|
424
398
|
}
|
|
@@ -426,28 +400,21 @@ async function parseCapabilitiesFlag(value) {
|
|
|
426
400
|
try {
|
|
427
401
|
parsed = JSON.parse(source);
|
|
428
402
|
} catch {
|
|
429
|
-
throw usageError(
|
|
403
|
+
throw usageError(`${flag} is not valid JSON.`);
|
|
430
404
|
}
|
|
431
405
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
432
406
|
throw usageError(
|
|
433
|
-
|
|
407
|
+
`${flag} must be a JSON object, e.g. '{"<name>":true}' ({} clears them).`
|
|
434
408
|
);
|
|
435
409
|
}
|
|
436
410
|
return parsed;
|
|
437
411
|
}
|
|
438
|
-
function
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return value;
|
|
444
|
-
}
|
|
445
|
-
if (/^\d+$/.test(value)) {
|
|
446
|
-
return Number(value);
|
|
412
|
+
function rejectRemovedContractFlag(args) {
|
|
413
|
+
if (hasFlag(args, "--contract")) {
|
|
414
|
+
throw usageError(
|
|
415
|
+
"--contract was removed: there is one page contract, and every page gets the `artis` global."
|
|
416
|
+
);
|
|
447
417
|
}
|
|
448
|
-
throw usageError(
|
|
449
|
-
`Invalid --contract "${value}". Expected a version number or latest.`
|
|
450
|
-
);
|
|
451
418
|
}
|
|
452
419
|
function parseTypeFlag(value) {
|
|
453
420
|
if (value === void 0) {
|
|
@@ -459,7 +426,7 @@ function parseTypeFlag(value) {
|
|
|
459
426
|
return value.trim();
|
|
460
427
|
}
|
|
461
428
|
function describeType(declaration) {
|
|
462
|
-
return declaration.type
|
|
429
|
+
return declaration.type !== "html" ? `${declaration.type} (format ${declaration.typeFormat})` : void 0;
|
|
463
430
|
}
|
|
464
431
|
function parseAnnotationStatus(value) {
|
|
465
432
|
if (cliAnnotationStatusOptions.includes(value)) {
|
|
@@ -536,47 +503,64 @@ function resolveBaseUrl(args, config) {
|
|
|
536
503
|
const host = parseFlagValue(args, "--host") || parseFlagValue(args, "--url") || process.env["ARTIS_URL"] || config?.defaultHost || ARTIS_DEFAULT_HOST;
|
|
537
504
|
return normalizeHost(host);
|
|
538
505
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
506
|
+
var refreshMarginMs = 6e4;
|
|
507
|
+
function needsRefresh(profile) {
|
|
508
|
+
return profile.expiresAt !== void 0 && profile.expiresAt - refreshMarginMs <= Date.now() && Boolean(profile.refreshToken);
|
|
509
|
+
}
|
|
510
|
+
async function savedAccessToken(config, baseUrl) {
|
|
511
|
+
const saved = findProfileForHost(config, baseUrl);
|
|
512
|
+
if (!saved) return void 0;
|
|
513
|
+
if (!needsRefresh(saved)) return saved.accessToken;
|
|
514
|
+
return withConfigLock(async () => {
|
|
515
|
+
const profile = findProfileForHost(await readCliConfig(), baseUrl);
|
|
516
|
+
if (!profile) return void 0;
|
|
517
|
+
if (!needsRefresh(profile) || !profile.refreshToken) {
|
|
518
|
+
return profile.accessToken;
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const tokens = await refreshTokens(baseUrl, profile.refreshToken);
|
|
522
|
+
await updateProfileTokens(baseUrl, {
|
|
523
|
+
accessToken: tokens.accessToken,
|
|
524
|
+
refreshToken: tokens.refreshToken ?? profile.refreshToken,
|
|
525
|
+
expiresAt: tokens.expiresAt
|
|
526
|
+
});
|
|
527
|
+
return tokens.accessToken;
|
|
528
|
+
} catch (error) {
|
|
529
|
+
if (error instanceof OAuthError && error.status < 500 && error.status !== 429) {
|
|
530
|
+
return void 0;
|
|
531
|
+
}
|
|
532
|
+
return profile.accessToken;
|
|
533
|
+
}
|
|
534
|
+
});
|
|
552
535
|
}
|
|
553
536
|
async function resolveCredentials(args) {
|
|
554
537
|
const config = await readCliConfig();
|
|
555
538
|
const baseUrl = resolveBaseUrl(args, config);
|
|
556
|
-
const
|
|
557
|
-
if (!
|
|
539
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
540
|
+
if (!accessToken) {
|
|
558
541
|
throw new CliError(
|
|
559
|
-
`
|
|
542
|
+
`Not signed in to ${baseUrl}. Run "artis login --host ${baseUrl}".`,
|
|
560
543
|
exitCodes.auth
|
|
561
544
|
);
|
|
562
545
|
}
|
|
563
|
-
return {
|
|
546
|
+
return { accessToken, baseUrl, origin: await resolveOrigin() };
|
|
564
547
|
}
|
|
565
548
|
async function resolveOptionalTarget(args) {
|
|
566
549
|
const config = await readCliConfig();
|
|
567
550
|
const baseUrl = resolveBaseUrl(args, config);
|
|
568
|
-
const
|
|
569
|
-
return {
|
|
551
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
552
|
+
return {
|
|
553
|
+
accessToken,
|
|
554
|
+
baseUrl,
|
|
555
|
+
origin: accessToken ? await resolveOrigin() : void 0
|
|
556
|
+
};
|
|
570
557
|
}
|
|
571
558
|
async function guidelinesFromCli(args) {
|
|
559
|
+
rejectRemovedContractFlag(args);
|
|
572
560
|
const [section] = getPositionals(args);
|
|
573
|
-
const contract = parseContractFlag(parseFlagValue(args, "--contract"));
|
|
574
561
|
const config = await readCliConfig();
|
|
575
562
|
const baseUrl = resolveBaseUrl(args, config);
|
|
576
563
|
const query = new URLSearchParams({ section: section ?? "index" });
|
|
577
|
-
if (contract !== void 0) {
|
|
578
|
-
query.set("contract", String(contract));
|
|
579
|
-
}
|
|
580
564
|
const response = await fetch(`${baseUrl}/skills.md?${query.toString()}`);
|
|
581
565
|
const text = await response.text();
|
|
582
566
|
if (!response.ok) {
|
|
@@ -589,14 +573,14 @@ async function guidelinesFromCli(args) {
|
|
|
589
573
|
`);
|
|
590
574
|
}
|
|
591
575
|
function rejectRemovedKindFlag(args) {
|
|
592
|
-
if (args
|
|
576
|
+
if (hasFlag(args, "--kind")) {
|
|
593
577
|
throw usageError(
|
|
594
578
|
"--kind was removed: artifacts no longer have a kind. Use --type for the type an artifact is written in (html by default), or tags to group artifacts."
|
|
595
579
|
);
|
|
596
580
|
}
|
|
597
581
|
}
|
|
598
582
|
function rejectRemovedResolveFlag(args) {
|
|
599
|
-
if (args
|
|
583
|
+
if (hasFlag(args, "--resolve")) {
|
|
600
584
|
throw usageError(
|
|
601
585
|
'--resolve was removed: a revision no longer changes review status. Reply in each thread you addressed with "artis reply"; the reviewers resolve it.'
|
|
602
586
|
);
|
|
@@ -604,11 +588,12 @@ function rejectRemovedResolveFlag(args) {
|
|
|
604
588
|
}
|
|
605
589
|
async function parsePublishOptions(args) {
|
|
606
590
|
rejectRemovedKindFlag(args);
|
|
591
|
+
rejectRemovedContractFlag(args);
|
|
607
592
|
const [filePath] = getPositionals(args);
|
|
608
593
|
const root = parseFlagValue(args, "--root");
|
|
609
594
|
if (!filePath && !root) {
|
|
610
595
|
throw usageError(
|
|
611
|
-
"Missing artifact HTML file path (or --root <dir> for
|
|
596
|
+
"Missing artifact HTML file path (or --root <dir> for an artifact as a directory of files, e.g. a slides deck)."
|
|
612
597
|
);
|
|
613
598
|
}
|
|
614
599
|
if (filePath && root) {
|
|
@@ -621,7 +606,7 @@ async function parsePublishOptions(args) {
|
|
|
621
606
|
return {
|
|
622
607
|
filePath,
|
|
623
608
|
root,
|
|
624
|
-
|
|
609
|
+
credentials,
|
|
625
610
|
baseUrl: credentials.baseUrl,
|
|
626
611
|
title: parseFlagValue(args, "--title"),
|
|
627
612
|
description: parseFlagValue(args, "--description") ?? "Published from Artis CLI.",
|
|
@@ -630,12 +615,54 @@ async function parsePublishOptions(args) {
|
|
|
630
615
|
capabilities: await parseCapabilitiesFlag(
|
|
631
616
|
parseFlagValue(args, "--capabilities")
|
|
632
617
|
),
|
|
633
|
-
|
|
618
|
+
reloadPages: hasFlag(args, "--reload-pages") || void 0,
|
|
634
619
|
type: parseTypeFlag(parseFlagValue(args, "--type")),
|
|
635
620
|
json: hasFlag(args, "--json")
|
|
636
621
|
};
|
|
637
622
|
}
|
|
638
|
-
function
|
|
623
|
+
async function apiCallRoot(root, credentials, key, ...input) {
|
|
624
|
+
try {
|
|
625
|
+
return await apiClient(credentials).call(key, ...input);
|
|
626
|
+
} catch (error) {
|
|
627
|
+
const cliError = cliErrorOf(error, {
|
|
628
|
+
artifact: root.artifact,
|
|
629
|
+
root: root.dir
|
|
630
|
+
});
|
|
631
|
+
const issue = error instanceof ApiError && layoutIssueOf(error);
|
|
632
|
+
if (!issue || !(cliError instanceof CliError)) throw cliError;
|
|
633
|
+
const stray = /does not take (\S+):/.exec(issue)?.[1];
|
|
634
|
+
let hint = stray ? ` Every file under --root is sent (dotfiles and node_modules are skipped): move ${stray} out of ${root.dir}.` : "";
|
|
635
|
+
if (root.untyped) {
|
|
636
|
+
hint += " Without --type the files are an html artifact; for another type, pass --type <type>, e.g. --type slides.";
|
|
637
|
+
}
|
|
638
|
+
throw new CliError(`${cliError.message}${hint}`, cliError.exitCode);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function layoutIssueOf(error) {
|
|
642
|
+
if (error.status !== 400 || error.code !== "invalid_request") {
|
|
643
|
+
return void 0;
|
|
644
|
+
}
|
|
645
|
+
const issues = error.body?.["issues"];
|
|
646
|
+
if (!Array.isArray(issues)) return void 0;
|
|
647
|
+
for (const issue of issues) {
|
|
648
|
+
if (!issue || typeof issue !== "object") continue;
|
|
649
|
+
const { path, message } = issue;
|
|
650
|
+
if ((path === "files" || path === "type") && typeof message === "string") {
|
|
651
|
+
return message;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return void 0;
|
|
655
|
+
}
|
|
656
|
+
function conflictingPathsHint(body, context = {}) {
|
|
657
|
+
const paths = body?.["conflictingPaths"];
|
|
658
|
+
if (body?.["code"] !== "revision_conflict" || !Array.isArray(paths) || paths.length === 0) {
|
|
659
|
+
return "";
|
|
660
|
+
}
|
|
661
|
+
const artifact = context.artifact ?? "<artifact>";
|
|
662
|
+
const recover = context.root ? `Pull the current revision into a new directory (artis artifact files ${artifact} --output <new-dir>), reapply your change there, and revise with --root <new-dir>.` : `Read the current version (artis artifact files ${artifact} ${paths.length === 1 ? paths[0] : "<path>"}), reapply your change, and revise again.`;
|
|
663
|
+
return `Conflicting files: ${paths.join(", ")}. ${recover}`;
|
|
664
|
+
}
|
|
665
|
+
function cliErrorOf(error, context = {}) {
|
|
639
666
|
if (!(error instanceof ApiError)) {
|
|
640
667
|
return error;
|
|
641
668
|
}
|
|
@@ -643,6 +670,10 @@ function cliErrorOf(error) {
|
|
|
643
670
|
formatRevisionConflictMessage(error.message, error.body),
|
|
644
671
|
error.body
|
|
645
672
|
);
|
|
673
|
+
const conflict = conflictingPathsHint(error.body, context);
|
|
674
|
+
if (conflict) {
|
|
675
|
+
message = `${message.replace(/[.\s]*$/, "")}. ${conflict}`;
|
|
676
|
+
}
|
|
646
677
|
if (error.status === 429 && error.retryAfter) {
|
|
647
678
|
message += ` Retry after ${error.retryAfter} s.`;
|
|
648
679
|
}
|
|
@@ -651,7 +682,8 @@ function cliErrorOf(error) {
|
|
|
651
682
|
function apiClient(target) {
|
|
652
683
|
return createApiClient({
|
|
653
684
|
baseUrl: target.baseUrl,
|
|
654
|
-
auth: target.
|
|
685
|
+
auth: target.accessToken ? { bearer: target.accessToken } : void 0,
|
|
686
|
+
headers: target.accessToken && target.origin ? { "artis-origin": target.origin } : void 0
|
|
655
687
|
});
|
|
656
688
|
}
|
|
657
689
|
async function apiCall(credentials, key, ...input) {
|
|
@@ -665,7 +697,7 @@ async function apiCallOptional(target, key, ...input) {
|
|
|
665
697
|
try {
|
|
666
698
|
return await apiClient(target).call(key, ...input);
|
|
667
699
|
} catch (error) {
|
|
668
|
-
if (!(error instanceof ApiError) || error.status !== 401 || !target.
|
|
700
|
+
if (!(error instanceof ApiError) || error.status !== 401 || !target.accessToken) {
|
|
669
701
|
throw cliErrorOf(error);
|
|
670
702
|
}
|
|
671
703
|
}
|
|
@@ -675,7 +707,7 @@ async function apiCallOptional(target, key, ...input) {
|
|
|
675
707
|
...input
|
|
676
708
|
);
|
|
677
709
|
console.warn(
|
|
678
|
-
`Saved
|
|
710
|
+
`Saved sign-in was rejected by ${target.baseUrl}; retried without credentials. Run "artis login --host ${target.baseUrl}" to sign in again.`
|
|
679
711
|
);
|
|
680
712
|
return result;
|
|
681
713
|
} catch (error) {
|
|
@@ -737,27 +769,28 @@ Usage:
|
|
|
737
769
|
artis --version
|
|
738
770
|
artis login [--host <url>]
|
|
739
771
|
artis whoami [--host <url>]
|
|
740
|
-
artis guidelines [section] [--
|
|
772
|
+
artis guidelines [section] [--host <url>]
|
|
741
773
|
artis types [name [reference]] [--json] [--host <url>]
|
|
742
774
|
artis install-skill [--harness <id>]... [--yes] [--dir <path>] [--force] [--list] [--json]
|
|
743
775
|
artis publish artifact.html [options]
|
|
744
|
-
artis publish --root <dir> --type <type> [options]
|
|
776
|
+
artis publish --root <dir> [--type <type>] [options]
|
|
745
777
|
artis artifact get <artifact> [--json]
|
|
746
|
-
artis artifact html <artifact> [--output <path>] [--revision <revision-id>] [--json]
|
|
747
778
|
artis artifact files <artifact> [path] [--output <dir>] [--revision <revision-id>] [--json]
|
|
748
779
|
artis artifact feedback <artifact> [--json] [--revision <revision-id>]
|
|
749
780
|
artis artifact list [--query <text>] [--tag <tag>] [--type <type>] [--limit <n>] [--cursor <cursor>] [--json]
|
|
750
781
|
artis artifact visibility <artifact> <public|unlisted|private> [--json]
|
|
751
782
|
artis artifact delete <artifact> --yes
|
|
752
|
-
artis verify <artifact.html | artifact> [--
|
|
753
|
-
artis verify --root <dir> --type slides [--json]
|
|
783
|
+
artis verify <artifact.html | artifact> [--revision <revision-id>] [--json]
|
|
784
|
+
artis verify --root <dir> [--type slides] [--json]
|
|
754
785
|
artis share <artifact> [--email <email> --role <viewer|commenter|contributor|editor>] [--remove]
|
|
755
|
-
artis revise <artifact> (artifact.html | --root <dir>) --summary <text> [--base <revision-id>] [--capabilities <json|file>] [--
|
|
786
|
+
artis revise <artifact> (artifact.html | --root <dir>) --summary <text> [--base <revision-id>] [--capabilities <json|file>] [--reload-pages] [--type <type>]
|
|
787
|
+
artis capabilities show <artifact> [--json]
|
|
788
|
+
artis capabilities set <artifact> <json|file> [--reload-pages] [--json]
|
|
756
789
|
artis annotate <artifact> --comment <text> [anchor options]
|
|
757
790
|
artis reply <annotation-id> --comment <text>
|
|
758
791
|
artis annotation edit <annotation-id> [--comment <text>] [--title <text>] [--requested-change <text>]
|
|
759
792
|
artis annotation retract <annotation-id>
|
|
760
|
-
artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--
|
|
793
|
+
artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--self origin|client|none] [--types <families>]
|
|
761
794
|
artis data get <artifact> <path> [--as-role <role>]
|
|
762
795
|
artis data list <artifact> [prefix] [--depth children|all] [--order path|created] [--limit <n>] [--after <next>] [--as-role <role>]
|
|
763
796
|
artis data set <artifact> <path> --value <json|file|-> [--if-match <id>@<version> | --if-absent] [--idempotency-key <key>]
|
|
@@ -766,9 +799,12 @@ Usage:
|
|
|
766
799
|
artis data batch <artifact> --ops <json|file|-> [--idempotency-key <key>]
|
|
767
800
|
artis data export <artifact> [--output <path>] [--as-role <role>]
|
|
768
801
|
artis data usage <artifact>
|
|
802
|
+
artis asset upload <artifact> <file> [--name <name>] [--content-type <type>]
|
|
803
|
+
artis asset list <artifact>
|
|
804
|
+
artis asset get <artifact> <asset-id> [--output <path>]
|
|
805
|
+
artis asset rm <artifact> <asset-id>
|
|
769
806
|
|
|
770
807
|
Options:
|
|
771
|
-
--api-key <key> API key. Defaults to ARTIS_API_KEY or ~/.artis/config.json. Run "artis login" to obtain one.
|
|
772
808
|
--host, --url <url> Artis server URL. Falls back to ARTIS_URL, then a saved login, then https://artis.xiispace.eu.org.
|
|
773
809
|
--title <title> Artifact title. Defaults to the file name.
|
|
774
810
|
--description <text> Artifact description.
|
|
@@ -776,9 +812,9 @@ Options:
|
|
|
776
812
|
--type <type> The type the artifact is created with, e.g. slides (publish, revise, verify; artifact list keeps your artifacts of that type). It is fixed at publish: revise keeps it, and may only repeat it. Verify of a published artifact reads it from the revision.
|
|
777
813
|
--author <name> Artifact author/agent name. Defaults to Artis CLI.
|
|
778
814
|
--summary <text> Revision summary. Write one change per line; they render as a list.
|
|
779
|
-
--base <revision-id> Revision the file was edited from. Defaults to the revision this machine last published, read (artifact html), or revised. Refuses the revise if someone revised since.
|
|
780
|
-
--capabilities <json|file> Page capabilities as a JSON object or JSON file (publish, revise).
|
|
781
|
-
--
|
|
815
|
+
--base <revision-id> Revision the file was edited from. Defaults to the revision this machine last published, read whole (artifact files --output, or an html artifact's index.html), or revised. Refuses the revise if someone revised since.
|
|
816
|
+
--capabilities <json|file> Page capabilities as a JSON object or JSON file (publish, revise). They belong to the artifact, not the revision: revise keeps them without it; '{}' clears them.
|
|
817
|
+
--reload-pages Make open pages reload (revise, capabilities set), e.g. when stored data changes shape. A revise that leaves the capabilities alone does not interrupt open pages without it.
|
|
782
818
|
--comment <text> Annotation or reply comment text (annotate, reply).
|
|
783
819
|
--requested-change <text> Structured change request for the artifact author (annotate).
|
|
784
820
|
--status <value> Annotation status: open or resolved. Defaults to open.
|
|
@@ -790,9 +826,9 @@ Options:
|
|
|
790
826
|
--text-end <n> Document offset where the quote ends (annotate, TextPositionSelector).
|
|
791
827
|
--rect <x,y,w,h> Canvas point/rect as percentages (annotate, FragmentSelector). w,h default to 0.
|
|
792
828
|
--pin-label <text> Short label shown on the artifact canvas pin (annotate).
|
|
793
|
-
--output <path> Write
|
|
794
|
-
--root <dir>
|
|
795
|
-
--revision <revision-id> Revision to read (artifact
|
|
829
|
+
--output <path> Write every file of the revision under this directory, downloaded in parallel (artifact files).
|
|
830
|
+
--root <dir> An artifact as a directory of files, any type (an html artifact is one file, index.html): publish every file under it, or revise with only the ones that differ from the base revision (files gone from it are removed). The type checks the files, so keep anything else (notes, a README) out of it. Dotfiles and node_modules are skipped. verify serves the files at the paths usercontent serves them at.
|
|
831
|
+
--revision <revision-id> Revision to read (artifact files, artifact feedback). Defaults to the current revision.
|
|
796
832
|
--query <text> Text to find in your artifacts' titles and descriptions (artifact list).
|
|
797
833
|
--tag <tag> Only your artifacts carrying this tag (artifact list).
|
|
798
834
|
--limit <n> Artifacts per page, 1-100 (artifact list). Defaults to 50.
|
|
@@ -808,8 +844,8 @@ Options:
|
|
|
808
844
|
--since <cursor> Feedback cursor to watch from (watch). Defaults to now; 0 replays every event.
|
|
809
845
|
--once Exit after the first batch of events, printed as {events, cursor} (watch).
|
|
810
846
|
--timeout <duration> Give up after this long, e.g. 30s, 10m (watch). Exits 6 if nothing happened.
|
|
811
|
-
--
|
|
812
|
-
--types <families> Only these event families, comma-separated: annotation, revision (watch). Defaults to all.
|
|
847
|
+
--self <scope> Which of your own events to leave out (watch): origin (default) leaves out this machine's, client those of every machine signed in with the CLI, none leaves out nothing. --include-self is --self none. The origin is ARTIS_ORIGIN, else one generated per machine.
|
|
848
|
+
--types <families> Only these event families, comma-separated: annotation, revision, page, policy (watch). Defaults to all.
|
|
813
849
|
--value <json|file|-> The whole document, a JSON object: inline, a file, or - for stdin (data set).
|
|
814
850
|
--patch <json|file|-> A JSON object deep-merged into the document (data update).
|
|
815
851
|
--ops <json|file|-> Writes for data batch: [{"op":"set","path":"...","value":{...}}, ...] or {"ops":[...]}.
|
|
@@ -831,9 +867,12 @@ Examples (--host is optional; without it commands target https://artis.xiispace.
|
|
|
831
867
|
artis publish report.html --host https://artis.example.com --visibility private
|
|
832
868
|
artis share 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --email reviewer@example.com --role commenter
|
|
833
869
|
artis artifact get 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --json
|
|
834
|
-
artis artifact
|
|
870
|
+
artis artifact files 4kq9Zt2LmX8vRbP3nWc7Hy index.html > report.html
|
|
871
|
+
artis publish --root deck --type slides
|
|
872
|
+
artis artifact files 4kq9Zt2LmX8vRbP3nWc7Hy --output deck
|
|
873
|
+
artis revise 4kq9Zt2LmX8vRbP3nWc7Hy --root deck --summary "Fix the cover slide"
|
|
835
874
|
artis verify report.html
|
|
836
|
-
artis verify deck
|
|
875
|
+
artis verify --root deck --type slides
|
|
837
876
|
artis artifact feedback 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --json
|
|
838
877
|
artis annotate 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --comment "Tighten this heading" --quote "Checkout latency" --requested-change "Add the affected checkout count"
|
|
839
878
|
artis reply annotation-123 --host https://artis.example.com --comment "Addressed in the latest revision"
|
|
@@ -847,7 +886,7 @@ Examples (--host is optional; without it commands target https://artis.xiispace.
|
|
|
847
886
|
}
|
|
848
887
|
async function publishArtifactFromCli(args) {
|
|
849
888
|
const options = await parsePublishOptions(args);
|
|
850
|
-
const credentials =
|
|
889
|
+
const credentials = options.credentials;
|
|
851
890
|
const source = options.root ?? options.filePath ?? "";
|
|
852
891
|
const title = options.title ?? inferTitleFromPath(source);
|
|
853
892
|
const query = {
|
|
@@ -857,21 +896,18 @@ async function publishArtifactFromCli(args) {
|
|
|
857
896
|
authorName: options.authorName,
|
|
858
897
|
source: "cli",
|
|
859
898
|
capabilities: options.capabilities,
|
|
860
|
-
|
|
899
|
+
reloadPages: options.reloadPages,
|
|
861
900
|
type: options.type
|
|
862
901
|
};
|
|
863
902
|
let result;
|
|
864
903
|
if (options.root) {
|
|
865
|
-
if (!options.type || options.type === "html") {
|
|
866
|
-
throw usageError(
|
|
867
|
-
"--root publishes an artifact made of files: pass the type it is written in, e.g. --type slides. An html artifact is one HTML file."
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
904
|
const files = await readFilesDir(options.root);
|
|
871
|
-
({ result } = await
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
905
|
+
({ result } = await apiCallRoot(
|
|
906
|
+
{ dir: options.root, untyped: !options.type },
|
|
907
|
+
credentials,
|
|
908
|
+
"POST /api/artifacts",
|
|
909
|
+
{ query, body: { files } }
|
|
910
|
+
));
|
|
875
911
|
} else {
|
|
876
912
|
const html = await readHtmlUpload(source, "Artifact file");
|
|
877
913
|
({ result } = await apiCall(credentials, "POST /api/artifacts", {
|
|
@@ -886,52 +922,82 @@ async function publishArtifactFromCli(args) {
|
|
|
886
922
|
title,
|
|
887
923
|
url: buildArtifactUrl(options.baseUrl, result.url),
|
|
888
924
|
visibility: options.visibility,
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
typeFormat: result.typeFormat ?? null
|
|
925
|
+
type: result.type,
|
|
926
|
+
typeFormat: result.typeFormat
|
|
892
927
|
};
|
|
893
928
|
}
|
|
894
929
|
async function loginFromCli(args) {
|
|
895
930
|
const config = await readCliConfig();
|
|
896
931
|
const baseUrl = resolveBaseUrl(args, config);
|
|
897
|
-
const api = apiClient({ baseUrl });
|
|
898
932
|
let login;
|
|
899
933
|
try {
|
|
900
|
-
login = await
|
|
934
|
+
login = await startDeviceAuthorization(baseUrl);
|
|
901
935
|
} catch (error) {
|
|
902
|
-
throw
|
|
936
|
+
throw loginErrorOf(error, baseUrl);
|
|
903
937
|
}
|
|
904
|
-
|
|
905
|
-
|
|
938
|
+
const verificationUrl = login.verificationUriComplete ?? login.verificationUri;
|
|
939
|
+
assertSafeLoginUrl(verificationUrl, baseUrl);
|
|
940
|
+
console.log(`Opening ${verificationUrl}`);
|
|
906
941
|
console.log(`Code: ${login.userCode}`);
|
|
907
942
|
try {
|
|
908
|
-
openBrowser(
|
|
943
|
+
openBrowser(verificationUrl);
|
|
909
944
|
} catch {
|
|
910
945
|
console.log("Could not open a browser automatically.");
|
|
911
946
|
}
|
|
912
|
-
|
|
913
|
-
|
|
947
|
+
let intervalMs = Math.max(login.interval, 1) * 1e3;
|
|
948
|
+
const expiresAt = Date.now() + login.expiresIn * 1e3;
|
|
949
|
+
while (Date.now() < expiresAt) {
|
|
914
950
|
await sleep(intervalMs);
|
|
915
951
|
let poll;
|
|
916
952
|
try {
|
|
917
|
-
poll = await
|
|
918
|
-
body: { deviceCode: login.deviceCode }
|
|
919
|
-
});
|
|
953
|
+
poll = await pollDeviceToken(baseUrl, login.deviceCode);
|
|
920
954
|
} catch (error) {
|
|
921
|
-
|
|
922
|
-
await sleep((error.retryAfter ?? 10) * 1e3);
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
throw cliErrorOf(error);
|
|
955
|
+
throw loginErrorOf(error, baseUrl);
|
|
926
956
|
}
|
|
927
957
|
if (poll.status === "pending") {
|
|
928
958
|
continue;
|
|
929
959
|
}
|
|
930
|
-
|
|
960
|
+
if (poll.status === "slow_down") {
|
|
961
|
+
intervalMs += 5e3;
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
const previous = findProfileForHost(await readCliConfig(), baseUrl);
|
|
965
|
+
await saveDefaultProfile({ host: baseUrl, ...poll.tokens });
|
|
966
|
+
if (previous?.refreshToken) {
|
|
967
|
+
await revokeToken(baseUrl, previous.refreshToken, "refresh_token");
|
|
968
|
+
}
|
|
969
|
+
if (previous?.accessToken) {
|
|
970
|
+
await revokeToken(baseUrl, previous.accessToken, "access_token");
|
|
971
|
+
}
|
|
972
|
+
await resolveOrigin();
|
|
931
973
|
console.log(`Saved artis credentials to ${getConfigPath()}`);
|
|
932
974
|
return;
|
|
933
975
|
}
|
|
934
|
-
throw new
|
|
976
|
+
throw new CliError("Login expired. Run artis login again.", exitCodes.auth);
|
|
977
|
+
}
|
|
978
|
+
function loginErrorOf(error, baseUrl) {
|
|
979
|
+
if (!(error instanceof OAuthError)) {
|
|
980
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
981
|
+
}
|
|
982
|
+
if (error.code === "access_denied") {
|
|
983
|
+
return new CliError("Login was denied in the browser.", exitCodes.auth);
|
|
984
|
+
}
|
|
985
|
+
if (error.code === "expired_token") {
|
|
986
|
+
return new CliError(
|
|
987
|
+
"Login expired. Run artis login again.",
|
|
988
|
+
exitCodes.auth
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
if (error.status === 429) {
|
|
992
|
+
return new CliError(
|
|
993
|
+
`Too many logins from here; ${baseUrl} asked to slow down. Try again in a minute.`,
|
|
994
|
+
exitCodes.rateLimited
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
return new CliError(
|
|
998
|
+
`Login failed on ${baseUrl}: ${error.message}`,
|
|
999
|
+
exitCodeForResponse(error.status, error.code)
|
|
1000
|
+
);
|
|
935
1001
|
}
|
|
936
1002
|
async function typesFromCli(args) {
|
|
937
1003
|
const [name, file] = getPositionals(args);
|
|
@@ -1038,6 +1104,44 @@ async function getArtifactFromCli(args) {
|
|
|
1038
1104
|
`Open annotations: ${result.annotations.filter((annotation) => isRootAnnotation(annotation) && !isReviewClosed(annotation["artis:status"])).length}`
|
|
1039
1105
|
);
|
|
1040
1106
|
}
|
|
1107
|
+
var parallelFileReads = 6;
|
|
1108
|
+
async function mapConcurrent(items, limit, run) {
|
|
1109
|
+
const results = new Array(items.length);
|
|
1110
|
+
let next = 0;
|
|
1111
|
+
async function worker() {
|
|
1112
|
+
while (next < items.length) {
|
|
1113
|
+
const index = next++;
|
|
1114
|
+
results[index] = await run(items[index]);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
await Promise.all(
|
|
1118
|
+
Array.from({ length: Math.min(limit, items.length) }, worker)
|
|
1119
|
+
);
|
|
1120
|
+
return results;
|
|
1121
|
+
}
|
|
1122
|
+
function listRevisionFiles(target, artifactId, revisionId) {
|
|
1123
|
+
return apiCallOptional(target, "GET /api/artifacts/{artifactId}/files", {
|
|
1124
|
+
params: { artifactId },
|
|
1125
|
+
query: { revisionId }
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
function readListedFiles(target, artifactId, listed) {
|
|
1129
|
+
return mapConcurrent(listed.files, parallelFileReads, async (file) => {
|
|
1130
|
+
const read = await apiCallOptional(
|
|
1131
|
+
target,
|
|
1132
|
+
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1133
|
+
{
|
|
1134
|
+
params: { artifactId, path: file.path },
|
|
1135
|
+
query: { revisionId: listed.revisionId }
|
|
1136
|
+
}
|
|
1137
|
+
);
|
|
1138
|
+
return { path: file.path, content: read.content };
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
async function readRevisionFiles(target, artifactId, revisionId) {
|
|
1142
|
+
const listed = await listRevisionFiles(target, artifactId, revisionId);
|
|
1143
|
+
return { listed, files: await readListedFiles(target, artifactId, listed) };
|
|
1144
|
+
}
|
|
1041
1145
|
async function getArtifactFilesFromCli(args) {
|
|
1042
1146
|
const [artifactRef, filePath] = getPositionals(args);
|
|
1043
1147
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
@@ -1049,41 +1153,45 @@ async function getArtifactFilesFromCli(args) {
|
|
|
1049
1153
|
const target = await resolveOptionalTarget(args);
|
|
1050
1154
|
const revisionId = parseFlagValue(args, "--revision");
|
|
1051
1155
|
const json = hasFlag(args, "--json");
|
|
1156
|
+
const output = parseFlagValue(args, "--output");
|
|
1157
|
+
if (filePath && output) {
|
|
1158
|
+
throw usageError(
|
|
1159
|
+
`--output writes every file of the revision under a directory. To save one file, redirect it: artis artifact files ${artifactRef} ${filePath} > <file>.`
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1052
1162
|
if (filePath) {
|
|
1053
1163
|
const file = await apiCallOptional(
|
|
1054
1164
|
target,
|
|
1055
1165
|
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1056
1166
|
{ params: { artifactId, path: filePath }, query: { revisionId } }
|
|
1057
1167
|
);
|
|
1168
|
+
const revision = await apiCallOptional(
|
|
1169
|
+
target,
|
|
1170
|
+
"GET /api/artifacts/{artifactId}/files",
|
|
1171
|
+
{ params: { artifactId }, query: { revisionId: file.revisionId } }
|
|
1172
|
+
);
|
|
1173
|
+
if (revision.files.length === 1) {
|
|
1174
|
+
await rememberBase(
|
|
1175
|
+
target.baseUrl,
|
|
1176
|
+
[artifactId, file.artifactId],
|
|
1177
|
+
file.revisionId
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
if (file.isLatest === false) {
|
|
1181
|
+
console.error(
|
|
1182
|
+
`Note: version ${file.version} is not the latest. The latest is version ${file.latestVersion} (revision ${file.latestRevisionId}); a revise based on this one will be refused if it changes a file changed since.`
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1058
1185
|
if (json) {
|
|
1059
1186
|
console.log(JSON.stringify(file, null, 2));
|
|
1060
1187
|
return;
|
|
1061
1188
|
}
|
|
1062
|
-
process.stdout.write(
|
|
1063
|
-
file.content.endsWith("\n") ? file.content : `${file.content}
|
|
1064
|
-
`
|
|
1065
|
-
);
|
|
1189
|
+
process.stdout.write(file.content);
|
|
1066
1190
|
return;
|
|
1067
1191
|
}
|
|
1068
|
-
const listed = await
|
|
1069
|
-
target,
|
|
1070
|
-
"GET /api/artifacts/{artifactId}/files",
|
|
1071
|
-
{ params: { artifactId }, query: { revisionId } }
|
|
1072
|
-
);
|
|
1073
|
-
const output = parseFlagValue(args, "--output");
|
|
1192
|
+
const listed = await listRevisionFiles(target, artifactId, revisionId);
|
|
1074
1193
|
if (output) {
|
|
1075
|
-
const files =
|
|
1076
|
-
for (const file of listed.files) {
|
|
1077
|
-
const read = await apiCallOptional(
|
|
1078
|
-
target,
|
|
1079
|
-
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1080
|
-
{
|
|
1081
|
-
params: { artifactId, path: file.path },
|
|
1082
|
-
query: { revisionId: listed.revisionId }
|
|
1083
|
-
}
|
|
1084
|
-
);
|
|
1085
|
-
files.push({ path: file.path, content: read.content });
|
|
1086
|
-
}
|
|
1194
|
+
const files = await readListedFiles(target, artifactId, listed);
|
|
1087
1195
|
await writeFilesDir(output, files);
|
|
1088
1196
|
await rememberBase(
|
|
1089
1197
|
target.baseUrl,
|
|
@@ -1102,50 +1210,6 @@ async function getArtifactFilesFromCli(args) {
|
|
|
1102
1210
|
output ? `Wrote ${listed.files.length} files of revision ${listed.revisionId} (v${listed.version}) to ${output}.` : `Revision ${listed.revisionId} (v${listed.version})${listed.isLatest ? "" : ", not the latest"}.`
|
|
1103
1211
|
);
|
|
1104
1212
|
}
|
|
1105
|
-
async function getArtifactHtmlFromCli(args) {
|
|
1106
|
-
const [artifactRef] = getPositionals(args);
|
|
1107
|
-
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1108
|
-
if (!artifactId) {
|
|
1109
|
-
throw usageError(
|
|
1110
|
-
"Usage: artis artifact html <artifact> [--output <path>] [--revision <revision-id>]"
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
const target = await resolveOptionalTarget(args);
|
|
1114
|
-
const result = await apiCallOptional(
|
|
1115
|
-
target,
|
|
1116
|
-
"GET /api/artifacts/{artifactId}/html",
|
|
1117
|
-
{
|
|
1118
|
-
params: { artifactId },
|
|
1119
|
-
query: { revisionId: parseFlagValue(args, "--revision") }
|
|
1120
|
-
}
|
|
1121
|
-
);
|
|
1122
|
-
if (typeof result.html !== "string") {
|
|
1123
|
-
throw new Error("Artifact response did not include revision HTML.");
|
|
1124
|
-
}
|
|
1125
|
-
await rememberBase(
|
|
1126
|
-
target.baseUrl,
|
|
1127
|
-
[artifactId, result.artifactId],
|
|
1128
|
-
result.revisionId
|
|
1129
|
-
);
|
|
1130
|
-
if (result.isLatest === false) {
|
|
1131
|
-
console.error(
|
|
1132
|
-
`Note: version ${result.version} is not the latest. The latest is version ${result.latestVersion} (revision ${result.latestRevisionId}); a revise based on this one will be refused.`
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
if (hasFlag(args, "--json")) {
|
|
1136
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
const outputPath = parseFlagValue(args, "--output");
|
|
1140
|
-
if (!outputPath) {
|
|
1141
|
-
process.stdout.write(result.html);
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
await writeFile(outputPath, result.html, "utf8");
|
|
1145
|
-
console.log(`Wrote ${outputPath}`);
|
|
1146
|
-
console.log(`Revision: ${result.revisionId}`);
|
|
1147
|
-
console.log(`Version: ${result.version}`);
|
|
1148
|
-
}
|
|
1149
1213
|
function parseVerifyType(value) {
|
|
1150
1214
|
const type = parseTypeFlag(value);
|
|
1151
1215
|
if (type === void 0 || type === "html") {
|
|
@@ -1163,15 +1227,16 @@ async function verifyFromCli(args) {
|
|
|
1163
1227
|
const root = parseFlagValue(args, "--root");
|
|
1164
1228
|
if (!target && !root) {
|
|
1165
1229
|
throw usageError(
|
|
1166
|
-
"Usage: artis verify <artifact.html | artifact> [--
|
|
1230
|
+
"Usage: artis verify <artifact.html | artifact> [--revision <revision-id>] [--json]\n artis verify --root <dir> [--type slides] [--json]"
|
|
1167
1231
|
);
|
|
1168
1232
|
}
|
|
1169
1233
|
if (root) {
|
|
1170
1234
|
return verifyFilesDirFromCli(args, root, target);
|
|
1171
1235
|
}
|
|
1172
1236
|
let type = parseVerifyType(parseFlagValue(args, "--type"));
|
|
1173
|
-
let
|
|
1237
|
+
let files;
|
|
1174
1238
|
let label;
|
|
1239
|
+
let loadAsset;
|
|
1175
1240
|
const referenced = artifactIdFromReference(target);
|
|
1176
1241
|
const looksLikePath = !referenced && (/[\\/]/.test(target) || /\.html?$/i.test(target));
|
|
1177
1242
|
const local = await readFile(target, "utf8").catch(
|
|
@@ -1186,30 +1251,43 @@ async function verifyFromCli(args) {
|
|
|
1186
1251
|
"--revision applies to a published artifact, not a local file."
|
|
1187
1252
|
);
|
|
1188
1253
|
}
|
|
1189
|
-
|
|
1254
|
+
if (type) {
|
|
1255
|
+
throw usageError(
|
|
1256
|
+
`A ${type} artifact is a directory of files: artis verify --root <dir> --type ${type}.`
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
files = { "index.html": local };
|
|
1190
1260
|
label = target;
|
|
1191
1261
|
} else {
|
|
1192
1262
|
const remote = await resolveOptionalTarget(args);
|
|
1193
|
-
const
|
|
1263
|
+
const artifactId = referenced ?? target;
|
|
1264
|
+
const read = await readRevisionFiles(
|
|
1194
1265
|
remote,
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
params: { artifactId: referenced ?? target },
|
|
1198
|
-
query: { revisionId: parseFlagValue(args, "--revision") }
|
|
1199
|
-
}
|
|
1266
|
+
artifactId,
|
|
1267
|
+
parseFlagValue(args, "--revision")
|
|
1200
1268
|
);
|
|
1201
|
-
|
|
1202
|
-
|
|
1269
|
+
files = Object.fromEntries(
|
|
1270
|
+
read.files.map((file) => [file.path, file.content])
|
|
1271
|
+
);
|
|
1272
|
+
label = `${target} v${read.listed.version}`;
|
|
1273
|
+
if (remote.accessToken) {
|
|
1274
|
+
loadAsset = (assetId) => fetchAssetContent(remote, artifactId, assetId).catch((error) => {
|
|
1275
|
+
if (error instanceof CliError && error.exitCode === exitCodes.notFound) {
|
|
1276
|
+
return void 0;
|
|
1277
|
+
}
|
|
1278
|
+
throw error;
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1203
1281
|
if (type === void 0) {
|
|
1204
1282
|
const { artifact } = await apiCallOptional(
|
|
1205
1283
|
remote,
|
|
1206
1284
|
"GET /api/artifacts/{artifactId}",
|
|
1207
|
-
{ params: { artifactId
|
|
1285
|
+
{ params: { artifactId } }
|
|
1208
1286
|
);
|
|
1209
1287
|
const declared = artifact.revisions.find(
|
|
1210
|
-
(revision) => revision.id ===
|
|
1288
|
+
(revision) => revision.id === read.listed.revisionId
|
|
1211
1289
|
)?.type;
|
|
1212
|
-
if (declared && declared !== "html") {
|
|
1290
|
+
if (declared !== void 0 && declared !== "html") {
|
|
1213
1291
|
if (!verifyTypes.includes(declared)) {
|
|
1214
1292
|
throw new CliError(
|
|
1215
1293
|
`${label} is of type ${declared}, which this CLI cannot verify. Update the CLI.`,
|
|
@@ -1220,7 +1298,7 @@ async function verifyFromCli(args) {
|
|
|
1220
1298
|
}
|
|
1221
1299
|
}
|
|
1222
1300
|
}
|
|
1223
|
-
await runVerify(args,
|
|
1301
|
+
await runVerify(args, files, label, type, loadAsset);
|
|
1224
1302
|
}
|
|
1225
1303
|
async function verifyFilesDirFromCli(args, root, target) {
|
|
1226
1304
|
if (target) {
|
|
@@ -1230,22 +1308,20 @@ async function verifyFilesDirFromCli(args, root, target) {
|
|
|
1230
1308
|
throw usageError("--revision applies to a published artifact.");
|
|
1231
1309
|
}
|
|
1232
1310
|
const type = parseVerifyType(parseFlagValue(args, "--type"));
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
console.error(composed.error);
|
|
1239
|
-
throw new CliError("", exitCodes.verifyFailed);
|
|
1311
|
+
const files = await readFilesDir(root);
|
|
1312
|
+
if (!type && files["index.html"] === void 0) {
|
|
1313
|
+
throw usageError(
|
|
1314
|
+
`${root} has no index.html: an html artifact is that one file. For a deck, add --type slides.`
|
|
1315
|
+
);
|
|
1240
1316
|
}
|
|
1241
|
-
await runVerify(args,
|
|
1317
|
+
await runVerify(args, files, root, type);
|
|
1242
1318
|
}
|
|
1243
|
-
async function runVerify(args,
|
|
1319
|
+
async function runVerify(args, files, label, type, loadAsset) {
|
|
1244
1320
|
const json = hasFlag(args, "--json");
|
|
1245
1321
|
const title = `Verified ${label}${type ? ` (type ${type})` : ""}`;
|
|
1246
1322
|
let report;
|
|
1247
1323
|
try {
|
|
1248
|
-
report = await
|
|
1324
|
+
report = await verifyFiles(files, { type, loadAsset });
|
|
1249
1325
|
} catch (error) {
|
|
1250
1326
|
if (error instanceof VerifyUnavailableError) {
|
|
1251
1327
|
if (error.partial && !json) {
|
|
@@ -1319,7 +1395,7 @@ async function listArtifactsFromCli(args) {
|
|
|
1319
1395
|
);
|
|
1320
1396
|
}
|
|
1321
1397
|
}
|
|
1322
|
-
async function getArtifactFeedbackFromCli(args) {
|
|
1398
|
+
async function getArtifactFeedbackFromCli(args, agent = false) {
|
|
1323
1399
|
const [artifactRef] = getPositionals(args);
|
|
1324
1400
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1325
1401
|
if (!artifactId) {
|
|
@@ -1334,15 +1410,19 @@ async function getArtifactFeedbackFromCli(args) {
|
|
|
1334
1410
|
query: { revisionId: parseFlagValue(args, "--revision") }
|
|
1335
1411
|
}
|
|
1336
1412
|
);
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1413
|
+
const actions = feedbackActions(
|
|
1414
|
+
artifactId,
|
|
1415
|
+
result.cursor,
|
|
1416
|
+
result.bundle.openAnnotations.length,
|
|
1417
|
+
args
|
|
1418
|
+
);
|
|
1419
|
+
if (renderResult(result, actions, args, agent)) return;
|
|
1341
1420
|
console.log(result.prompt);
|
|
1342
1421
|
console.log(
|
|
1343
1422
|
`
|
|
1344
1423
|
Feedback cursor: ${result.cursor} (artis watch ${artifactId} --since ${result.cursor})`
|
|
1345
1424
|
);
|
|
1425
|
+
if (agent) renderNextActions(actions);
|
|
1346
1426
|
}
|
|
1347
1427
|
async function shareArtifactFromCli(args) {
|
|
1348
1428
|
const [artifactRef] = getPositionals(args);
|
|
@@ -1416,6 +1496,60 @@ async function setArtifactVisibilityFromCli(args) {
|
|
|
1416
1496
|
}
|
|
1417
1497
|
console.log(`Visibility: ${result.artifact.metadata.visibility}`);
|
|
1418
1498
|
}
|
|
1499
|
+
function printPolicy(artifact) {
|
|
1500
|
+
console.log(`Declared: ${JSON.stringify(artifact.declaredCapabilities)}`);
|
|
1501
|
+
console.log(`Served: ${JSON.stringify(artifact.capabilities)}`);
|
|
1502
|
+
console.log(`Page epoch: ${artifact.pageEpoch}`);
|
|
1503
|
+
}
|
|
1504
|
+
async function capabilitiesFromCli(args) {
|
|
1505
|
+
const [subcommand, ...rest] = args;
|
|
1506
|
+
const [artifactRef, value] = getPositionals(rest);
|
|
1507
|
+
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1508
|
+
const usage = "Usage: artis capabilities show <artifact> | artis capabilities set <artifact> <json|file> [--reload-pages]";
|
|
1509
|
+
if (subcommand === "show" && artifactId) {
|
|
1510
|
+
const credentials = await resolveCredentials(rest);
|
|
1511
|
+
const { artifact } = await apiCall(
|
|
1512
|
+
credentials,
|
|
1513
|
+
"GET /api/artifacts/{artifactId}",
|
|
1514
|
+
{ params: { artifactId } }
|
|
1515
|
+
);
|
|
1516
|
+
if (hasFlag(rest, "--json")) {
|
|
1517
|
+
const { capabilities, declaredCapabilities, pageEpoch } = artifact;
|
|
1518
|
+
console.log(
|
|
1519
|
+
JSON.stringify(
|
|
1520
|
+
{ capabilities, declaredCapabilities, pageEpoch },
|
|
1521
|
+
null,
|
|
1522
|
+
2
|
|
1523
|
+
)
|
|
1524
|
+
);
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
printPolicy(artifact);
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
if (subcommand === "set" && artifactId && value !== void 0) {
|
|
1531
|
+
const capabilities = await parseCapabilitiesFlag(value, "capabilities");
|
|
1532
|
+
const credentials = await resolveCredentials(rest);
|
|
1533
|
+
const { artifact } = await apiCall(
|
|
1534
|
+
credentials,
|
|
1535
|
+
"PUT /api/artifacts/{artifactId}/capabilities",
|
|
1536
|
+
{
|
|
1537
|
+
params: { artifactId },
|
|
1538
|
+
body: {
|
|
1539
|
+
capabilities: capabilities ?? {},
|
|
1540
|
+
reloadPages: hasFlag(rest, "--reload-pages") || void 0
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
);
|
|
1544
|
+
if (hasFlag(rest, "--json")) {
|
|
1545
|
+
console.log(JSON.stringify({ artifact }, null, 2));
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
printPolicy(artifact);
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
throw usageError(usage);
|
|
1552
|
+
}
|
|
1419
1553
|
async function deleteArtifactFromCli(args) {
|
|
1420
1554
|
const [artifactRef] = getPositionals(args);
|
|
1421
1555
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
@@ -1433,8 +1567,9 @@ async function deleteArtifactFromCli(args) {
|
|
|
1433
1567
|
});
|
|
1434
1568
|
console.log(`Deleted ${artifactId}`);
|
|
1435
1569
|
}
|
|
1436
|
-
async function reviseArtifactFromCli(args) {
|
|
1570
|
+
async function reviseArtifactFromCli(args, agent = false) {
|
|
1437
1571
|
rejectRemovedResolveFlag(args);
|
|
1572
|
+
rejectRemovedContractFlag(args);
|
|
1438
1573
|
const [artifactRef, filePath] = getPositionals(args);
|
|
1439
1574
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1440
1575
|
const summary = parseFlagValue(args, "--summary");
|
|
@@ -1450,7 +1585,6 @@ async function reviseArtifactFromCli(args) {
|
|
|
1450
1585
|
const capabilities = await parseCapabilitiesFlag(
|
|
1451
1586
|
parseFlagValue(args, "--capabilities")
|
|
1452
1587
|
);
|
|
1453
|
-
const contract = parseContractFlag(parseFlagValue(args, "--contract"));
|
|
1454
1588
|
const type = parseTypeFlag(parseFlagValue(args, "--type"));
|
|
1455
1589
|
const credentials = await resolveCredentials(args);
|
|
1456
1590
|
const explicitBase = parseFlagValue(args, "--base");
|
|
@@ -1461,7 +1595,7 @@ async function reviseArtifactFromCli(args) {
|
|
|
1461
1595
|
source: "cli",
|
|
1462
1596
|
summary,
|
|
1463
1597
|
capabilities,
|
|
1464
|
-
|
|
1598
|
+
reloadPages: hasFlag(args, "--reload-pages") || void 0,
|
|
1465
1599
|
type
|
|
1466
1600
|
};
|
|
1467
1601
|
let result;
|
|
@@ -1474,14 +1608,24 @@ async function reviseArtifactFromCli(args) {
|
|
|
1474
1608
|
);
|
|
1475
1609
|
const files = changedFiles(local, remote.files);
|
|
1476
1610
|
if (Object.keys(files).length === 0) {
|
|
1611
|
+
if (agent && hasFlag(args, "--json") && hasFlag(args, "--next")) {
|
|
1612
|
+
renderResult(
|
|
1613
|
+
{ revisionId: remote.revisionId, unchanged: true },
|
|
1614
|
+
publishedActions(artifactId, args),
|
|
1615
|
+
args,
|
|
1616
|
+
agent
|
|
1617
|
+
);
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1477
1620
|
console.log(
|
|
1478
1621
|
`No files differ from revision ${remote.revisionId}; nothing to revise.`
|
|
1479
1622
|
);
|
|
1480
1623
|
return;
|
|
1481
1624
|
}
|
|
1482
|
-
result = await
|
|
1625
|
+
result = await apiCallRoot(
|
|
1626
|
+
{ dir: root, untyped: false, artifact: artifactRef },
|
|
1483
1627
|
credentials,
|
|
1484
|
-
"POST /api/artifacts/{artifactId}/revisions
|
|
1628
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1485
1629
|
{ params: { artifactId }, query, body: { files } }
|
|
1486
1630
|
);
|
|
1487
1631
|
if (!hasFlag(args, "--json")) {
|
|
@@ -1494,11 +1638,14 @@ async function reviseArtifactFromCli(args) {
|
|
|
1494
1638
|
}
|
|
1495
1639
|
} else {
|
|
1496
1640
|
const html = await readHtmlUpload(filePath ?? "", "Revision file");
|
|
1497
|
-
|
|
1498
|
-
credentials
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1641
|
+
try {
|
|
1642
|
+
result = await apiClient(credentials).call(
|
|
1643
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1644
|
+
{ params: { artifactId }, query, body: html }
|
|
1645
|
+
);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
throw cliErrorOf(error, { artifact: artifactRef });
|
|
1648
|
+
}
|
|
1502
1649
|
}
|
|
1503
1650
|
await rememberBase(
|
|
1504
1651
|
credentials.baseUrl,
|
|
@@ -1506,10 +1653,8 @@ async function reviseArtifactFromCli(args) {
|
|
|
1506
1653
|
result.revision.id,
|
|
1507
1654
|
baseRevisionId
|
|
1508
1655
|
);
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
return;
|
|
1512
|
-
}
|
|
1656
|
+
const actions = publishedActions(artifactId, args);
|
|
1657
|
+
if (renderResult({ revision: result.revision }, actions, args, agent)) return;
|
|
1513
1658
|
console.log(`Revision ${result.revision.id}`);
|
|
1514
1659
|
console.log(`Version ${result.revision.version}`);
|
|
1515
1660
|
const revisionType = describeType(result.revision);
|
|
@@ -1520,9 +1665,10 @@ async function reviseArtifactFromCli(args) {
|
|
|
1520
1665
|
console.log(`Base ${baseRevisionId} (remembered from this machine)`);
|
|
1521
1666
|
} else if (!baseRevisionId) {
|
|
1522
1667
|
console.log(
|
|
1523
|
-
"No base revision: pass --base, or read the artifact with publish or artifact
|
|
1668
|
+
"No base revision: pass --base, or read the artifact with publish or artifact files first, so a concurrent revision is refused instead of overwritten."
|
|
1524
1669
|
);
|
|
1525
1670
|
}
|
|
1671
|
+
if (agent) renderNextActions(actions);
|
|
1526
1672
|
}
|
|
1527
1673
|
async function createAnnotationFromCli(args) {
|
|
1528
1674
|
const [artifactRef] = getPositionals(args);
|
|
@@ -1545,7 +1691,6 @@ async function createAnnotationFromCli(args) {
|
|
|
1545
1691
|
comment,
|
|
1546
1692
|
pinLabel: parseFlagValue(args, "--pin-label"),
|
|
1547
1693
|
requestedChange: parseFlagValue(args, "--requested-change"),
|
|
1548
|
-
role: "agent",
|
|
1549
1694
|
selectors: selectors.length ? selectors : void 0,
|
|
1550
1695
|
status: parseAnnotationStatus(
|
|
1551
1696
|
parseFlagValue(args, "--status") ?? "open"
|
|
@@ -1571,8 +1716,7 @@ async function replyFromCli(args) {
|
|
|
1571
1716
|
params: { annotationId },
|
|
1572
1717
|
body: {
|
|
1573
1718
|
authorName: parseFlagValue(args, "--author") ?? "Artis CLI",
|
|
1574
|
-
comment
|
|
1575
|
-
role: "agent"
|
|
1719
|
+
comment
|
|
1576
1720
|
}
|
|
1577
1721
|
}
|
|
1578
1722
|
);
|
|
@@ -1624,12 +1768,23 @@ function parseDuration(value) {
|
|
|
1624
1768
|
const unitMs = { ms: 1, s: 1e3, m: 6e4, h: 36e5 }[match[2] ?? "s"];
|
|
1625
1769
|
return Number(match[1]) * unitMs;
|
|
1626
1770
|
}
|
|
1771
|
+
var watchSelfScopes = ["origin", "client", "none"];
|
|
1772
|
+
function parseSelfFlag(args) {
|
|
1773
|
+
const value = parseFlagValue(args, "--self");
|
|
1774
|
+
if (value === void 0) {
|
|
1775
|
+
return hasFlag(args, "--include-self") ? "none" : void 0;
|
|
1776
|
+
}
|
|
1777
|
+
if (!watchSelfScopes.includes(value)) {
|
|
1778
|
+
throw usageError(`Invalid --self "${value}". Use origin, client or none.`);
|
|
1779
|
+
}
|
|
1780
|
+
return value;
|
|
1781
|
+
}
|
|
1627
1782
|
async function watchArtifactFromCli(args) {
|
|
1628
1783
|
const [artifactRef] = getPositionals(args);
|
|
1629
1784
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1630
1785
|
if (!artifactId) {
|
|
1631
1786
|
throw usageError(
|
|
1632
|
-
"Usage: artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--
|
|
1787
|
+
"Usage: artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--self origin|client|none] [--types <families>]"
|
|
1633
1788
|
);
|
|
1634
1789
|
}
|
|
1635
1790
|
const typesFlag = parseFlagValue(args, "--types");
|
|
@@ -1643,9 +1798,10 @@ async function watchArtifactFromCli(args) {
|
|
|
1643
1798
|
const timeoutFlag = parseFlagValue(args, "--timeout");
|
|
1644
1799
|
const deadline = timeoutFlag !== void 0 ? Date.now() + parseDuration(timeoutFlag) : void 0;
|
|
1645
1800
|
const once = hasFlag(args, "--once");
|
|
1646
|
-
const
|
|
1647
|
-
|
|
1648
|
-
|
|
1801
|
+
const self = parseSelfFlag(args);
|
|
1802
|
+
let credentials = await resolveCredentials(args);
|
|
1803
|
+
let api = apiClient(credentials);
|
|
1804
|
+
let reauthorized = false;
|
|
1649
1805
|
let backoffMs = watchInitialBackoffMs;
|
|
1650
1806
|
let delivered = false;
|
|
1651
1807
|
const timedOut = () => new CliError(
|
|
@@ -1679,7 +1835,7 @@ async function watchArtifactFromCli(args) {
|
|
|
1679
1835
|
query: {
|
|
1680
1836
|
wait: Math.min(watchMaxWaitSeconds, Math.floor(remainingMs / 1e3)),
|
|
1681
1837
|
since: cursor,
|
|
1682
|
-
|
|
1838
|
+
self,
|
|
1683
1839
|
types
|
|
1684
1840
|
}
|
|
1685
1841
|
});
|
|
@@ -1690,6 +1846,15 @@ async function watchArtifactFromCli(args) {
|
|
|
1690
1846
|
}
|
|
1691
1847
|
return;
|
|
1692
1848
|
}
|
|
1849
|
+
if (error.status === 401 && !reauthorized) {
|
|
1850
|
+
reauthorized = true;
|
|
1851
|
+
const next = await resolveCredentials(args).catch(() => void 0);
|
|
1852
|
+
if (next && next.accessToken !== credentials.accessToken) {
|
|
1853
|
+
credentials = next;
|
|
1854
|
+
api = apiClient(credentials);
|
|
1855
|
+
continue;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1693
1858
|
if ((error.status === 429 || error.status >= 500) && !once) {
|
|
1694
1859
|
if (await backOff()) {
|
|
1695
1860
|
continue;
|
|
@@ -1702,6 +1867,7 @@ async function watchArtifactFromCli(args) {
|
|
|
1702
1867
|
);
|
|
1703
1868
|
}
|
|
1704
1869
|
backoffMs = watchInitialBackoffMs;
|
|
1870
|
+
reauthorized = false;
|
|
1705
1871
|
const { events } = page;
|
|
1706
1872
|
cursor = page.cursor;
|
|
1707
1873
|
if (events.length === 0) {
|
|
@@ -1836,6 +2002,120 @@ async function readJsonObjectFlag(args, flag) {
|
|
|
1836
2002
|
function printJson(value) {
|
|
1837
2003
|
console.log(JSON.stringify(value, null, 2));
|
|
1838
2004
|
}
|
|
2005
|
+
var assetUsage = `Usage:
|
|
2006
|
+
artis asset upload <artifact> <file> [--name <name>] [--content-type <type>]
|
|
2007
|
+
artis asset list <artifact>
|
|
2008
|
+
artis asset get <artifact> <asset-id> [--output <path>]
|
|
2009
|
+
artis asset rm <artifact> <asset-id>`;
|
|
2010
|
+
var textAssetTypes = {
|
|
2011
|
+
".json": "application/json",
|
|
2012
|
+
".csv": "text/csv",
|
|
2013
|
+
".txt": "text/plain",
|
|
2014
|
+
".svg": "image/svg+xml"
|
|
2015
|
+
};
|
|
2016
|
+
async function fetchAssetContent(credentials, artifactId, assetId) {
|
|
2017
|
+
const response = await fetch(
|
|
2018
|
+
`${credentials.baseUrl.replace(/\/+$/, "")}/api/artifacts/${encodeURIComponent(artifactId)}/assets/${encodeURIComponent(assetId)}/content`,
|
|
2019
|
+
{
|
|
2020
|
+
headers: credentials.accessToken ? {
|
|
2021
|
+
authorization: `Bearer ${credentials.accessToken}`,
|
|
2022
|
+
...credentials.origin ? { "artis-origin": credentials.origin } : {}
|
|
2023
|
+
} : {}
|
|
2024
|
+
}
|
|
2025
|
+
);
|
|
2026
|
+
if (!response.ok) {
|
|
2027
|
+
let body = {};
|
|
2028
|
+
try {
|
|
2029
|
+
body = await response.json();
|
|
2030
|
+
} catch {
|
|
2031
|
+
}
|
|
2032
|
+
throw cliErrorOf(
|
|
2033
|
+
new ApiError(
|
|
2034
|
+
response.status,
|
|
2035
|
+
typeof body["code"] === "string" ? body["code"] : "http_error",
|
|
2036
|
+
typeof body["error"] === "string" ? body["error"] : `Request failed with ${response.status}.`,
|
|
2037
|
+
body,
|
|
2038
|
+
response.headers
|
|
2039
|
+
)
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
return {
|
|
2043
|
+
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
2044
|
+
contentType: response.headers.get("artis-asset-content-type") ?? "application/octet-stream"
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
async function assetFromCli(args) {
|
|
2048
|
+
const [action, artifactRef, target, extra] = getPositionals(args);
|
|
2049
|
+
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
2050
|
+
if (!artifactId || extra !== void 0 || !["upload", "list", "get", "rm"].includes(action ?? "") || (action === "list" ? target !== void 0 : target === void 0)) {
|
|
2051
|
+
throw usageError(assetUsage);
|
|
2052
|
+
}
|
|
2053
|
+
const credentials = await resolveCredentials(args);
|
|
2054
|
+
switch (action) {
|
|
2055
|
+
case "upload": {
|
|
2056
|
+
const filePath = target;
|
|
2057
|
+
let bytes;
|
|
2058
|
+
try {
|
|
2059
|
+
bytes = await readFile(filePath);
|
|
2060
|
+
} catch {
|
|
2061
|
+
throw usageError(`Could not read "${filePath}".`);
|
|
2062
|
+
}
|
|
2063
|
+
const contentType = parseFlagValue(args, "--content-type") ?? textAssetTypes[extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
2064
|
+
printJson(
|
|
2065
|
+
await apiCall(credentials, "POST /api/artifacts/{artifactId}/assets", {
|
|
2066
|
+
params: { artifactId },
|
|
2067
|
+
query: { name: parseFlagValue(args, "--name") ?? basename(filePath) },
|
|
2068
|
+
body: new Uint8Array(
|
|
2069
|
+
bytes.buffer,
|
|
2070
|
+
bytes.byteOffset,
|
|
2071
|
+
bytes.byteLength
|
|
2072
|
+
),
|
|
2073
|
+
headers: { "content-type": contentType }
|
|
2074
|
+
})
|
|
2075
|
+
);
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
case "list": {
|
|
2079
|
+
printJson(
|
|
2080
|
+
await apiCall(credentials, "GET /api/artifacts/{artifactId}/assets", {
|
|
2081
|
+
params: { artifactId }
|
|
2082
|
+
})
|
|
2083
|
+
);
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
case "get": {
|
|
2087
|
+
const assetId = target;
|
|
2088
|
+
const output = parseFlagValue(args, "--output");
|
|
2089
|
+
if (!output) {
|
|
2090
|
+
printJson(
|
|
2091
|
+
await apiCall(
|
|
2092
|
+
credentials,
|
|
2093
|
+
"GET /api/artifacts/{artifactId}/assets/{assetId}",
|
|
2094
|
+
{ params: { artifactId, assetId } }
|
|
2095
|
+
)
|
|
2096
|
+
);
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
const { bytes: data } = await fetchAssetContent(
|
|
2100
|
+
credentials,
|
|
2101
|
+
artifactId,
|
|
2102
|
+
assetId
|
|
2103
|
+
);
|
|
2104
|
+
await writeFile(output, data);
|
|
2105
|
+
console.error(`Wrote ${data.byteLength} bytes to ${output}.`);
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
case "rm": {
|
|
2109
|
+
await apiCall(
|
|
2110
|
+
credentials,
|
|
2111
|
+
"DELETE /api/artifacts/{artifactId}/assets/{assetId}",
|
|
2112
|
+
{ params: { artifactId, assetId: target } }
|
|
2113
|
+
);
|
|
2114
|
+
console.error(`Deleted asset ${target}.`);
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
1839
2119
|
async function dataFromCli(args) {
|
|
1840
2120
|
const command = parseDataCommand(args);
|
|
1841
2121
|
const credentials = await resolveCredentials(args);
|
|
@@ -1983,12 +2263,16 @@ async function dataFromCli(args) {
|
|
|
1983
2263
|
}
|
|
1984
2264
|
}
|
|
1985
2265
|
async function runArtisCli(args = process.argv.slice(2)) {
|
|
2266
|
+
const { runAgentCli } = await import("./app.js");
|
|
2267
|
+
await runAgentCli(args);
|
|
2268
|
+
}
|
|
2269
|
+
async function executeArtisCommand(args, agent = false) {
|
|
1986
2270
|
const [command, ...rest] = args;
|
|
1987
2271
|
if (command === "version" || command === "--version" || command === "-v") {
|
|
1988
2272
|
console.log(`artis ${artisCliVersion}`);
|
|
1989
2273
|
return;
|
|
1990
2274
|
}
|
|
1991
|
-
if (!command || command === "help" || hasFlag(args, "--help")) {
|
|
2275
|
+
if (!agent && (!command || command === "help" || hasFlag(args, "--help"))) {
|
|
1992
2276
|
console.log(getCliHelp());
|
|
1993
2277
|
return;
|
|
1994
2278
|
}
|
|
@@ -2014,10 +2298,8 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2014
2298
|
}
|
|
2015
2299
|
if (command === "publish") {
|
|
2016
2300
|
const published = await publishArtifactFromCli(rest);
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
return;
|
|
2020
|
-
}
|
|
2301
|
+
const actions = publishedActions(published.artifactId, rest);
|
|
2302
|
+
if (renderResult(published, actions, rest, agent)) return;
|
|
2021
2303
|
console.log(`Published "${published.title}"`);
|
|
2022
2304
|
console.log(`Artifact: ${published.artifactId}`);
|
|
2023
2305
|
console.log(`Revision: ${published.revisionId}`);
|
|
@@ -2027,6 +2309,7 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2027
2309
|
console.log(`Type: ${publishedType}`);
|
|
2028
2310
|
}
|
|
2029
2311
|
console.log(published.url);
|
|
2312
|
+
if (agent) renderNextActions(actions);
|
|
2030
2313
|
return;
|
|
2031
2314
|
}
|
|
2032
2315
|
if (command === "artifact" && rest[0] === "get") {
|
|
@@ -2034,8 +2317,9 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2034
2317
|
return;
|
|
2035
2318
|
}
|
|
2036
2319
|
if (command === "artifact" && rest[0] === "html") {
|
|
2037
|
-
|
|
2038
|
-
|
|
2320
|
+
throw usageError(
|
|
2321
|
+
"artifact html was removed: every artifact is a set of files, and an html artifact is one, index.html. Use artis artifact files <artifact> index.html (or --output <dir>)."
|
|
2322
|
+
);
|
|
2039
2323
|
}
|
|
2040
2324
|
if (command === "artifact" && rest[0] === "files") {
|
|
2041
2325
|
await getArtifactFilesFromCli(rest.slice(1));
|
|
@@ -2058,15 +2342,19 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2058
2342
|
return;
|
|
2059
2343
|
}
|
|
2060
2344
|
if (command === "artifact" && rest[0] === "feedback") {
|
|
2061
|
-
await getArtifactFeedbackFromCli(rest.slice(1));
|
|
2345
|
+
await getArtifactFeedbackFromCli(rest.slice(1), agent);
|
|
2062
2346
|
return;
|
|
2063
2347
|
}
|
|
2064
2348
|
if (command === "share") {
|
|
2065
2349
|
await shareArtifactFromCli(rest);
|
|
2066
2350
|
return;
|
|
2067
2351
|
}
|
|
2352
|
+
if (command === "capabilities") {
|
|
2353
|
+
await capabilitiesFromCli(rest);
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2068
2356
|
if (command === "revise") {
|
|
2069
|
-
await reviseArtifactFromCli(rest);
|
|
2357
|
+
await reviseArtifactFromCli(rest, agent);
|
|
2070
2358
|
return;
|
|
2071
2359
|
}
|
|
2072
2360
|
if (command === "annotate") {
|
|
@@ -2093,6 +2381,10 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2093
2381
|
await dataFromCli(rest);
|
|
2094
2382
|
return;
|
|
2095
2383
|
}
|
|
2384
|
+
if (command === "asset") {
|
|
2385
|
+
await assetFromCli(rest);
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2096
2388
|
throw usageError(`Unknown command "${args.join(" ")}". Run artis help.`);
|
|
2097
2389
|
}
|
|
2098
2390
|
|
|
@@ -2107,12 +2399,12 @@ export {
|
|
|
2107
2399
|
whoamiFromCli,
|
|
2108
2400
|
getArtifactFromCli,
|
|
2109
2401
|
getArtifactFilesFromCli,
|
|
2110
|
-
getArtifactHtmlFromCli,
|
|
2111
2402
|
verifyFromCli,
|
|
2112
2403
|
listArtifactsFromCli,
|
|
2113
2404
|
getArtifactFeedbackFromCli,
|
|
2114
2405
|
shareArtifactFromCli,
|
|
2115
2406
|
setArtifactVisibilityFromCli,
|
|
2407
|
+
capabilitiesFromCli,
|
|
2116
2408
|
deleteArtifactFromCli,
|
|
2117
2409
|
reviseArtifactFromCli,
|
|
2118
2410
|
createAnnotationFromCli,
|
|
@@ -2121,6 +2413,8 @@ export {
|
|
|
2121
2413
|
retractAnnotationFromCli,
|
|
2122
2414
|
watchArtifactFromCli,
|
|
2123
2415
|
parseDataCommand,
|
|
2416
|
+
assetFromCli,
|
|
2124
2417
|
dataFromCli,
|
|
2125
|
-
runArtisCli
|
|
2418
|
+
runArtisCli,
|
|
2419
|
+
executeArtisCommand
|
|
2126
2420
|
};
|