longtable 0.1.0 → 0.1.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/bin/longtable.mjs CHANGED
@@ -42,22 +42,30 @@ async function connect() {
42
42
  if (ai === "claude" && !claude) throw new Error("Claude Code isn't installed on this computer. Install it from claude.com/claude-code, then press Connect again.");
43
43
  if (ai === "codex" && !codex) throw new Error("Codex's command-line tool isn't installed on this computer. Install it with npm install -g @openai/codex, then press Connect again.");
44
44
 
45
+ // Find the code before the one-use code is spent: a repository this computer cannot open stops here, with
46
+ // nothing changed at the table. (A client's AI gets no code; whether this is one is only known after pairing.)
47
+ let source = null;
48
+ const repo = option("repo");
49
+ try {
50
+ source = resolveSource(repo || process.cwd());
51
+ } catch (e) {
52
+ if (repo) throw e;
53
+ }
54
+
45
55
  const cfg = await fetchConfig(app);
46
56
  const rpc = client(cfg);
47
57
  const paired = await rpc("pair_connection", { code, device_label: hostname() });
48
- if (paired.kind !== ai) throw new Error(`That connect code is for ${paired.kind === "codex" ? "Codex" : "Claude"}. Press Connect again.`);
58
+ // From here on, anything that goes wrong takes the connection off the table again, so the table never shows an AI
59
+ // as connected that is not running.
60
+ const leave = async (message) => {
61
+ try { await rpc("runner_leave", { token: paired.token, reason: message }); } catch {}
62
+ forgetSecret(`device-${paired.table_id}-${paired.kind}`);
63
+ throw new Error(message);
64
+ };
65
+ if (paired.kind !== ai) await leave(`That connect code is for ${paired.kind === "codex" ? "Codex" : "Claude"}. Press Connect again.`);
49
66
  saveSecret(`device-${paired.table_id}-${paired.kind}`, paired.token);
50
-
51
- // A client's AI never gets the code. A team member's reads a clean copy of the project.
52
- let source = null;
53
- const repo = option("repo");
54
- if (paired.role !== "client") {
55
- try {
56
- source = resolveSource(repo || process.cwd());
57
- } catch (e) {
58
- if (repo) throw e;
59
- }
60
- }
67
+ if (paired.role === "client") source = null;
68
+ else if (!source) await leave("This folder is not the project. Open your AI in the project's own folder, then press Connect again.");
61
69
 
62
70
  const config = readConfig();
63
71
  config.app = app;
@@ -77,7 +85,14 @@ async function connect() {
77
85
  });
78
86
  writeConfig(config);
79
87
 
80
- if (source) freshCopy(paired.table_id, source);
88
+ if (source) {
89
+ try {
90
+ freshCopy(paired.table_id, source);
91
+ } catch (e) {
92
+ writeConfig({ ...config, connections: config.connections.filter((c) => c.table_id !== paired.table_id) });
93
+ await leave(`The connection could not copy the project's code: ${String(e.message).split("\n").pop()}`);
94
+ }
95
+ }
81
96
 
82
97
  if (ai === "claude") {
83
98
  const token = loadSecret("claude-token");
@@ -85,11 +100,11 @@ async function connect() {
85
100
  say("A page is opening in your browser so this connection can have its own Claude sign-in. Approve it there.");
86
101
  // Loaded only here: it needs packages that the copy kept for start-up does not carry.
87
102
  const { signIn } = await import("../src/signin.mjs");
88
- if (!(await signIn(claude))) throw new Error("The Claude sign-in didn't finish. Press Connect again.");
103
+ if (!(await signIn(claude))) await leave("The Claude sign-in didn't finish. Press Connect again.");
89
104
  }
90
105
  } else if (!codexSignedIn(codex)) {
91
106
  say("A page is opening in your browser so this connection can have its own ChatGPT sign-in for Codex. Approve it there.");
92
- if (!(await codexSignIn(codex))) throw new Error("The ChatGPT sign-in didn't finish. Press Connect again.");
107
+ if (!(await codexSignIn(codex))) await leave("The ChatGPT sign-in didn't finish. Press Connect again.");
93
108
  }
94
109
 
95
110
  const auto = has("no-autostart") ? { started: false } : enableAutostart(process.execPath, binPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "longtable",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Brings your own Claude Code or Codex to your team's table on longtable.chat, quietly, on your own plan.",
5
5
  "homepage": "https://longtable.chat",
6
6
  "repository": {
package/src/claude.mjs CHANGED
@@ -110,7 +110,8 @@ export function claudeLimits(rate) {
110
110
  if (!rate) return null;
111
111
  const names = { five_hour: "5-hour", seven_day: "weekly" };
112
112
  const windows = Object.entries(rate.unifiedWindows || {}).map(([k, w]) => ({
113
- name: names[k] || k.replace(/_/g, " "),
113
+ // A week counted for one model alone arrives as seven_day_<model>.
114
+ name: names[k] || (k.startsWith("seven_day_") ? `weekly ${k.slice(10).replace(/_/g, " ")}` : k.replace(/_/g, " ")),
114
115
  used: Math.round((w.utilization ?? 0) * 100),
115
116
  resets: w.resetsAt ? new Date(w.resetsAt * 1000).toISOString() : null,
116
117
  }));
package/src/codex.mjs CHANGED
@@ -141,7 +141,7 @@ export function codexLimits(codex) {
141
141
  // The model Codex uses when none is asked for: the one it marks as its default, else the first it lists.
142
142
  const list = m.result?.data || [];
143
143
  const pick = list.find((x) => x.isDefault) || list[0];
144
- done(limits ? { ...limits, model: pick?.displayName || pick?.id || null } : null);
144
+ done(limits ? { ...limits, model: pick?.id || null, models: list.filter((x) => !x.hidden).map((x) => x.id).filter(Boolean).slice(0, 12) } : null);
145
145
  }
146
146
  }
147
147
  });
package/src/repo.mjs CHANGED
@@ -5,19 +5,36 @@ import { existsSync, mkdirSync } from "node:fs";
5
5
  import { join, resolve } from "node:path";
6
6
  import { home } from "./store.mjs";
7
7
 
8
- const git = (args, cwd) => execFileSync("git", args, { cwd, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] }).toString().trim();
8
+ // Git never stops to ask for a name or password here: if this computer's saved sign-in cannot reach a repository,
9
+ // the command fails and the connection says so.
10
+ const quiet = { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" };
11
+ const git = (args, cwd) => execFileSync("git", args, { cwd, env: quiet, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], timeout: 120000 }).toString().trim();
9
12
 
10
- // Given a folder or a git address, find where to copy from: the folder's origin if it has one, else the folder itself.
13
+ export function canReach(source) {
14
+ try {
15
+ git(["ls-remote", "--exit-code", source, "HEAD"]);
16
+ return true;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ // Given a folder or a git address, find where to copy from. For a folder: its origin when this computer can reach
23
+ // it, else the folder's own history, which is still only committed work. An address that cannot be reached is an
24
+ // error, said before anything else happens.
11
25
  export function resolveSource(repo) {
12
26
  if (!repo) return null;
13
- if (/^(https?:|git@|ssh:)/.test(repo)) return repo;
27
+ if (/^(https?:|git@|ssh:)/.test(repo)) {
28
+ if (!canReach(repo)) throw new Error(`This computer's git cannot open ${repo}. Sign in to git for it, or open your AI in the project's own folder and connect from there.`);
29
+ return repo;
30
+ }
14
31
  const folder = resolve(repo);
15
32
  if (!existsSync(join(folder, ".git"))) throw new Error(`${folder} is not a git repository`);
16
33
  try {
17
34
  const origin = git(["-C", folder, "remote", "get-url", "origin"]);
18
- if (origin) return origin;
35
+ if (origin && canReach(origin)) return origin;
19
36
  } catch {
20
- // No origin: copy from the folder's own history, which is still only committed work.
37
+ // No origin: fall through to the folder itself.
21
38
  }
22
39
  return "file:///" + folder.replace(/\\/g, "/");
23
40
  }
package/src/run.mjs CHANGED
@@ -157,7 +157,7 @@ async function workClient(rpc, seat, engines, job) {
157
157
  model: seat.model || process.env.LONGTABLE_MODEL });
158
158
  if (result.is_error) throw new Error(result.result || "Claude Code reported an error");
159
159
  s = result.structured_output;
160
- limits = result.limits;
160
+ limits = result.limits && { ...result.limits, models: ["opus", "sonnet", "haiku"] };
161
161
  info = { model: Object.keys(result.modelUsage || {})[0] || seat.model || process.env.LONGTABLE_MODEL || "default",
162
162
  usage: { input: result.usage?.input_tokens, output: result.usage?.output_tokens, wall_ms: result.wall_ms,
163
163
  cost_usd_equivalent: result.total_cost_usd } };
@@ -208,8 +208,27 @@ async function workPacked(rpc, seat, engines, job, copy) {
208
208
  await report(rpc, seat, limits, model);
209
209
  }
210
210
 
211
+ // The model for this job. The table's own answer (a direct answer, or the one combined from views) runs on the
212
+ // model picked for the table; a view or an introduction runs on the one the person picked for their own AI. Neither
213
+ // pick stands in for the other. With no pick, Claude runs Sonnet 5.5 for the table and Opus 5.5 for the person;
214
+ // ChatGPT keeps Codex's own default. A pick made for the other maker's AI is ignored.
215
+ const fits = (kind, model) => !!model && (/^(claude|opus|sonnet|haiku|fable)/i.test(model) === (kind === "claude"));
216
+ const AUTOMATIC = { table: "claude-sonnet-5-5", mine: "claude-opus-5-5" };
217
+ async function chosenModel(rpc, seat, job) {
218
+ const forTable = job.kind === "answer" || job.kind === "combine";
219
+ let pick = null;
220
+ try {
221
+ const picks = (await rpc("runner_models", { token: seat.token })) || {};
222
+ pick = forTable ? picks.table : picks.mine;
223
+ } catch {}
224
+ if (fits(seat.kind, pick)) return pick;
225
+ // A model named when connecting, or by the tests, comes before the automatic one.
226
+ return seat.model || process.env.LONGTABLE_MODEL || (seat.kind === "claude" ? AUTOMATIC[forTable ? "table" : "mine"] : null);
227
+ }
228
+
211
229
  async function work(rpc, seat, engines, job) {
212
230
  log(`${job.kind} job ${job.job_id} for ${job.me}`);
231
+ seat = { ...seat, model: await chosenModel(rpc, seat, job) };
213
232
  if (job.kind === "client") {
214
233
  try {
215
234
  await workClient(rpc, seat, engines, job);
@@ -262,7 +281,7 @@ async function work(rpc, seat, engines, job) {
262
281
  },
263
282
  });
264
283
  log(`${job.kind} job ${job.job_id} done in ${result.wall_ms} ms`);
265
- await report(rpc, seat, result.limits, Object.keys(result.modelUsage || {})[0] || seat.model || process.env.LONGTABLE_MODEL);
284
+ await report(rpc, seat, { ai: "claude", ...(result.limits || {}), models: ["opus", "sonnet", "haiku"] }, Object.keys(result.modelUsage || {})[0] || seat.model || process.env.LONGTABLE_MODEL);
266
285
  } catch (e) {
267
286
  log(`${job.kind} job ${job.job_id} failed: ${e.message}`);
268
287
  try { await rpc("runner_fail", { token: seat.token, job: job.job_id, reason: e.message }); } catch {}