longtable 0.1.30 → 0.1.32
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 +17 -5
- package/package.json +1 -1
- package/src/autostart.mjs +5 -2
- package/src/claude.mjs +23 -4
- package/src/run.mjs +4 -1
package/bin/longtable.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { rmSync } from "node:fs";
|
|
|
15
15
|
import { join, resolve } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import { client, fetchConfig } from "../src/api.mjs";
|
|
18
|
-
import { claudeVersion, findClaude, tokenWorks } from "../src/claude.mjs";
|
|
18
|
+
import { claudeVersion, findClaude, installClaude, tokenWorks } from "../src/claude.mjs";
|
|
19
19
|
import { codexSignIn, codexSignedIn, codexVersion, findCodex } from "../src/codex.mjs";
|
|
20
20
|
import { disableAutostart, enableAutostart } from "../src/autostart.mjs";
|
|
21
21
|
import { forgetCopies, freshCopy, gitCanJoin, resolveSource } from "../src/repo.mjs";
|
|
@@ -40,8 +40,15 @@ async function connect() {
|
|
|
40
40
|
const ai = option("ai") || "claude";
|
|
41
41
|
if (!["claude", "codex"].includes(ai)) throw new Error("--ai is claude or codex.");
|
|
42
42
|
// Check the AI is here before the one-use code is spent.
|
|
43
|
-
|
|
43
|
+
let claude = ai === "claude" ? findClaude() : null;
|
|
44
44
|
const codex = ai === "codex" ? findCodex() : null;
|
|
45
|
+
// No Claude Code this connection can run: it is installed now with Anthropic's own installer, so connecting never
|
|
46
|
+
// stops on a step someone skipped. --no-install leaves it to the person.
|
|
47
|
+
if (ai === "claude" && !claude && !args.includes("--no-install")) {
|
|
48
|
+
say("Claude Code isn't on this computer yet, outside the Claude app. Installing it with Anthropic's installer (claude.ai/install), one moment.");
|
|
49
|
+
claude = installClaude();
|
|
50
|
+
if (claude) say("Claude Code is installed.");
|
|
51
|
+
}
|
|
45
52
|
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.");
|
|
46
53
|
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.");
|
|
47
54
|
|
|
@@ -113,11 +120,16 @@ async function connect() {
|
|
|
113
120
|
|
|
114
121
|
const auto = has("no-autostart") ? { started: false } : enableAutostart(process.execPath, binPath);
|
|
115
122
|
if (!has("no-run") && !auto.started) {
|
|
116
|
-
|
|
123
|
+
// A stand-in until the start-up task runs it: it never ends a connection the task started.
|
|
124
|
+
spawn(process.execPath, [binPath, "run", "--backup"], { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
117
125
|
}
|
|
118
126
|
const word = ai === "codex" ? "Codex" : "Claude";
|
|
119
127
|
log(`connected to "${paired.table_name}" for ${paired.member_name} (${ai === "codex" ? codexVersion(codex) : claudeVersion(claude)})`);
|
|
120
|
-
say(
|
|
128
|
+
say(auto.started || has("no-autostart")
|
|
129
|
+
? `Connected. ${paired.member_name}'s ${word} is now at "${paired.table_name}". It answers in the background whenever this computer is on.`
|
|
130
|
+
// Said plainly when it could not be set to run by itself: today it runs from here, and from the next sign-in on
|
|
131
|
+
// Windows starts it, so closing this window takes it away until then.
|
|
132
|
+
: `Connected. ${paired.member_name}'s ${word} is now at "${paired.table_name}". It could not start in the background just now, so it is running from this window: leave it open for now. From the next time you sign in to this computer it starts by itself.`);
|
|
121
133
|
const git = gitCanJoin();
|
|
122
134
|
if (!git.ok) {
|
|
123
135
|
log(`git cannot join two parts of work (${git.version})`);
|
|
@@ -179,7 +191,7 @@ try {
|
|
|
179
191
|
// Started from an older copy (a cache, or an old start-up entry) while ~/.longtable/app holds a newer one: run that.
|
|
180
192
|
const newerCopy = handOffTo();
|
|
181
193
|
if (newerCopy) { log(`run: handing over to the newer copy in ${newerCopy}`); await import(pathToFileURL(newerCopy).href); }
|
|
182
|
-
else await runLoop();
|
|
194
|
+
else await runLoop({ backup: args.includes("--backup") });
|
|
183
195
|
}
|
|
184
196
|
else if (command === "status") await status();
|
|
185
197
|
else if (command === "disconnect") await disconnect();
|
package/package.json
CHANGED
package/src/autostart.mjs
CHANGED
|
@@ -102,8 +102,11 @@ export function enableAutostart(nodePath, binPath) {
|
|
|
102
102
|
rmSync(legacyStartup(), { force: true });
|
|
103
103
|
const asked = Date.now();
|
|
104
104
|
startTask(TASK);
|
|
105
|
-
// Said started only when the connection really wrote its note; otherwise `connect` runs
|
|
106
|
-
|
|
105
|
+
// Said started only when the connection really wrote its note; otherwise `connect` runs a stand-in itself. A
|
|
106
|
+
// first start can be slow (Windows looking over a new program), so it is asked once more and given a minute.
|
|
107
|
+
if (wroteNoteSince(asked, 20000)) return { started: true, where: `Task Scheduler: ${TASK}` };
|
|
108
|
+
try { startTask(TASK); } catch {}
|
|
109
|
+
return { started: wroteNoteSince(asked, 40000), where: `Task Scheduler: ${TASK}` };
|
|
107
110
|
}
|
|
108
111
|
// Every system runs the copy in ~/.longtable/app, which the connection keeps up to date itself, never the copy
|
|
109
112
|
// that ran `connect` (on Mac and Linux that was a cache folder npm may clear).
|
package/src/claude.mjs
CHANGED
|
@@ -24,11 +24,19 @@ export function findClaude() {
|
|
|
24
24
|
const native = join(homedir(), ".local", "bin", exe);
|
|
25
25
|
if (existsSync(native)) return native;
|
|
26
26
|
if (isWindows) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// The Claude app's own copy: where the app sees it, and where Windows really keeps it for a packaged app, which
|
|
28
|
+
// is what a connection started outside the app sees.
|
|
29
|
+
const roots = [join(process.env.APPDATA || "", "Claude", "claude-code")];
|
|
30
|
+
const packages = join(process.env.LOCALAPPDATA || "", "Packages");
|
|
31
|
+
try { for (const d of readdirSync(packages)) if (/^Claude_/i.test(d)) roots.push(join(packages, d, "LocalCache", "Roaming", "Claude", "claude-code")); } catch {}
|
|
32
|
+
for (const root of roots) {
|
|
33
|
+
if (!existsSync(root)) continue;
|
|
34
|
+
let versions = [];
|
|
35
|
+
try { versions = readdirSync(root).filter((v) => /^\d+\.\d+\.\d+$/.test(v)).sort(byVersionDesc); } catch {}
|
|
30
36
|
for (const v of versions) {
|
|
31
|
-
|
|
37
|
+
let builds = [];
|
|
38
|
+
try { builds = readdirSync(join(root, v)); } catch {}
|
|
39
|
+
for (const h of builds) {
|
|
32
40
|
const p = join(root, v, h, exe);
|
|
33
41
|
if (existsSync(p)) return p;
|
|
34
42
|
}
|
|
@@ -38,6 +46,17 @@ export function findClaude() {
|
|
|
38
46
|
return null;
|
|
39
47
|
}
|
|
40
48
|
|
|
49
|
+
// Claude Code from Anthropic's own installer, for a computer that has none the connection can run (only the
|
|
50
|
+
// Claude app's, kept to itself, or none at all). It is the documented way to install it; what it prints is shown.
|
|
51
|
+
export function installClaude() {
|
|
52
|
+
const cmd = isWindows
|
|
53
|
+
? ["powershell", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "irm https://claude.ai/install.ps1 | iex"]]
|
|
54
|
+
: ["bash", ["-c", "curl -fsSL https://claude.ai/install.sh | bash"]];
|
|
55
|
+
const r = spawnSync(cmd[0], cmd[1], { stdio: "inherit", windowsHide: true, timeout: 10 * 60 * 1000 });
|
|
56
|
+
if (r.error) log(`installing Claude Code failed to start: ${r.error.message}`);
|
|
57
|
+
return findClaude();
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
// A clean environment: only what the operating system needs, plus the connection's own sign-in.
|
|
42
61
|
// Nothing from the parent process leaks in: no API keys, no settings from whatever started the connection.
|
|
43
62
|
// apiKey is only for the evals in CI, on the owner's own key; a person's connection always uses their own sign-in.
|
package/src/run.mjs
CHANGED
|
@@ -1060,7 +1060,7 @@ async function tellCommands(rpc, seat) {
|
|
|
1060
1060
|
} catch (e) { log(`commands not sent: ${e.message}`); }
|
|
1061
1061
|
}
|
|
1062
1062
|
|
|
1063
|
-
export async function runLoop({ pollMs = 2000 } = {}) {
|
|
1063
|
+
export async function runLoop({ pollMs = 2000, backup = false } = {}) {
|
|
1064
1064
|
const config = readConfig();
|
|
1065
1065
|
if (!config.connections?.length) throw new Error("Not connected to any table yet.");
|
|
1066
1066
|
const engines = { claude: findClaude(), codex: findCodex() };
|
|
@@ -1072,6 +1072,9 @@ export async function runLoop({ pollMs = 2000 } = {}) {
|
|
|
1072
1072
|
// Only one connection runs on a computer. A second one would wipe the first one's work folder under it.
|
|
1073
1073
|
const lock = join(home, "runner.pid");
|
|
1074
1074
|
const old = runningConnection();
|
|
1075
|
+
// The stand-in `connect` starts when the start-up task was slow never ends the real one: it would leave a
|
|
1076
|
+
// connection tied to the window that ran `connect`, gone when that window closes. It steps aside instead.
|
|
1077
|
+
if (old && old !== process.pid && backup) { log(`a connection is already running (${old}); this stand-in steps aside`); process.exit(0); }
|
|
1075
1078
|
if (old && old !== process.pid) { endConnection(old); log(`ended the connection that was already running (${old})`); }
|
|
1076
1079
|
writeFileSync(lock, `${process.pid} ${Date.now()}`);
|
|
1077
1080
|
const unlock = () => { try { if (runningConnection() === process.pid) rmSync(lock, { force: true }); } catch {} };
|