pontive 0.0.0-stage → 1.17.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.
Files changed (3) hide show
  1. package/README.md +8 -2
  2. package/dist/cli.js +233 -0
  3. package/package.json +25 -4
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # pontive
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Pontive CLI.
4
+
5
+ ```sh
6
+ npx pontive@latest --help
7
+ ```
8
+
9
+ Node.js 20 or later.
package/dist/cli.js ADDED
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { resolve } from "node:path";
4
+ import { spawn } from "node:child_process";
5
+ import { createInterface } from "node:readline/promises";
6
+ const AGENT_VARIABLES = [
7
+ ["CLAUDECODE", "claude-code"],
8
+ ["CURSOR_AGENT", "cursor"],
9
+ ["CODEX_SANDBOX", "codex"],
10
+ ["GEMINI_CLI", "gemini-cli"]
11
+ ];
12
+ function isSet(value) {
13
+ return value !== void 0 && value !== "" && value !== "0" && value.toLowerCase() !== "false";
14
+ }
15
+ function detectAgent(env) {
16
+ for (const [variable, agent] of AGENT_VARIABLES) {
17
+ if (isSet(env[variable])) return agent;
18
+ }
19
+ return void 0;
20
+ }
21
+ function isAgentMode(env, json) {
22
+ return json || detectAgent(env) !== void 0 || isSet(env.CI);
23
+ }
24
+ const ExitCode = {
25
+ /** Done. */
26
+ Success: 0,
27
+ /** Anything else that went wrong. */
28
+ Error: 1,
29
+ /** The user, or a missing `--yes` in agent mode, declined. */
30
+ Cancelled: 2
31
+ };
32
+ class CliError extends Error {
33
+ code;
34
+ exitCode;
35
+ extra;
36
+ constructor(code2, message, exitCode = ExitCode.Error, extra = {}) {
37
+ super(message);
38
+ this.name = "CliError";
39
+ this.code = code2;
40
+ this.exitCode = exitCode;
41
+ this.extra = extra;
42
+ }
43
+ }
44
+ const modules = /* @__PURE__ */ Object.assign({});
45
+ const commands = new Map(
46
+ Object.values(modules).map((m) => m.command).filter((c) => c !== void 0).sort((a, b) => a.name.localeCompare(b.name)).map((c) => [c.name, c])
47
+ );
48
+ const GLOBAL_OPTIONS = {
49
+ json: { type: "boolean" },
50
+ yes: { type: "boolean", short: "y" },
51
+ cwd: { type: "string" },
52
+ help: { type: "boolean", short: "h" }
53
+ };
54
+ const GLOBAL_HELP = `Global options:
55
+ --json Agent mode: no prompts, one JSON object on stdout
56
+ -y, --yes Answer yes to confirmations; lets agent mode write outside its own files
57
+ --cwd <dir> The project directory (default: the current directory)
58
+ -h, --help Show help`;
59
+ function usage(version) {
60
+ const width = Math.max(0, ...[...commands.keys()].map((n) => n.length));
61
+ const list = [...commands.values()].map((c) => ` ${c.name.padEnd(width)} ${c.summary}`).join("\n");
62
+ return `pontive ${version}
63
+
64
+ Usage: pontive <command> [options]
65
+
66
+ Commands:
67
+ ${list}
68
+
69
+ ${GLOBAL_HELP}
70
+
71
+ Agent mode is on when CLAUDECODE, CURSOR_AGENT, CODEX_SANDBOX, GEMINI_CLI or CI is set.
72
+ Exit codes: 0 success, 1 error, 2 cancelled, 3 rate limited, 4 sign-in required,
73
+ 5 the unclaimed instance expired or was claimed away.`;
74
+ }
75
+ async function main(options) {
76
+ const { argv, env, out, version } = options;
77
+ const name = argv[0];
78
+ const wantsJson = argv.includes("--json");
79
+ const agentMode = isAgentMode(env, wantsJson);
80
+ const report = (commandName, error) => {
81
+ const err = error instanceof CliError ? error : options.signal.aborted ? new CliError("cancelled", "Cancelled.", ExitCode.Cancelled) : new CliError("internal_error", error instanceof Error ? error.message : String(error));
82
+ if (agentMode) {
83
+ out.result(JSON.stringify({ ok: false, command: commandName ?? null, error: { code: err.code, message: err.message }, ...err.extra }));
84
+ } else {
85
+ out.info(`error: ${err.message}`);
86
+ }
87
+ return err.exitCode;
88
+ };
89
+ if (name === void 0 || name === "--help" || name === "-h" || name === "help") {
90
+ out.result(usage(version));
91
+ return ExitCode.Success;
92
+ }
93
+ if (name === "--version" || name === "-v") {
94
+ out.result(agentMode ? JSON.stringify({ ok: true, command: "version", version }) : version);
95
+ return ExitCode.Success;
96
+ }
97
+ const command = commands.get(name);
98
+ if (!command) return report(void 0, new CliError("unknown_command", `Unknown command "${name}". Run pontive --help.`));
99
+ let parsed;
100
+ try {
101
+ parsed = parseArgs({
102
+ args: argv.slice(1),
103
+ options: { ...GLOBAL_OPTIONS, ...command.options },
104
+ allowPositionals: command.allowPositionals ?? false,
105
+ strict: true
106
+ });
107
+ } catch (error) {
108
+ return report(name, new CliError("invalid_arguments", error instanceof Error ? error.message : String(error)));
109
+ }
110
+ const { values, positionals } = parsed;
111
+ if (values.help) {
112
+ out.result(`Usage: pontive ${command.name} [options]
113
+
114
+ ${command.summary}
115
+
116
+ ${command.help}
117
+
118
+ ${GLOBAL_HELP}`);
119
+ return ExitCode.Success;
120
+ }
121
+ const ctx = {
122
+ ...options.runtime(agentMode),
123
+ cwd: resolve(options.cwd, typeof values.cwd === "string" ? values.cwd : "."),
124
+ env,
125
+ out,
126
+ agentMode,
127
+ agent: detectAgent(env),
128
+ yes: values.yes === true,
129
+ values,
130
+ positionals,
131
+ signal: options.signal,
132
+ version
133
+ };
134
+ let result;
135
+ try {
136
+ result = await command.run(ctx);
137
+ } catch (error) {
138
+ return report(name, error);
139
+ }
140
+ const exitCode = result.exitCode ?? ExitCode.Success;
141
+ if (agentMode) {
142
+ out.result(JSON.stringify({ ok: exitCode === ExitCode.Success, command: name, ...result.data }));
143
+ } else {
144
+ out.result(result.human.join("\n"));
145
+ }
146
+ return exitCode;
147
+ }
148
+ function streamOutput(stdout, stderr) {
149
+ return {
150
+ info: (message) => void stderr.write(`${message}
151
+ `),
152
+ warn: (message) => void stderr.write(`warning: ${message}
153
+ `),
154
+ result: (text) => void stdout.write(text.endsWith("\n") ? text : `${text}
155
+ `)
156
+ };
157
+ }
158
+ function run(command, args, options) {
159
+ return new Promise((resolve2) => {
160
+ const child = spawn(command, args, {
161
+ cwd: options.cwd,
162
+ // Agent mode keeps stdout for the one JSON object, so a child's output goes to stderr.
163
+ stdio: options.stdio === "inherit" ? "inherit" : ["ignore", process.stderr, process.stderr],
164
+ // npm, pnpm and yarn are .cmd shims on Windows.
165
+ shell: process.platform === "win32"
166
+ });
167
+ child.on("error", () => resolve2(127));
168
+ child.on("close", (code2) => resolve2(code2 ?? 1));
169
+ });
170
+ }
171
+ function hasDisplay(env) {
172
+ if (process.platform === "darwin" || process.platform === "win32") return !env.SSH_CONNECTION;
173
+ return Boolean(env.DISPLAY || env.WAYLAND_DISPLAY);
174
+ }
175
+ function nodeRuntime(agentMode) {
176
+ return {
177
+ fetch: (...args) => fetch(...args),
178
+ interactive: Boolean(process.stdin.isTTY),
179
+ exec: (command, args, options) => run(command, args, { cwd: options.cwd, stdio: agentMode ? "stderr" : "inherit" }),
180
+ async openUrl(url) {
181
+ if (!hasDisplay(process.env)) return false;
182
+ const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", '""', url.replace(/&/g, "^&")]] : ["xdg-open", [url]];
183
+ return new Promise((resolve2) => {
184
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
185
+ child.on("error", () => resolve2(false));
186
+ child.on("spawn", () => {
187
+ child.unref();
188
+ resolve2(true);
189
+ });
190
+ });
191
+ },
192
+ async ask(question) {
193
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
194
+ try {
195
+ const answer = await rl.question(`${question} [y/N] `);
196
+ return /^y(es)?$/i.test(answer.trim());
197
+ } finally {
198
+ rl.close();
199
+ }
200
+ },
201
+ sleep: (ms, signal) => new Promise((resolve2, reject) => {
202
+ if (signal?.aborted) return reject(signal.reason);
203
+ const timer = setTimeout(() => {
204
+ signal?.removeEventListener("abort", onAbort);
205
+ resolve2();
206
+ }, ms);
207
+ const onAbort = () => {
208
+ clearTimeout(timer);
209
+ reject(signal.reason);
210
+ };
211
+ signal?.addEventListener("abort", onAbort, { once: true });
212
+ }),
213
+ now: () => /* @__PURE__ */ new Date()
214
+ };
215
+ }
216
+ const [major] = process.versions.node.split(".").map(Number);
217
+ if (major < 20) {
218
+ process.stderr.write(`pontive needs Node.js 20 or later; this is ${process.versions.node}.
219
+ `);
220
+ process.exit(1);
221
+ }
222
+ const controller = new AbortController();
223
+ process.once("SIGINT", () => controller.abort(new Error("Cancelled.")));
224
+ const code = await main({
225
+ argv: process.argv.slice(2),
226
+ env: process.env,
227
+ cwd: process.cwd(),
228
+ out: streamOutput(process.stdout, process.stderr),
229
+ runtime: nodeRuntime,
230
+ signal: controller.signal,
231
+ version: "1.17.0"
232
+ });
233
+ process.exitCode = code;
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "pontive",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.17.0",
4
+ "license": "MIT",
5
+ "description": "The Pontive CLI: add Pontive sign-in to an app, with or without an account.",
6
+ "type": "module",
7
+ "bin": {
8
+ "pontive": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "engines": {
14
+ "node": ">=20"
15
+ },
16
+ "scripts": {
17
+ "build": "vite build",
18
+ "test": "vitest run",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "jose": "^6.2.3"
26
+ }
27
+ }