@cultured_computer/sight 0.8.0 → 0.8.2
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 +46 -0
- package/README.md +183 -584
- package/dist/cli.js +68 -93
- package/dist/index.cjs +301 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +287 -314
- package/dist/index.d.ts +287 -314
- 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,10 +13,10 @@ 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
|
-
" sight auth login [--base <dashboard-url>]",
|
|
19
|
+
" sight auth login [--base <dashboard-url>] [--no-browser]",
|
|
20
20
|
" sight auth logout",
|
|
21
21
|
" sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]",
|
|
22
22
|
" sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]",
|
|
@@ -26,57 +26,27 @@ 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
|
-
"
|
|
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
|
+
" SIGHT_NO_BROWSER 1 prints the auth login link without opening a browser (same as --no-browser).",
|
|
45
|
+
" XDG_CONFIG_HOME Directory for the stored login and key files. Default ~/.config",
|
|
74
46
|
"",
|
|
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"
|
|
47
|
+
"Docs:",
|
|
48
|
+
" CLI https://sight.cultured.computer/docs/cli",
|
|
49
|
+
" SDK https://sight.cultured.computer/docs"
|
|
80
50
|
].join("\n")
|
|
81
51
|
);
|
|
82
52
|
}
|
|
@@ -91,9 +61,8 @@ async function connect(args) {
|
|
|
91
61
|
if (!invite) {
|
|
92
62
|
console.error(
|
|
93
63
|
[
|
|
94
|
-
"connect needs --invite <code>: one single-use invite
|
|
95
|
-
"
|
|
96
|
-
"This stays manual on purpose: your community, your authority."
|
|
64
|
+
"connect needs --invite <code>: one single-use invite code that you create.",
|
|
65
|
+
"Create it on your relay: its admin page, or POST /api/invites as the owner."
|
|
97
66
|
].join("\n")
|
|
98
67
|
);
|
|
99
68
|
return 1;
|
|
@@ -117,37 +86,20 @@ async function connect(args) {
|
|
|
117
86
|
if (body["status"] === "already-connected") {
|
|
118
87
|
console.log(`this relay is already connected. ${body["note"] ?? ""}`);
|
|
119
88
|
console.log(`deployment: ${body["deploymentSlug"]}`);
|
|
120
|
-
if (body["claimUrl"]) console.log(`claim
|
|
89
|
+
if (body["claimUrl"]) console.log(`claim link: ${body["claimUrl"]}`);
|
|
121
90
|
return 0;
|
|
122
91
|
}
|
|
123
|
-
console.log("connected.
|
|
92
|
+
console.log("connected. Sight now reads this relay as a read-only observer.");
|
|
124
93
|
console.log(` deployment: ${body["deploymentSlug"]}`);
|
|
125
94
|
console.log(` first sync: ${body["firstSync"]}`);
|
|
126
|
-
console.log(`
|
|
95
|
+
console.log(` daily pulse: ${body["pulse"]} ${body["pulse"] === "off" ? "(re-run with --pulse, or turn it on after claiming)" : ""}`);
|
|
127
96
|
console.log("");
|
|
128
|
-
console.log("
|
|
129
|
-
console.log("
|
|
97
|
+
console.log("The recorded sessions become yours when you open the claim link.");
|
|
98
|
+
console.log("Keep this link, it is the only copy:");
|
|
130
99
|
console.log(` ${body["claimUrl"]}`);
|
|
131
100
|
return 0;
|
|
132
101
|
}
|
|
133
102
|
var DEFAULT_DASHBOARD = "https://sight.cultured.computer";
|
|
134
|
-
var [, , command, ...rest] = process.argv;
|
|
135
|
-
if (command === "connect") {
|
|
136
|
-
connect(rest).then((code) => process.exit(code));
|
|
137
|
-
} else if (command === "auth") {
|
|
138
|
-
auth(rest).then((code) => process.exit(code));
|
|
139
|
-
} else if (command === "account") {
|
|
140
|
-
account(rest).then((code) => process.exit(code));
|
|
141
|
-
} else if (command === "openrouter") {
|
|
142
|
-
openrouter(rest).then((code) => process.exit(code));
|
|
143
|
-
} else if (command === "export") {
|
|
144
|
-
exportRecord(rest).then((code) => process.exit(code));
|
|
145
|
-
} else if (command === "conditions") {
|
|
146
|
-
conditions(rest).then((code) => process.exit(code));
|
|
147
|
-
} else {
|
|
148
|
-
usage();
|
|
149
|
-
process.exit(command && command !== "--help" && command !== "-h" ? 1 : 0);
|
|
150
|
-
}
|
|
151
103
|
var CLIENT_ID = "sight-cli";
|
|
152
104
|
function credentialsPath() {
|
|
153
105
|
return join(process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config"), "sight", "credentials.json");
|
|
@@ -225,7 +177,7 @@ async function connectOpenRouter(api, sightKey, args) {
|
|
|
225
177
|
return 1;
|
|
226
178
|
}
|
|
227
179
|
const body = await response.json();
|
|
228
|
-
console.log(`OpenRouter connected (
|
|
180
|
+
console.log(`OpenRouter connected (key ending ${String(body["last4"] ?? "")}); monthly budget: $${budget}.`);
|
|
229
181
|
return 0;
|
|
230
182
|
}
|
|
231
183
|
async function account(args) {
|
|
@@ -267,7 +219,7 @@ async function account(args) {
|
|
|
267
219
|
console.log(`capabilities: ${body.capabilities.join(", ") || "none"}`);
|
|
268
220
|
if (!args.includes("--openrouter")) return 0;
|
|
269
221
|
if (!body.capabilities.includes("providers:write")) {
|
|
270
|
-
console.error("The Sight key was saved, but
|
|
222
|
+
console.error("The Sight key was saved, but connecting OpenRouter requires providers:write. Ask the project owner for an Admin key, set it as SIGHT_API_KEY, then run: sight openrouter connect --budget <usd>");
|
|
271
223
|
return 1;
|
|
272
224
|
}
|
|
273
225
|
const connected = await connectOpenRouter(api, body.key, args);
|
|
@@ -279,14 +231,14 @@ async function account(args) {
|
|
|
279
231
|
async function openrouter(args) {
|
|
280
232
|
const sub = args[0];
|
|
281
233
|
if (sub !== "connect" && sub !== "status") {
|
|
282
|
-
console.error("usage: sight openrouter connect --budget <usd> [--api <base>]
|
|
234
|
+
console.error("usage: sight openrouter connect --budget <usd> [--api <base>] | sight openrouter status [--api <base>]");
|
|
283
235
|
return 1;
|
|
284
236
|
}
|
|
285
237
|
const stored = readMachineCredentials();
|
|
286
238
|
const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
|
|
287
239
|
const api = (flag(args, "--api") ?? process.env["SIGHT_API"] ?? stored?.api ?? DEFAULT_API).replace(/\/+$/, "");
|
|
288
240
|
if (!sightKey) {
|
|
289
|
-
console.error("No
|
|
241
|
+
console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
|
|
290
242
|
return 1;
|
|
291
243
|
}
|
|
292
244
|
if (sub === "connect") return connectOpenRouter(api, sightKey, args);
|
|
@@ -300,10 +252,11 @@ async function openrouter(args) {
|
|
|
300
252
|
return 1;
|
|
301
253
|
}
|
|
302
254
|
const body = await response.json();
|
|
303
|
-
console.log(`OpenRouter ${body["status"]} (
|
|
255
|
+
console.log(`OpenRouter ${body["status"]} (key ending ${String(body["last4"] ?? "")}); monthly budget: $${body["monthlyBudgetUsd"]}.`);
|
|
304
256
|
return 0;
|
|
305
257
|
}
|
|
306
258
|
function openBrowser(url) {
|
|
259
|
+
if (process.argv.includes("--no-browser") || process.env["SIGHT_NO_BROWSER"] === "1") return;
|
|
307
260
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
308
261
|
exec(`${cmd} "${url}"`);
|
|
309
262
|
}
|
|
@@ -313,14 +266,14 @@ async function auth(args) {
|
|
|
313
266
|
if (sub === "logout") {
|
|
314
267
|
try {
|
|
315
268
|
rmSync(credentialsPath());
|
|
316
|
-
console.log("signed out
|
|
269
|
+
console.log("signed out. The local token is deleted; the session it held stays valid until it expires.");
|
|
317
270
|
} catch {
|
|
318
271
|
console.log("nothing to sign out of.");
|
|
319
272
|
}
|
|
320
273
|
return 0;
|
|
321
274
|
}
|
|
322
275
|
if (sub !== "login") {
|
|
323
|
-
console.error("usage: sight auth login [--base <dashboard-url>]
|
|
276
|
+
console.error("usage: sight auth login [--base <dashboard-url>] | sight auth logout");
|
|
324
277
|
return 1;
|
|
325
278
|
}
|
|
326
279
|
const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
|
|
@@ -329,8 +282,13 @@ async function auth(args) {
|
|
|
329
282
|
headers: { "content-type": "application/json" },
|
|
330
283
|
body: JSON.stringify({ client_id: CLIENT_ID })
|
|
331
284
|
}).catch((err) => ({ __err: err }));
|
|
332
|
-
if (!codeRes ||
|
|
333
|
-
console.error(`could not
|
|
285
|
+
if (!codeRes || codeRes.__err) {
|
|
286
|
+
console.error(`could not reach ${base}. Check the URL (--base or SIGHT_BASE) and your network.`);
|
|
287
|
+
return 1;
|
|
288
|
+
}
|
|
289
|
+
if (!codeRes.ok) {
|
|
290
|
+
const detail = await codeRes.text().catch(() => "");
|
|
291
|
+
console.error(`the login was refused by ${base} (${codeRes.status})${detail ? `: ${detail.slice(0, 300)}` : ""}`);
|
|
334
292
|
return 1;
|
|
335
293
|
}
|
|
336
294
|
const grant = await codeRes.json();
|
|
@@ -345,7 +303,7 @@ async function auth(args) {
|
|
|
345
303
|
const deadline = Date.now() + (grant.expires_in ?? 300) * 1e3;
|
|
346
304
|
for (; ; ) {
|
|
347
305
|
if (Date.now() > deadline) {
|
|
348
|
-
console.error("the code expired
|
|
306
|
+
console.error("the code expired. Run sight auth login again.");
|
|
349
307
|
return 1;
|
|
350
308
|
}
|
|
351
309
|
await sleep(intervalMs);
|
|
@@ -362,21 +320,21 @@ async function auth(args) {
|
|
|
362
320
|
if (poll.ok) {
|
|
363
321
|
const body = await poll.json();
|
|
364
322
|
if (!body.access_token) {
|
|
365
|
-
console.error("the server answered without a token
|
|
323
|
+
console.error("the server answered without a token. Run sight auth login again.");
|
|
366
324
|
return 1;
|
|
367
325
|
}
|
|
368
326
|
writeCredentials(body.access_token, base);
|
|
369
327
|
console.log(`signed in. token stored at ${credentialsPath()} (0600).`);
|
|
370
|
-
console.log(`try: sight export --project <slug> --deployment <slug> --out
|
|
328
|
+
console.log(`try: sight export --project <slug> --deployment <slug> --out record.jsonl`);
|
|
371
329
|
return 0;
|
|
372
330
|
}
|
|
373
331
|
const err = await poll.json().catch(() => ({}));
|
|
374
332
|
if (err.error === "access_denied") {
|
|
375
|
-
console.error("denied
|
|
333
|
+
console.error("the request was denied in the browser; nothing was granted. Run sight auth login again to retry.");
|
|
376
334
|
return 1;
|
|
377
335
|
}
|
|
378
336
|
if (err.error === "expired_token") {
|
|
379
|
-
console.error("the code expired
|
|
337
|
+
console.error("the code expired. Run sight auth login again.");
|
|
380
338
|
return 1;
|
|
381
339
|
}
|
|
382
340
|
}
|
|
@@ -393,7 +351,7 @@ async function exportRecord(args) {
|
|
|
393
351
|
}
|
|
394
352
|
const creds = readCredentials();
|
|
395
353
|
if (!creds) {
|
|
396
|
-
console.error("no stored login
|
|
354
|
+
console.error("no stored login. Run sight auth login first.");
|
|
397
355
|
return 1;
|
|
398
356
|
}
|
|
399
357
|
const kind = conditions2 ? "conditions" : readings ? "readings" : null;
|
|
@@ -404,7 +362,7 @@ async function exportRecord(args) {
|
|
|
404
362
|
if (!res.ok) {
|
|
405
363
|
const status = res.status ?? "unreachable";
|
|
406
364
|
console.error(
|
|
407
|
-
`export failed (${status})
|
|
365
|
+
`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
366
|
);
|
|
409
367
|
return 1;
|
|
410
368
|
}
|
|
@@ -430,7 +388,7 @@ async function conditions(args) {
|
|
|
430
388
|
const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
|
|
431
389
|
const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
|
|
432
390
|
if (!sightKey) {
|
|
433
|
-
console.error("No
|
|
391
|
+
console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
|
|
434
392
|
return 1;
|
|
435
393
|
}
|
|
436
394
|
const params = new URLSearchParams();
|
|
@@ -454,3 +412,20 @@ async function conditions(args) {
|
|
|
454
412
|
process.stdout.write(await res.text());
|
|
455
413
|
return 0;
|
|
456
414
|
}
|
|
415
|
+
var [, , command, ...rest] = process.argv;
|
|
416
|
+
if (command === "connect") {
|
|
417
|
+
connect(rest).then((code) => process.exit(code));
|
|
418
|
+
} else if (command === "auth") {
|
|
419
|
+
auth(rest).then((code) => process.exit(code));
|
|
420
|
+
} else if (command === "account") {
|
|
421
|
+
account(rest).then((code) => process.exit(code));
|
|
422
|
+
} else if (command === "openrouter") {
|
|
423
|
+
openrouter(rest).then((code) => process.exit(code));
|
|
424
|
+
} else if (command === "export") {
|
|
425
|
+
exportRecord(rest).then((code) => process.exit(code));
|
|
426
|
+
} else if (command === "conditions") {
|
|
427
|
+
conditions(rest).then((code) => process.exit(code));
|
|
428
|
+
} else {
|
|
429
|
+
usage();
|
|
430
|
+
process.exit(command && command !== "--help" && command !== "-h" ? 1 : 0);
|
|
431
|
+
}
|