longtable 0.1.53 → 0.1.55
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/package.json +1 -1
- package/src/bridge.mjs +26 -0
- package/src/claude.mjs +3 -0
- package/src/client-rules.mjs +1 -1
- package/src/context.mjs +208 -0
- package/src/copy-guard.mjs +71 -0
- package/src/extras.mjs +7 -5
- package/src/local.mjs +32 -9
- package/src/pointed.mjs +11 -12
- package/src/prompts.mjs +365 -0
- package/src/repo.mjs +1 -1
- package/src/run.mjs +69 -694
- package/src/signin.mjs +3 -0
- package/src/store.mjs +5 -0
- package/src/typecheck.mjs +3 -3
- package/src/browser.mjs +0 -340
package/package.json
CHANGED
package/src/bridge.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The terminal bridge's own process (started by forkBridge in local.mjs). It serves the person's terminals and nothing
|
|
2
|
+
// else; the connection tells it which tables it may serve, and when the connection ends, so does it, closing every
|
|
3
|
+
// terminal it holds.
|
|
4
|
+
import { startBridge } from "./local.mjs";
|
|
5
|
+
import { log } from "./store.mjs";
|
|
6
|
+
|
|
7
|
+
let seats = [];
|
|
8
|
+
let bridge = null;
|
|
9
|
+
process.on("disconnect", () => { bridge?.close(); process.exit(0); });
|
|
10
|
+
process.on("message", async (m) => {
|
|
11
|
+
if (m?.start) {
|
|
12
|
+
seats = m.start.seats;
|
|
13
|
+
try {
|
|
14
|
+
bridge = await startBridge({ app: m.start.app, seats, home: m.start.home, log, port: m.start.port });
|
|
15
|
+
process.send({ port: bridge.port });
|
|
16
|
+
} catch (e) {
|
|
17
|
+
process.send({ error: e.message });
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
} else if (m?.allow) {
|
|
21
|
+
for (const s of seats) if (s.table_id === m.allow.table) s.local.allowed = !!m.allow.on;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
// A fault in a terminal is written down and the rest go on, as in the connection itself.
|
|
25
|
+
process.on("uncaughtException", (e) => log(`tripwire: the terminal bridge: ${e.message}`));
|
|
26
|
+
process.on("unhandledRejection", (e) => log(`tripwire: the terminal bridge: ${e?.message || e}`));
|
package/src/claude.mjs
CHANGED
|
@@ -71,6 +71,9 @@ export function childEnv(token, apiKey) {
|
|
|
71
71
|
for (const k of keep) if (process.env[k] !== undefined) env[k] = process.env[k];
|
|
72
72
|
if (token) env.CLAUDE_CODE_OAUTH_TOKEN = token;
|
|
73
73
|
if (apiKey) env.ANTHROPIC_API_KEY = apiKey;
|
|
74
|
+
// Claude Code's own update checks and reports held every start back about three seconds (measured: 5.2 s to 2.0 s for
|
|
75
|
+
// the same one-line answer). The table's own runs need none of it; a person's full Claude Code keeps theirs, as at home.
|
|
76
|
+
env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
|
|
74
77
|
return env;
|
|
75
78
|
}
|
|
76
79
|
|
package/src/client-rules.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The one rulebook for everything that answers a client: the team's assistant (the desk), a client's own assistant,
|
|
2
2
|
// and the deeper look that reads the code. Every client-facing prompt is built from here, the connection checks each
|
|
3
|
-
// answer against it before the client sees it (checkClientReply), and tests/
|
|
3
|
+
// answer against it before the client sees it (checkClientReply), and tests/ai/probe-client.mjs runs every case.
|
|
4
4
|
// The gaps found so far all came from two places saying different things ("pass on any change" beside "try changes in
|
|
5
5
|
// their copy", "say the team has new features" beside "build it"), so a rule lives here and nowhere else.
|
|
6
6
|
import { inert } from "./fence.mjs";
|
package/src/context.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// What a person's own Claude knows and keeps on their own computer, laid beside a job for it.
|
|
2
|
+
|
|
3
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
5
|
+
import { fileFolder, neverCommit, safeTable } from "./repo.mjs";
|
|
6
|
+
import { tableSessionIds } from "./sessions.mjs";
|
|
7
|
+
import { claudeHome } from "./extras.mjs";
|
|
8
|
+
import { cut, hideSecrets, home, log, trip, writeWhole } from "./store.mjs";
|
|
9
|
+
|
|
10
|
+
const NL = String.fromCharCode(10);
|
|
11
|
+
|
|
12
|
+
// What this person's Claude already knows on their own computer: their standing instructions, the project's
|
|
13
|
+
// instructions in their folder, and the memory their Claude keeps for this project. Read fresh for every job, so it
|
|
14
|
+
// is as up to date as their own Claude is. It goes to their own AI on their own plan, and nowhere else.
|
|
15
|
+
export function knows(seat, { talkOnly = false } = {}) {
|
|
16
|
+
if (seat.kind !== "claude") return "";
|
|
17
|
+
if (talkOnly) {
|
|
18
|
+
const folder = seat.folder || fileFolder(seat.source);
|
|
19
|
+
let talk = "";
|
|
20
|
+
if (folder) { try { talk = recentSession(folder, 16000); } catch (e) { log(`their recent conversation could not be read: ${e.message}`); } }
|
|
21
|
+
return talk ? `## The latest of your own conversation with them about this project (newest last)${NL}${talk}` : "";
|
|
22
|
+
}
|
|
23
|
+
const parts = [];
|
|
24
|
+
const add = (label, file, cap) => {
|
|
25
|
+
try {
|
|
26
|
+
const t = hideSecrets(readFileSync(file, "utf8")).trim();
|
|
27
|
+
if (t) parts.push(`## ${label}${NL}${t.length > cap ? t.slice(0, cap) + NL + "[cut short here]" : t}`);
|
|
28
|
+
} catch {}
|
|
29
|
+
};
|
|
30
|
+
const folder = seat.folder || fileFolder(seat.source);
|
|
31
|
+
add("Your person's standing instructions", join(claudeHome(), "CLAUDE.md"), 4000);
|
|
32
|
+
if (folder) {
|
|
33
|
+
add("This project's instructions in their folder", join(folder, "CLAUDE.md"), 12000);
|
|
34
|
+
add("This project's instructions in their folder (.claude)", join(folder, ".claude", "CLAUDE.md"), 6000);
|
|
35
|
+
add("Their own notes for this project", join(folder, "CLAUDE.local.md"), 4000);
|
|
36
|
+
const memory = join(claudeHome(), "projects", resolve(folder).replace(/[^a-zA-Z0-9]/g, "-"), "memory");
|
|
37
|
+
add("Your memory for this project: the index", join(memory, "MEMORY.md"), 6000);
|
|
38
|
+
try {
|
|
39
|
+
const files = readdirSync(memory).filter((f) => f.endsWith(".md") && f !== "MEMORY.md")
|
|
40
|
+
.map((f) => ({ f, at: statSync(join(memory, f)).mtimeMs })).sort((a, b) => b.at - a.at).slice(0, 12);
|
|
41
|
+
for (const { f } of files) add(`Your memory: ${f}`, join(memory, f), 1200);
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
// The end of their own conversation about this project comes first: it is what the two of them were just doing.
|
|
45
|
+
let talk = "";
|
|
46
|
+
if (folder) { try { talk = recentSession(folder, 16000); } catch (e) { log(`their recent conversation could not be read: ${e.message}`); } }
|
|
47
|
+
// The rest has what room the conversation leaves, so the whole stays within 36,000 characters.
|
|
48
|
+
const head = talk ? `## The latest of your own conversation with them about this project (newest last)${NL}${talk}${NL}${NL}` : "";
|
|
49
|
+
const out = head + parts.join(NL + NL).slice(0, Math.max(0, 36000 - head.length));
|
|
50
|
+
if (out.length > 36000) trip("what a person's Claude knows came out over its 36,000 characters");
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Everything this person's Claude knows on their own computer, whole, laid in a folder beside the code for it to
|
|
55
|
+
// read when a question needs it: their instructions in full (the summary above is cut to size), every memory file,
|
|
56
|
+
// and the latest of their own conversation with their Claude about this project. That last part is what makes it
|
|
57
|
+
// the same Claude: what the two of them were just doing, said in their own words. It is read on their computer, by
|
|
58
|
+
// their own AI, on their own plan, and it is never committed and never sent to Longtable.
|
|
59
|
+
export const YOURS = ".longtable-yours";
|
|
60
|
+
function said(content) {
|
|
61
|
+
if (typeof content === "string") return content;
|
|
62
|
+
if (!Array.isArray(content)) return "";
|
|
63
|
+
return content.filter((p) => p?.type === "text" && typeof p.text === "string").map((p) => p.text).join(NL);
|
|
64
|
+
}
|
|
65
|
+
// Where Claude Code keeps the sessions it ran in a folder.
|
|
66
|
+
const sessionsDir = (folder) => join(claudeHome(), "projects", resolve(folder).replace(/[^a-zA-Z0-9]/g, "-"));
|
|
67
|
+
// The kinds of job that are a person's own request to their own AI, and so carry on the chat's session.
|
|
68
|
+
export const SESSION_KINDS = new Set(["look", "work", "answer", "plan"]);
|
|
69
|
+
// A session can only be picked up while Claude Code still has it (the person may have cleared it).
|
|
70
|
+
export const sessionOnDisk = (folder, id) => { try { return statSync(join(sessionsDir(folder), `${id}.jsonl`)).isFile(); } catch { return false; } };
|
|
71
|
+
// The person's own Claude Code sessions in this folder (never a table's), each with its size, to tell afterwards whether
|
|
72
|
+
// one was written to while a run worked.
|
|
73
|
+
export function folderSessions(folder) {
|
|
74
|
+
const tables = tableSessionIds();
|
|
75
|
+
const out = new Map();
|
|
76
|
+
try { for (const f of readdirSync(sessionsDir(folder))) if (f.endsWith(".jsonl") && !tables.has(f.slice(0, -6))) out.set(f, statSync(join(sessionsDir(folder), f)).size); } catch {}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
export const sessionsGrew = (before, folder) => !!before && [...folderSessions(folder)].some(([f, size]) => before.get(f) !== size);
|
|
80
|
+
|
|
81
|
+
// Whether one of the person's own Claude Code sessions (not a table's) was at work in this folder in the last two
|
|
82
|
+
// minutes: then two Claudes are changing the same files, which is worth saying, not stopping.
|
|
83
|
+
export function folderBusy(folder, withinMs = 120000) {
|
|
84
|
+
const tables = tableSessionIds();
|
|
85
|
+
try {
|
|
86
|
+
return readdirSync(sessionsDir(folder)).some((f) => f.endsWith(".jsonl") && !tables.has(f.slice(0, -6))
|
|
87
|
+
&& Date.now() - statSync(join(sessionsDir(folder), f)).mtimeMs < withinMs);
|
|
88
|
+
} catch { return false; }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function recentSession(folder, room = 90000) {
|
|
92
|
+
const dir = sessionsDir(folder);
|
|
93
|
+
// A table's own sessions are not the person's conversation with their Claude.
|
|
94
|
+
const tables = tableSessionIds();
|
|
95
|
+
let files = [];
|
|
96
|
+
try { files = readdirSync(dir).filter((f) => f.endsWith(".jsonl") && !tables.has(f.slice(0, -6))).map((f) => ({ f, at: statSync(join(dir, f)).mtimeMs, size: statSync(join(dir, f)).size })).sort((a, b) => b.at - a.at).slice(0, 3); } catch { return ""; }
|
|
97
|
+
const turns = [];
|
|
98
|
+
let used = 0;
|
|
99
|
+
for (const { f, size } of files) {
|
|
100
|
+
let text = "";
|
|
101
|
+
try {
|
|
102
|
+
// Only the end of a long conversation is read: the newest part is what matters, and a session can be very large.
|
|
103
|
+
const fd = openSync(join(dir, f), "r");
|
|
104
|
+
const take = Math.min(size, 6 * 1024 * 1024);
|
|
105
|
+
const buf = Buffer.alloc(take);
|
|
106
|
+
readSync(fd, buf, 0, take, size - take);
|
|
107
|
+
closeSync(fd);
|
|
108
|
+
text = buf.toString("utf8");
|
|
109
|
+
} catch { continue; }
|
|
110
|
+
const lines = text.split(NL);
|
|
111
|
+
const mine = [];
|
|
112
|
+
for (let i = lines.length - 1; i >= 0 && used < room; i--) {
|
|
113
|
+
let e;
|
|
114
|
+
try { e = JSON.parse(lines[i]); } catch { continue; }
|
|
115
|
+
// A line that is valid JSON but not a turn ("null", left by a crash) is skipped, not allowed to stop the rest.
|
|
116
|
+
if (!e || typeof e !== "object") continue;
|
|
117
|
+
if (e.isSidechain || (e.type !== "user" && e.type !== "assistant")) continue;
|
|
118
|
+
const words = said(e.message?.content).trim();
|
|
119
|
+
// Reminders the app adds to a message are not something either of them said.
|
|
120
|
+
if (!words || /^<(system-reminder|command-|local-command)/.test(words)) continue;
|
|
121
|
+
const line = `${e.type === "user" ? "They said" : "You said"}: ${words.length > 4000 ? words.slice(0, 4000) + " […]" : words}`;
|
|
122
|
+
// Within its room: the line that would go over it is left out (the newest always comes), so what follows it in
|
|
123
|
+
// what their Claude knows keeps its share.
|
|
124
|
+
if (used + line.length > room && turns.length + mine.length) { used = room; break; }
|
|
125
|
+
used += line.length;
|
|
126
|
+
mine.unshift(line);
|
|
127
|
+
}
|
|
128
|
+
turns.unshift(...mine);
|
|
129
|
+
if (used >= room) break;
|
|
130
|
+
}
|
|
131
|
+
return hideSecrets(turns.join(NL + NL));
|
|
132
|
+
}
|
|
133
|
+
// Where a handout's HTML is left for this job to open when it needs it: beside the attachments, never committed. Named
|
|
134
|
+
// by its path inside the working folder, or whole when it sits beside their own folder.
|
|
135
|
+
export function handoutPlace(seat, folder, handed, dir) {
|
|
136
|
+
return {
|
|
137
|
+
write(name, text) {
|
|
138
|
+
if (seat.source && !folder) neverCommit(seat.table_id, YOURS);
|
|
139
|
+
const at = join(handed, YOURS, "handouts");
|
|
140
|
+
mkdirSync(at, { recursive: true });
|
|
141
|
+
writeFileSync(join(at, name), text);
|
|
142
|
+
const file = join(at, name);
|
|
143
|
+
const rel = relative(dir, file);
|
|
144
|
+
return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel.split(/[\\/]/).join("/") : file;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function layYours(seat, dir) {
|
|
149
|
+
if (seat.kind !== "claude") return false;
|
|
150
|
+
const folder = seat.folder || fileFolder(seat.source);
|
|
151
|
+
const dest = join(dir, YOURS);
|
|
152
|
+
let any = false;
|
|
153
|
+
try {
|
|
154
|
+
rmSync(dest, { recursive: true, force: true });
|
|
155
|
+
mkdirSync(join(dest, "memory"), { recursive: true });
|
|
156
|
+
const put = (from, to) => {
|
|
157
|
+
try {
|
|
158
|
+
if (statSync(from).size > 1024 * 1024) return;
|
|
159
|
+
const t = hideSecrets(readFileSync(from, "utf8"));
|
|
160
|
+
if (t.trim()) { writeFileSync(join(dest, to), t); any = true; }
|
|
161
|
+
} catch {}
|
|
162
|
+
};
|
|
163
|
+
put(join(claudeHome(), "CLAUDE.md"), "their-standing-instructions.md");
|
|
164
|
+
if (folder) {
|
|
165
|
+
put(join(folder, "CLAUDE.md"), "project-instructions.md");
|
|
166
|
+
put(join(folder, ".claude", "CLAUDE.md"), "project-instructions-2.md");
|
|
167
|
+
put(join(folder, "CLAUDE.local.md"), "their-project-notes.md");
|
|
168
|
+
const memory = join(claudeHome(), "projects", resolve(folder).replace(/[^a-zA-Z0-9]/g, "-"), "memory");
|
|
169
|
+
try { for (const f of readdirSync(memory).filter((x) => x.endsWith(".md")).slice(0, 200)) put(join(memory, f), join("memory", f.replace(/[^A-Za-z0-9._-]/g, "_"))); } catch {}
|
|
170
|
+
const talk = recentSession(folder);
|
|
171
|
+
if (talk) { writeFileSync(join(dest, "recent-conversation.md"), talk); any = true; }
|
|
172
|
+
}
|
|
173
|
+
if (!any) rmSync(dest, { recursive: true, force: true });
|
|
174
|
+
} catch {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Each person's AI keeps its own short notes on that person's computer. They are what makes one person's AI differ
|
|
181
|
+
// from another's on the same model: what it has learned here, in its own words. They never leave this computer.
|
|
182
|
+
const mindFile = (tableId) => join(home, "minds", `${safeTable(tableId)}.md`);
|
|
183
|
+
export function mind(tableId) {
|
|
184
|
+
try { return readFileSync(mindFile(tableId), "utf8").trim(); } catch { return ""; }
|
|
185
|
+
}
|
|
186
|
+
export function remember(tableId, text) {
|
|
187
|
+
const line = cut(hideSecrets(String(text || "")).replace(/\s+/g, " ").trim(), 300);
|
|
188
|
+
if (line.length < 12) return;
|
|
189
|
+
mkdirSync(join(home, "minds"), { recursive: true });
|
|
190
|
+
const kept = mind(tableId).split(NL).filter(Boolean).slice(-39);
|
|
191
|
+
writeWhole(mindFile(tableId), [...kept, `- ${new Date().toISOString().slice(0, 10)}: ${line}`].join(NL) + NL);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Keep only sources that are real files inside the copy, written relative to it.
|
|
195
|
+
export function cleanSources(dir, sources) {
|
|
196
|
+
const out = [];
|
|
197
|
+
for (const s of sources || []) {
|
|
198
|
+
if (typeof s !== "string" || !s.trim()) continue;
|
|
199
|
+
let p = s.trim().replace(/^\.\//, "");
|
|
200
|
+
if (isAbsolute(p)) p = relative(dir, p);
|
|
201
|
+
p = normalize(p).replace(/\\/g, "/");
|
|
202
|
+
// On Windows and macOS ".LONGTABLE-YOURS" is the same folder, so the person's own is matched in any letter case.
|
|
203
|
+
if (p.startsWith("..") || isAbsolute(p) || p.toLowerCase().startsWith(YOURS)) continue;
|
|
204
|
+
if (existsSync(join(dir, p)) && !out.includes(p)) out.push(p);
|
|
205
|
+
}
|
|
206
|
+
return out.slice(0, 6);
|
|
207
|
+
}
|
|
208
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// What a change in a client's copy may never touch, checked by the connection on the change itself.
|
|
2
|
+
|
|
3
|
+
// What a sandbox change may never be, whatever was asked. The connection checks the change itself, never the AI's
|
|
4
|
+
// word for it, and it checks every file the change touched as a whole, not only the new lines.
|
|
5
|
+
// It is a strong filter, not a wall: a copy is still code a client asked for, running where the team puts it up, so
|
|
6
|
+
// that place must hold no real keys and no real data. The owner is told so before giving a copy.
|
|
7
|
+
// Each rule is written once and both modes are built from them, so tightening one can never miss the other.
|
|
8
|
+
const BUILD_FILES = [
|
|
9
|
+
// how the product is built, set up, deployed and versioned
|
|
10
|
+
"(^|/)[.]git(hub|lab|attributes|modules|ignore)", "(^|/)[.](circleci|husky|vscode|devcontainer)/", "(^|/)[.]env", "(^|/)[.](npmrc|yarnrc|babelrc|vercelignore|dockerignore)",
|
|
11
|
+
"(^|/)(package|composer|turbo|tsconfig[^/]*|jsconfig|vercel|netlify|firebase|app|now)[.]json$", "[.](toml|ya?ml|lock|lockb|sql|sh|bat|ps1|cjs|mjs|pem|key|crt)$",
|
|
12
|
+
"(^|/)(package-lock[.]json|Dockerfile[^/]*|docker-compose[^/]*|Makefile|Procfile|Gemfile|requirements[^/]*[.]txt|go[.](mod|sum))$", "[.]config[.][cm]?[jt]sx?$",
|
|
13
|
+
];
|
|
14
|
+
const SAFETY_FILES = [
|
|
15
|
+
// sign-in and who may do what
|
|
16
|
+
"(^|[/._-])(auth|login|signin|sign-in|session|permissions?|polic(y|ies)|rls|guard|admin|secrets?|credentials?)([/._-]|$)",
|
|
17
|
+
// Words that are also ordinary parts of a name ("role-picker", "token-list") only count as a whole folder or file.
|
|
18
|
+
"(^|/)(roles?|tokens?|keys?)([/.]|$)",
|
|
19
|
+
// tests, so one cannot be changed to pass
|
|
20
|
+
"(^|/)(tests?|__tests__|e2e|spec|cypress|playwright)/", "[.](test|spec)[.]",
|
|
21
|
+
];
|
|
22
|
+
const REACHES_OUT = [
|
|
23
|
+
"\\bprocess\\s*\\??\\.[A-Za-z_$]", "\\bprocess\\s*\\[", "[=(,:]\\s*process\\s*[;),}\\]]", "[=(,:]\\s*process\\s*$", "import\\s*[.]\\s*meta", "\\b(Deno|Bun)\\s*[.]",
|
|
24
|
+
"\\benv\\s*\\[", "\\benv\\s*\\??\\.[A-Za-z_$]", "[{,]\\s*env\\s*[,})]", "\\bgetenv\\b", "os[.]environ", "\\bENV\\s*[\\[.]",
|
|
25
|
+
"\\b(readFile|readFileSync|readdir|readdirSync|createReadStream|child_process|execSync|spawn)\\b", "[\"'`](node:)?(fs|fs/promises|vm|net|dns|child_process|worker_threads)[\"'`]",
|
|
26
|
+
// The server's other ways out, named where a module is asked for, so "http" in an ordinary sentence is left alone.
|
|
27
|
+
"\\b(require|import)\\s*\\(\\s*[\"'`](node:)?(https?|http2|os|tls|dgram|module)[\"'`]", "\\bfrom\\s*[\"'`](node:)?(https?|http2|os|tls|dgram|module)[\"'`]",
|
|
28
|
+
"\\beval\\s*\\(", "new\\s+Function\\b", "\\bFunction\\s*\\(",
|
|
29
|
+
];
|
|
30
|
+
const REACHES_OUT_TOO = ["\\b(fetch|XMLHttpRequest|WebSocket|EventSource|sendBeacon)\\b[^;]{0,80}(https?:|[\"'`]//)", "<script\\b", "\\bsecrets[.][A-Za-z_]"];
|
|
31
|
+
const NOT_IN_A_SANDBOX = new RegExp([
|
|
32
|
+
...BUILD_FILES,
|
|
33
|
+
// what runs on the server or at build time
|
|
34
|
+
"(^|/)(scripts?|migrations?|supabase|prisma|drizzle|db|database|server|functions|workers?|lambda|infra|deploy|ops|bin|tools)/",
|
|
35
|
+
"(^|/)(api|trpc|actions?)/", "(^|/)(route|middleware|instrumentation|proxy|actions?|server)[.][cm]?[jt]sx?$",
|
|
36
|
+
...SAFETY_FILES,
|
|
37
|
+
].join("|"), "i");
|
|
38
|
+
const NOT_A_SANDBOX_WORD = new RegExp([...REACHES_OUT, "\\bglobalThis\\b", "[\"']use server[\"']", "\\bserver-only\\b", "dangerouslySetInnerHTML", ...REACHES_OUT_TOO].join("|"), "m");
|
|
39
|
+
// With the table's copy rules set to "code" (a preview that is fully separate: made-up data, no real keys, no email),
|
|
40
|
+
// a copy may also change the code behind the screens: server components, actions, API routes. Still never how the
|
|
41
|
+
// product is built, set up or deployed, migrations and the database, scripts, middleware, sign-in and permissions,
|
|
42
|
+
// or tests; and the code still may not reach for env values, programs, files or outside sites.
|
|
43
|
+
const NOT_IN_A_CODE_COPY = new RegExp([
|
|
44
|
+
...BUILD_FILES,
|
|
45
|
+
"(^|/)(scripts?|migrations?|supabase|prisma|drizzle|infra|deploy|ops|bin|tools|docker)/",
|
|
46
|
+
"(^|/)(middleware|instrumentation|proxy)[.][cm]?[jt]sx?$",
|
|
47
|
+
...SAFETY_FILES,
|
|
48
|
+
].join("|"), "i");
|
|
49
|
+
const NOT_A_CODE_COPY_WORD = new RegExp([...REACHES_OUT, "dangerouslySetInnerHTML", ...REACHES_OUT_TOO].join("|"), "m");
|
|
50
|
+
// The owner's own list of paths a copy may never change, whatever the mode: a folder ends in "/", anything else is a
|
|
51
|
+
// file or a folder by that name.
|
|
52
|
+
export const blockedList = (blocked) => String(blocked || "").split(/[,\n]/).map((x) => x.trim().replace(/^[/]+/, "")).filter(Boolean);
|
|
53
|
+
const isBlocked = (f, list) => list.some((b) => (b.endsWith("/") ? f.startsWith(b) : f === b || f.startsWith(b + "/")));
|
|
54
|
+
|
|
55
|
+
export function sandboxRefusal({ files, text, unread }, paths = "", { scope = "screens", blocked = "" } = {}) {
|
|
56
|
+
const code = scope === "code";
|
|
57
|
+
const theirs = blockedList(blocked);
|
|
58
|
+
const kept = theirs.length ? files.find((f) => isBlocked(f, theirs)) : null;
|
|
59
|
+
if (kept) return `it changes ${kept}, which this table keeps out of every copy`;
|
|
60
|
+
const file = files.find((f) => (code ? NOT_IN_A_CODE_COPY : NOT_IN_A_SANDBOX).test(f));
|
|
61
|
+
if (file) return `it changes ${file}, which is part of how the product is built, run or kept safe`;
|
|
62
|
+
// Folders the owner said a copy may change: with any set, everything outside them is the team's.
|
|
63
|
+
const allowed = String(paths || "").split(",").map((x) => x.trim().replace(/^[/]+|[/]+$/g, "")).filter(Boolean);
|
|
64
|
+
const outside = allowed.length ? files.find((f) => !allowed.some((a) => f === a || f.startsWith(a + "/"))) : null;
|
|
65
|
+
if (outside) return `it changes ${outside}, which is outside the folders a copy may change`;
|
|
66
|
+
if (unread) return "it changes a file that could not be read through";
|
|
67
|
+
const word = (code ? NOT_A_CODE_COPY_WORD : NOT_A_SANDBOX_WORD).exec(text || "");
|
|
68
|
+
if (word) return `a file it changed reaches for something a copy must not (${word[0].trim().slice(0, 40)})`;
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
package/src/extras.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
// Three things a job can carry besides the conversation: the person's own commands and skills ("/" at the table),
|
|
2
2
|
// what was attached to the messages, and what another person's AI shared from their own computer.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { basename, join, relative, sep } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { cut, hideSecrets } from "./store.mjs";
|
|
9
9
|
import { inert } from "./fence.mjs";
|
|
10
|
+
import { isSecretName } from "./pointed.mjs";
|
|
10
11
|
|
|
11
12
|
const NL = String.fromCharCode(10);
|
|
12
|
-
const claudeHome = () => process.env.LONGTABLE_CLAUDE_HOME || join(homedir(), ".claude");
|
|
13
|
+
export const claudeHome = () => process.env.LONGTABLE_CLAUDE_HOME || join(homedir(), ".claude");
|
|
13
14
|
const codexHome = () => process.env.LONGTABLE_CODEX_HOME || process.env.CODEX_HOME || join(homedir(), ".codex");
|
|
14
15
|
const folderOf = (seat) => {
|
|
15
16
|
if (seat.folder) return seat.folder;
|
|
@@ -239,7 +240,7 @@ function textFiles(dir, depth) {
|
|
|
239
240
|
for (const e of list) {
|
|
240
241
|
if (e.name === "node_modules" || e.name === ".git" || PRIVATE_DIR.test(e.name)) continue;
|
|
241
242
|
const p = join(dir, e.name);
|
|
242
|
-
if (e.isFile() && TEXTISH.test(e.name) && !
|
|
243
|
+
if (e.isFile() && TEXTISH.test(e.name) && !isPrivate(e.name)) here.push(p);
|
|
243
244
|
else if (e.isDirectory() && depth > 0) below.push(...textFiles(p, depth - 1));
|
|
244
245
|
}
|
|
245
246
|
return [...here.sort(), ...below];
|
|
@@ -248,7 +249,8 @@ function textFiles(dir, depth) {
|
|
|
248
249
|
// What is never handed to another person's AI from a folder someone pointed at, even with sharing on: their own
|
|
249
250
|
// Claude's instructions and settings, AI tool settings that carry keys, and anything shaped like a secrets file.
|
|
250
251
|
const PRIVATE_DIR = /^\.(claude|codex|cursor|vscode|idea|aws|ssh|gnupg|docker|kube|config)$/i;
|
|
251
|
-
const PRIVATE_FILE = /^(claude(\.local)?\.md|agents\.md|\.mcp\.json|mcp\.json|.*settings.*\.json|\.env.*|.*secret.*|.*credential
|
|
252
|
+
const PRIVATE_FILE = /^(claude(\.local)?\.md|agents\.md|\.mcp\.json|mcp\.json|.*settings.*\.json|\.env.*|.*secret.*|.*credential.*)$/i;
|
|
253
|
+
const isPrivate = (name) => PRIVATE_FILE.test(name) || isSecretName(name);
|
|
252
254
|
|
|
253
255
|
// The text of what was pointed at, for the other AIs: text files only, small, a few, keys hidden.
|
|
254
256
|
export function shareable(laid) {
|
|
@@ -257,7 +259,7 @@ export function shareable(laid) {
|
|
|
257
259
|
const take = (name, file) => {
|
|
258
260
|
if (out.length >= 8) return;
|
|
259
261
|
try {
|
|
260
|
-
if (
|
|
262
|
+
if (isPrivate(basename(file))) return;
|
|
261
263
|
const st = statSync(file);
|
|
262
264
|
if (!st.isFile() || st.size > 110000) return;
|
|
263
265
|
const text = readFileSync(file, "utf8");
|
package/src/local.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
1
2
|
import { createServer } from "node:http";
|
|
2
3
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
3
4
|
import { release } from "node:os";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
4
6
|
import { Terminal } from "./terminal.mjs";
|
|
5
7
|
|
|
6
8
|
// The bridge: a small server on this computer only (127.0.0.1), which the person's own Longtable page reaches
|
|
7
|
-
// directly, for their terminal
|
|
8
|
-
//
|
|
9
|
+
// directly, for their terminal. Nothing sent through it passes through Longtable, so a password typed into the terminal
|
|
10
|
+
// stays on this computer.
|
|
9
11
|
// Who may use it: a page on Longtable's own address (the browser says which site a request comes from, and no site can
|
|
10
12
|
// pretend), sent to this computer by name (so a web address made to point here cannot reach it), carrying the key of a
|
|
11
13
|
// table whose Longtable says this connection may serve it (runner_local: only their own full Claude Code, which can
|
|
@@ -25,7 +27,30 @@ export function fromPage({ host, origin }, { port, app }) {
|
|
|
25
27
|
// And carrying the table's key.
|
|
26
28
|
export const keyOk = (auth, key) => !!key && same(String(auth || "").replace(/^Bearer /, ""), key);
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
// The bridge in a process of its own (bridge.mjs), so nothing the connection does in its own process (a git fetch,
|
|
31
|
+
// listing processes) ever holds up what the person types. It is told each table's key at start and whether this
|
|
32
|
+
// computer may serve that table after; it ends with the connection. A bridge started again asks for the port it had, so
|
|
33
|
+
// a page already open keeps reaching it. Resolves to { port, child, allow(table, on), close }.
|
|
34
|
+
export function forkBridge({ app, seats, home, port = 0 }) {
|
|
35
|
+
return new Promise((ok, fail) => {
|
|
36
|
+
const child = fork(fileURLToPath(new URL("./bridge.mjs", import.meta.url)), [], { stdio: ["ignore", "ignore", "ignore", "ipc"], windowsHide: true });
|
|
37
|
+
child.once("error", fail);
|
|
38
|
+
child.once("exit", (code) => fail(new Error(`the bridge stopped as it started (${code})`)));
|
|
39
|
+
child.once("message", (m) => {
|
|
40
|
+
if (!m?.port) return fail(new Error(m?.error || "the bridge did not say where it listens"));
|
|
41
|
+
ok({
|
|
42
|
+
port: m.port,
|
|
43
|
+
child,
|
|
44
|
+
allow: (table, on) => { if (child.connected) child.send({ allow: { table, on } }); },
|
|
45
|
+
// Letting go is enough: the bridge closes its terminals and ends when the connection lets go of it.
|
|
46
|
+
close: () => { try { child.disconnect(); } catch { /* gone already */ } },
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
child.send({ start: { app, home, port, seats: seats.map((s) => ({ table_id: s.table_id, terminalFolder: s.terminalFolder, local: { key: s.local.key, allowed: false } })) } });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function startBridge({ app, seats, home, log, port = 0 }) {
|
|
29
54
|
const origin = new URL(app).origin;
|
|
30
55
|
// Each table's terminals, as many as the person opens (tabs on their page), by a name the page gives each.
|
|
31
56
|
const terms = new Map(); // "<table>:<terminal>" -> { term, listeners, id }
|
|
@@ -83,9 +108,6 @@ export function startBridge({ app, seats, home, browser, log }) {
|
|
|
83
108
|
return stream(req, res, { data: t.term.text, all: true, os: SYSTEM }, async (w) => { t.listeners.add(w); await t.term.open(url.searchParams.get("cols"), url.searchParams.get("rows")); },
|
|
84
109
|
(w) => t.listeners.delete(w));
|
|
85
110
|
}
|
|
86
|
-
if (req.method === "GET" && path === "/browser") {
|
|
87
|
-
return stream(req, res, null, (w) => browser.watch(w), (w) => browser.unwatch(w));
|
|
88
|
-
}
|
|
89
111
|
if (req.method !== "POST") return send(res, 404, { error: "nothing here" });
|
|
90
112
|
const b = await body(req);
|
|
91
113
|
// Keys as typed, or a whole command from the chat's "!".
|
|
@@ -93,7 +115,6 @@ export function startBridge({ app, seats, home, browser, log }) {
|
|
|
93
115
|
if (path === "/term/size") { termFor(seat, termId(url)).term.resize(b.cols, b.rows); return send(res, 200, { ok: true }); }
|
|
94
116
|
// A terminal's tab closed: that shell ends, as closing a tab in a terminal app does.
|
|
95
117
|
if (path === "/term/close") { const key = `${seat.table_id}:${termId(url)}`; terms.get(key)?.term.stop(); terms.delete(key); return send(res, 200, { ok: true }); }
|
|
96
|
-
if (path === "/browser") { await browser.act(b); return send(res, 200, { ok: true }); }
|
|
97
118
|
return send(res, 404, { error: "nothing here" });
|
|
98
119
|
} catch (e) {
|
|
99
120
|
log(`bridge: ${e.message}`);
|
|
@@ -101,8 +122,10 @@ export function startBridge({ app, seats, home, browser, log }) {
|
|
|
101
122
|
else res.end();
|
|
102
123
|
}
|
|
103
124
|
});
|
|
104
|
-
|
|
125
|
+
const listen = (at) => new Promise((ok, fail) => {
|
|
105
126
|
server.once("error", fail);
|
|
106
|
-
server.listen(
|
|
127
|
+
server.listen(at, "127.0.0.1", () => { server.off("error", fail); ok({ port: server.address().port, close: () => { for (const t of terms.values()) t.term.stop(); server.close(); } }); });
|
|
107
128
|
});
|
|
129
|
+
// The port asked for when it is free; any free one when it is not.
|
|
130
|
+
return port ? listen(port).catch(() => listen(0)) : listen(0);
|
|
108
131
|
}
|
package/src/pointed.mjs
CHANGED
|
@@ -7,24 +7,23 @@ import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readdirSync, re
|
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { basename, isAbsolute, join, parse, resolve, sep } from "node:path";
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// A file whose name says it holds keys, passwords or sign-ins, wherever it sits. The one list: never opened from the
|
|
11
|
+
// table here, never shared with another AI (extras.mjs), never linked into a working folder (typecheck.mjs). A .env and
|
|
12
|
+
// every kind of it (.env.local, .env.production), but not the example a project keeps to show which settings it wants:
|
|
13
|
+
// .env.example, .env.sample and .env.template hold names, not values, and nearly every project has one.
|
|
14
|
+
// A "credentials" file counts unless it is code (a credentials.ts that handles sign-in is the project's own source).
|
|
15
|
+
const SECRET_NAME = /^(\.env(\.(?!(example|sample|template)$)[\w.-]+)?|.+\.env|\.envrc|\.(npmrc|netrc|pypirc|pgpass|git-credentials)|id_(rsa|dsa|ecdsa|ed25519)(_sk)?(\.pub)?|(?!.*\.([cm]?[jt]sx?|py|rb|go|rs|java|kt|swift|php|cs|vue|svelte|s?css|html|md)$)credentials?([._-][\w.-]*)?|.*\.(pem|key|pfx|p12|kdbx|keystore|jks|ovpn|tfvars|tfstate))$/i;
|
|
16
|
+
export const isSecretName = (name) => SECRET_NAME.test(String(name));
|
|
17
|
+
const lastPart = (p) => String(p).split(/[\\/]/).filter(Boolean).pop() || "";
|
|
18
|
+
|
|
19
|
+
// Folders of keys, passwords, sign-ins and browser profiles. A path is checked as written and as it really is on disk.
|
|
11
20
|
const NEVER = [
|
|
12
21
|
/(^|[\\/])\.(ssh|gnupg|aws|azure|kube|docker|password-store)([\\/]|$)/i,
|
|
13
22
|
/(^|[\\/])\.longtable([\\/]|$)/i,
|
|
14
23
|
/(^|[\\/])\.claude[\\/]\.credentials/i,
|
|
15
24
|
/(^|[\\/])\.codex[\\/]auth/i,
|
|
16
|
-
// A .env and every kind of it (.env.local, .env.production), but not the example a project keeps to show which
|
|
17
|
-
// settings it wants: .env.example, .env.sample and .env.template hold names, not values, and nearly every project
|
|
18
|
-
// has one.
|
|
19
|
-
/(^|[\\/])\.env(\.(?!(example|sample|template)$)[\w.-]+)?$/i,
|
|
20
|
-
/\.env$/i,
|
|
21
|
-
/(^|[\\/])\.envrc$/i,
|
|
22
|
-
/\.(tfvars|tfstate)$/i,
|
|
23
25
|
/[\\/]\.config[\\/](gcloud|gh|google-chrome|chromium|BraveSoftware)([\\/]|$)/i,
|
|
24
26
|
/(^|[\\/])\.mozilla([\\/]|$)/i,
|
|
25
|
-
/(^|[\\/])\.(npmrc|netrc|pgpass|git-credentials)$/i,
|
|
26
|
-
/\.(pem|key|pfx|p12|kdbx|keystore|jks|ovpn)$/i,
|
|
27
|
-
/(^|[\\/])id_(rsa|dsa|ed25519|ecdsa)(\.pub)?$/i,
|
|
28
27
|
/[\\/](Login Data|Cookies|Web Data|Local State|key[34]\.db|logins\.json)$/i,
|
|
29
28
|
/[\\/]AppData[\\/](Local|Roaming)[\\/](Google|BraveSoftware|Mozilla|Opera Software|Microsoft[\\/]Edge|Microsoft[\\/]Credentials|Microsoft[\\/]Protect)([\\/]|$)/i,
|
|
30
29
|
/[\\/]Library[\\/](Keychains|Application Support[\\/](Google|BraveSoftware|Firefox))([\\/]|$)/i,
|
|
@@ -32,7 +31,7 @@ const NEVER = [
|
|
|
32
31
|
];
|
|
33
32
|
// On Windows a colon after the drive names one of a file's streams (".env::$DATA" reads the .env itself), and no
|
|
34
33
|
// ordinary file name holds one there, so a path with one is never opened.
|
|
35
|
-
export const refused = (p) => NEVER.some((r) => r.test(p)) || (process.platform === "win32" && String(p).replace(/^(\\\\[?.]\\)?[A-Za-z]:/, "").includes(":"));
|
|
34
|
+
export const refused = (p) => NEVER.some((r) => r.test(p)) || isSecretName(lastPart(p)) || (process.platform === "win32" && String(p).replace(/^(\\\\[?.]\\)?[A-Za-z]:/, "").includes(":"));
|
|
36
35
|
const isLink = (p) => { try { return lstatSync(p).isSymbolicLink(); } catch { return true; } };
|
|
37
36
|
// A whole drive, a whole home folder or the system's own folders are not "a place someone pointed at".
|
|
38
37
|
function tooWide(p) {
|