@cultured_computer/sight 0.8.0 → 0.8.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/CHANGELOG.md +33 -0
- package/README.md +182 -584
- package/dist/cli.js +42 -74
- package/dist/index.cjs +301 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -313
- package/dist/index.d.ts +286 -313
- package/dist/index.js +301 -275
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { exec } from "child_process";
|
|
|
5
5
|
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
6
6
|
import { homedir } from "os";
|
|
7
7
|
import { dirname, join } from "path";
|
|
8
|
-
var DEFAULT_API = "https://
|
|
8
|
+
var DEFAULT_API = "https://api.cultured.computer";
|
|
9
9
|
function flag(args, name) {
|
|
10
10
|
const i = args.indexOf(name);
|
|
11
11
|
return i === -1 ? null : args[i + 1] ?? null;
|
|
@@ -13,7 +13,7 @@ function flag(args, name) {
|
|
|
13
13
|
function usage() {
|
|
14
14
|
console.log(
|
|
15
15
|
[
|
|
16
|
-
"sight: the command line for Sight.
|
|
16
|
+
"sight: the command line for Sight.",
|
|
17
17
|
"",
|
|
18
18
|
"Usage:",
|
|
19
19
|
" sight auth login [--base <dashboard-url>]",
|
|
@@ -26,57 +26,26 @@ function usage() {
|
|
|
26
26
|
" sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
|
|
27
27
|
"",
|
|
28
28
|
"Commands:",
|
|
29
|
-
" auth login
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
" checked sentence, flagged / not flagged /",
|
|
38
|
-
" not checked.",
|
|
39
|
-
" --out <file> write to a file (default: stdout).",
|
|
40
|
-
" conditions pull one session\u2019s (or one run\u2019s) detector checks with",
|
|
41
|
-
" the machine key: NDJSON to stdout, errors to stderr.",
|
|
42
|
-
" account create redeem SIGHT_PROVISION_TOKEN without a browser and save",
|
|
43
|
-
" the scoped Sight key at ~/.config/sight/machine.json",
|
|
44
|
-
" (0600). Add --openrouter --budget <usd> to also",
|
|
45
|
-
" validate and store OPENROUTER_API_KEY.",
|
|
46
|
-
" openrouter connect attach or rotate your own OpenRouter key; requires a",
|
|
47
|
-
" positive monthly --budget and a Sight key with",
|
|
48
|
-
" providers:write.",
|
|
49
|
-
" openrouter status print the stored provider connection: status, last",
|
|
50
|
-
" four characters of the key, monthly budget.",
|
|
51
|
-
" connect attach Sight to a buzz community as a read-only",
|
|
52
|
-
" observer. No account needed.",
|
|
53
|
-
" --invite one single-use invite code, minted by you on",
|
|
54
|
-
" your relay (its admin surface, or",
|
|
55
|
-
" POST /api/invites as the community owner).",
|
|
56
|
-
" Sight can never enter a community you did",
|
|
57
|
-
" not invite it into.",
|
|
58
|
-
" --pulse opt into the daily readout (off by default;",
|
|
59
|
-
" counts, times, and links only).",
|
|
29
|
+
" auth login Sign this terminal in: approve the printed link in your browser.",
|
|
30
|
+
" auth logout Delete the stored login token.",
|
|
31
|
+
" export Write a deployment's record (or --readings, --conditions) as JSONL. Needs auth login, owner role.",
|
|
32
|
+
" conditions Print a session's or a run's detector checks as NDJSON. Needs a key with studio:run.",
|
|
33
|
+
" account create Redeem SIGHT_PROVISION_TOKEN; save the key to ~/.config/sight/machine.json (0600).",
|
|
34
|
+
" openrouter connect Connect your OpenRouter key with a monthly USD budget. Needs a key with providers:write.",
|
|
35
|
+
" openrouter status Print the stored OpenRouter connection: status, last four characters, budget.",
|
|
36
|
+
" connect Connect a relay as a read-only observer, with a single-use invite code.",
|
|
60
37
|
"",
|
|
61
38
|
"Environment:",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
" SIGHT_BASE
|
|
67
|
-
"
|
|
68
|
-
" overrides it. export uses the base stored at login.",
|
|
69
|
-
" SIGHT_API_KEY Sight key for openrouter and conditions; overrides",
|
|
70
|
-
" the key stored in machine.json.",
|
|
71
|
-
" SIGHT_PROVISION_TOKEN one-time token redeemed by account create.",
|
|
72
|
-
" OPENROUTER_API_KEY your OpenRouter key, read by account create",
|
|
73
|
-
" --openrouter and openrouter connect. Never printed.",
|
|
39
|
+
" SIGHT_API_KEY Sight key for conditions and openrouter. Default: the key saved by account create.",
|
|
40
|
+
" SIGHT_PROVISION_TOKEN One-time token redeemed by account create.",
|
|
41
|
+
" OPENROUTER_API_KEY Your OpenRouter key, for account create --openrouter and openrouter connect.",
|
|
42
|
+
" SIGHT_API API base for account create, openrouter, connect. Default https://api.cultured.computer",
|
|
43
|
+
" SIGHT_BASE Dashboard base for auth login and conditions. Default https://sight.cultured.computer",
|
|
44
|
+
" XDG_CONFIG_HOME Directory for the stored login and key files. Default ~/.config",
|
|
74
45
|
"",
|
|
75
|
-
"
|
|
76
|
-
"https://sight.cultured.computer/docs/
|
|
77
|
-
""
|
|
78
|
-
"The capture SDK in this package (server-side Node >=20.6) is documented at",
|
|
79
|
-
"https://sight.cultured.computer/docs"
|
|
46
|
+
"Docs:",
|
|
47
|
+
" CLI https://sight.cultured.computer/docs/cli",
|
|
48
|
+
" SDK https://sight.cultured.computer/docs"
|
|
80
49
|
].join("\n")
|
|
81
50
|
);
|
|
82
51
|
}
|
|
@@ -91,9 +60,8 @@ async function connect(args) {
|
|
|
91
60
|
if (!invite) {
|
|
92
61
|
console.error(
|
|
93
62
|
[
|
|
94
|
-
"connect needs --invite <code>: one single-use invite
|
|
95
|
-
"
|
|
96
|
-
"This stays manual on purpose: your community, your authority."
|
|
63
|
+
"connect needs --invite <code>: one single-use invite code that you create.",
|
|
64
|
+
"Create it on your relay: its admin page, or POST /api/invites as the owner."
|
|
97
65
|
].join("\n")
|
|
98
66
|
);
|
|
99
67
|
return 1;
|
|
@@ -117,16 +85,16 @@ async function connect(args) {
|
|
|
117
85
|
if (body["status"] === "already-connected") {
|
|
118
86
|
console.log(`this relay is already connected. ${body["note"] ?? ""}`);
|
|
119
87
|
console.log(`deployment: ${body["deploymentSlug"]}`);
|
|
120
|
-
if (body["claimUrl"]) console.log(`claim
|
|
88
|
+
if (body["claimUrl"]) console.log(`claim link: ${body["claimUrl"]}`);
|
|
121
89
|
return 0;
|
|
122
90
|
}
|
|
123
|
-
console.log("connected.
|
|
91
|
+
console.log("connected. Sight now reads this relay as a read-only observer.");
|
|
124
92
|
console.log(` deployment: ${body["deploymentSlug"]}`);
|
|
125
93
|
console.log(` first sync: ${body["firstSync"]}`);
|
|
126
|
-
console.log(`
|
|
94
|
+
console.log(` daily pulse: ${body["pulse"]} ${body["pulse"] === "off" ? "(re-run with --pulse, or turn it on after claiming)" : ""}`);
|
|
127
95
|
console.log("");
|
|
128
|
-
console.log("
|
|
129
|
-
console.log("
|
|
96
|
+
console.log("The recorded sessions become yours when you open the claim link.");
|
|
97
|
+
console.log("Keep this link, it is the only copy:");
|
|
130
98
|
console.log(` ${body["claimUrl"]}`);
|
|
131
99
|
return 0;
|
|
132
100
|
}
|
|
@@ -225,7 +193,7 @@ async function connectOpenRouter(api, sightKey, args) {
|
|
|
225
193
|
return 1;
|
|
226
194
|
}
|
|
227
195
|
const body = await response.json();
|
|
228
|
-
console.log(`OpenRouter connected (
|
|
196
|
+
console.log(`OpenRouter connected (key ending ${String(body["last4"] ?? "")}); monthly budget: $${budget}.`);
|
|
229
197
|
return 0;
|
|
230
198
|
}
|
|
231
199
|
async function account(args) {
|
|
@@ -267,7 +235,7 @@ async function account(args) {
|
|
|
267
235
|
console.log(`capabilities: ${body.capabilities.join(", ") || "none"}`);
|
|
268
236
|
if (!args.includes("--openrouter")) return 0;
|
|
269
237
|
if (!body.capabilities.includes("providers:write")) {
|
|
270
|
-
console.error(
|
|
238
|
+
console.error('The Sight key was saved, but connecting OpenRouter requires providers:write. Ask the project owner for a key with access "manage", set it as SIGHT_API_KEY, then run: sight openrouter connect --budget <usd>');
|
|
271
239
|
return 1;
|
|
272
240
|
}
|
|
273
241
|
const connected = await connectOpenRouter(api, body.key, args);
|
|
@@ -279,14 +247,14 @@ async function account(args) {
|
|
|
279
247
|
async function openrouter(args) {
|
|
280
248
|
const sub = args[0];
|
|
281
249
|
if (sub !== "connect" && sub !== "status") {
|
|
282
|
-
console.error("usage: sight openrouter connect --budget <usd> [--api <base>]
|
|
250
|
+
console.error("usage: sight openrouter connect --budget <usd> [--api <base>] | sight openrouter status [--api <base>]");
|
|
283
251
|
return 1;
|
|
284
252
|
}
|
|
285
253
|
const stored = readMachineCredentials();
|
|
286
254
|
const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
|
|
287
255
|
const api = (flag(args, "--api") ?? process.env["SIGHT_API"] ?? stored?.api ?? DEFAULT_API).replace(/\/+$/, "");
|
|
288
256
|
if (!sightKey) {
|
|
289
|
-
console.error("No
|
|
257
|
+
console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
|
|
290
258
|
return 1;
|
|
291
259
|
}
|
|
292
260
|
if (sub === "connect") return connectOpenRouter(api, sightKey, args);
|
|
@@ -300,7 +268,7 @@ async function openrouter(args) {
|
|
|
300
268
|
return 1;
|
|
301
269
|
}
|
|
302
270
|
const body = await response.json();
|
|
303
|
-
console.log(`OpenRouter ${body["status"]} (
|
|
271
|
+
console.log(`OpenRouter ${body["status"]} (key ending ${String(body["last4"] ?? "")}); monthly budget: $${body["monthlyBudgetUsd"]}.`);
|
|
304
272
|
return 0;
|
|
305
273
|
}
|
|
306
274
|
function openBrowser(url) {
|
|
@@ -313,14 +281,14 @@ async function auth(args) {
|
|
|
313
281
|
if (sub === "logout") {
|
|
314
282
|
try {
|
|
315
283
|
rmSync(credentialsPath());
|
|
316
|
-
console.log("signed out
|
|
284
|
+
console.log("signed out. The local token is deleted; the session it held stays valid until it expires.");
|
|
317
285
|
} catch {
|
|
318
286
|
console.log("nothing to sign out of.");
|
|
319
287
|
}
|
|
320
288
|
return 0;
|
|
321
289
|
}
|
|
322
290
|
if (sub !== "login") {
|
|
323
|
-
console.error("usage: sight auth login [--base <dashboard-url>]
|
|
291
|
+
console.error("usage: sight auth login [--base <dashboard-url>] | sight auth logout");
|
|
324
292
|
return 1;
|
|
325
293
|
}
|
|
326
294
|
const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
|
|
@@ -330,7 +298,7 @@ async function auth(args) {
|
|
|
330
298
|
body: JSON.stringify({ client_id: CLIENT_ID })
|
|
331
299
|
}).catch((err) => ({ __err: err }));
|
|
332
300
|
if (!codeRes || !codeRes.ok) {
|
|
333
|
-
console.error(`could not start the login at ${base}
|
|
301
|
+
console.error(`could not start the login at ${base}. Check the URL (--base or SIGHT_BASE) and your network.`);
|
|
334
302
|
return 1;
|
|
335
303
|
}
|
|
336
304
|
const grant = await codeRes.json();
|
|
@@ -345,7 +313,7 @@ async function auth(args) {
|
|
|
345
313
|
const deadline = Date.now() + (grant.expires_in ?? 300) * 1e3;
|
|
346
314
|
for (; ; ) {
|
|
347
315
|
if (Date.now() > deadline) {
|
|
348
|
-
console.error("the code expired
|
|
316
|
+
console.error("the code expired. Run sight auth login again.");
|
|
349
317
|
return 1;
|
|
350
318
|
}
|
|
351
319
|
await sleep(intervalMs);
|
|
@@ -362,21 +330,21 @@ async function auth(args) {
|
|
|
362
330
|
if (poll.ok) {
|
|
363
331
|
const body = await poll.json();
|
|
364
332
|
if (!body.access_token) {
|
|
365
|
-
console.error("the server answered without a token
|
|
333
|
+
console.error("the server answered without a token. Run sight auth login again.");
|
|
366
334
|
return 1;
|
|
367
335
|
}
|
|
368
336
|
writeCredentials(body.access_token, base);
|
|
369
337
|
console.log(`signed in. token stored at ${credentialsPath()} (0600).`);
|
|
370
|
-
console.log(`try: sight export --project <slug> --deployment <slug> --out
|
|
338
|
+
console.log(`try: sight export --project <slug> --deployment <slug> --out record.jsonl`);
|
|
371
339
|
return 0;
|
|
372
340
|
}
|
|
373
341
|
const err = await poll.json().catch(() => ({}));
|
|
374
342
|
if (err.error === "access_denied") {
|
|
375
|
-
console.error("denied
|
|
343
|
+
console.error("the request was denied in the browser; nothing was granted. Run sight auth login again to retry.");
|
|
376
344
|
return 1;
|
|
377
345
|
}
|
|
378
346
|
if (err.error === "expired_token") {
|
|
379
|
-
console.error("the code expired
|
|
347
|
+
console.error("the code expired. Run sight auth login again.");
|
|
380
348
|
return 1;
|
|
381
349
|
}
|
|
382
350
|
}
|
|
@@ -393,7 +361,7 @@ async function exportRecord(args) {
|
|
|
393
361
|
}
|
|
394
362
|
const creds = readCredentials();
|
|
395
363
|
if (!creds) {
|
|
396
|
-
console.error("no stored login
|
|
364
|
+
console.error("no stored login. Run sight auth login first.");
|
|
397
365
|
return 1;
|
|
398
366
|
}
|
|
399
367
|
const kind = conditions2 ? "conditions" : readings ? "readings" : null;
|
|
@@ -404,7 +372,7 @@ async function exportRecord(args) {
|
|
|
404
372
|
if (!res.ok) {
|
|
405
373
|
const status = res.status ?? "unreachable";
|
|
406
374
|
console.error(
|
|
407
|
-
`export failed (${status})
|
|
375
|
+
`export failed (${status}): ${status === 401 || status === 403 ? "the login token is expired, or your role on that project is not owner. Run sight auth login again" : "check the project and deployment slugs"}.`
|
|
408
376
|
);
|
|
409
377
|
return 1;
|
|
410
378
|
}
|
|
@@ -430,7 +398,7 @@ async function conditions(args) {
|
|
|
430
398
|
const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
|
|
431
399
|
const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
|
|
432
400
|
if (!sightKey) {
|
|
433
|
-
console.error("No
|
|
401
|
+
console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
|
|
434
402
|
return 1;
|
|
435
403
|
}
|
|
436
404
|
const params = new URLSearchParams();
|