@artis-lab/cli 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/package.json +52 -0
- package/src/bin.d.ts +2 -0
- package/src/bin.js +10 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -0
- package/src/lib/args.d.ts +2 -0
- package/src/lib/args.js +11 -0
- package/src/lib/cli.d.ts +43 -0
- package/src/lib/cli.js +806 -0
- package/src/lib/config.d.ts +13 -0
- package/src/lib/config.js +51 -0
- package/src/lib/version.d.ts +7 -0
- package/src/lib/version.js +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xiispace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @artis-lab/cli
|
|
2
|
+
|
|
3
|
+
Agent-first CLI for publishing, reviewing, and revising self-contained HTML
|
|
4
|
+
artifacts on an [Artis](https://github.com/xiispace/artis) server.
|
|
5
|
+
|
|
6
|
+
Artis is self-hosted, so the CLI has no built-in default host — every server
|
|
7
|
+
command needs `--host`, `ARTIS_URL`, or a saved login.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @artis-lab/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node.js 20 or newer. Upgrade with
|
|
16
|
+
`npm install -g @artis-lab/cli@latest`.
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
Publishing requires authentication. `artis login` runs a device-code flow: it
|
|
21
|
+
opens a browser for approval and stores the resulting API key at
|
|
22
|
+
`~/.artis/config.json`.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
artis login --host https://artis.example.com
|
|
26
|
+
artis whoami
|
|
27
|
+
artis publish artifact.html --host https://artis.example.com
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Defaults:
|
|
31
|
+
|
|
32
|
+
- Host: `--host`, `ARTIS_URL`, or saved config (required — no built-in default)
|
|
33
|
+
- `visibility=unlisted`
|
|
34
|
+
- `kind=custom-html`
|
|
35
|
+
- `author=Artis CLI`
|
|
36
|
+
|
|
37
|
+
## Collaboration commands
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
artis artifact feedback artifact-slug
|
|
41
|
+
artis revise artifact-slug revised.html --summary "Addressed review feedback"
|
|
42
|
+
artis share artifact-slug --email reviewer@example.com --role commenter
|
|
43
|
+
artis annotate artifact-slug --comment "Tighten this heading" --quote "Checkout latency"
|
|
44
|
+
artis reply annotation-123 --comment "Fixed in revision 2."
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run `artis help` for the full command and flag reference.
|
|
48
|
+
|
|
49
|
+
## Development
|
|
50
|
+
|
|
51
|
+
This package lives in the Artis monorepo. Build it with `nx build cli`; the
|
|
52
|
+
output in `dist/packages/cli` is exactly what gets published.
|
|
53
|
+
|
|
54
|
+
The tracked `package.json` is the publishable manifest — `bin`, `files`,
|
|
55
|
+
`engines`, and `publishConfig` all ship as written. Bump the version only here;
|
|
56
|
+
the CLI reads it back at runtime, and the release workflow refuses to publish
|
|
57
|
+
when the git tag and this version disagree.
|
|
58
|
+
|
|
59
|
+
`@artis/sdk` is a **devDependency**: the CLI imports only types from it, and a
|
|
60
|
+
few trivial helpers are inlined rather than imported so nothing resolves the
|
|
61
|
+
workspace-only package at runtime. Keep it that way — a runtime import would
|
|
62
|
+
break every installed copy.
|
|
63
|
+
|
|
64
|
+
Both halves of that rule are enforced by `npm run test:cli`, not by convention:
|
|
65
|
+
it imports from `dist/`, so a runtime import fails immediately, and it asserts
|
|
66
|
+
that no emitted `.d.ts` mentions `@artis/sdk`. The second check matters because
|
|
67
|
+
declaration emit leaks the specifier as soon as an sdk-typed symbol reaches an
|
|
68
|
+
_exported_ declaration — which is why `CliArtifactVisibility` is re-declared
|
|
69
|
+
locally and `publishArtifactFromCli` has an explicit return type.
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@artis-lab/cli",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Agent-first CLI for publishing, reviewing, and revising self-contained HTML artifacts on an Artis server.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"artis": "./src/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src/**/*.js",
|
|
13
|
+
"src/**/*.d.ts",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublishOnly": "node -e \"require('node:fs').existsSync('src/index.js') || (console.error('Publish the build output: npm run publish:cli'), process.exit(1))\""
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/xiispace/artis.git",
|
|
29
|
+
"directory": "packages/cli"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/xiispace/artis/tree/main/packages/cli#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/xiispace/artis/issues"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"author": "xiispace",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"artis",
|
|
39
|
+
"cli",
|
|
40
|
+
"agents",
|
|
41
|
+
"html",
|
|
42
|
+
"artifacts",
|
|
43
|
+
"review"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"tslib": "^2.3.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@artis/sdk": "0.0.1"
|
|
50
|
+
},
|
|
51
|
+
"module": "./src/index.js"
|
|
52
|
+
}
|
package/src/bin.d.ts
ADDED
package/src/bin.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The published `artis` bin. It runs unconditionally: npm installs a bin as a
|
|
3
|
+
// symlink, so `import.meta.url` (realpath) never equals `process.argv[1]` (the
|
|
4
|
+
// symlink) and any main-module guard here would silently do nothing.
|
|
5
|
+
import { runArtisCli } from './lib/cli.js';
|
|
6
|
+
runArtisCli().catch((error) => {
|
|
7
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=bin.js.map
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/cli.js';
|
package/src/index.js
ADDED
package/src/lib/args.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseFlagValue(args, name) {
|
|
2
|
+
const index = args.indexOf(name);
|
|
3
|
+
if (index === -1) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return args[index + 1];
|
|
7
|
+
}
|
|
8
|
+
export function hasFlag(args, name) {
|
|
9
|
+
return args.includes(name);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=args.js.map
|
package/src/lib/cli.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { artisCliVersion } from './version.js';
|
|
2
|
+
export { artisCliVersion };
|
|
3
|
+
export declare const commands: readonly ["annotate", "annotation", "artifact", "help", "login", "publish", "reply", "revise", "share", "version", "whoami"];
|
|
4
|
+
export type ArtisCommand = (typeof commands)[number];
|
|
5
|
+
/**
|
|
6
|
+
* Mirrors the sdk's `ArtifactVisibility`, deliberately re-declared instead of
|
|
7
|
+
* imported: this union reaches the published `.d.ts`, and `@artis/sdk` is a
|
|
8
|
+
* workspace-only package that consumers of `@artis-lab/cli` cannot resolve.
|
|
9
|
+
* `packages/sdk/src/lib/sdk.ts` stays the source of truth for these values.
|
|
10
|
+
*
|
|
11
|
+
* Importing sdk types is fine wherever they stay out of exported declarations;
|
|
12
|
+
* `scripts/cli-unit.mjs` fails the build if any of them reach the emitted
|
|
13
|
+
* `.d.ts`, so that boundary is enforced rather than remembered.
|
|
14
|
+
*/
|
|
15
|
+
declare const cliVisibilityOptions: readonly ["public", "unlisted", "private"];
|
|
16
|
+
export type CliArtifactVisibility = (typeof cliVisibilityOptions)[number];
|
|
17
|
+
export interface PublishedArtifactResult {
|
|
18
|
+
artifactId: string;
|
|
19
|
+
revisionId: string;
|
|
20
|
+
title: string;
|
|
21
|
+
url: string;
|
|
22
|
+
visibility: CliArtifactVisibility;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate a login `verificationUrl` returned by the configured host before it
|
|
26
|
+
* crosses a local process/shell boundary (Windows `cmd /c start`). A malicious
|
|
27
|
+
* or compromised host could otherwise return a crafted URL that reaches the
|
|
28
|
+
* shell. Requires an http(s) scheme and an origin matching `baseUrl`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertSafeLoginUrl(url: string, baseUrl: string): void;
|
|
31
|
+
export declare function getCliHelp(): string;
|
|
32
|
+
export declare function publishArtifactFromCli(args: string[]): Promise<PublishedArtifactResult>;
|
|
33
|
+
export declare function loginFromCli(args: string[]): Promise<void>;
|
|
34
|
+
export declare function whoamiFromCli(args: string[]): Promise<void>;
|
|
35
|
+
export declare function getArtifactFromCli(args: string[]): Promise<void>;
|
|
36
|
+
export declare function getArtifactFeedbackFromCli(args: string[]): Promise<void>;
|
|
37
|
+
export declare function shareArtifactFromCli(args: string[]): Promise<void>;
|
|
38
|
+
export declare function reviseArtifactFromCli(args: string[]): Promise<void>;
|
|
39
|
+
export declare function createAnnotationFromCli(args: string[]): Promise<void>;
|
|
40
|
+
export declare function replyFromCli(args: string[]): Promise<void>;
|
|
41
|
+
export declare function editAnnotationFromCli(args: string[]): Promise<void>;
|
|
42
|
+
export declare function retractAnnotationFromCli(args: string[]): Promise<void>;
|
|
43
|
+
export declare function runArtisCli(args?: string[]): Promise<void>;
|
package/src/lib/cli.js
ADDED
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { basename, extname } from 'node:path';
|
|
5
|
+
// `@artis/sdk` is a type-only dependency here: the CLI's tsc output can't
|
|
6
|
+
// resolve the package specifier at runtime, so these two trivial helpers are
|
|
7
|
+
// inlined rather than imported (they mirror the sdk's implementations).
|
|
8
|
+
function annotationIdFromIri(iri) {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = iri.replace(/\/+$/, '').split('/').pop()) !== null && _a !== void 0 ? _a : iri;
|
|
11
|
+
}
|
|
12
|
+
function isRootAnnotation(annotation) {
|
|
13
|
+
return annotation.motivation === 'commenting';
|
|
14
|
+
}
|
|
15
|
+
import { findProfileForHost, getConfigPath, normalizeHost, readCliConfig, saveDefaultProfile, } from './config.js';
|
|
16
|
+
import { artisCliVersion } from './version.js';
|
|
17
|
+
import { hasFlag, parseFlagValue } from './args.js';
|
|
18
|
+
export { artisCliVersion };
|
|
19
|
+
export const commands = [
|
|
20
|
+
'annotate',
|
|
21
|
+
'annotation',
|
|
22
|
+
'artifact',
|
|
23
|
+
'help',
|
|
24
|
+
'login',
|
|
25
|
+
'publish',
|
|
26
|
+
'reply',
|
|
27
|
+
'revise',
|
|
28
|
+
'share',
|
|
29
|
+
'version',
|
|
30
|
+
'whoami',
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Mirrors the sdk's `ArtifactVisibility`, deliberately re-declared instead of
|
|
34
|
+
* imported: this union reaches the published `.d.ts`, and `@artis/sdk` is a
|
|
35
|
+
* workspace-only package that consumers of `@artis-lab/cli` cannot resolve.
|
|
36
|
+
* `packages/sdk/src/lib/sdk.ts` stays the source of truth for these values.
|
|
37
|
+
*
|
|
38
|
+
* Importing sdk types is fine wherever they stay out of exported declarations;
|
|
39
|
+
* `scripts/cli-unit.mjs` fails the build if any of them reach the emitted
|
|
40
|
+
* `.d.ts`, so that boundary is enforced rather than remembered.
|
|
41
|
+
*/
|
|
42
|
+
const cliVisibilityOptions = ['public', 'unlisted', 'private'];
|
|
43
|
+
const cliArtifactKinds = [
|
|
44
|
+
'incident-timeline',
|
|
45
|
+
'migration-plan',
|
|
46
|
+
'generated-dashboard',
|
|
47
|
+
'architecture-explainer',
|
|
48
|
+
'animated-report',
|
|
49
|
+
'ui-prototype',
|
|
50
|
+
'pr-review',
|
|
51
|
+
'custom-html',
|
|
52
|
+
];
|
|
53
|
+
const cliAnnotationStatusOptions = [
|
|
54
|
+
'open',
|
|
55
|
+
'needs-revision',
|
|
56
|
+
'resolved',
|
|
57
|
+
];
|
|
58
|
+
const cliShareRoleOptions = ['viewer', 'commenter'];
|
|
59
|
+
const valueFlags = new Set([
|
|
60
|
+
'--api-key',
|
|
61
|
+
'--author',
|
|
62
|
+
'--comment',
|
|
63
|
+
'--css',
|
|
64
|
+
'--description',
|
|
65
|
+
'--email',
|
|
66
|
+
'--host',
|
|
67
|
+
'--kind',
|
|
68
|
+
'--output',
|
|
69
|
+
'--pin-label',
|
|
70
|
+
'--quote',
|
|
71
|
+
'--quote-prefix',
|
|
72
|
+
'--quote-suffix',
|
|
73
|
+
'--rect',
|
|
74
|
+
'--requested-change',
|
|
75
|
+
'--resolve',
|
|
76
|
+
'--revision',
|
|
77
|
+
'--role',
|
|
78
|
+
'--status',
|
|
79
|
+
'--summary',
|
|
80
|
+
'--text-end',
|
|
81
|
+
'--text-start',
|
|
82
|
+
'--title',
|
|
83
|
+
'--url',
|
|
84
|
+
'--visibility',
|
|
85
|
+
]);
|
|
86
|
+
function collectFlagValues(args, name) {
|
|
87
|
+
return args.reduce((values, arg, index) => {
|
|
88
|
+
if (arg === name && args[index + 1]) {
|
|
89
|
+
values.push(args[index + 1]);
|
|
90
|
+
}
|
|
91
|
+
return values;
|
|
92
|
+
}, []);
|
|
93
|
+
}
|
|
94
|
+
function getPositionals(args) {
|
|
95
|
+
const positionals = [];
|
|
96
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
97
|
+
const arg = args[index];
|
|
98
|
+
if (arg.startsWith('-')) {
|
|
99
|
+
if (valueFlags.has(arg)) {
|
|
100
|
+
index += 1;
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
positionals.push(arg);
|
|
105
|
+
}
|
|
106
|
+
return positionals;
|
|
107
|
+
}
|
|
108
|
+
function inferTitleFromPath(filePath) {
|
|
109
|
+
const fileName = basename(filePath);
|
|
110
|
+
const extension = extname(fileName);
|
|
111
|
+
return extension ? fileName.slice(0, -extension.length) : fileName;
|
|
112
|
+
}
|
|
113
|
+
function parseVisibility(value) {
|
|
114
|
+
if (cliVisibilityOptions.includes(value)) {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
throw new Error(`Invalid visibility "${value}". Expected one of: ${cliVisibilityOptions.join(', ')}`);
|
|
118
|
+
}
|
|
119
|
+
function parseKind(value) {
|
|
120
|
+
if (cliArtifactKinds.includes(value)) {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Invalid kind "${value}". Expected one of: ${cliArtifactKinds.join(', ')}`);
|
|
124
|
+
}
|
|
125
|
+
function parseAnnotationStatus(value) {
|
|
126
|
+
if (cliAnnotationStatusOptions.includes(value)) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`Invalid status "${value}". Expected one of: ${cliAnnotationStatusOptions.join(', ')}`);
|
|
130
|
+
}
|
|
131
|
+
function parseShareRole(value) {
|
|
132
|
+
if (cliShareRoleOptions.includes(value)) {
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Invalid role "${value}". Expected one of: ${cliShareRoleOptions.join(', ')}`);
|
|
136
|
+
}
|
|
137
|
+
/** Parse a `--rect x,y,w,h` percentage tuple into a Media Fragments
|
|
138
|
+
* `xywh=percent:` FragmentSelector. Width/height default to 0 (a point pin). */
|
|
139
|
+
function parseRectSelector(value) {
|
|
140
|
+
if (!value) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
const parts = value.split(',').map((part) => Number(part.trim()));
|
|
144
|
+
if ((parts.length !== 2 && parts.length !== 4) ||
|
|
145
|
+
parts.some((part) => !Number.isFinite(part))) {
|
|
146
|
+
throw new Error(`Invalid --rect "${value}". Expected "x,y" or "x,y,w,h" percentages.`);
|
|
147
|
+
}
|
|
148
|
+
const [x, y, width = 0, height = 0] = parts;
|
|
149
|
+
return {
|
|
150
|
+
type: 'FragmentSelector',
|
|
151
|
+
conformsTo: 'http://www.w3.org/TR/media-frags/',
|
|
152
|
+
value: `xywh=percent:${x},${y},${width},${height}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** Assemble the annotate flags into a W3C selector array. Each anchor kind is
|
|
156
|
+
* independent, so text quotes, offsets, an element selector, and a canvas
|
|
157
|
+
* point/rect can all be supplied together. */
|
|
158
|
+
function buildAnnotationSelectors(args) {
|
|
159
|
+
const selectors = [];
|
|
160
|
+
const quote = parseFlagValue(args, '--quote');
|
|
161
|
+
if (quote) {
|
|
162
|
+
const textQuote = {
|
|
163
|
+
type: 'TextQuoteSelector',
|
|
164
|
+
exact: quote,
|
|
165
|
+
};
|
|
166
|
+
const prefix = parseFlagValue(args, '--quote-prefix');
|
|
167
|
+
const suffix = parseFlagValue(args, '--quote-suffix');
|
|
168
|
+
if (prefix) {
|
|
169
|
+
textQuote.prefix = prefix;
|
|
170
|
+
}
|
|
171
|
+
if (suffix) {
|
|
172
|
+
textQuote.suffix = suffix;
|
|
173
|
+
}
|
|
174
|
+
selectors.push(textQuote);
|
|
175
|
+
}
|
|
176
|
+
const textStart = parseFlagValue(args, '--text-start');
|
|
177
|
+
const textEnd = parseFlagValue(args, '--text-end');
|
|
178
|
+
if (textStart !== undefined && textEnd !== undefined) {
|
|
179
|
+
const start = Number(textStart);
|
|
180
|
+
const end = Number(textEnd);
|
|
181
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
|
182
|
+
throw new Error('--text-start and --text-end must be numbers.');
|
|
183
|
+
}
|
|
184
|
+
selectors.push({ type: 'TextPositionSelector', start, end });
|
|
185
|
+
}
|
|
186
|
+
const css = parseFlagValue(args, '--css');
|
|
187
|
+
if (css) {
|
|
188
|
+
selectors.push({ type: 'CssSelector', value: css });
|
|
189
|
+
}
|
|
190
|
+
const rect = parseRectSelector(parseFlagValue(args, '--rect'));
|
|
191
|
+
if (rect) {
|
|
192
|
+
selectors.push(rect);
|
|
193
|
+
}
|
|
194
|
+
return selectors;
|
|
195
|
+
}
|
|
196
|
+
function resolveBaseUrl(args, config) {
|
|
197
|
+
var _a, _b, _c;
|
|
198
|
+
const host = (_c = (_b = (_a = parseFlagValue(args, '--host')) !== null && _a !== void 0 ? _a : parseFlagValue(args, '--url')) !== null && _b !== void 0 ? _b : process.env['ARTIS_URL']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config.defaultHost;
|
|
199
|
+
if (!host) {
|
|
200
|
+
throw new Error('No Artis host configured. Pass --host <url>, set ARTIS_URL, or run "artis login --host <url>" to save one.');
|
|
201
|
+
}
|
|
202
|
+
return normalizeHost(host);
|
|
203
|
+
}
|
|
204
|
+
function resolveApiKey(args, config, baseUrl) {
|
|
205
|
+
var _a;
|
|
206
|
+
const flagApiKey = parseFlagValue(args, '--api-key');
|
|
207
|
+
if (flagApiKey) {
|
|
208
|
+
return { apiKey: flagApiKey, apiKeySource: 'flag' };
|
|
209
|
+
}
|
|
210
|
+
if (process.env['ARTIS_API_KEY']) {
|
|
211
|
+
return { apiKey: process.env['ARTIS_API_KEY'], apiKeySource: 'env' };
|
|
212
|
+
}
|
|
213
|
+
const profileApiKey = (_a = findProfileForHost(config, baseUrl)) === null || _a === void 0 ? void 0 : _a.apiKey;
|
|
214
|
+
if (profileApiKey) {
|
|
215
|
+
return { apiKey: profileApiKey, apiKeySource: 'config' };
|
|
216
|
+
}
|
|
217
|
+
return {};
|
|
218
|
+
}
|
|
219
|
+
function resolveCredentials(args) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const config = yield readCliConfig();
|
|
222
|
+
const baseUrl = resolveBaseUrl(args, config);
|
|
223
|
+
const { apiKey } = resolveApiKey(args, config, baseUrl);
|
|
224
|
+
if (!apiKey) {
|
|
225
|
+
throw new Error(`Missing API key. Run "artis login --host ${baseUrl}" or set ARTIS_API_KEY.`);
|
|
226
|
+
}
|
|
227
|
+
return { apiKey, baseUrl };
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function resolveOptionalTarget(args) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const config = yield readCliConfig();
|
|
233
|
+
const baseUrl = resolveBaseUrl(args, config);
|
|
234
|
+
const { apiKey, apiKeySource } = resolveApiKey(args, config, baseUrl);
|
|
235
|
+
return { apiKey, apiKeySource, baseUrl };
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function parsePublishOptions(args) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
var _a, _b, _c, _d;
|
|
241
|
+
const [filePath] = getPositionals(args);
|
|
242
|
+
if (!filePath) {
|
|
243
|
+
throw new Error('Missing artifact HTML file path.');
|
|
244
|
+
}
|
|
245
|
+
const credentials = yield resolveCredentials(args);
|
|
246
|
+
const visibility = parseVisibility((_a = parseFlagValue(args, '--visibility')) !== null && _a !== void 0 ? _a : 'unlisted');
|
|
247
|
+
return {
|
|
248
|
+
filePath,
|
|
249
|
+
apiKey: credentials.apiKey,
|
|
250
|
+
baseUrl: credentials.baseUrl,
|
|
251
|
+
title: parseFlagValue(args, '--title'),
|
|
252
|
+
description: (_b = parseFlagValue(args, '--description')) !== null && _b !== void 0 ? _b : 'Published from Artis CLI.',
|
|
253
|
+
visibility,
|
|
254
|
+
authorName: (_c = parseFlagValue(args, '--author')) !== null && _c !== void 0 ? _c : 'Artis CLI',
|
|
255
|
+
kind: parseKind((_d = parseFlagValue(args, '--kind')) !== null && _d !== void 0 ? _d : 'custom-html'),
|
|
256
|
+
json: hasFlag(args, '--json'),
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function readJsonResponse(response) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
return response.json().catch(() => null);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function apiFetch(credentials_1, path_1) {
|
|
266
|
+
return __awaiter(this, arguments, void 0, function* (credentials, path, init = {}) {
|
|
267
|
+
var _a;
|
|
268
|
+
const response = yield fetch(`${credentials.baseUrl}${path}`, Object.assign(Object.assign({}, init), { headers: Object.assign({ authorization: `Bearer ${credentials.apiKey}`, 'content-type': 'application/json' }, init.headers) }));
|
|
269
|
+
const payload = yield readJsonResponse(response);
|
|
270
|
+
if (!response.ok) {
|
|
271
|
+
throw new Error((_a = payload === null || payload === void 0 ? void 0 : payload.error) !== null && _a !== void 0 ? _a : `Request failed with ${response.status}.`);
|
|
272
|
+
}
|
|
273
|
+
return payload;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function apiFetchOptional(target_1, path_1) {
|
|
277
|
+
return __awaiter(this, arguments, void 0, function* (target, path, init = {}) {
|
|
278
|
+
var _a;
|
|
279
|
+
const headers = Object.assign(Object.assign(Object.assign({}, (target.apiKey ? { authorization: `Bearer ${target.apiKey}` } : {})), { 'content-type': 'application/json' }), init.headers);
|
|
280
|
+
const response = yield fetch(`${target.baseUrl}${path}`, Object.assign(Object.assign({}, init), { headers }));
|
|
281
|
+
let payload = yield readJsonResponse(response);
|
|
282
|
+
let status = response.status;
|
|
283
|
+
if (!response.ok &&
|
|
284
|
+
response.status === 401 &&
|
|
285
|
+
target.apiKey &&
|
|
286
|
+
target.apiKeySource === 'config') {
|
|
287
|
+
const retryResponse = yield fetch(`${target.baseUrl}${path}`, Object.assign(Object.assign({}, init), { headers: Object.assign({ 'content-type': 'application/json' }, init.headers) }));
|
|
288
|
+
const retryPayload = yield readJsonResponse(retryResponse);
|
|
289
|
+
if (retryResponse.ok) {
|
|
290
|
+
console.warn(`Saved API key was rejected by ${target.baseUrl}; retried without credentials. Run "artis login --host ${target.baseUrl}" to refresh local credentials.`);
|
|
291
|
+
return retryPayload;
|
|
292
|
+
}
|
|
293
|
+
payload = retryPayload;
|
|
294
|
+
status = retryResponse.status;
|
|
295
|
+
}
|
|
296
|
+
if (status < 200 || status >= 300) {
|
|
297
|
+
throw new Error((_a = payload === null || payload === void 0 ? void 0 : payload.error) !== null && _a !== void 0 ? _a : `Request failed with ${status}.`);
|
|
298
|
+
}
|
|
299
|
+
return payload;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Validate a login `verificationUrl` returned by the configured host before it
|
|
304
|
+
* crosses a local process/shell boundary (Windows `cmd /c start`). A malicious
|
|
305
|
+
* or compromised host could otherwise return a crafted URL that reaches the
|
|
306
|
+
* shell. Requires an http(s) scheme and an origin matching `baseUrl`.
|
|
307
|
+
*/
|
|
308
|
+
export function assertSafeLoginUrl(url, baseUrl) {
|
|
309
|
+
let parsed;
|
|
310
|
+
try {
|
|
311
|
+
parsed = new URL(url);
|
|
312
|
+
}
|
|
313
|
+
catch (_a) {
|
|
314
|
+
throw new Error('Login host returned an invalid verification URL.');
|
|
315
|
+
}
|
|
316
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
317
|
+
throw new Error('Login host returned an unsafe verification URL scheme.');
|
|
318
|
+
}
|
|
319
|
+
let expected;
|
|
320
|
+
try {
|
|
321
|
+
expected = new URL(baseUrl);
|
|
322
|
+
}
|
|
323
|
+
catch (_b) {
|
|
324
|
+
throw new Error('Configured login host is not a valid URL.');
|
|
325
|
+
}
|
|
326
|
+
if (parsed.hostname !== expected.hostname || parsed.port !== expected.port) {
|
|
327
|
+
throw new Error('Login host returned a verification URL that does not match the configured host.');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function openBrowser(url) {
|
|
331
|
+
// The URL crosses a shell boundary on Windows (`cmd /c start`), so this
|
|
332
|
+
// guard lives here rather than at any single call site: every caller gets
|
|
333
|
+
// it, whatever the URL's provenance.
|
|
334
|
+
let protocol;
|
|
335
|
+
try {
|
|
336
|
+
protocol = new URL(url).protocol;
|
|
337
|
+
}
|
|
338
|
+
catch (_a) {
|
|
339
|
+
throw new Error('Refusing to open an invalid URL in the browser.');
|
|
340
|
+
}
|
|
341
|
+
if (protocol !== 'http:' && protocol !== 'https:') {
|
|
342
|
+
throw new Error('Refusing to open a non-http(s) URL in the browser.');
|
|
343
|
+
}
|
|
344
|
+
const command = process.platform === 'darwin'
|
|
345
|
+
? 'open'
|
|
346
|
+
: process.platform === 'win32'
|
|
347
|
+
? 'cmd'
|
|
348
|
+
: 'xdg-open';
|
|
349
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
350
|
+
const child = spawn(command, args, {
|
|
351
|
+
detached: true,
|
|
352
|
+
stdio: 'ignore',
|
|
353
|
+
});
|
|
354
|
+
child.unref();
|
|
355
|
+
}
|
|
356
|
+
function sleep(ms) {
|
|
357
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
358
|
+
}
|
|
359
|
+
function buildArtifactUrl(baseUrl, pathOrUrl) {
|
|
360
|
+
return pathOrUrl.startsWith('http') ? pathOrUrl : `${baseUrl}${pathOrUrl}`;
|
|
361
|
+
}
|
|
362
|
+
export function getCliHelp() {
|
|
363
|
+
return `artis
|
|
364
|
+
|
|
365
|
+
Host, share, and collaborate on AI-generated HTML artifacts.
|
|
366
|
+
|
|
367
|
+
Usage:
|
|
368
|
+
artis --version
|
|
369
|
+
artis login [--host <url>]
|
|
370
|
+
artis whoami [--host <url>]
|
|
371
|
+
artis publish artifact.html [options]
|
|
372
|
+
artis artifact get <artifact-id-or-slug> [--json]
|
|
373
|
+
artis artifact feedback <artifact-id-or-slug> [--json] [--revision <revision-id>]
|
|
374
|
+
artis share <artifact-id-or-slug> [--email <email> --role <viewer|commenter>] [--remove]
|
|
375
|
+
artis revise <artifact-id-or-slug> artifact.html --summary <text> [--resolve <annotation-id>]
|
|
376
|
+
artis annotate <artifact-id-or-slug> --comment <text> [anchor options]
|
|
377
|
+
artis reply <annotation-id> --comment <text>
|
|
378
|
+
artis annotation edit <annotation-id> [--comment <text>] [--title <text>] [--requested-change <text>]
|
|
379
|
+
artis annotation retract <annotation-id>
|
|
380
|
+
|
|
381
|
+
Options:
|
|
382
|
+
--api-key <key> API key. Defaults to ARTIS_API_KEY or ~/.artis/config.json. Run "artis login" to obtain one.
|
|
383
|
+
--host, --url <url> Artis server URL (required). Set via --host/--url, ARTIS_URL, or a saved login.
|
|
384
|
+
--title <title> Artifact title. Defaults to the file name.
|
|
385
|
+
--description <text> Artifact description.
|
|
386
|
+
--visibility <value> public, unlisted, or private. Defaults to unlisted.
|
|
387
|
+
--kind <value> Artifact kind. Defaults to custom-html.
|
|
388
|
+
--author <name> Artifact author/agent name. Defaults to Artis CLI.
|
|
389
|
+
--summary <text> Revision summary.
|
|
390
|
+
--resolve <annotation-id> Mark an annotation resolved when revising. Repeatable.
|
|
391
|
+
--comment <text> Annotation or reply comment text (annotate, reply).
|
|
392
|
+
--requested-change <text> Structured change request for the artifact author (annotate).
|
|
393
|
+
--status <value> Annotation status: open, needs-revision, or resolved. Defaults to open.
|
|
394
|
+
--quote <text> Exact artifact text to anchor to (annotate, TextQuoteSelector).
|
|
395
|
+
--quote-prefix <text> Text just before --quote, to disambiguate repeats.
|
|
396
|
+
--quote-suffix <text> Text just after --quote, to disambiguate repeats.
|
|
397
|
+
--css <selector> CSS selector to anchor to (annotate, CssSelector).
|
|
398
|
+
--text-start <n> Document offset where the quote starts (annotate, TextPositionSelector).
|
|
399
|
+
--text-end <n> Document offset where the quote ends (annotate, TextPositionSelector).
|
|
400
|
+
--rect <x,y,w,h> Canvas point/rect as percentages (annotate, FragmentSelector). w,h default to 0.
|
|
401
|
+
--pin-label <text> Short label shown on the artifact canvas pin (annotate).
|
|
402
|
+
--email <email> Email address for artis share.
|
|
403
|
+
--role <role> Share role: viewer or commenter. Defaults to viewer.
|
|
404
|
+
--remove Remove the email from an artifact share list.
|
|
405
|
+
--json Print machine-readable JSON for supported commands.
|
|
406
|
+
|
|
407
|
+
Examples (server commands also need --host, ARTIS_URL, or a saved login):
|
|
408
|
+
artis publish report.html --host https://artis.example.com
|
|
409
|
+
artis login --host https://artis.example.com
|
|
410
|
+
artis publish report.html --host https://artis.example.com --visibility private
|
|
411
|
+
artis share artifact-slug --host https://artis.example.com --email reviewer@example.com --role commenter
|
|
412
|
+
artis artifact get artifact-slug --host https://artis.example.com --json
|
|
413
|
+
artis artifact feedback artifact-slug --host https://artis.example.com --json
|
|
414
|
+
artis annotate artifact-slug --host https://artis.example.com --comment "Tighten this heading" --quote "Checkout latency" --requested-change "Add the affected checkout count"
|
|
415
|
+
artis reply annotation-123 --host https://artis.example.com --comment "Addressed in the latest revision"
|
|
416
|
+
artis annotation edit annotation-123 --host https://artis.example.com --comment "Corrected: the latency spike is on checkout, not search"
|
|
417
|
+
artis annotation retract annotation-123 --host https://artis.example.com
|
|
418
|
+
artis revise artifact-slug report.html --host https://artis.example.com --summary "Addressed open feedback" --resolve annotation-123`;
|
|
419
|
+
}
|
|
420
|
+
// Annotated rather than inferred: the returned `visibility` flows through the
|
|
421
|
+
// sdk's `CreateArtifactInput`, so declaration emit would otherwise print an
|
|
422
|
+
// inline `import('@artis/sdk')` here. The `.d.ts` check in
|
|
423
|
+
// `scripts/cli-unit.mjs` catches it if this annotation is ever dropped.
|
|
424
|
+
export function publishArtifactFromCli(args) {
|
|
425
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
+
var _a;
|
|
427
|
+
const options = yield parsePublishOptions(args);
|
|
428
|
+
const html = yield readFile(options.filePath, 'utf8');
|
|
429
|
+
if (!html.toLowerCase().includes('<html')) {
|
|
430
|
+
throw new Error('Artifact file must be self-contained HTML including <html>.');
|
|
431
|
+
}
|
|
432
|
+
const payload = {
|
|
433
|
+
title: (_a = options.title) !== null && _a !== void 0 ? _a : inferTitleFromPath(options.filePath),
|
|
434
|
+
description: options.description,
|
|
435
|
+
html,
|
|
436
|
+
visibility: options.visibility,
|
|
437
|
+
authorName: options.authorName,
|
|
438
|
+
source: 'cli',
|
|
439
|
+
kind: options.kind,
|
|
440
|
+
};
|
|
441
|
+
const result = yield apiFetch({ apiKey: options.apiKey, baseUrl: options.baseUrl }, '/api/artifacts', { method: 'POST', body: JSON.stringify(payload) });
|
|
442
|
+
if (!(result === null || result === void 0 ? void 0 : result.result)) {
|
|
443
|
+
throw new Error('Publish response did not include artifact details.');
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
artifactId: result.result.artifactId,
|
|
447
|
+
revisionId: result.result.revisionId,
|
|
448
|
+
title: payload.title,
|
|
449
|
+
url: buildArtifactUrl(options.baseUrl, result.result.url),
|
|
450
|
+
visibility: payload.visibility,
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
export function loginFromCli(args) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
var _a, _b, _c, _d;
|
|
457
|
+
const config = yield readCliConfig();
|
|
458
|
+
const baseUrl = resolveBaseUrl(args, config);
|
|
459
|
+
const response = yield fetch(`${baseUrl}/api/cli/auth/start`, {
|
|
460
|
+
method: 'POST',
|
|
461
|
+
});
|
|
462
|
+
const login = yield readJsonResponse(response);
|
|
463
|
+
if (!response.ok ||
|
|
464
|
+
!(login === null || login === void 0 ? void 0 : login.deviceCode) ||
|
|
465
|
+
!login.userCode ||
|
|
466
|
+
!login.verificationUrl ||
|
|
467
|
+
!login.expiresAt) {
|
|
468
|
+
throw new Error((_a = login === null || login === void 0 ? void 0 : login.error) !== null && _a !== void 0 ? _a : `Login failed with ${response.status}.`);
|
|
469
|
+
}
|
|
470
|
+
// Validate the host-controlled verification URL before opening a browser.
|
|
471
|
+
// A non-default or compromised host could otherwise return a crafted URL
|
|
472
|
+
// that reaches a local shell (Windows `cmd /c start`). An unsafe URL aborts
|
|
473
|
+
// login rather than opening anything.
|
|
474
|
+
assertSafeLoginUrl(login.verificationUrl, baseUrl);
|
|
475
|
+
console.log(`Opening ${login.verificationUrl}`);
|
|
476
|
+
console.log(`Code: ${login.userCode}`);
|
|
477
|
+
try {
|
|
478
|
+
openBrowser(login.verificationUrl);
|
|
479
|
+
}
|
|
480
|
+
catch (_e) {
|
|
481
|
+
console.log('Could not open a browser automatically.');
|
|
482
|
+
}
|
|
483
|
+
const intervalMs = ((_b = login.intervalSeconds) !== null && _b !== void 0 ? _b : 2) * 1000;
|
|
484
|
+
while (Date.now() < Date.parse(login.expiresAt)) {
|
|
485
|
+
yield sleep(intervalMs);
|
|
486
|
+
const pollResponse = yield fetch(`${baseUrl}/api/cli/auth/poll`, {
|
|
487
|
+
method: 'POST',
|
|
488
|
+
headers: { 'content-type': 'application/json' },
|
|
489
|
+
body: JSON.stringify({ deviceCode: login.deviceCode }),
|
|
490
|
+
});
|
|
491
|
+
const poll = yield readJsonResponse(pollResponse);
|
|
492
|
+
if ((poll === null || poll === void 0 ? void 0 : poll.status) === 'pending') {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if ((poll === null || poll === void 0 ? void 0 : poll.status) === 'approved' && poll.token) {
|
|
496
|
+
yield saveDefaultProfile({ apiKey: poll.token, host: baseUrl });
|
|
497
|
+
console.log(`Saved artis credentials to ${getConfigPath()}`);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
throw new Error((_c = poll === null || poll === void 0 ? void 0 : poll.error) !== null && _c !== void 0 ? _c : `Login ${(_d = poll === null || poll === void 0 ? void 0 : poll.status) !== null && _d !== void 0 ? _d : 'failed'}.`);
|
|
501
|
+
}
|
|
502
|
+
throw new Error('Login expired. Run artis login again.');
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
export function whoamiFromCli(args) {
|
|
506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
var _a;
|
|
508
|
+
const credentials = yield resolveCredentials(args);
|
|
509
|
+
const result = yield apiFetch(credentials, '/api/me');
|
|
510
|
+
if (!(result === null || result === void 0 ? void 0 : result.principal)) {
|
|
511
|
+
throw new Error('whoami response did not include a principal.');
|
|
512
|
+
}
|
|
513
|
+
console.log(`Signed in to ${credentials.baseUrl} as ${(_a = result.principal.name) !== null && _a !== void 0 ? _a : result.principal.userId}`);
|
|
514
|
+
console.log(`Principal: ${result.principal.kind}`);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
export function getArtifactFromCli(args) {
|
|
518
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
var _a;
|
|
520
|
+
const [artifactId] = getPositionals(args);
|
|
521
|
+
if (!artifactId) {
|
|
522
|
+
throw new Error('Missing artifact id or slug.');
|
|
523
|
+
}
|
|
524
|
+
const target = yield resolveOptionalTarget(args);
|
|
525
|
+
const result = yield apiFetchOptional(target, `/api/artifacts/${encodeURIComponent(artifactId)}`);
|
|
526
|
+
if (hasFlag(args, '--json')) {
|
|
527
|
+
console.log(JSON.stringify(result, null, 2));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (!(result === null || result === void 0 ? void 0 : result.artifact)) {
|
|
531
|
+
throw new Error('Artifact response did not include artifact details.');
|
|
532
|
+
}
|
|
533
|
+
console.log(`${result.artifact.metadata.title}`);
|
|
534
|
+
console.log(`Artifact: ${result.artifact.id}`);
|
|
535
|
+
console.log(`Revision: ${result.artifact.currentRevisionId}`);
|
|
536
|
+
console.log(`Open annotations: ${((_a = result.annotations) !== null && _a !== void 0 ? _a : []).filter((annotation) => isRootAnnotation(annotation) && annotation['artis:status'] !== 'resolved').length}`);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
export function getArtifactFeedbackFromCli(args) {
|
|
540
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
541
|
+
const [artifactId] = getPositionals(args);
|
|
542
|
+
if (!artifactId) {
|
|
543
|
+
throw new Error('Missing artifact id or slug.');
|
|
544
|
+
}
|
|
545
|
+
const target = yield resolveOptionalTarget(args);
|
|
546
|
+
const revisionId = parseFlagValue(args, '--revision');
|
|
547
|
+
const query = revisionId
|
|
548
|
+
? `?revisionId=${encodeURIComponent(revisionId)}`
|
|
549
|
+
: '';
|
|
550
|
+
const result = yield apiFetchOptional(target, `/api/artifacts/${encodeURIComponent(artifactId)}/feedback${query}`);
|
|
551
|
+
if (hasFlag(args, '--json')) {
|
|
552
|
+
console.log(JSON.stringify(result, null, 2));
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (!(result === null || result === void 0 ? void 0 : result.prompt)) {
|
|
556
|
+
throw new Error('Feedback response did not include a prompt.');
|
|
557
|
+
}
|
|
558
|
+
console.log(result.prompt);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
export function shareArtifactFromCli(args) {
|
|
562
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
563
|
+
var _a, _b, _c;
|
|
564
|
+
const [artifactId] = getPositionals(args);
|
|
565
|
+
if (!artifactId) {
|
|
566
|
+
throw new Error('Usage: artis share <artifact-id-or-slug> [--email <email> --role <viewer|commenter>] [--remove]');
|
|
567
|
+
}
|
|
568
|
+
const email = (_a = parseFlagValue(args, '--email')) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
569
|
+
const credentials = yield resolveCredentials(args);
|
|
570
|
+
const path = `/api/artifacts/${encodeURIComponent(artifactId)}/shares`;
|
|
571
|
+
if (!email) {
|
|
572
|
+
const result = yield apiFetch(credentials, path);
|
|
573
|
+
if (hasFlag(args, '--json')) {
|
|
574
|
+
console.log(JSON.stringify(result, null, 2));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const shares = (_b = result === null || result === void 0 ? void 0 : result.shares) !== null && _b !== void 0 ? _b : [];
|
|
578
|
+
if (!shares.length) {
|
|
579
|
+
console.log('No invited people yet.');
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
for (const share of shares) {
|
|
583
|
+
console.log(`${share.email} ${share.role}`);
|
|
584
|
+
}
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (hasFlag(args, '--remove')) {
|
|
588
|
+
yield apiFetch(credentials, path, {
|
|
589
|
+
method: 'DELETE',
|
|
590
|
+
body: JSON.stringify({ email }),
|
|
591
|
+
});
|
|
592
|
+
console.log(`Removed ${email}`);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const role = parseShareRole((_c = parseFlagValue(args, '--role')) !== null && _c !== void 0 ? _c : 'viewer');
|
|
596
|
+
const result = yield apiFetch(credentials, path, {
|
|
597
|
+
method: 'POST',
|
|
598
|
+
body: JSON.stringify({ email, role }),
|
|
599
|
+
});
|
|
600
|
+
if (!(result === null || result === void 0 ? void 0 : result.share)) {
|
|
601
|
+
throw new Error('Share response did not include share details.');
|
|
602
|
+
}
|
|
603
|
+
if (hasFlag(args, '--json')) {
|
|
604
|
+
console.log(JSON.stringify(result, null, 2));
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
console.log(`Shared with ${result.share.email} as ${result.share.role}`);
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
export function reviseArtifactFromCli(args) {
|
|
611
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
+
var _a;
|
|
613
|
+
const [artifactId, filePath] = getPositionals(args);
|
|
614
|
+
const summary = parseFlagValue(args, '--summary');
|
|
615
|
+
if (!artifactId || !filePath) {
|
|
616
|
+
throw new Error('Usage: artis revise <artifact-id-or-slug> artifact.html --summary <text>');
|
|
617
|
+
}
|
|
618
|
+
if (!summary) {
|
|
619
|
+
throw new Error('Missing --summary for revision.');
|
|
620
|
+
}
|
|
621
|
+
const credentials = yield resolveCredentials(args);
|
|
622
|
+
const html = yield readFile(filePath, 'utf8');
|
|
623
|
+
if (!html.toLowerCase().includes('<html')) {
|
|
624
|
+
throw new Error('Revision file must be self-contained HTML including <html>.');
|
|
625
|
+
}
|
|
626
|
+
const result = yield apiFetch(credentials, `/api/artifacts/${encodeURIComponent(artifactId)}/revisions`, {
|
|
627
|
+
method: 'POST',
|
|
628
|
+
body: JSON.stringify({
|
|
629
|
+
authorName: (_a = parseFlagValue(args, '--author')) !== null && _a !== void 0 ? _a : 'Artis CLI',
|
|
630
|
+
html,
|
|
631
|
+
resolvedAnnotationIds: collectFlagValues(args, '--resolve'),
|
|
632
|
+
source: 'cli',
|
|
633
|
+
summary,
|
|
634
|
+
}),
|
|
635
|
+
});
|
|
636
|
+
if (hasFlag(args, '--json')) {
|
|
637
|
+
console.log(JSON.stringify(result, null, 2));
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (!(result === null || result === void 0 ? void 0 : result.revision)) {
|
|
641
|
+
throw new Error('Revision response did not include revision details.');
|
|
642
|
+
}
|
|
643
|
+
console.log(`Revision ${result.revision.id}`);
|
|
644
|
+
console.log(`Version ${result.revision.version}`);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
export function createAnnotationFromCli(args) {
|
|
648
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
649
|
+
var _a, _b;
|
|
650
|
+
const [artifactId] = getPositionals(args);
|
|
651
|
+
const comment = parseFlagValue(args, '--comment');
|
|
652
|
+
if (!artifactId || !comment) {
|
|
653
|
+
throw new Error('Usage: artis annotate <artifact-id-or-slug> --comment <text> [--title <text>] [--quote <text>] [--css <selector>] [--text-start <n> --text-end <n>] [--rect <x,y,w,h>] [--pin-label <text>] [--requested-change <text>] [--status <open|needs-revision|resolved>]');
|
|
654
|
+
}
|
|
655
|
+
const selectors = buildAnnotationSelectors(args);
|
|
656
|
+
const credentials = yield resolveCredentials(args);
|
|
657
|
+
const result = yield apiFetch(credentials, `/api/artifacts/${encodeURIComponent(artifactId)}/annotations`, {
|
|
658
|
+
method: 'POST',
|
|
659
|
+
body: JSON.stringify({
|
|
660
|
+
authorName: (_a = parseFlagValue(args, '--author')) !== null && _a !== void 0 ? _a : 'Artis CLI',
|
|
661
|
+
comment,
|
|
662
|
+
pinLabel: parseFlagValue(args, '--pin-label'),
|
|
663
|
+
requestedChange: parseFlagValue(args, '--requested-change'),
|
|
664
|
+
role: 'agent',
|
|
665
|
+
selectors: selectors.length ? selectors : undefined,
|
|
666
|
+
status: parseAnnotationStatus((_b = parseFlagValue(args, '--status')) !== null && _b !== void 0 ? _b : 'open'),
|
|
667
|
+
title: parseFlagValue(args, '--title'),
|
|
668
|
+
}),
|
|
669
|
+
});
|
|
670
|
+
if (!(result === null || result === void 0 ? void 0 : result.annotation)) {
|
|
671
|
+
throw new Error('Annotation response did not include annotation details.');
|
|
672
|
+
}
|
|
673
|
+
console.log(`Annotation ${annotationIdFromIri(result.annotation.id)}`);
|
|
674
|
+
console.log(`Status ${result.annotation['artis:status']}`);
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
export function replyFromCli(args) {
|
|
678
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
679
|
+
var _a;
|
|
680
|
+
const [annotationId] = getPositionals(args);
|
|
681
|
+
const comment = parseFlagValue(args, '--comment');
|
|
682
|
+
if (!annotationId || !comment) {
|
|
683
|
+
throw new Error('Usage: artis reply <annotation-id> --comment <text>');
|
|
684
|
+
}
|
|
685
|
+
const credentials = yield resolveCredentials(args);
|
|
686
|
+
const result = yield apiFetch(credentials, `/api/annotations/${encodeURIComponent(annotationId)}/replies`, {
|
|
687
|
+
method: 'POST',
|
|
688
|
+
body: JSON.stringify({
|
|
689
|
+
authorName: (_a = parseFlagValue(args, '--author')) !== null && _a !== void 0 ? _a : 'Artis CLI',
|
|
690
|
+
comment,
|
|
691
|
+
role: 'agent',
|
|
692
|
+
}),
|
|
693
|
+
});
|
|
694
|
+
if (!(result === null || result === void 0 ? void 0 : result.annotation)) {
|
|
695
|
+
throw new Error('Reply response did not include annotation details.');
|
|
696
|
+
}
|
|
697
|
+
console.log(`Reply ${annotationIdFromIri(result.annotation.id)}`);
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
export function editAnnotationFromCli(args) {
|
|
701
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
702
|
+
const [annotationId] = getPositionals(args);
|
|
703
|
+
const comment = parseFlagValue(args, '--comment');
|
|
704
|
+
const title = parseFlagValue(args, '--title');
|
|
705
|
+
const requestedChange = parseFlagValue(args, '--requested-change');
|
|
706
|
+
if (!annotationId ||
|
|
707
|
+
(comment === undefined &&
|
|
708
|
+
title === undefined &&
|
|
709
|
+
requestedChange === undefined)) {
|
|
710
|
+
throw new Error('Usage: artis annotation edit <annotation-id> [--comment <text>] [--title <text>] [--requested-change <text>]');
|
|
711
|
+
}
|
|
712
|
+
const credentials = yield resolveCredentials(args);
|
|
713
|
+
const result = yield apiFetch(credentials, `/api/annotations/${encodeURIComponent(annotationId)}`, {
|
|
714
|
+
method: 'PATCH',
|
|
715
|
+
body: JSON.stringify({ comment, title, requestedChange }),
|
|
716
|
+
});
|
|
717
|
+
if (!(result === null || result === void 0 ? void 0 : result.annotation)) {
|
|
718
|
+
throw new Error('Annotation response did not include annotation details.');
|
|
719
|
+
}
|
|
720
|
+
console.log(`Annotation ${annotationIdFromIri(result.annotation.id)} edited`);
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
export function retractAnnotationFromCli(args) {
|
|
724
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
725
|
+
const [annotationId] = getPositionals(args);
|
|
726
|
+
if (!annotationId) {
|
|
727
|
+
throw new Error('Usage: artis annotation retract <annotation-id>');
|
|
728
|
+
}
|
|
729
|
+
const credentials = yield resolveCredentials(args);
|
|
730
|
+
const result = yield apiFetch(credentials, `/api/annotations/${encodeURIComponent(annotationId)}`, {
|
|
731
|
+
method: 'DELETE',
|
|
732
|
+
});
|
|
733
|
+
if (!(result === null || result === void 0 ? void 0 : result.annotation)) {
|
|
734
|
+
throw new Error('Annotation response did not include annotation details.');
|
|
735
|
+
}
|
|
736
|
+
console.log(`Annotation ${annotationIdFromIri(result.annotation.id)} retracted`);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
export function runArtisCli() {
|
|
740
|
+
return __awaiter(this, arguments, void 0, function* (args = process.argv.slice(2)) {
|
|
741
|
+
const [command, ...rest] = args;
|
|
742
|
+
if (command === 'version' || command === '--version' || command === '-v') {
|
|
743
|
+
console.log(`artis ${artisCliVersion}`);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (!command || command === 'help' || hasFlag(args, '--help')) {
|
|
747
|
+
console.log(getCliHelp());
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (command === 'login') {
|
|
751
|
+
yield loginFromCli(rest);
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (command === 'whoami') {
|
|
755
|
+
yield whoamiFromCli(rest);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (command === 'publish') {
|
|
759
|
+
const published = yield publishArtifactFromCli(rest);
|
|
760
|
+
if (hasFlag(rest, '--json')) {
|
|
761
|
+
console.log(JSON.stringify(published, null, 2));
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
console.log(`Published "${published.title}"`);
|
|
765
|
+
console.log(`Artifact: ${published.artifactId}`);
|
|
766
|
+
console.log(`Revision: ${published.revisionId}`);
|
|
767
|
+
console.log(`Visibility: ${published.visibility}`);
|
|
768
|
+
console.log(published.url);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (command === 'artifact' && rest[0] === 'get') {
|
|
772
|
+
yield getArtifactFromCli(rest.slice(1));
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (command === 'artifact' && rest[0] === 'feedback') {
|
|
776
|
+
yield getArtifactFeedbackFromCli(rest.slice(1));
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (command === 'share') {
|
|
780
|
+
yield shareArtifactFromCli(rest);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (command === 'revise') {
|
|
784
|
+
yield reviseArtifactFromCli(rest);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (command === 'annotate') {
|
|
788
|
+
yield createAnnotationFromCli(rest);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (command === 'reply') {
|
|
792
|
+
yield replyFromCli(rest);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (command === 'annotation' && rest[0] === 'edit') {
|
|
796
|
+
yield editAnnotationFromCli(rest.slice(1));
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (command === 'annotation' && rest[0] === 'retract') {
|
|
800
|
+
yield retractAnnotationFromCli(rest.slice(1));
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
throw new Error(`Unknown command "${args.join(' ')}". Run artis help.`);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ArtisCliProfile {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
host: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ArtisCliConfig {
|
|
6
|
+
defaultHost?: string;
|
|
7
|
+
profiles: Record<string, ArtisCliProfile>;
|
|
8
|
+
}
|
|
9
|
+
export declare function normalizeHost(value: string): string;
|
|
10
|
+
export declare function getConfigPath(): string;
|
|
11
|
+
export declare function readCliConfig(): Promise<ArtisCliConfig | undefined>;
|
|
12
|
+
export declare function findProfileForHost(config: ArtisCliConfig | undefined, host: string): ArtisCliProfile | undefined;
|
|
13
|
+
export declare function saveDefaultProfile(input: ArtisCliProfile): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
export function normalizeHost(value) {
|
|
6
|
+
return value.replace(/\/+$/, '');
|
|
7
|
+
}
|
|
8
|
+
export function getConfigPath() {
|
|
9
|
+
var _a;
|
|
10
|
+
return join((_a = process.env['ARTIS_CONFIG_DIR']) !== null && _a !== void 0 ? _a : homedir(), '.artis', 'config.json');
|
|
11
|
+
}
|
|
12
|
+
export function readCliConfig() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(yield readFile(getConfigPath(), 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function writeCliConfig(config) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const configPath = getConfigPath();
|
|
25
|
+
yield mkdir(dirname(configPath), { mode: 0o700, recursive: true });
|
|
26
|
+
yield writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, {
|
|
27
|
+
mode: 0o600,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function findProfileForHost(config, host) {
|
|
32
|
+
if (!config) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return Object.values(config.profiles).find((profile) => normalizeHost(profile.host) === normalizeHost(host));
|
|
36
|
+
}
|
|
37
|
+
export function saveDefaultProfile(input) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
40
|
+
const existing = yield readCliConfig();
|
|
41
|
+
const host = normalizeHost(input.host);
|
|
42
|
+
yield writeCliConfig({
|
|
43
|
+
defaultHost: host,
|
|
44
|
+
profiles: Object.assign(Object.assign({}, ((_a = existing === null || existing === void 0 ? void 0 : existing.profiles) !== null && _a !== void 0 ? _a : {})), { default: {
|
|
45
|
+
apiKey: input.apiKey,
|
|
46
|
+
host,
|
|
47
|
+
} }),
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI version, read from the package manifest that ships alongside the compiled
|
|
3
|
+
* output. The relative specifier resolves against this file's directory, which
|
|
4
|
+
* holds for both the Nx build output (`dist/packages/cli/src/lib/`) and an
|
|
5
|
+
* installed package (`node_modules/@artis-lab/cli/src/lib/`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const artisCliVersion: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* CLI version, read from the package manifest that ships alongside the compiled
|
|
5
|
+
* output. The relative specifier resolves against this file's directory, which
|
|
6
|
+
* holds for both the Nx build output (`dist/packages/cli/src/lib/`) and an
|
|
7
|
+
* installed package (`node_modules/@artis-lab/cli/src/lib/`).
|
|
8
|
+
*/
|
|
9
|
+
export const artisCliVersion = require('../../package.json')
|
|
10
|
+
.version;
|
|
11
|
+
//# sourceMappingURL=version.js.map
|