@atelier201/cli 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +379 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/dist/api-types.generated.js +8 -0
- package/dist/api-types.generated.js.map +1 -0
- package/dist/commands/api.js +111 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.js +284 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/builds.js +169 -0
- package/dist/commands/builds.js.map +1 -0
- package/dist/commands/changesets.js +91 -0
- package/dist/commands/changesets.js.map +1 -0
- package/dist/commands/common.js +89 -0
- package/dist/commands/common.js.map +1 -0
- package/dist/commands/completion.js +120 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/content.js +281 -0
- package/dist/commands/content.js.map +1 -0
- package/dist/commands/doctor.js +141 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/domains.js +109 -0
- package/dist/commands/domains.js.map +1 -0
- package/dist/commands/feedback.js +39 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/files.js +286 -0
- package/dist/commands/files.js.map +1 -0
- package/dist/commands/help-json.js +128 -0
- package/dist/commands/help-json.js.map +1 -0
- package/dist/commands/history.js +83 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/mcp.js +129 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/media.js +273 -0
- package/dist/commands/media.js.map +1 -0
- package/dist/commands/pages.js +33 -0
- package/dist/commands/pages.js.map +1 -0
- package/dist/commands/previews.js +73 -0
- package/dist/commands/previews.js.map +1 -0
- package/dist/commands/publish.js +228 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/read.js +85 -0
- package/dist/commands/read.js.map +1 -0
- package/dist/commands/site-guest.js +159 -0
- package/dist/commands/site-guest.js.map +1 -0
- package/dist/commands/site.js +204 -0
- package/dist/commands/site.js.map +1 -0
- package/dist/commands/sites.js +168 -0
- package/dist/commands/sites.js.map +1 -0
- package/dist/commands/skills.js +45 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/workspace.js +89 -0
- package/dist/commands/workspace.js.map +1 -0
- package/dist/credentials.js +151 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.js +166 -0
- package/dist/errors.js.map +1 -0
- package/dist/exit-codes.js +88 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/http.js +275 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +184 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain.js +185 -0
- package/dist/keychain.js.map +1 -0
- package/dist/oauth/browser.js +33 -0
- package/dist/oauth/browser.js.map +1 -0
- package/dist/oauth/pkce.js +118 -0
- package/dist/oauth/pkce.js.map +1 -0
- package/dist/oauth/server.js +276 -0
- package/dist/oauth/server.js.map +1 -0
- package/dist/output.js +163 -0
- package/dist/output.js.map +1 -0
- package/dist/project.js +178 -0
- package/dist/project.js.map +1 -0
- package/dist/refresh-lock.js +84 -0
- package/dist/refresh-lock.js.map +1 -0
- package/dist/run.js +197 -0
- package/dist/run.js.map +1 -0
- package/dist/session.js +147 -0
- package/dist/session.js.map +1 -0
- package/dist/site-link.js +145 -0
- package/dist/site-link.js.map +1 -0
- package/dist/site-sync.js +191 -0
- package/dist/site-sync.js.map +1 -0
- package/dist/tar.js +228 -0
- package/dist/tar.js.map +1 -0
- package/dist/version.js +34 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -3
package/dist/project.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which files of a project folder `atelier201 site push` sends.
|
|
3
|
+
*
|
|
4
|
+
* Two layers. The first is fixed and cannot be switched off: dependencies,
|
|
5
|
+
* build output, Git internals, the CLI's own state and every file that usually
|
|
6
|
+
* holds a secret never leave the machine, whatever the `.gitignore` says. The
|
|
7
|
+
* second is the folder's root `.gitignore`, read with the basics of its syntax
|
|
8
|
+
* (comments, `!`, a trailing `/`, a leading `/`, `*`, `?`, `**`, `[...]`).
|
|
9
|
+
* Nested `.gitignore` files are not read.
|
|
10
|
+
*
|
|
11
|
+
* The fixed layer mirrors the server's own refusals (`sourcePath()` in
|
|
12
|
+
* `@atelier201/site-format`), so the server never has to skip something the CLI
|
|
13
|
+
* already withheld, and a secret is never put on the wire to be refused.
|
|
14
|
+
*/
|
|
15
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
/** A folder with one of these names is skipped at any depth. */
|
|
18
|
+
const SKIPPED_FOLDERS = new Set(["node_modules", "dist", ".astro", ".atelier201", ".git", ".wrangler"]);
|
|
19
|
+
/** Skipped at any depth, silently: operating-system litter. */
|
|
20
|
+
const LITTER = new Set([".DS_Store", "Thumbs.db"]);
|
|
21
|
+
const ENV_EXAMPLE = /^\.env\.(example|sample|template)$/i;
|
|
22
|
+
const SECRET_NAMES = [
|
|
23
|
+
/^\.env(\..*)?$/i,
|
|
24
|
+
/^\.npmrc$/i,
|
|
25
|
+
/^\.yarnrc(\.yml)?$/i,
|
|
26
|
+
/^id_(rsa|ed25519|ecdsa)(\.pub)?$/i,
|
|
27
|
+
/\.pem$/i,
|
|
28
|
+
/\.key$/i,
|
|
29
|
+
];
|
|
30
|
+
/** Why a file is never sent, or null when nothing forbids it. */
|
|
31
|
+
export function forbiddenReason(name) {
|
|
32
|
+
if (!ENV_EXAMPLE.test(name) && SECRET_NAMES.some((pattern) => pattern.test(name))) {
|
|
33
|
+
return "holds secrets, never sent";
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
function globToRegex(glob) {
|
|
38
|
+
let out = "";
|
|
39
|
+
for (let i = 0; i < glob.length; i++) {
|
|
40
|
+
const char = glob[i];
|
|
41
|
+
if (char === "*") {
|
|
42
|
+
if (glob[i + 1] === "*") {
|
|
43
|
+
// `**/` matches zero or more folders; a trailing `/**` or a bare `**` matches anything.
|
|
44
|
+
if (glob[i + 2] === "/") {
|
|
45
|
+
out += "(?:.*/)?";
|
|
46
|
+
i += 2;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
out += ".*";
|
|
50
|
+
i += 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
out += "[^/]*";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (char === "?") {
|
|
58
|
+
out += "[^/]";
|
|
59
|
+
}
|
|
60
|
+
else if (char === "[") {
|
|
61
|
+
const close = glob.indexOf("]", i + 2);
|
|
62
|
+
if (close === -1) {
|
|
63
|
+
out += "\\[";
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
let set = glob.slice(i + 1, close);
|
|
67
|
+
if (set.startsWith("!"))
|
|
68
|
+
set = `^${set.slice(1)}`;
|
|
69
|
+
out += `[${set.replace(/\\/g, "\\\\")}]`;
|
|
70
|
+
i = close;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (char === "\\" && i + 1 < glob.length) {
|
|
74
|
+
out += glob[i + 1].replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
75
|
+
i += 1;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
out += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
export function parseGitignore(text) {
|
|
84
|
+
const rules = [];
|
|
85
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
86
|
+
let line = raw.replace(/(?<!\\)\s+$/, "");
|
|
87
|
+
if (!line || line.startsWith("#"))
|
|
88
|
+
continue;
|
|
89
|
+
let negate = false;
|
|
90
|
+
if (line.startsWith("!")) {
|
|
91
|
+
negate = true;
|
|
92
|
+
line = line.slice(1);
|
|
93
|
+
}
|
|
94
|
+
let directoryOnly = false;
|
|
95
|
+
if (line.endsWith("/")) {
|
|
96
|
+
directoryOnly = true;
|
|
97
|
+
line = line.slice(0, -1);
|
|
98
|
+
}
|
|
99
|
+
if (!line)
|
|
100
|
+
continue;
|
|
101
|
+
const anchored = line.includes("/");
|
|
102
|
+
if (line.startsWith("/"))
|
|
103
|
+
line = line.slice(1);
|
|
104
|
+
const body = globToRegex(line);
|
|
105
|
+
rules.push({
|
|
106
|
+
negate,
|
|
107
|
+
directoryOnly,
|
|
108
|
+
pattern: new RegExp(anchored ? `^${body}$` : `^(?:.*/)?${body}$`),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return rules;
|
|
112
|
+
}
|
|
113
|
+
/** The last matching rule wins, as in Git. */
|
|
114
|
+
export function isIgnored(rules, relativePath, isDirectory) {
|
|
115
|
+
let ignored = false;
|
|
116
|
+
for (const rule of rules) {
|
|
117
|
+
if (rule.directoryOnly && !isDirectory)
|
|
118
|
+
continue;
|
|
119
|
+
if (rule.pattern.test(relativePath))
|
|
120
|
+
ignored = !rule.negate;
|
|
121
|
+
}
|
|
122
|
+
return ignored;
|
|
123
|
+
}
|
|
124
|
+
// ── The walk ────────────────────────────────────────────────────────────────
|
|
125
|
+
export async function collectProject(root) {
|
|
126
|
+
let rules = [];
|
|
127
|
+
try {
|
|
128
|
+
rules = parseGitignore(await readFile(path.join(root, ".gitignore"), "utf8"));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// no .gitignore: only the fixed layer applies
|
|
132
|
+
}
|
|
133
|
+
const files = [];
|
|
134
|
+
const skipped = [];
|
|
135
|
+
async function walk(directory, prefix) {
|
|
136
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
137
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
140
|
+
const absolute = path.join(directory, entry.name);
|
|
141
|
+
if (entry.isSymbolicLink()) {
|
|
142
|
+
skipped.push({ path: relative, reason: "symbolic link, not sent" });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (entry.isDirectory()) {
|
|
146
|
+
if (SKIPPED_FOLDERS.has(entry.name))
|
|
147
|
+
continue;
|
|
148
|
+
if (isIgnored(rules, relative, true))
|
|
149
|
+
continue;
|
|
150
|
+
await walk(absolute, relative);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!entry.isFile()) {
|
|
154
|
+
skipped.push({ path: relative, reason: "not a regular file, not sent" });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (LITTER.has(entry.name))
|
|
158
|
+
continue;
|
|
159
|
+
const forbidden = forbiddenReason(entry.name);
|
|
160
|
+
if (forbidden) {
|
|
161
|
+
skipped.push({ path: relative, reason: forbidden });
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (isIgnored(rules, relative, false))
|
|
165
|
+
continue;
|
|
166
|
+
const info = await lstat(absolute);
|
|
167
|
+
files.push({
|
|
168
|
+
path: relative,
|
|
169
|
+
absolute,
|
|
170
|
+
size: info.size,
|
|
171
|
+
mode: info.mode & 0o111 ? 0o755 : 0o644,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
await walk(root, "");
|
|
176
|
+
return { files, skipped };
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,gEAAgE;AAChE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;A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AAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;aACxC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cross-process lock around an OAuth token refresh.
|
|
3
|
+
*
|
|
4
|
+
* Why it exists: rotating a refresh token makes the previous one worthless. An
|
|
5
|
+
* agent that runs two `atelier201` commands in parallel as the access token
|
|
6
|
+
* expires used to send the same refresh token twice, and the second request
|
|
7
|
+
* lost. (The server no longer revokes the connection for that, but the loser
|
|
8
|
+
* still had no token.) With the lock, the second process waits, re-reads the
|
|
9
|
+
* credential the first one saved, and uses it without a request of its own.
|
|
10
|
+
*
|
|
11
|
+
* The lock is a file created with the exclusive flag (`wx`), which the
|
|
12
|
+
* operating system makes atomic, so it needs no dependency and works on every
|
|
13
|
+
* platform the CLI supports. A lock older than `staleMs` belongs to a process
|
|
14
|
+
* that died holding it and is taken over. If the lock cannot be had within
|
|
15
|
+
* `timeoutMs` the work runs anyway: blocking an unattended caller is worse than
|
|
16
|
+
* the race this prevents, and the server-side grace window and the re-read
|
|
17
|
+
* after a failed refresh cover that case.
|
|
18
|
+
*/
|
|
19
|
+
import { promises as fs } from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
const DEFAULTS = { timeoutMs: 20_000, staleMs: 45_000, pollMs: 100 };
|
|
22
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
23
|
+
async function tryCreate(lockPath) {
|
|
24
|
+
try {
|
|
25
|
+
const handle = await fs.open(lockPath, "wx", 0o600);
|
|
26
|
+
await handle.writeFile(`${process.pid} ${Date.now()}\n`);
|
|
27
|
+
await handle.close();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === "EEXIST")
|
|
32
|
+
return false;
|
|
33
|
+
// The directory is missing: the credential store has not been created yet.
|
|
34
|
+
if (error.code === "ENOENT") {
|
|
35
|
+
await fs.mkdir(path.dirname(lockPath), { recursive: true, mode: 0o700 });
|
|
36
|
+
return tryCreate(lockPath);
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function isStale(lockPath, staleMs, now) {
|
|
42
|
+
try {
|
|
43
|
+
const stat = await fs.stat(lockPath);
|
|
44
|
+
return now - stat.mtimeMs > staleMs;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Gone between the failed create and now: free to take.
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Runs `work` while holding the lock at `lockPath`. */
|
|
52
|
+
export async function withRefreshLock(lockPath, work, options = {}) {
|
|
53
|
+
const { timeoutMs, staleMs, pollMs } = { ...DEFAULTS, ...options };
|
|
54
|
+
const sleep = options.sleep ?? delay;
|
|
55
|
+
const now = options.now ?? Date.now;
|
|
56
|
+
const deadline = now() + timeoutMs;
|
|
57
|
+
let held = false;
|
|
58
|
+
try {
|
|
59
|
+
for (;;) {
|
|
60
|
+
if (await tryCreate(lockPath)) {
|
|
61
|
+
held = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
if (await isStale(lockPath, staleMs, now())) {
|
|
65
|
+
await fs.rm(lockPath, { force: true });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (now() >= deadline)
|
|
69
|
+
break;
|
|
70
|
+
await sleep(pollMs);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// A read-only or unwritable config directory: no lock, same as a timeout.
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
return await work();
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (held)
|
|
81
|
+
await fs.rm(lockPath, { force: true }).catch(() => undefined);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=refresh-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-lock.js","sourceRoot":"","sources":["../src/refresh-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAY7B,MAAM,QAAQ,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAErE,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEtF,KAAK,UAAU,SAAS,CAAC,QAAgB;IACvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACpD,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACzD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QACrE,2EAA2E;QAC3E,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAA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AC7B,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;IAC5E,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;YAAS,CAAC;QACT,IAAI,IAAI;YAAE,MAAM,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC"}
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single error boundary.
|
|
3
|
+
*
|
|
4
|
+
* Every command body runs inside `run()`, so there is exactly one place that
|
|
5
|
+
* decides how a failure is printed and which exit code it produces. A command
|
|
6
|
+
* that wants to fail simply throws.
|
|
7
|
+
*/
|
|
8
|
+
import readline from "node:readline";
|
|
9
|
+
import { CliError, forceRequired, toErrorReport, visibleYesRequired, spendYesRequired, } from "./errors.js";
|
|
10
|
+
import { EXIT } from "./exit-codes.js";
|
|
11
|
+
import { createPrinter, resolveOutput } from "./output.js";
|
|
12
|
+
import { createSession } from "./session.js";
|
|
13
|
+
/**
|
|
14
|
+
* Commands whose `--output` means the display mode. A download command owns a
|
|
15
|
+
* `--output <path>` of its own (that is the flag people expect for "write it
|
|
16
|
+
* here"), so its value must never be read as a display mode.
|
|
17
|
+
*/
|
|
18
|
+
export const OWNS_GLOBAL_OUTPUT_FLAG = new WeakSet();
|
|
19
|
+
/**
|
|
20
|
+
* A command that has subcommands AND an action of its own (`atelier201 publish`
|
|
21
|
+
* publishes; `atelier201 publish rollback` rolls back). The global flags are added
|
|
22
|
+
* to leaves, so such a command is registered here to receive them too.
|
|
23
|
+
*/
|
|
24
|
+
export const HAS_OWN_ACTION = new WeakSet();
|
|
25
|
+
/**
|
|
26
|
+
* Global flags are declared on the root *and* on every leaf, so both
|
|
27
|
+
* `atelier201 --json sites list` and `atelier201 sites list --json` work. This walks
|
|
28
|
+
* the chain root-to-leaf and merges them.
|
|
29
|
+
*
|
|
30
|
+
* `--no-retry` is merged specially: commander gives a negated option a default
|
|
31
|
+
* of `true`, so a leaf's untouched default would otherwise silently cancel a
|
|
32
|
+
* `--no-retry` typed before the subcommand. Any `false` anywhere wins.
|
|
33
|
+
*/
|
|
34
|
+
export function collectGlobalOptions(command) {
|
|
35
|
+
const chain = [];
|
|
36
|
+
for (let node = command; node; node = node.parent)
|
|
37
|
+
chain.push(node);
|
|
38
|
+
chain.reverse();
|
|
39
|
+
const merged = {};
|
|
40
|
+
for (const node of chain) {
|
|
41
|
+
const options = node.opts();
|
|
42
|
+
if (options.output !== undefined && OWNS_GLOBAL_OUTPUT_FLAG.has(node)) {
|
|
43
|
+
merged.output = options.output;
|
|
44
|
+
}
|
|
45
|
+
if (options.json !== undefined)
|
|
46
|
+
merged.json = options.json;
|
|
47
|
+
if (options.profile !== undefined)
|
|
48
|
+
merged.profile = options.profile;
|
|
49
|
+
if (options.retry === false)
|
|
50
|
+
merged.retry = false;
|
|
51
|
+
if (options.timeout !== undefined)
|
|
52
|
+
merged.timeout = options.timeout;
|
|
53
|
+
}
|
|
54
|
+
return merged;
|
|
55
|
+
}
|
|
56
|
+
export async function run(command, handler) {
|
|
57
|
+
let session;
|
|
58
|
+
try {
|
|
59
|
+
session = createSession(collectGlobalOptions(command));
|
|
60
|
+
await handler(session);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof SilentAbort) {
|
|
64
|
+
// The person answered "no" at a confirmation prompt. That is not a failure.
|
|
65
|
+
process.exitCode = EXIT.OK;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const { envelope, exitCode } = toErrorReport(error);
|
|
69
|
+
const printer = session?.printer ??
|
|
70
|
+
createPrinter(resolveOutput({}, { env: process.env, stdoutIsTTY: Boolean(process.stdout.isTTY) }));
|
|
71
|
+
printer.error(envelope);
|
|
72
|
+
process.exitCode = exitCode;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** `{ data, request_id }` → `data`. Tolerates a bare payload for robustness. */
|
|
76
|
+
export function unwrap(body) {
|
|
77
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
78
|
+
return body.data;
|
|
79
|
+
}
|
|
80
|
+
return body;
|
|
81
|
+
}
|
|
82
|
+
export function paginationOf(body) {
|
|
83
|
+
const record = (body ?? {});
|
|
84
|
+
return {
|
|
85
|
+
has_more: record.has_more === true,
|
|
86
|
+
next_cursor: typeof record.next_cursor === "string" ? record.next_cursor : null,
|
|
87
|
+
limit: typeof record.limit === "number" ? record.limit : null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Follows `next_cursor` until a list is exhausted, for `--all`.
|
|
92
|
+
*
|
|
93
|
+
* `ndjson` mode wants every row printed as it arrives rather than held in
|
|
94
|
+
* memory until the last page lands — pass `onPage` for that. Table and JSON
|
|
95
|
+
* mode want the whole set at once, which is the return value.
|
|
96
|
+
*
|
|
97
|
+
* Capped at `maxPages` (200, ~20,000 rows at the max page size) as a backstop
|
|
98
|
+
* against a cursor that never terminates; a real account is expected to hit
|
|
99
|
+
* `has_more: false` long before that.
|
|
100
|
+
*/
|
|
101
|
+
export async function collectPages(fetchPage, options = {}) {
|
|
102
|
+
const maxPages = options.maxPages ?? 200;
|
|
103
|
+
const all = [];
|
|
104
|
+
let cursor = options.startCursor;
|
|
105
|
+
for (let page = 0; page < maxPages; page++) {
|
|
106
|
+
const result = await fetchPage(cursor);
|
|
107
|
+
all.push(...result.rows);
|
|
108
|
+
options.onPage?.(result.rows, page);
|
|
109
|
+
if (!result.has_more || !result.next_cursor)
|
|
110
|
+
return { rows: all, pages: page + 1 };
|
|
111
|
+
cursor = result.next_cursor;
|
|
112
|
+
}
|
|
113
|
+
throw new CliError(`Stopped after fetching ${maxPages} pages with --all, that is an unusually large result set. Narrow the filters, or page manually with --cursor.`, { exitCode: EXIT.API_ERROR, code: "internal_error", type: "api_error" });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Destructive commands ask before acting. When there is no terminal to ask,
|
|
117
|
+
* they fail with an error naming `--force` rather than hanging on a prompt
|
|
118
|
+
* nobody will ever answer — that hang is the classic way an agent burns a
|
|
119
|
+
* timeout budget.
|
|
120
|
+
*/
|
|
121
|
+
export async function confirmDestructive(session, question, options) {
|
|
122
|
+
if (options.force)
|
|
123
|
+
return;
|
|
124
|
+
if (!session.canPrompt || !session.printer.resolution.interactive) {
|
|
125
|
+
throw forceRequired(options.command);
|
|
126
|
+
}
|
|
127
|
+
const answer = await ask(`${question} [y/N] `);
|
|
128
|
+
if (!/^y(es)?$/i.test(answer.trim())) {
|
|
129
|
+
session.printer.note("Cancelled.");
|
|
130
|
+
process.exitCode = EXIT.OK;
|
|
131
|
+
throw new SilentAbort();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The same gate for a command that changes what a site's visitors see. `--yes`
|
|
136
|
+
* skips the question and is required when there is no terminal. Declining
|
|
137
|
+
* changes nothing and exits 0.
|
|
138
|
+
*/
|
|
139
|
+
export async function confirmVisible(session, question, options) {
|
|
140
|
+
if (options.yes)
|
|
141
|
+
return;
|
|
142
|
+
if (!session.canPrompt || !session.printer.resolution.interactive) {
|
|
143
|
+
throw visibleYesRequired(options.command);
|
|
144
|
+
}
|
|
145
|
+
const answer = await ask(`${question} [y/N] `);
|
|
146
|
+
if (!/^y(es)?$/i.test(answer.trim())) {
|
|
147
|
+
session.printer.note("Cancelled. Nothing changed.");
|
|
148
|
+
process.exitCode = EXIT.OK;
|
|
149
|
+
throw new SilentAbort();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The same gate for a command that spends credits. The price is shown first; `--yes` accepts it
|
|
154
|
+
* and is required when there is no terminal. Declining spends nothing and exits 0.
|
|
155
|
+
*/
|
|
156
|
+
export async function confirmSpend(session, question, options) {
|
|
157
|
+
if (options.yes)
|
|
158
|
+
return;
|
|
159
|
+
if (!session.canPrompt || !session.printer.resolution.interactive) {
|
|
160
|
+
throw spendYesRequired(options.command);
|
|
161
|
+
}
|
|
162
|
+
const answer = await ask(`${question} [y/N] `);
|
|
163
|
+
if (!/^y(es)?$/i.test(answer.trim())) {
|
|
164
|
+
session.printer.note("Cancelled. Nothing was charged.");
|
|
165
|
+
process.exitCode = EXIT.OK;
|
|
166
|
+
throw new SilentAbort();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Thrown after a user-cancelled confirmation; produces no output and exit 0. */
|
|
170
|
+
export class SilentAbort extends Error {
|
|
171
|
+
exitCode = EXIT.OK;
|
|
172
|
+
constructor() {
|
|
173
|
+
super("cancelled");
|
|
174
|
+
this.name = "SilentAbort";
|
|
175
|
+
}
|
|
176
|
+
toEnvelope() {
|
|
177
|
+
return {
|
|
178
|
+
error: {
|
|
179
|
+
type: "invalid_request_error",
|
|
180
|
+
code: "invalid_request",
|
|
181
|
+
message: "Cancelled.",
|
|
182
|
+
docs_url: "https://atelier201.com/docs/api/errors#invalid_request",
|
|
183
|
+
},
|
|
184
|
+
request_id: null,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function ask(prompt) {
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
191
|
+
rl.question(prompt, (answer) => {
|
|
192
|
+
rl.close();
|
|
193
|
+
resolve(answer);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,QAAQ,MAAM,eAAe,CAAC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AAE,EAAE;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YAC7B,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-invocation context: which profile, which credential, which output
|
|
3
|
+
* mode, and a ready-to-use API client.
|
|
4
|
+
*
|
|
5
|
+
* Every command receives one of these, so no command reads `process.env` or
|
|
6
|
+
* decides on its own how to print a failure.
|
|
7
|
+
*/
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { clearCredential, configDir, loadCredential, resolveProfile, saveCredential, } from "./credentials.js";
|
|
10
|
+
import { CliError, notAuthenticated } from "./errors.js";
|
|
11
|
+
import { ApiClient } from "./http.js";
|
|
12
|
+
import { createPrinter, resolveOutput } from "./output.js";
|
|
13
|
+
import { AuthServer, defaultEndpoints } from "./oauth/server.js";
|
|
14
|
+
import { withRefreshLock } from "./refresh-lock.js";
|
|
15
|
+
import { apiBaseUrl, apiOrigin, authBaseUrl, mcpBaseUrl } from "./version.js";
|
|
16
|
+
/**
|
|
17
|
+
* A hung request is the worst outcome for an unattended caller: it produces no
|
|
18
|
+
* output at all and burns the whole budget of whatever is waiting on it. The
|
|
19
|
+
* ceiling exists so `--timeout 0` or a typo cannot switch that protection off.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveTimeoutMs(value) {
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
const seconds = Number(value);
|
|
25
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
26
|
+
throw new CliError(`--timeout expects a positive number of seconds, got '${value}'.`, { code: "invalid_parameter", param: "timeout" });
|
|
27
|
+
}
|
|
28
|
+
return Math.round(seconds * 1000);
|
|
29
|
+
}
|
|
30
|
+
/** An access token is used as long as it has at least this much life left. */
|
|
31
|
+
const EXPIRY_MARGIN_MS = 60_000;
|
|
32
|
+
const isFresh = (record) => !record.expires_at || record.expires_at - Date.now() > EXPIRY_MARGIN_MS;
|
|
33
|
+
export function createSession(options, env = process.env, deps = {}) {
|
|
34
|
+
const resolution = resolveOutput(options, {
|
|
35
|
+
env,
|
|
36
|
+
stdoutIsTTY: Boolean(process.stdout.isTTY),
|
|
37
|
+
});
|
|
38
|
+
const printer = createPrinter(resolution);
|
|
39
|
+
const profile = resolveProfile(options.profile, env);
|
|
40
|
+
let cachedCredential;
|
|
41
|
+
const credentialDeps = { ...deps.credentials, env };
|
|
42
|
+
const peekCredential = async () => {
|
|
43
|
+
if (cachedCredential === undefined) {
|
|
44
|
+
cachedCredential = await loadCredential(profile, credentialDeps);
|
|
45
|
+
}
|
|
46
|
+
return cachedCredential;
|
|
47
|
+
};
|
|
48
|
+
const authServer = deps.authServer ?? new AuthServer(authBaseUrl(env));
|
|
49
|
+
const requireToken = async () => {
|
|
50
|
+
const resolved = await peekCredential();
|
|
51
|
+
if (!resolved)
|
|
52
|
+
throw notAuthenticated();
|
|
53
|
+
if (resolved.record.kind === "api_key") {
|
|
54
|
+
return { token: resolved.record.api_key, source: resolved.source, kind: "api_key" };
|
|
55
|
+
}
|
|
56
|
+
if (isFresh(resolved.record)) {
|
|
57
|
+
return { token: resolved.record.access_token, source: resolved.source, kind: "oauth" };
|
|
58
|
+
}
|
|
59
|
+
if (!resolved.record.refresh_token)
|
|
60
|
+
throw notAuthenticated();
|
|
61
|
+
// Refreshing rotates the refresh token, so two processes refreshing at the
|
|
62
|
+
// same time cannot both win. One at a time, and whoever comes second finds
|
|
63
|
+
// the credential the first already saved.
|
|
64
|
+
const lockPath = path.join(configDir(env), `refresh-${profile.replace(/[^A-Za-z0-9._-]/g, "_")}.lock`);
|
|
65
|
+
return withRefreshLock(lockPath, () => refreshStored(resolved), deps.lock);
|
|
66
|
+
};
|
|
67
|
+
/** Called with the refresh lock held (or after it timed out). */
|
|
68
|
+
const refreshStored = async (seen) => {
|
|
69
|
+
let current = seen;
|
|
70
|
+
// At most one retry: the second pass exists only for "another process
|
|
71
|
+
// rotated the token while this request was in flight".
|
|
72
|
+
for (let attempt = 0;; attempt++) {
|
|
73
|
+
// Re-read: the process holding the lock before us may have refreshed.
|
|
74
|
+
const latest = await loadCredential(profile, credentialDeps);
|
|
75
|
+
if (latest && latest.record.kind === "oauth") {
|
|
76
|
+
current = latest;
|
|
77
|
+
cachedCredential = latest;
|
|
78
|
+
}
|
|
79
|
+
const record = current.record;
|
|
80
|
+
if (record.kind !== "oauth")
|
|
81
|
+
throw notAuthenticated();
|
|
82
|
+
if (isFresh(record)) {
|
|
83
|
+
return { token: record.access_token, source: current.source, kind: "oauth" };
|
|
84
|
+
}
|
|
85
|
+
if (!record.refresh_token)
|
|
86
|
+
throw notAuthenticated();
|
|
87
|
+
const tokenEndpoint = record.token_endpoint ?? defaultEndpoints(authBaseUrl(env)).token_endpoint;
|
|
88
|
+
let refreshed;
|
|
89
|
+
try {
|
|
90
|
+
refreshed = await authServer.refresh(tokenEndpoint, record.refresh_token);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof CliError && error.code === "api_key_revoked") {
|
|
94
|
+
// `invalid_grant` is either a real revocation or the loser of a race:
|
|
95
|
+
// another process rotated the token between our read and our request.
|
|
96
|
+
// The store tells them apart, because the winner saved a new refresh
|
|
97
|
+
// token before releasing the lock.
|
|
98
|
+
const after = await loadCredential(profile, credentialDeps);
|
|
99
|
+
const rotatedByAnother = after?.record.kind === "oauth" &&
|
|
100
|
+
after.record.refresh_token !== undefined &&
|
|
101
|
+
after.record.refresh_token !== record.refresh_token;
|
|
102
|
+
if (rotatedByAnother && attempt === 0)
|
|
103
|
+
continue;
|
|
104
|
+
// A revoked or expired grant can never be refreshed again, so keeping
|
|
105
|
+
// it on disk leaves every later command retrying the same doomed
|
|
106
|
+
// request and reporting a confusing failure. Dropping it makes `auth
|
|
107
|
+
// status` tell the truth and turns the next command into a plain
|
|
108
|
+
// "not logged in".
|
|
109
|
+
await clearCredential(profile, credentialDeps);
|
|
110
|
+
cachedCredential = null;
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
const updated = {
|
|
115
|
+
...record,
|
|
116
|
+
access_token: refreshed.access_token,
|
|
117
|
+
refresh_token: refreshed.refresh_token ?? record.refresh_token,
|
|
118
|
+
expires_at: refreshed.expires_in ? Date.now() + refreshed.expires_in * 1000 : undefined,
|
|
119
|
+
};
|
|
120
|
+
await saveCredential(profile, updated, credentialDeps);
|
|
121
|
+
cachedCredential = { ...current, record: updated };
|
|
122
|
+
return { token: refreshed.access_token, source: current.source, kind: "oauth" };
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const client = new ApiClient({
|
|
126
|
+
baseUrl: apiBaseUrl(env),
|
|
127
|
+
getToken: async () => (await requireToken()).token,
|
|
128
|
+
retry: options.retry !== false,
|
|
129
|
+
timeoutMs: resolveTimeoutMs(options.timeout),
|
|
130
|
+
onNotice: (message) => printer.warn(message),
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
profile,
|
|
134
|
+
printer,
|
|
135
|
+
apiUrl: apiBaseUrl(env),
|
|
136
|
+
apiOrigin: apiOrigin(env),
|
|
137
|
+
authUrl: authBaseUrl(env),
|
|
138
|
+
mcpUrl: mcpBaseUrl(env),
|
|
139
|
+
env,
|
|
140
|
+
requireToken,
|
|
141
|
+
peekCredential,
|
|
142
|
+
client,
|
|
143
|
+
authServer,
|
|
144
|
+
canPrompt: Boolean(process.stdin.isTTY),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=session.js.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