longtable 0.1.0 → 0.1.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/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.1",
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/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
  }