@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
package/README.md
CHANGED
|
@@ -21,8 +21,8 @@ Requires Node.js 20 or newer. Upgrade with
|
|
|
21
21
|
## Quick start
|
|
22
22
|
|
|
23
23
|
Publishing requires authentication. `artis login` runs a device-code flow: it
|
|
24
|
-
opens a browser for approval and stores the resulting
|
|
25
|
-
`~/.artis/config.json
|
|
24
|
+
opens a browser for approval and stores the resulting OAuth tokens at
|
|
25
|
+
`~/.artis/config.json`, refreshing them as they expire.
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
artis login
|
|
@@ -42,7 +42,6 @@ Defaults:
|
|
|
42
42
|
- Host: `--host`, then `ARTIS_URL`, then saved config, then
|
|
43
43
|
`https://artis.xiispace.eu.org`
|
|
44
44
|
- `visibility=unlisted`
|
|
45
|
-
- `kind=custom-html`
|
|
46
45
|
- `author=Artis CLI`
|
|
47
46
|
|
|
48
47
|
## Collaboration commands
|
|
@@ -60,6 +59,18 @@ artis annotate 4kq9Zt2LmX8vRbP3nWc7Hy --comment "Tighten this heading" --quote "
|
|
|
60
59
|
artis reply annotation-123 --comment "Fixed in revision 2."
|
|
61
60
|
```
|
|
62
61
|
|
|
62
|
+
## Assets
|
|
63
|
+
|
|
64
|
+
Images, fonts, media and other files an artifact keeps across revisions
|
|
65
|
+
(ADR 0023). A page shows one at `/_blob/<id>` on its own host.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
artis asset upload 4kq9Zt2LmX8vRbP3nWc7Hy chart.png # prints the asset, with its id and url
|
|
69
|
+
artis asset list 4kq9Zt2LmX8vRbP3nWc7Hy
|
|
70
|
+
artis asset get 4kq9Zt2LmX8vRbP3nWc7Hy <asset-id> --output chart.png
|
|
71
|
+
artis asset rm 4kq9Zt2LmX8vRbP3nWc7Hy <asset-id>
|
|
72
|
+
```
|
|
73
|
+
|
|
63
74
|
## Check a page before publishing
|
|
64
75
|
|
|
65
76
|
```bash
|
|
@@ -67,23 +78,41 @@ artis verify artifact.html # or a published artifact: artis verify 4kq9Zt
|
|
|
67
78
|
```
|
|
68
79
|
|
|
69
80
|
`verify` renders the page in your system Chrome (or Edge) at 1280 and 390 px
|
|
70
|
-
in light and dark themes, served
|
|
71
|
-
|
|
81
|
+
in light and dark themes, served the way Artis serves it (on an artifact host
|
|
82
|
+
of its own, `<uuid>.localhost`, with the same Content-Security-Policy), and
|
|
83
|
+
reports horizontal overflow, clipped SVG, console errors and CSP
|
|
72
84
|
violations. It exits 8 when it finds any. It needs the optional
|
|
73
85
|
`playwright-core` dependency (installed with the CLI by default, about
|
|
74
86
|
10 MB and no browser binaries) and a
|
|
75
87
|
Chromium-based browser; set `ARTIS_CHROME_PATH` to use a specific one.
|
|
76
88
|
|
|
77
|
-
A slide deck is checked as its type:
|
|
78
|
-
(a published deck's revision already
|
|
79
|
-
slides format check and lists each issue
|
|
80
|
-
line: errors exit 8, hints are reported
|
|
81
|
-
|
|
89
|
+
A slide deck is a directory of files, checked as its type:
|
|
90
|
+
`artis verify --root deck --type slides` (a published deck's revision already
|
|
91
|
+
names its type). It first runs the slides format check and lists each issue
|
|
92
|
+
with its level, rule, slide, file and line: errors exit 8, hints are reported
|
|
93
|
+
only. It then serves the files at the paths Artis serves them at, with the
|
|
94
|
+
slides entry page, runtime and the Google Fonts CSP a typed revision gets, in light
|
|
82
95
|
and dark themes, and reports every slide whose content runs past its
|
|
83
96
|
1920×1080 (4:3: 1440×1080) canvas. The server never runs these checks, so
|
|
84
97
|
run `verify` before every publish and revise.
|
|
85
98
|
|
|
86
|
-
|
|
99
|
+
Discover commands progressively; help is local and never authenticates:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
artis -h
|
|
103
|
+
artis artifact -h
|
|
104
|
+
artis artifact files -h
|
|
105
|
+
artis help data set
|
|
106
|
+
artis help --all # full legacy reference
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The CLI prints concise suggested next actions to stderr after publish, revise
|
|
110
|
+
and feedback when applicable (e.g. inspect files when there are open review
|
|
111
|
+
threads, or watch from the returned cursor when there are none). They are optional, not executed automatically. Existing
|
|
112
|
+
`--json` responses are unchanged. Use `--json --next` on those commands
|
|
113
|
+
for a structured `{ data, nextActions }` response; each action has an
|
|
114
|
+
`argv` array, description, kind and effect. Error recovery hints go to stderr,
|
|
115
|
+
and raw file output and watch event streams remain untouched.
|
|
87
116
|
|
|
88
117
|
## Install the agent skill
|
|
89
118
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artis-lab/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Agent-first CLI for creating, sharing and maintaining artifacts on Artis, an open-source, self-hostable place for what AI agents build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"artifacts",
|
|
43
43
|
"review"
|
|
44
44
|
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@stricli/core": "^1.3.0"
|
|
47
|
+
},
|
|
45
48
|
"optionalDependencies": {
|
|
46
49
|
"playwright-core": "^1.64.1"
|
|
47
50
|
},
|
package/src/bin.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "./lib/chunk-
|
|
5
|
-
import "./lib/chunk-
|
|
6
|
-
import "./lib/chunk-
|
|
7
|
-
import "./lib/chunk-IZYFOV2K.js";
|
|
8
|
-
import "./lib/chunk-U3ZF6SRR.js";
|
|
9
|
-
import "./lib/chunk-QDQQASRY.js";
|
|
3
|
+
runAgentCli
|
|
4
|
+
} from "./lib/chunk-CCCATRMP.js";
|
|
5
|
+
import "./lib/chunk-Q5KBGVKT.js";
|
|
6
|
+
import "./lib/chunk-KJV7R7DE.js";
|
|
10
7
|
import {
|
|
11
8
|
exitCodeFor
|
|
12
9
|
} from "./lib/chunk-H32QAUSA.js";
|
|
13
|
-
import "./lib/chunk-KY47KP5E.js";
|
|
14
|
-
import "./lib/chunk-QNS7GLAA.js";
|
|
15
10
|
|
|
16
11
|
// packages/cli/src/bin.ts
|
|
17
|
-
|
|
12
|
+
runAgentCli().catch((error) => {
|
|
18
13
|
const message = error instanceof Error ? error.message : String(error);
|
|
19
14
|
if (message) {
|
|
20
15
|
console.error(message);
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertSafeLoginUrl,
|
|
3
|
+
assetFromCli,
|
|
4
|
+
capabilitiesFromCli,
|
|
3
5
|
commands,
|
|
4
6
|
createAnnotationFromCli,
|
|
5
7
|
dataFromCli,
|
|
6
8
|
deleteArtifactFromCli,
|
|
7
9
|
editAnnotationFromCli,
|
|
10
|
+
executeArtisCommand,
|
|
8
11
|
getArtifactFeedbackFromCli,
|
|
9
12
|
getArtifactFilesFromCli,
|
|
10
13
|
getArtifactFromCli,
|
|
11
|
-
getArtifactHtmlFromCli,
|
|
12
14
|
getCliHelp,
|
|
13
15
|
guidelinesFromCli,
|
|
14
16
|
listArtifactsFromCli,
|
|
@@ -25,31 +27,35 @@ import {
|
|
|
25
27
|
verifyFromCli,
|
|
26
28
|
watchArtifactFromCli,
|
|
27
29
|
whoamiFromCli
|
|
28
|
-
} from "./lib/chunk-
|
|
30
|
+
} from "./lib/chunk-PG7WDW5F.js";
|
|
31
|
+
import "./lib/chunk-43WVFZLO.js";
|
|
32
|
+
import "./lib/chunk-JYMG2Y6C.js";
|
|
29
33
|
import {
|
|
30
34
|
installSkillFromCli
|
|
31
|
-
} from "./lib/chunk-
|
|
32
|
-
import "./lib/chunk-
|
|
35
|
+
} from "./lib/chunk-CT5TD6L2.js";
|
|
36
|
+
import "./lib/chunk-QZFIUZXT.js";
|
|
33
37
|
import {
|
|
34
38
|
artisCliVersion
|
|
35
39
|
} from "./lib/chunk-IZYFOV2K.js";
|
|
36
|
-
import "./lib/chunk-
|
|
37
|
-
import "./lib/chunk-
|
|
40
|
+
import "./lib/chunk-Q5KBGVKT.js";
|
|
41
|
+
import "./lib/chunk-KJV7R7DE.js";
|
|
42
|
+
import "./lib/chunk-46DMRA3V.js";
|
|
43
|
+
import "./lib/chunk-MEPQKMK5.js";
|
|
38
44
|
import "./lib/chunk-H32QAUSA.js";
|
|
39
|
-
import "./lib/chunk-KY47KP5E.js";
|
|
40
|
-
import "./lib/chunk-QNS7GLAA.js";
|
|
41
45
|
export {
|
|
42
46
|
artisCliVersion,
|
|
43
47
|
assertSafeLoginUrl,
|
|
48
|
+
assetFromCli,
|
|
49
|
+
capabilitiesFromCli,
|
|
44
50
|
commands,
|
|
45
51
|
createAnnotationFromCli,
|
|
46
52
|
dataFromCli,
|
|
47
53
|
deleteArtifactFromCli,
|
|
48
54
|
editAnnotationFromCli,
|
|
55
|
+
executeArtisCommand,
|
|
49
56
|
getArtifactFeedbackFromCli,
|
|
50
57
|
getArtifactFilesFromCli,
|
|
51
58
|
getArtifactFromCli,
|
|
52
|
-
getArtifactHtmlFromCli,
|
|
53
59
|
getCliHelp,
|
|
54
60
|
guidelinesFromCli,
|
|
55
61
|
installSkillFromCli,
|
package/src/lib/app.d.ts
ADDED
package/src/lib/app.js
ADDED
package/src/lib/args.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const valueFlags: Set<string>;
|
|
1
2
|
export declare function parseFlagValue(args: string[], name: string): string | undefined;
|
|
2
3
|
export declare function hasFlag(args: string[], name: string): boolean;
|
|
3
4
|
export declare function collectFlagValues(args: string[], name: string): string[];
|
package/src/lib/args.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectFlagValues,
|
|
3
3
|
hasFlag,
|
|
4
|
-
parseFlagValue
|
|
5
|
-
|
|
4
|
+
parseFlagValue,
|
|
5
|
+
valueFlags
|
|
6
|
+
} from "./chunk-KJV7R7DE.js";
|
|
6
7
|
export {
|
|
7
8
|
collectFlagValues,
|
|
8
9
|
hasFlag,
|
|
9
|
-
parseFlagValue
|
|
10
|
+
parseFlagValue,
|
|
11
|
+
valueFlags
|
|
10
12
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// packages/cli/src/lib/oauth.ts
|
|
2
|
+
var CLI_CLIENT_ID = "artis-cli";
|
|
3
|
+
var CLI_SCOPE = "artis offline_access";
|
|
4
|
+
var deviceCodeGrant = "urn:ietf:params:oauth:grant-type:device_code";
|
|
5
|
+
var OAuthError = class extends Error {
|
|
6
|
+
constructor(status, code, description) {
|
|
7
|
+
super(description ? `${code}: ${description}` : code);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = "OAuthError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
async function postForm(baseUrl, path, fields) {
|
|
14
|
+
const response = await fetch(`${baseUrl}/api/auth${path}`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
18
|
+
accept: "application/json"
|
|
19
|
+
},
|
|
20
|
+
body: new URLSearchParams(fields).toString()
|
|
21
|
+
});
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
let body = {};
|
|
24
|
+
try {
|
|
25
|
+
body = text ? JSON.parse(text) : {};
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const code = typeof body["error"] === "string" ? body["error"] : `http_${response.status}`;
|
|
30
|
+
const description = typeof body["error_description"] === "string" ? body["error_description"] : typeof body["message"] === "string" ? body["message"] : void 0;
|
|
31
|
+
throw new OAuthError(response.status, code, description);
|
|
32
|
+
}
|
|
33
|
+
return body;
|
|
34
|
+
}
|
|
35
|
+
function tokenSetOf(body, now) {
|
|
36
|
+
if (typeof body["access_token"] !== "string") {
|
|
37
|
+
throw new OAuthError(500, "invalid_response", "No access token returned.");
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
accessToken: body["access_token"],
|
|
41
|
+
refreshToken: typeof body["refresh_token"] === "string" ? body["refresh_token"] : void 0,
|
|
42
|
+
expiresAt: typeof body["expires_in"] === "number" ? now + body["expires_in"] * 1e3 : void 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function startDeviceAuthorization(baseUrl) {
|
|
46
|
+
const body = await postForm(baseUrl, "/device/code", {
|
|
47
|
+
client_id: CLI_CLIENT_ID,
|
|
48
|
+
scope: CLI_SCOPE
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
deviceCode: String(body["device_code"]),
|
|
52
|
+
userCode: String(body["user_code"]),
|
|
53
|
+
verificationUri: String(body["verification_uri"]),
|
|
54
|
+
verificationUriComplete: typeof body["verification_uri_complete"] === "string" ? body["verification_uri_complete"] : void 0,
|
|
55
|
+
expiresIn: Number(body["expires_in"] ?? 900),
|
|
56
|
+
interval: Number(body["interval"] ?? 5)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function pollDeviceToken(baseUrl, deviceCode) {
|
|
60
|
+
try {
|
|
61
|
+
const body = await postForm(baseUrl, "/oauth2/token", {
|
|
62
|
+
grant_type: deviceCodeGrant,
|
|
63
|
+
device_code: deviceCode,
|
|
64
|
+
client_id: CLI_CLIENT_ID
|
|
65
|
+
});
|
|
66
|
+
return { status: "approved", tokens: tokenSetOf(body, Date.now()) };
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (error instanceof OAuthError) {
|
|
69
|
+
if (error.code === "authorization_pending") return { status: "pending" };
|
|
70
|
+
if (error.code === "slow_down" || error.status === 429) {
|
|
71
|
+
return { status: "slow_down" };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function refreshTokens(baseUrl, refreshToken) {
|
|
78
|
+
const body = await postForm(baseUrl, "/oauth2/token", {
|
|
79
|
+
grant_type: "refresh_token",
|
|
80
|
+
refresh_token: refreshToken,
|
|
81
|
+
client_id: CLI_CLIENT_ID
|
|
82
|
+
});
|
|
83
|
+
return tokenSetOf(body, Date.now());
|
|
84
|
+
}
|
|
85
|
+
async function revokeToken(baseUrl, token, hint) {
|
|
86
|
+
try {
|
|
87
|
+
await postForm(baseUrl, "/oauth2/revoke", {
|
|
88
|
+
token,
|
|
89
|
+
token_type_hint: hint,
|
|
90
|
+
client_id: CLI_CLIENT_ID
|
|
91
|
+
});
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
CLI_CLIENT_ID,
|
|
98
|
+
CLI_SCOPE,
|
|
99
|
+
OAuthError,
|
|
100
|
+
startDeviceAuthorization,
|
|
101
|
+
pollDeviceToken,
|
|
102
|
+
refreshTokens,
|
|
103
|
+
revokeToken
|
|
104
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// packages/cli/src/lib/config.ts
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
mkdir,
|
|
5
|
+
open,
|
|
6
|
+
readFile,
|
|
7
|
+
rename,
|
|
8
|
+
stat,
|
|
9
|
+
unlink,
|
|
10
|
+
writeFile
|
|
11
|
+
} from "node:fs/promises";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
var ARTIS_DEFAULT_HOST = "https://artis.xiispace.eu.org";
|
|
15
|
+
function normalizeHost(value) {
|
|
16
|
+
return value.replace(/\/+$/, "");
|
|
17
|
+
}
|
|
18
|
+
function getConfigPath() {
|
|
19
|
+
return join(
|
|
20
|
+
process.env["ARTIS_CONFIG_DIR"] ?? homedir(),
|
|
21
|
+
".artis",
|
|
22
|
+
"config.json"
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
async function readCliConfig() {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(
|
|
28
|
+
await readFile(getConfigPath(), "utf8")
|
|
29
|
+
);
|
|
30
|
+
} catch {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function writeCliConfig(config) {
|
|
35
|
+
const configPath = getConfigPath();
|
|
36
|
+
await mkdir(dirname(configPath), { mode: 448, recursive: true });
|
|
37
|
+
const temporary = `${configPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
38
|
+
await writeFile(temporary, `${JSON.stringify(config, null, 2)}
|
|
39
|
+
`, {
|
|
40
|
+
mode: 384
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
await rename(temporary, configPath);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
await unlink(temporary).catch(() => void 0);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function findProfileForHost(config, host) {
|
|
50
|
+
if (!config) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
return Object.values(config.profiles ?? {}).find(
|
|
54
|
+
(profile) => normalizeHost(profile.host) === normalizeHost(host) && typeof profile.accessToken === "string"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
async function saveDefaultProfile(input) {
|
|
58
|
+
const existing = await readCliConfig();
|
|
59
|
+
const host = normalizeHost(input.host);
|
|
60
|
+
await writeCliConfig({
|
|
61
|
+
...existing,
|
|
62
|
+
defaultHost: host,
|
|
63
|
+
profiles: {
|
|
64
|
+
...existing?.profiles ?? {},
|
|
65
|
+
default: { ...input, host }
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function updateProfileTokens(host, tokens) {
|
|
70
|
+
const existing = await readCliConfig();
|
|
71
|
+
if (!existing) return;
|
|
72
|
+
const profiles = { ...existing.profiles };
|
|
73
|
+
for (const [name, profile] of Object.entries(profiles)) {
|
|
74
|
+
if (normalizeHost(profile.host) === normalizeHost(host)) {
|
|
75
|
+
profiles[name] = { ...tokens, host: profile.host };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
await writeCliConfig({ ...existing, profiles });
|
|
79
|
+
}
|
|
80
|
+
async function resolveOrigin() {
|
|
81
|
+
const fromEnv = process.env["ARTIS_ORIGIN"]?.trim();
|
|
82
|
+
if (fromEnv) return fromEnv;
|
|
83
|
+
const existing = await readCliConfig();
|
|
84
|
+
if (existing?.origin) return existing.origin;
|
|
85
|
+
const origin = randomUUID();
|
|
86
|
+
if (!existing && await stat(getConfigPath()).catch(() => void 0)) {
|
|
87
|
+
return origin;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
await writeCliConfig({
|
|
91
|
+
...existing,
|
|
92
|
+
profiles: existing?.profiles ?? {},
|
|
93
|
+
origin
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
return origin;
|
|
98
|
+
}
|
|
99
|
+
var lockWaitMs = 15e3;
|
|
100
|
+
var lockStaleMs = 3e4;
|
|
101
|
+
async function withConfigLock(task) {
|
|
102
|
+
const lockPath = `${getConfigPath()}.lock`;
|
|
103
|
+
await mkdir(dirname(lockPath), { mode: 448, recursive: true });
|
|
104
|
+
const deadline = Date.now() + lockWaitMs;
|
|
105
|
+
let held = false;
|
|
106
|
+
while (!held) {
|
|
107
|
+
try {
|
|
108
|
+
await (await open(lockPath, "wx", 384)).close();
|
|
109
|
+
held = true;
|
|
110
|
+
} catch {
|
|
111
|
+
const age = await stat(lockPath).then(
|
|
112
|
+
(info) => Date.now() - info.mtimeMs,
|
|
113
|
+
() => 0
|
|
114
|
+
);
|
|
115
|
+
if (age > lockStaleMs) {
|
|
116
|
+
await unlink(lockPath).catch(() => void 0);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (Date.now() > deadline) break;
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return await task();
|
|
125
|
+
} finally {
|
|
126
|
+
if (held) await unlink(lockPath).catch(() => void 0);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
ARTIS_DEFAULT_HOST,
|
|
132
|
+
normalizeHost,
|
|
133
|
+
getConfigPath,
|
|
134
|
+
readCliConfig,
|
|
135
|
+
writeCliConfig,
|
|
136
|
+
findProfileForHost,
|
|
137
|
+
saveDefaultProfile,
|
|
138
|
+
updateProfileTokens,
|
|
139
|
+
resolveOrigin,
|
|
140
|
+
withConfigLock
|
|
141
|
+
};
|