@cultured_computer/sight 0.7.1 → 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/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://fieldwork-ingest.fly.dev";
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,48 +13,39 @@ function flag(args, name) {
13
13
  function usage() {
14
14
  console.log(
15
15
  [
16
- "sight: the observer for agent conversations",
16
+ "sight: the command line for Sight.",
17
17
  "",
18
18
  "Usage:",
19
- " sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
20
19
  " sight auth login [--base <dashboard-url>]",
21
20
  " sight auth logout",
21
+ " sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]",
22
+ " sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]",
22
23
  " sight account create [--openrouter --budget <usd>] [--api <base>]",
23
24
  " sight openrouter connect --budget <usd> [--api <base>]",
24
25
  " sight openrouter status [--api <base>]",
25
- " sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]",
26
- " sight conditions --session <id-or-external-id> [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]",
26
+ " sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
27
27
  "",
28
- " connect attach Sight to a buzz community as a read-only observer.",
29
- " --invite one single-use invite code, minted by you on",
30
- " your relay (its admin surface, or",
31
- " POST /api/invites as the community owner).",
32
- " Your invite is the authorization: Sight can",
33
- " never enter a community you did not invite it into.",
34
- " --pulse opt into the daily readout (off by",
35
- " default; counts, times, and links only).",
28
+ "Commands:",
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.",
36
37
  "",
37
- " auth login sign this terminal in with your browser session \u2014 a",
38
- " code prints, you approve on the dashboard, done. The",
39
- " token lives at ~/.config/sight/credentials.json (0600).",
40
- " account create redeem SIGHT_PROVISION_TOKEN without a browser and",
41
- " save the scoped Sight key in machine.json (0600). Add",
42
- " --openrouter to validate + seal OPENROUTER_API_KEY.",
43
- " openrouter connect attach/rotate your BYOK key; requires a positive",
44
- " local monthly --budget and a providers:write Sight key.",
45
- " export pull a deployment\u2019s full record (RLDS JSONL) with that",
46
- " token. Owner role on the project required.",
47
- " --readings pull the per-turn judge labels (the graded",
48
- " reads: closure, backward-pass, and the rest)",
49
- " instead of the record.",
50
- " --conditions pull the detector checks: each checked",
51
- " sentence, flagged / not flagged / not checked.",
52
- " conditions pull one session\u2019s (or one run\u2019s) detector checks with",
53
- " the machine key from ~/.config/sight/machine.json \u2014",
54
- " NDJSON to stdout, errors to stderr.",
38
+ "Environment:",
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",
55
45
  "",
56
- "The SDK half of this package (serving-path capture) is documented at",
57
- "https://sight.cultured.computer/docs (the two lanes share one project)."
46
+ "Docs:",
47
+ " CLI https://sight.cultured.computer/docs/cli",
48
+ " SDK https://sight.cultured.computer/docs"
58
49
  ].join("\n")
59
50
  );
60
51
  }
@@ -69,9 +60,8 @@ async function connect(args) {
69
60
  if (!invite) {
70
61
  console.error(
71
62
  [
72
- "connect needs --invite <code>: one single-use invite, minted by you.",
73
- "On your relay: the community admin surface, or POST /api/invites as owner.",
74
- "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."
75
65
  ].join("\n")
76
66
  );
77
67
  return 1;
@@ -95,16 +85,16 @@ async function connect(args) {
95
85
  if (body["status"] === "already-connected") {
96
86
  console.log(`this relay is already connected. ${body["note"] ?? ""}`);
97
87
  console.log(`deployment: ${body["deploymentSlug"]}`);
98
- if (body["claimUrl"]) console.log(`claim/archive: ${body["claimUrl"]}`);
88
+ if (body["claimUrl"]) console.log(`claim link: ${body["claimUrl"]}`);
99
89
  return 0;
100
90
  }
101
- console.log("connected. sight is observing your community.");
91
+ console.log("connected. Sight now reads this relay as a read-only observer.");
102
92
  console.log(` deployment: ${body["deploymentSlug"]}`);
103
93
  console.log(` first sync: ${body["firstSync"]}`);
104
- console.log(` room pulse: ${body["pulse"]} ${body["pulse"] === "off" ? "(re-run with --pulse, or toggle after claiming)" : ""}`);
94
+ console.log(` daily pulse: ${body["pulse"]} ${body["pulse"] === "off" ? "(re-run with --pulse, or turn it on after claiming)" : ""}`);
105
95
  console.log("");
106
- console.log("the archive (sessions, measurements, the label queue) attaches when");
107
- console.log("you claim. keep this link, it is the only copy:");
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:");
108
98
  console.log(` ${body["claimUrl"]}`);
109
99
  return 0;
110
100
  }
@@ -203,7 +193,7 @@ async function connectOpenRouter(api, sightKey, args) {
203
193
  return 1;
204
194
  }
205
195
  const body = await response.json();
206
- console.log(`OpenRouter connected (\u2026${String(body["last4"] ?? "")}); local monthly budget: $${budget}.`);
196
+ console.log(`OpenRouter connected (key ending ${String(body["last4"] ?? "")}); monthly budget: $${budget}.`);
207
197
  return 0;
208
198
  }
209
199
  async function account(args) {
@@ -245,7 +235,7 @@ async function account(args) {
245
235
  console.log(`capabilities: ${body.capabilities.join(", ") || "none"}`);
246
236
  if (!args.includes("--openrouter")) return 0;
247
237
  if (!body.capabilities.includes("providers:write")) {
248
- console.error("The Sight key was saved, but provider setup requires providers:write. Ask the owner or operator for a separate management key.");
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>');
249
239
  return 1;
250
240
  }
251
241
  const connected = await connectOpenRouter(api, body.key, args);
@@ -257,14 +247,14 @@ async function account(args) {
257
247
  async function openrouter(args) {
258
248
  const sub = args[0];
259
249
  if (sub !== "connect" && sub !== "status") {
260
- console.error("usage: sight openrouter connect --budget <usd> [--api <base>] \xB7 sight openrouter status");
250
+ console.error("usage: sight openrouter connect --budget <usd> [--api <base>] | sight openrouter status [--api <base>]");
261
251
  return 1;
262
252
  }
263
253
  const stored = readMachineCredentials();
264
254
  const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
265
255
  const api = (flag(args, "--api") ?? process.env["SIGHT_API"] ?? stored?.api ?? DEFAULT_API).replace(/\/+$/, "");
266
256
  if (!sightKey) {
267
- console.error("No machine credential. Run sight account create or set SIGHT_API_KEY.");
257
+ console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
268
258
  return 1;
269
259
  }
270
260
  if (sub === "connect") return connectOpenRouter(api, sightKey, args);
@@ -278,7 +268,7 @@ async function openrouter(args) {
278
268
  return 1;
279
269
  }
280
270
  const body = await response.json();
281
- console.log(`OpenRouter ${body["status"]} (\u2026${String(body["last4"] ?? "")}); monthly budget: $${body["monthlyBudgetUsd"]}.`);
271
+ console.log(`OpenRouter ${body["status"]} (key ending ${String(body["last4"] ?? "")}); monthly budget: $${body["monthlyBudgetUsd"]}.`);
282
272
  return 0;
283
273
  }
284
274
  function openBrowser(url) {
@@ -291,14 +281,14 @@ async function auth(args) {
291
281
  if (sub === "logout") {
292
282
  try {
293
283
  rmSync(credentialsPath());
294
- console.log("signed out (the local token is gone; the session it held stays valid until it expires).");
284
+ console.log("signed out. The local token is deleted; the session it held stays valid until it expires.");
295
285
  } catch {
296
286
  console.log("nothing to sign out of.");
297
287
  }
298
288
  return 0;
299
289
  }
300
290
  if (sub !== "login") {
301
- console.error("usage: sight auth login [--base <dashboard-url>] \xB7 sight auth logout");
291
+ console.error("usage: sight auth login [--base <dashboard-url>] | sight auth logout");
302
292
  return 1;
303
293
  }
304
294
  const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
@@ -308,7 +298,7 @@ async function auth(args) {
308
298
  body: JSON.stringify({ client_id: CLIENT_ID })
309
299
  }).catch((err) => ({ __err: err }));
310
300
  if (!codeRes || !codeRes.ok) {
311
- console.error(`could not start the login at ${base} \u2014 is the URL right?`);
301
+ console.error(`could not start the login at ${base}. Check the URL (--base or SIGHT_BASE) and your network.`);
312
302
  return 1;
313
303
  }
314
304
  const grant = await codeRes.json();
@@ -323,7 +313,7 @@ async function auth(args) {
323
313
  const deadline = Date.now() + (grant.expires_in ?? 300) * 1e3;
324
314
  for (; ; ) {
325
315
  if (Date.now() > deadline) {
326
- console.error("the code expired \u2014 run sight auth login again.");
316
+ console.error("the code expired. Run sight auth login again.");
327
317
  return 1;
328
318
  }
329
319
  await sleep(intervalMs);
@@ -340,21 +330,21 @@ async function auth(args) {
340
330
  if (poll.ok) {
341
331
  const body = await poll.json();
342
332
  if (!body.access_token) {
343
- console.error("the server answered without a token \u2014 unexpected; try again.");
333
+ console.error("the server answered without a token. Run sight auth login again.");
344
334
  return 1;
345
335
  }
346
336
  writeCredentials(body.access_token, base);
347
337
  console.log(`signed in. token stored at ${credentialsPath()} (0600).`);
348
- console.log(`try: sight export --project <slug> --deployment <slug> --out corpus.jsonl`);
338
+ console.log(`try: sight export --project <slug> --deployment <slug> --out record.jsonl`);
349
339
  return 0;
350
340
  }
351
341
  const err = await poll.json().catch(() => ({}));
352
342
  if (err.error === "access_denied") {
353
- console.error("denied on the browser side \u2014 nothing was granted.");
343
+ console.error("the request was denied in the browser; nothing was granted. Run sight auth login again to retry.");
354
344
  return 1;
355
345
  }
356
346
  if (err.error === "expired_token") {
357
- console.error("the code expired \u2014 run sight auth login again.");
347
+ console.error("the code expired. Run sight auth login again.");
358
348
  return 1;
359
349
  }
360
350
  }
@@ -371,7 +361,7 @@ async function exportRecord(args) {
371
361
  }
372
362
  const creds = readCredentials();
373
363
  if (!creds) {
374
- console.error("no stored login \u2014 run sight auth login first.");
364
+ console.error("no stored login. Run sight auth login first.");
375
365
  return 1;
376
366
  }
377
367
  const kind = conditions2 ? "conditions" : readings ? "readings" : null;
@@ -382,7 +372,7 @@ async function exportRecord(args) {
382
372
  if (!res.ok) {
383
373
  const status = res.status ?? "unreachable";
384
374
  console.error(
385
- `export failed (${status}) \u2014 ${status === 401 || status === 403 ? "the token is expired or the role is not owner on that project; sight auth login refreshes it" : "check the project and deployment slugs"}.`
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"}.`
386
376
  );
387
377
  return 1;
388
378
  }
@@ -401,18 +391,20 @@ async function conditions(args) {
401
391
  const session = flag(args, "--session");
402
392
  const run = flag(args, "--run");
403
393
  if (!session && !run) {
404
- console.error("usage: sight conditions --session <id-or-external-id> [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]");
394
+ console.error("usage: sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]");
405
395
  return 1;
406
396
  }
407
397
  const stored = readMachineCredentials();
408
398
  const sightKey = process.env["SIGHT_API_KEY"] ?? stored?.apiKey;
409
399
  const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
410
400
  if (!sightKey) {
411
- console.error("No machine credential. Run sight account create or set SIGHT_API_KEY.");
401
+ console.error("No Sight key found. Set SIGHT_API_KEY, or run sight account create.");
412
402
  return 1;
413
403
  }
414
404
  const params = new URLSearchParams();
415
405
  if (session) params.set("session", session);
406
+ const deployment = flag(args, "--deployment");
407
+ if (deployment) params.set("deployment", deployment);
416
408
  if (run) params.set("run", run);
417
409
  const since = flag(args, "--since");
418
410
  if (since) params.set("since", since);