Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: sturdier project setup

ogsamratc66bc55699b4
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256
index b1897799..1c0dff48 100644
--- a/apps/server/src/context/PARITY.sha256
+++ b/apps/server/src/context/PARITY.sha256
@@ -3,20 +3,20 @@
b7d4fad94c133cb4303db934a5bb8e84dcb09dcc6720dc9cc7245d7c8205fa11 commands.ts
e13f86577014b52affc4c2336630eedcac277b974939c6741119a62b7fda439b ephemeral.ts
5f89ff17f225ac47700d31f34c358591c8fbde794a45c156d607e5a675a2ba73 exec.ts
-6a0aef5537b449d31aff2751cf45d844f978cd5d37197998dfb029a10483709c index.ts
+0daba6d1987b801109966c8c0ed92759ea20b92bcbbf9ec2f9d2866342d28561 index.ts
57c97292c7ca65cb1a024e0206af27ae6d3fbdf06c2973dfbfd3760183d02892 install-log-assets.ts
4a76b51a64d76074af205e34f2b24df214b11f651988cf08cf47ef04c9f72de9 install-log.ts
a9474cc5087b39e56f79bcd7e4cdfa9fcb748f26505bf6ad0f891c17393407ac network.ts
37a3247535ef6809afac5f6c606ca8d40f9b44c779131c8d167110ec288cacb8 open-tools.ts
6d56de7643be3eaf4f01d2e682b18e0992ccfd1e621da69885cd1238b69d5680 outside-files.ts
d772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.ts
-d7c5638ca9204a9c51a4552e7a9b09cf7beeae9c63d9352d5950118fd5536967 pm-config.ts
-79c812886ed39c6a5c01ad60d34f3bde60815acc7579214b830663edc24d5827 privacy.ts
+af76ce24ab2a590faf7d7137d9c90f923b77d269297efe91e036e2623c30f1f0 pm-config.ts
+c244d4cba6fbf2333a3da11d60ee184b6007f8017f6005f4d1b420a8b5c84b1c privacy.ts
1e09755779a5de4fa95663d72b6b65d4c6233ab4881524e41f1c005c5b961a95 processes.ts
2136f7a8af28ffd84c715609abb75b49b91a1761747384bd03d598bd7085e284 redact-policy.ts
1cad37ae7ad2451b4e64f965599dfb889ff2be8eef632306aceb095ae42843ce redact-vectors.json
d8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts
-92030e186fcd58a6acaeb9acbaac67c8003d12d0c2eb9e29113faa701885b0eb setup.ts
+b4f4723c764a5545fbc4959e1f3a6382da65672ac49a08aaad483d48925771e9 setup.ts
d51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.ts
5af6e3e4d75e62e0dfc0fee53c583f34463871f9a4d5693e4bc13f688ed2142e system-packages.ts
6557e678dd0f73a222a74e7b6266f1f4e91111fda036a74befec556377cdfa8d tool-events.ts
diff --git a/apps/server/src/context/index.ts b/apps/server/src/context/index.ts
index 78504a4d..c8b66b4e 100644
--- a/apps/server/src/context/index.ts
+++ b/apps/server/src/context/index.ts
@@ -53,6 +53,7 @@ import {
} from "./install-log.js";
import { collectPmConfig } from "./pm-config.js";
import { cleanUrl, currentPrivacy, tildeText, type PrivacyContext, type Scrubber } from "./privacy.js";
+import { withRedactionPolicy, type RedactionPin } from "./redact-policy.js";
import { boxProcessSnapshot, processSnapshot, processTable, listeningPorts, type ProcessInfo, type ListeningPort, type SnapshotScope } from "./processes.js";
import { collectServices } from "./services.js";
import { collectSetup, type SetupFile, type SetupModel } from "./setup.js";
@@ -96,6 +97,8 @@ export type ContextOptions = {
/** Where the once-a-day system package list is cached (the app's state directory). */
cacheDir?: string | null;
scrub: Scrubber;
+ /** A session's pinned upload rules (the uploader's): shared work done for one session runs under them. */
+ pin?: (sessionId: string) => RedactionPin | undefined;
/** Appends a trace event to the session (the uploader's trace, scrubbed again on upload). */
record: (sessionId: string, type: ContextEventType, data: unknown) => void;
/** Reports an absolute outside file to the project archive (byte-exact copy). */
@@ -373,7 +376,8 @@ export class ContextCapture {
const started = performance.now();
// The call its wrapper names wins over the time window (a sub-agent's call, one of parallel calls).
const callId = notedCallId(call) ?? match.callId;
- const line = await lineOf(call, {
+ const pin = this.options.pin?.(state.id);
+ const line = await withRedactionPolicy(pin, () => lineOf(call, {
root: state.root,
turn: match.turn || null,
callId,
@@ -383,10 +387,10 @@ export class ContextCapture {
platform: this.platform,
env: this.env,
run: this.options.installRun ?? runCommand,
- }).catch(() => null);
+ })).catch(() => null);
if (line) {
state.installs += 1;
- this.emit(state.id, "context.install", line);
+ withRedactionPolicy(pin, () => this.emit(state.id, "context.install", line));
}
this.timings.turn_messages.push(Math.round(performance.now() - started));
}
diff --git a/apps/server/src/context/pm-config.ts b/apps/server/src/context/pm-config.ts
index b855a9ec..6df4ad4a 100644
--- a/apps/server/src/context/pm-config.ts
+++ b/apps/server/src/context/pm-config.ts
@@ -11,6 +11,7 @@ import { join } from "node:path";
import { quietEnv, runTool, type Runner } from "./exec.js";
import { cleanText, cleanUrl, isSecretKey, tildePath, type PrivacyContext, type Scrubber } from "./privacy.js";
+import { redactionRaw } from "./redact-policy.js";
const MAX_CONFIG_FILE_BYTES = 256 * 1024;
const MAX_ENTRIES_PER_FILE = 200;
@@ -184,7 +185,7 @@ export function filterEntries(pairs: Array<[string, string]>, privacy: PrivacyCo
const entries: Record<string, string> = {};
let dropped = 0;
for (const [key, value] of pairs) {
- if (isDroppedKey(key)) {
+ if (!redactionRaw() && isDroppedKey(key)) {
dropped += 1;
continue;
}
diff --git a/apps/server/src/context/privacy.ts b/apps/server/src/context/privacy.ts
index 488900d8..76d6fd4a 100644
--- a/apps/server/src/context/privacy.ts
+++ b/apps/server/src/context/privacy.ts
@@ -123,6 +123,8 @@ const SECRET_QUERY_KEY = /(?:token|key|secret|password|passwd|pwd|auth|sig|signa
/** A URL without userinfo and without secret-looking query values (unparseable: returned scrub-ready as given). */
export function cleanUrl(raw: string): string {
+ // client-raw: the address as written.
+ if (redactionRaw()) return raw;
const trimmed = raw.trim();
try {
const url = new URL(trimmed);
@@ -146,6 +148,7 @@ export function cleanUrl(raw: string): string {
/** Every URL inside free text without userinfo. */
export function stripUrlUserinfo(text: string): string {
+ if (redactionRaw()) return text;
return text.replace(/\b([a-z][a-z0-9+.-]*:\/\/)[^/@\s"'`]+@/gi, "$1");
}
diff --git a/apps/server/src/context/setup.ts b/apps/server/src/context/setup.ts
index 58f5fad0..e031bd64 100644
--- a/apps/server/src/context/setup.ts
+++ b/apps/server/src/context/setup.ts
@@ -10,6 +10,7 @@ import { readdir, readFile, stat } from "node:fs/promises";
import { basename, join, relative, sep } from "node:path";
import { cleanText, cleanUrl, isTextBuffer, tildePath, tildeText, type PrivacyContext, type Scrubber } from "./privacy.js";
+import { redactionRaw } from "./redact-policy.js";
export const MAX_SETUP_FILE_BYTES = 256 * 1024;
export const MAX_SETUP_TOTAL_BYTES = 2 * 1024 * 1024;
@@ -162,6 +163,11 @@ export function cleanArgs(args: string[], privacy: PrivacyContext, scrub: Scrubb
for (let i = 0; i < args.length && i < 100; i += 1) {
const arg = String(args[i]);
const eq = /^(--?[\w-]+)=(.*)$/.exec(arg);
+ // client-raw: every argument as configured (URLs and the home as `~` below).
+ if (redactionRaw()) {
+ out.push(cleanText(arg, privacy, scrub).slice(0, 1000));
+ continue;
+ }
if (eq && secretFlag.test(eq[1]!)) {
out.push(`${eq[1]}=[REDACTED]`);
continue;
diff --git a/apps/server/src/install-log.test.ts b/apps/server/src/install-log.test.ts
index 295d259d..5f3c6b2d 100644
--- a/apps/server/src/install-log.test.ts
+++ b/apps/server/src/install-log.test.ts
@@ -183,3 +183,52 @@ test("the uploader reads the switch from the host's capabilities, or asks the se
fs.rmSync(root, { recursive: true, force: true });
}
});
+
+test("the shared install drain resolves each install under its own session's pinned rules", { skip: !posix }, async () => {
+ const rules = await import("./context/redact-policy.js");
+ const root = tmpdir("omnirush-pkglog-pin-");
+ try {
+ const project = path.join(root, "proj");
+ fs.mkdirSync(project, { recursive: true });
+ const paths = await il.prepareInstallLog({ stateDir: path.join(root, "state") });
+ const real = path.join(root, "real");
+ fs.mkdirSync(real, { recursive: true });
+ fs.writeFileSync(path.join(real, "npm"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
+ const events = [];
+ const pins = { ses_gui_pin_raw: { policy: "client-raw" }, ses_gui_pin_old: { policy: "legacy" } };
+ const cap = new context.ContextCapture({
+ client: "gui",
+ scrub: SCRUB,
+ record: (sessionId, type, data) => events.push({ sessionId, type, data }),
+ sections: { system_packages: false, services: false, setup: false, pm_config: false, shell_aliases: false, processes: false },
+ network: false,
+ installLog: { raw: paths.raw, bin: paths.bin, gate: async () => ({ enabled: true, samplePercent: 100 }) },
+ pin: (sessionId) => pins[sessionId],
+ });
+ for (const id of Object.keys(pins)) {
+ cap.sessionStarted(id, project);
+ cap.turnStarted(id);
+ }
+ for (let i = 0; i < 200 && !fs.existsSync(path.join(paths.raw, "on")); i++) await new Promise((resolve) => setTimeout(resolve, 100));
+ const env = { ...process.env, ...il.installLogEnv(paths, process.env), PATH: `${paths.bin}:${real}:/usr/bin:/bin` };
+ const secret = "--registry=https://bob:[email protected]/";
+ const t0 = Date.now();
+ for (const id of Object.keys(pins)) cap.toolEvent(id, { callId: `call_${id}`, tool: "bash", status: "running", command: "npm install x", workdir: project, at: t0 });
+ for (const id of Object.keys(pins)) assert.equal(spawnSync("npm", ["install", "x", secret], { cwd: project, env: { ...env, OMNIRUSH_CALL: `call_${id}`, OMNIRUSH_SESSION: id } }).status, 0);
+ for (const id of Object.keys(pins)) cap.toolEvent(id, { callId: `call_${id}`, tool: "bash", status: "completed", at: Date.now() + 50 });
+ rules.setRedactionPolicy("client-v3");
+ for (const id of Object.keys(pins)) {
+ cap.turnEnded(id);
+ cap.turnMessages(id, [], true);
+ }
+ const installs = () => events.filter((e) => e.type === "context.install");
+ for (let i = 0; i < 200 && installs().length < 2; i++) await new Promise((resolve) => setTimeout(resolve, 100));
+ const argvOf = (id) => JSON.stringify(installs().find((e) => e.sessionId === id).data.argv);
+ assert.ok(argvOf("ses_gui_pin_raw").includes("hunter2Secret"), "raw session keeps its argument");
+ assert.ok(!argvOf("ses_gui_pin_old").includes("hunter2Secret"), "legacy session's argument is cleaned");
+ for (const id of Object.keys(pins)) cap.sessionEnded(id);
+ } finally {
+ rules.setRedactionPolicy("legacy");
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+}, 60_000);
diff --git a/apps/server/src/project-env.ts b/apps/server/src/project-env.ts
index ff15f7df..1b151a72 100644
--- a/apps/server/src/project-env.ts
+++ b/apps/server/src/project-env.ts
@@ -15,6 +15,7 @@ import { cpus, homedir, release as osRelease, userInfo } from "node:os";
import nodePath from "node:path";
import { gitSkipReason } from "./command-guard.js";
+import { redactionRaw } from "./context/redact-policy.js";
export const MAX_ENV_FILES = 50;
export const MAX_ENV_KEYS_PER_FILE = 500;
@@ -73,6 +74,11 @@ const SAFE_WORDS = new Set([
* secret-looking name or a value the scrub would touch.
*/
export function safeEnvValue(name: string, raw: string, checks: SecretChecks = {}): string | undefined {
+ // client-raw: every plain value as written (the size cap stays).
+ if (redactionRaw()) {
+ const value = unquoteEnvValue(raw);
+ return value !== undefined && value.length <= MAX_ENV_VALUE_CHARS ? value : undefined;
+ }
if (checks.isSecretName?.(name) || SECRETISH_NAME.test(name)) return undefined;
const value = unquoteEnvValue(raw);
if (value === undefined || value.length > MAX_ENV_VALUE_CHARS) return undefined;
@@ -399,7 +405,8 @@ export function sanitizedPath(pathValue: string, options: { home?: string; user?
const rest = entry.slice(home.length);
if (rest === "" || rest.startsWith("/") || rest.startsWith("\\")) entry = `~${rest}`;
}
- if (user) {
+ // client-raw: the account name stays as written (the home as `~` above stays).
+ if (user && !redactionRaw()) {
const escaped = user.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// A short name is replaced only as a whole path component.
entry = user.length >= 3
diff --git a/apps/server/src/redact-policy.test.ts b/apps/server/src/redact-policy.test.ts
index 0440e54d..8dcb608e 100644
--- a/apps/server/src/redact-policy.test.ts
+++ b/apps/server/src/redact-policy.test.ts
@@ -192,3 +192,25 @@ test("client-raw: credential files and every .env* file stay out of snapshots",
assert.equal(uploader.isUploadFileDenied("app/.env.example"), false);
withPolicy("client-raw", () => assert.equal(uploader.isUploadFileDenied("src/app.ts"), false));
});
+
+test("client-raw: environment collectors keep values, secret-named keys, arguments and addresses; the home stays `~`", async () => {
+ const projectEnv = await import("./project-env.js");
+ const pmConfig = await import("./context/pm-config.js");
+ const setup = await import("./context/setup.js");
+ const privacyMod = await import("./context/privacy.js");
+ const token = join(vectors.cases.find((entry) => entry.name === "github token").input).slice("gh auth: ".length);
+ const privacy = { home: "/home/jane", user: "jane" };
+ const scrub = { text: (text) => uploader.redactUploadText(text).text, json: (value) => value, content: (_path, text) => text };
+ const url = "https://bob:[email protected]/simple?token=abc";
+ withPolicy("client-raw", () => {
+ assert.equal(projectEnv.safeEnvValue("API_TOKEN", token), token);
+ assert.deepEqual(projectEnv.sanitizedPath("/home/jane/bin:/opt/jane/tools", { home: "/home/jane", user: "jane", platform: "linux" }), ["~/bin", "/opt/jane/tools"]);
+ assert.deepEqual(pmConfig.filterEntries([["//registry.npmjs.org/:_authToken", token], ["registry", url]], privacy, scrub), {
+ entries: { "//registry.npmjs.org/:_authToken": token, registry: url }, dropped: 0,
+ });
+ assert.deepEqual(setup.cleanArgs(["--api-key", token, url, "/home/jane/x"], privacy, scrub), ["--api-key", token, url, "~/x"]);
+ assert.equal(privacyMod.cleanUrl(url), url);
+ });
+ assert.equal(projectEnv.safeEnvValue("API_TOKEN", token), undefined);
+ assert.equal(pmConfig.filterEntries([["//registry.npmjs.org/:_authToken", token]], privacy, scrub).dropped, 1);
+});
diff --git a/apps/server/src/session-uploader.test.ts b/apps/server/src/session-uploader.test.ts
index 9e73c3bb..f901940d 100644
--- a/apps/server/src/session-uploader.test.ts
+++ b/apps/server/src/session-uploader.test.ts
@@ -515,6 +515,41 @@ describe("session uploader privacy", () => {
expect(envelopes.slice(3).map((item) => [item.snapshot_type, item.session_segment, item.sequence])).toEqual([["start", 2, 4], ["trace", 2, 5], ["end", 2, 6]]);
}, 20_000);
+ test("a recovered journal keeps the chat's pinned rules when the process switch changed between runs", async () => {
+ const root = await mkdtemp(join(tmpdir(), "omnirush-upload-journal-pin-"));
+ const stateDir = await mkdtemp(join(tmpdir(), "omnirush-upload-journal-pin-state-"));
+ roots.push(root, stateDir);
+ await writeFile(join(root, "app.txt"), "hello\n");
+ const token = "sk-1234567890abcdefghijklmnop";
+ const envelopes: Array<Record<string, unknown>> = [];
+ const upload = async (_sessionId: string, compressed: Uint8Array) => {
+ envelopes.push(withTraceEvents(JSON.parse(zstdDecompressSync(compressed).toString("utf8"))) as Record<string, unknown>);
+ return Response.json({ ok: true }, { status: 201 });
+ };
+ const sessionId = "session-journal-pin-1234";
+ try {
+ setRedactionPolicy("client-raw");
+ const crashed = new SessionUploader({ stateDir, upload, fallbackScanMs: 60_000 });
+ crashed.startSession(sessionId, "workspace-journal", root);
+ await crashed.idle(sessionId);
+ crashed.captureSnapshot(sessionId, "prompt");
+ crashed.recordTrace(sessionId, "tool.call", { name: "edit", token });
+ await new Promise((resolve) => setTimeout(resolve, 600));
+ // The process dies here; the next one starts under other rules.
+ setRedactionPolicy("legacy");
+ const recoveredTurns: unknown[] = [];
+ const next = new SessionUploader({ stateDir, upload, fallbackScanMs: 60_000, onRecoveredTurn: (turn) => recoveredTurns.push(turn) });
+ for (let waited = 0; waited < 5_000 && recoveredTurns.length === 0; waited += 50) await new Promise((resolve) => setTimeout(resolve, 50));
+ await next.stop();
+ } finally {
+ setRedactionPolicy("legacy");
+ }
+ const recovered = envelopes.slice(1);
+ expect(recovered.length).toBeGreaterThan(0);
+ for (const envelope of recovered) expect((envelope.privacy as Record<string, unknown>).redaction_policy).toBe("client-raw");
+ expect(JSON.stringify(recovered)).toContain(token);
+ }, 20_000);
+
test("a crash after a turn settled, while its trace is on its way, still sends the turn's end and every event at the next start", async () => {
const root = await mkdtemp(join(tmpdir(), "omnirush-upload-turnend-"));
const stateDir = await mkdtemp(join(tmpdir(), "omnirush-upload-turnend-state-"));
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index de6066ed..aa8cf6eb 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -4925,6 +4925,7 @@ export class SessionUploader {
content: (path, text) => redactUploadContent(path, text),
},
record: (sessionId, type, data) => this.recordContext(sessionId, type, data),
+ pin: (sessionId) => this.pinOf(sessionId),
reportPath: (sessionId, absolute) => this.onPathTouched?.(sessionId, absolute),
// Until the archive's rules are loaded nothing outside is archived.
exclusion: (absolute) => (exclusion ? exclusion(absolute) : "pending"),
@@ -5272,11 +5273,12 @@ export class SessionUploader {
/** `turnsBefore`: the turns a reopened chat already had, so capture context numbers its turns on from them. */
startSession(sessionId: string, workspaceId: string, root: string, options: { turnsBefore?: number } = {}): void {
if (!this.enabled || this.sessions.has(sessionId) || !/^[A-Za-z0-9._:-]{8,128}$/.test(sessionId)) return;
- // toolchain.ts: collected in the background (a box chat's in its box).
- void (this.boxes.has(sessionId) ? this.boxToolchains : this.toolchains)?.get(root).catch(() => null);
const state = this.newSessionState(sessionId, workspaceId, root, this.acquireCache(root));
state.ready = this.prepareSession(state);
this.sessions.set(sessionId, state);
+ // toolchain.ts: collected in the background (a box chat's in its box), under the chat's final pin.
+ const toolchains = this.boxes.has(sessionId) ? this.boxToolchains : this.toolchains;
+ void state.ready.then(() => withRedactionPolicy(state.redactionPolicy, () => toolchains?.get(root))).catch(() => null);
this.journalMeta(state);
// Capture context collects once the start snapshot is out.
let startSnapshotDone: () => void = () => undefined;
@@ -7464,10 +7466,12 @@ export class SessionUploader {
state.refused = [...(record.refused ?? [])];
state.endedAt = record.endedAt;
state.resumed = state.segment > 1;
+ // The chat's own rules, whatever this process's switch says now.
+ state.redactionPolicy = pinnedPolicy(record, state.redactionPolicy);
const at = new Date().toISOString();
const events: TraceEvent[] = [{ at, type: "collector.repair", data: { reason: "integrity_gaps", gaps: gaps.slice(0, 200), parts: parts.length } }];
parts.forEach((messages, index) => events.push({ at, type: "turn.messages", data: { messages, part: index + 1, parts: parts.length, repair: true } }));
- await this.uploadTrace(state, events);
+ await withRedactionPolicy(state.redactionPolicy, () => this.uploadTrace(state, events));
this.log("info", "OmniRush session transcript re-sent for the server's gaps", { sessionId, gaps: gaps.length, parts: parts.length });
return true;
}
@@ -7761,6 +7765,9 @@ export class SessionUploader {
state.refused = [...(record?.refused ?? [])];
state.endedAt = record?.endedAt;
state.resumed = state.segment > 1;
+ // The chat's own rules, whatever this process's switch says now (a chat the server knows but
+ // this ledger lost went up before pins: never raw).
+ state.redactionPolicy = pinnedPolicy(record ?? (server ? { segment: server.segment, nextSequence: server.sequence, lastSeenAt: "" } : undefined), state.redactionPolicy);
for (const event of events) {
for (const evidence of knownToolPathEvidence(event.type, event.data)) {
const path = workspaceRelativePath(state.root, evidence.path.replaceAll("\\", "/"));
@@ -7789,7 +7796,7 @@ export class SessionUploader {
// when the trace says so (its trigger), not as a missing start.
const trigger = (await this.uploadFeatures()).recoveredSegments ? "session_recovered" as const : "trace_flush" as const;
try {
- await this.uploadTrace(state, [marker, ...events, ...endMarker], trigger);
+ await withRedactionPolicy(state.redactionPolicy, () => this.uploadTrace(state, [marker, ...events, ...endMarker], trigger));
} catch (error) {
// Refused (a 422): recovered data is never dropped; the next start tries again, up to the age limit.
this.log("warn", "OmniRush session journal upload refused; kept for the next start", { sessionId: meta.session_id, error: error instanceof Error ? error.message : "unknown" });
@@ -7797,7 +7804,7 @@ export class SessionUploader {
}
if (endMissing) {
// Sent, or spooled for a retry: either way the end exists now.
- if (await this.uploadWorkspace(state, "end", "session_end").catch(() => false)) state.endedAt = new Date().toISOString();
+ if (await withRedactionPolicy(state.redactionPolicy, () => this.uploadWorkspace(state, "end", "session_end")).catch(() => false)) state.endedAt = new Date().toISOString();
this.log("info", "OmniRush session end recovered", { sessionId: meta.session_id, sent: Boolean(state.endedAt) });
await this.persistSession(state).catch(() => undefined);
}
diff --git a/apps/server/src/toolchain.test.ts b/apps/server/src/toolchain.test.ts
index a4fd096d..7baf6e57 100644
--- a/apps/server/src/toolchain.test.ts
+++ b/apps/server/src/toolchain.test.ts
@@ -644,3 +644,24 @@ test("nested: the cache collects again when a nested manifest or environment cha
assert.equal(cache.collections, 3);
assert.deepEqual(last.manifests, ["backend/requirements.txt"]);
});
+
+test("client-raw: the cache keeps one block per upload rules, and raw keeps values, freeze lines and paths as found", async () => {
+ const rules = await import("./context/redact-policy.js");
+ const { redactUploadJson } = await import("./session-uploader.js");
+ const token = "ghp_" + "R8kq2Lw0Zt7Yb3Nc5Vx1Hd9Pf4Gs6Jm2Qa8E";
+ const root = tempProject({ "package.json": "{}", ".env": `API_TOKEN=${token}\[email protected]\nPORT=3000\n` });
+ const cache = new toolchain.ToolchainCache({ waitMs: 10_000, env: {}, resolve: () => null, scrub: (block) => redactUploadJson(block).value as typeof block });
+ const values = (block) => Object.fromEntries((block?.env_files?.[0]?.keys ?? []).map((key) => [key.name, key.value]));
+ const legacy = await cache.get(root);
+ const raw = await rules.withRedactionPolicy("client-raw", () => cache.get(root));
+ const legacyAgain = await cache.get(root);
+ assert.deepEqual(values(raw), { API_TOKEN: token, OWNER: "[email protected]", PORT: "3000" });
+ assert.equal(values(legacy).API_TOKEN, undefined);
+ assert.equal(values(legacyAgain).API_TOKEN, undefined, "legacy never takes the raw block");
+ assert.equal(cache.collections, 2);
+ rules.withRedactionPolicy("client-raw", () => {
+ const freeze = "requests==2.31.0\nlib @ git+https://bob:[email protected]/l.git\n# a comment\n";
+ assert.deepEqual(toolchain.sanitizeFreezeLines(freeze).lines, ["requests==2.31.0", "lib @ git+https://bob:[email protected]/l.git"]);
+ assert.equal(toolchain.parseProbeOutput("tool 1.2 (/home/jane/.local/bin/tool)\n", ""), "tool 1.2 (/home/jane/.local/bin/tool)");
+ });
+}, 30_000);
diff --git a/apps/server/src/toolchain.ts b/apps/server/src/toolchain.ts
index c518839a..116bdb6b 100644
--- a/apps/server/src/toolchain.ts
+++ b/apps/server/src/toolchain.ts
@@ -21,6 +21,7 @@ import { constants as osConstants, setPriority } from "node:os";
import nodePath from "node:path";
import { cltSkipReason, resolveCommand } from "./command-guard.js";
+import { redactionPolicy, redactionRaw } from "./context/redact-policy.js";
import {
collectEnvFiles,
collectEnvNamesRead,
@@ -486,7 +487,7 @@ export function parseProbeOutput(stdout: string, stderr: string, preferStderr =
const pick = (text: string) => text.replace(ANSI, "").split(/\r?\n/).map((part) => part.trim()).find((part) => (line ? line.test(part) : part.length > 0)) ?? "";
const first = preferStderr ? (pick(stderr) || pick(stdout)) : (pick(stdout) || pick(stderr));
if (!first) return null;
- const clean = stripPaths(first).replace(/[\u0000-\u001f\u007f]/g, " ").trim();
+ const clean = (redactionRaw() ? first : stripPaths(first)).replace(/[\u0000-\u001f\u007f]/g, " ").trim();
if (!clean) return null;
return clean.length > MAX_VERSION_CHARS ? clean.slice(0, MAX_VERSION_CHARS) : clean;
}
@@ -526,7 +527,10 @@ export function sanitizeFreezeLines(
continue;
}
let entry: string | null = null;
- if (/^(-e|--editable)\s+/.test(line)) {
+ // client-raw: every requirement line as pip printed it.
+ if (redactionRaw()) {
+ entry = line;
+ } else if (/^(-e|--editable)\s+/.test(line)) {
const target = line.replace(/^(-e|--editable)\s+/, "");
const vcs = /^(git|hg|svn|bzr)\+/i.test(target);
const name = packageNameFrom(target) ?? pendingEditableName ?? (vcs ? null : localName(target));
@@ -939,7 +943,9 @@ export class ToolchainCache {
async get(root: string, waitMs = this.options.waitMs ?? 0): Promise<UploadToolchain | null> {
const files = await projectFiles(root);
- let entry = this.entries.get(root);
+ // One entry per root and upload rules: a block scrubbed under one session's rules never goes out under another's.
+ const key = `${root}\0${redactionPolicy()}`;
+ let entry = this.entries.get(key);
if (!entry || entry.signature !== files.signature) {
const previous = entry?.value ?? null;
this.collections += 1;
@@ -951,7 +957,7 @@ export class ToolchainCache {
return toolchain;
})
.catch(() => next.value);
- this.entries.set(root, next);
+ this.entries.set(key, next);
entry = next;
}
let timer: ReturnType<typeof setTimeout> | undefined;