Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: files used set at chat start, notice per chat

ogsamrat94cf84c08304
diff --git a/apps/app/src/react-app/shell/files-used-notice.ts b/apps/app/src/react-app/shell/files-used-notice.ts
index a12999f6..cbec9cd0 100644
--- a/apps/app/src/react-app/shell/files-used-notice.ts
+++ b/apps/app/src/react-app/shell/files-used-notice.ts
@@ -31,7 +31,9 @@ function dismissNotice(): void {
/**
* Once per computer: omnirush.ai's session files line as a "what's new"
* notice that stays until dismissed. `show` puts it in the app's notices.
- * Never throws.
+ * Called when the app connects and whenever a session opens; it asks
+ * omnirush.ai each time until the notice is dismissed (a session only
+ * records files used when its base saw the flag on). Never throws.
*/
export async function showFilesUsedNoticeOnce(
client: Pick<OmniRushServerClient, "getFilesUsed">,
diff --git a/apps/app/src/react-app/shell/use-workspace-route-state.ts b/apps/app/src/react-app/shell/use-workspace-route-state.ts
index 13e0b567..064ab93a 100644
--- a/apps/app/src/react-app/shell/use-workspace-route-state.ts
+++ b/apps/app/src/react-app/shell/use-workspace-route-state.ts
@@ -1203,6 +1203,8 @@ export function useWorkspaceRouteState(input: UseWorkspaceRouteStateInput) {
const routingServerUrl = selectedWorkspaceEndpoint?.baseUrl ?? "";
const routingServerToken = selectedWorkspaceEndpoint?.token ?? "";
// Session files: omnirush.ai's line, once, as a "what's new" notice (desktop only; dismissed for good).
+ // Asked again whenever a session opens, until dismissed: a flag turned on while the app runs reaches new
+ // sessions only (session-archive/index.ts), so the line shows when the first session that records them opens.
useEffect(() => {
if (!isDesktopRuntime() || !routingServerUrl || !routingServerToken) return;
const client = createOmniRushServerClient({ baseUrl: routingServerUrl, token: routingServerToken });
@@ -1213,7 +1215,7 @@ export function useWorkspaceRouteState(input: UseWorkspaceRouteStateInput) {
action: { label: "Got it", onClick: onDismiss },
});
});
- }, [routingServerUrl, routingServerToken]);
+ }, [routingServerUrl, routingServerToken, selectedSessionId]);
useEffect(() => {
if (!routingServerUrl || !routingServerToken) {
diff --git a/apps/app/tests/files-used-notice.test.tsx b/apps/app/tests/files-used-notice.test.tsx
index 7a567f30..c9b5755d 100644
--- a/apps/app/tests/files-used-notice.test.tsx
+++ b/apps/app/tests/files-used-notice.test.tsx
@@ -51,4 +51,18 @@ describe("session files notice", () => {
expect(await showFilesUsedNoticeOnce({ getFilesUsed: async () => { throw new Error("down"); } }, () => shown.push("x"))).toBe(false);
});
});
+
+ test("asked again at each session until dismissed: a flag turned on later shows the line when the next session opens", async () => {
+ await withStorage(async () => {
+ let flag = false;
+ let asked = 0;
+ const client = { getFilesUsed: async () => { asked += 1; return flag ? status() : status({ active: false, available: false, consentText: null }); } };
+ const shown: string[] = [];
+ expect(await showFilesUsedNoticeOnce(client, (text) => shown.push(text))).toBe(false);
+ flag = true;
+ expect(await showFilesUsedNoticeOnce(client, (text) => shown.push(text))).toBe(true);
+ expect(shown).toEqual([`What's new: ${LINE}`]);
+ expect(asked).toBe(2);
+ });
+ });
});
diff --git a/apps/server/src/session-archive/files-used.test.ts b/apps/server/src/session-archive/files-used.test.ts
index decd14aa..8c47bba1 100644
--- a/apps/server/src/session-archive/files-used.test.ts
+++ b/apps/server/src/session-archive/files-used.test.ts
@@ -2,7 +2,7 @@ import { afterAll, afterEach, describe, expect, test } from "bun:test";
import { execFileSync } from "node:child_process";
import { createHash, randomBytes } from "node:crypto";
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs";
-import { tmpdir } from "node:os";
+import { homedir, tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { zstdDecompressSync } from "node:zlib";
@@ -113,6 +113,10 @@ describe("policy (shared with the CLI)", () => {
expect(classify("/home/u/.yarnrc.yml")).toBe("home stage captured");
expect(classify("/home/u/.config/pip/pip.conf")).toBe("home stage captured");
expect(classify("/home/u/.bashrc")).toBe("home hold not_allowlisted");
+ // Home files off the config allowlist are listed only, wherever they are under the home.
+ expect(classify("/home/u/Downloads/data.csv")).toBe("home hold not_allowlisted");
+ expect(classify("/home/u/Documents/report.docx")).toBe("home hold not_allowlisted");
+ expect(classify("/home/u/other-project/src/main.py")).toBe("home hold not_allowlisted");
expect(classify("/home/u/.cache/pip/x.whl")).toBe("home hold dependency_dir");
expect(classify("/w/node_modules/a/index.js")).toBe("project hold dependency_dir");
expect(classify("/w/dist/app.js")).toBe("project hold build_output");
@@ -156,13 +160,12 @@ describe("policy (shared with the CLI)", () => {
expect(policy.MAX_FILES_USED_SESSION_BYTES).toBe(256 * 1024 * 1024);
});
- test("GET /archives/key: files_used and its caps; the environment switch", () => {
+ test("GET /archives/key: files_used and its caps; no client override", () => {
expect(parseArchivePolicy({ policy: { capture_v2: true, files_used: true, files_used_max_file_bytes: 1024, files_used_max_session_bytes: null } }))
.toEqual({ allFolders: false, touchedFiles: false, captureV2: true, filesUsed: true, filesUsedMaxFileBytes: 1024 });
expect(parseArchivePolicy({ policy: { files_used: false } }).filesUsed).toBeUndefined();
- expect(policy.filesUsedOverride({ OMNIRUSH_ARCHIVE_FILES_USED: "1" })).toBe(true);
- expect(policy.filesUsedOverride({ OMNIRUSH_ARCHIVE_FILES_USED: "0" })).toBeNull();
- expect(policy.filesUsedOverride({})).toBeNull();
+ expect((policy as Record<string, unknown>).filesUsedOverride).toBeUndefined();
+ expect((used as Record<string, unknown>).filesUsedOverride).toBeUndefined();
});
test("dependencies: every subproject's lockfile with its resolved versions", async () => {
@@ -378,7 +381,7 @@ describe("a files-used chain", () => {
expect(quiet.state.dependencies).toBeUndefined();
});
- test("omnirush.ai's flag drives it: nothing before it is on, recorded once it is, and the notice status says so", async () => {
+ test("omnirush.ai's flag drives it: decided at a session's base (new sessions only), and the notice status says so", async () => {
const line = "OmniRush also saves the files the agent reads, runs or creates during a session (including temporary files and a few allowlisted config files, with secrets removed), so the session can be replayed.";
let flag = false;
let clock = Date.now();
@@ -391,27 +394,57 @@ describe("a files-used chain", () => {
expect(archiver.filesUsedMaybe()).toBe(false);
expect(await archiver.filesUsedStatus()).toEqual({ active: false, available: false, consentText: null });
+ // Turned on while the session runs: that session stays as it began (its notice moment has passed).
flag = true;
clock += 6 * 60_000;
const read = toolPart("r", "read", { filePath: join(root, "config.local.yaml") });
- // The answer is asked again at the turn's end (it is old): recorded from this turn on.
- expect((await archiver.filesUsedTurnEnded(sessionId, root, turn(read))).items).toBeGreaterThanOrEqual(1);
- expect(await archiver.filesUsedActive(sessionId)).toBe(true);
- const on = await open(await archiver.captureDelta(sessionId, root, 1));
- expect(on.state.files_used!.find((item) => item.path === "config.local.yaml")?.captured).toBe(true);
+ expect((await archiver.filesUsedTurnEnded(sessionId, root, turn(read))).items).toBe(0);
+ expect(await archiver.filesUsedActive(sessionId)).toBe(false);
expect(await archiver.filesUsedStatus()).toEqual({ active: true, available: true, consentText: line });
+
+ // The next session (the app shows the line when it opens) records them from its base on.
+ const next = "ses_files_used_gui_flag2";
+ const nextBase = await open(await archiver.captureBase(next, root, 0));
+ expect(nextBase.state.files_used).toEqual([]);
+ expect((await archiver.filesUsedTurnEnded(next, root, turn(read))).items).toBeGreaterThanOrEqual(1);
+ const on = await open(await archiver.captureDelta(next, root, 1));
+ expect(on.state.files_used!.find((item) => item.path === "config.local.yaml")?.captured).toBe(true);
});
- test("OMNIRUSH_ARCHIVE_FILES_USED=1 (tests) never overrides an answer that says no; =0 is no switch", async () => {
+ test("OMNIRUSH_ARCHIVE_FILES_USED in the environment never turns recording on (no client override)", async () => {
process.env.OMNIRUSH_ARCHIVE_FILES_USED = "1";
const off = rig({ capture_v2: true, files_used: false });
const root = project();
- await off.open(await off.archiver.captureBase("ses_files_used_gui_env1", root, 0));
+ const base = await off.open(await off.archiver.captureBase("ses_files_used_gui_env1", root, 0));
+ expect(base.state.files_used).toBeUndefined();
expect(await off.archiver.filesUsedActive("ses_files_used_gui_env1")).toBe(false);
- process.env.OMNIRUSH_ARCHIVE_FILES_USED = "0";
- const on = rig({ capture_v2: true, files_used: true });
- const base = await on.open(await on.archiver.captureBase("ses_files_used_gui_env0", project(), 0));
- expect(base.state.files_used).toEqual([]);
+ // Before any answer from omnirush.ai, nothing either.
+ const fresh = rig({ capture_v2: true, files_used: false });
+ expect(await fresh.archiver.filesUsedActive("ses_files_used_gui_env2")).toBe(false);
+ });
+
+ test("a home file off the config allowlist (~/Downloads) is listed not_allowlisted and its bytes never reach the chain", async () => {
+ // A folder under the real home (bun keeps the home it started with): only the home rules apply to it.
+ const home = realpathSync(mkdtempSync(join(homedir(), ".omnirush-fu-home-")));
+ cleanups.push(home);
+ {
+ const { archiver, open } = rig({ capture_v2: true, files_used: true });
+ const root = project();
+ const notes = write(join(home, "Downloads", "fu-notes.txt"), "DOWNLOADS-BYTES-fu\n");
+ const sessionId = "ses_files_used_gui_home";
+ await open(await archiver.captureBase(sessionId, root, 0));
+ const call = toolPart("c", "bash", { command: `cat ${notes}` });
+ await archiver.filesUsedToolCallEnded(sessionId, root, callOf(call));
+ // The session uploader reports it as touched too (outside capture).
+ archiver.recordTouched(sessionId, notes);
+ await archiver.filesUsedTurnEnded(sessionId, root, turn(call));
+ const after = await open(await archiver.captureDelta(sessionId, root, 1));
+ const item = after.state.files_used!.find((entry) => entry.path === notes);
+ expect(item, JSON.stringify(after.state.files_used)).toBeDefined();
+ expect([item!.scope, item!.captured, item!.reason, item!.size] as unknown[]).toEqual(["home", false, "not_allowlisted", 19]);
+ expect([...after.members.keys()].some((name) => name.includes("Downloads"))).toBe(false);
+ expect(after.bytes.toString("latin1")).not.toContain("DOWNLOADS-BYTES-fu");
+ }
});
test("a withdrawal on omnirush.ai stops recording at the next turn whose answer is old", async () => {
diff --git a/apps/server/src/session-archive/index.ts b/apps/server/src/session-archive/index.ts
index dca82065..06ee2c0c 100644
--- a/apps/server/src/session-archive/index.ts
+++ b/apps/server/src/session-archive/index.ts
@@ -74,7 +74,6 @@ import { discoverRepos } from "./repos.js";
import {
classifyUse,
collectDependencyProjects,
- filesUsedOverride,
FilesUsedStore,
FilesUsedTracker,
finalizeFilesUsed,
@@ -290,7 +289,10 @@ const sessionStateSchema = z.object({
last_activity_at: z.string().optional(),
/** Capture v2 (capture-v2.ts): this chain's archives are byte-exact states with a state.json. Set at the base. */
v2: z.boolean().optional(),
- /** Files used (files-used.ts): this v2 chain may list the files each turn used; whether it does is decided at each capture. */
+ /**
+ * Files used (files-used.ts): this v2 chain lists the files each turn used. Set at the base when the
+ * server's flag was on then; the flag, as last answered, can still stop it at any capture (kill switch).
+ */
files_used: z.boolean().optional(),
}).transform((state) => ({ ...state, last_activity_at: state.last_activity_at ?? state.updated_at }));
type SessionState = z.infer<typeof sessionStateSchema>;
@@ -673,29 +675,30 @@ export class SessionArchiver {
/**
* Files used: whether the session's chain lists the files each turn used
- * now: a v2 chain, and omnirush.ai records them for the account (the last
- * key answer's `policy.files_used`, its server setting). Cheap once the
- * session was loaded: asked at every tool call's end.
+ * now: a v2 chain whose base had omnirush.ai's flag on (`policy.files_used`),
+ * while the account's last answer still says on. The flag is the kill
+ * switch for running sessions; turning it on reaches new sessions only (the
+ * app's notice is checked when a session opens). Cheap once the session was
+ * loaded: asked at every tool call's end.
*/
async filesUsedActive(sessionId: string): Promise<boolean> {
if (this.disabled || !SESSION_ID_PATTERN.test(sessionId) || this.stoppedSessions.has(sessionId)) return false;
- if (!this.filesUsedOn()) return false;
+ if (this.filesUsedServer?.on === false) return false;
if (this.filesUsedSessions.has(sessionId)) return true;
await this.start();
const state = await this.loadSession(sessionId);
- // The base is still to come (it waits for a quiet moment): a v2 chain it will be when the server said so.
- if (!state) return captureV2Override() ?? this.policy?.value.captureV2 === true;
+ // The base is still to come (it waits for a quiet moment): a v2 chain with files used it will be when the server said so.
+ if (!state) return this.filesUsedServer?.on === true && (captureV2Override() ?? this.policy?.value.captureV2 === true);
return state.v2 === true && state.files_used === true && !state.stopped && !state.ended;
}
/**
- * Files used: the account's last answer (`policy.files_used`). Before
- * any answer, OMNIRUSH_ARCHIVE_FILES_USED=1 (tests) counts as on; an
- * answer always wins.
+ * Files used: whether the account's last answer (`policy.files_used`)
+ * lets a chain that began with it go on; before any answer in this app
+ * run, the chain's own decision stands. There is no client override.
*/
private filesUsedOn(): boolean {
- if (this.filesUsedServer) return this.filesUsedServer.on;
- return filesUsedOverride() === true;
+ return this.filesUsedServer?.on ?? true;
}
/**
@@ -1135,8 +1138,8 @@ export class SessionArchiver {
// Capture v2 when the server offers it (or the override says so); the chain keeps it.
...((captureV2Override() ?? (fetched.status === "ok" && fetched.policy.captureV2 === true)) ? { v2: true } : {}),
};
- // Files used: every v2 chain may list them; whether it does is decided at each capture (filesUsedOn).
- if (state.v2) state.files_used = true;
+ // Files used: a v2 chain whose base has the server's flag on (no client override); the flag can still stop it later.
+ if (state.v2 && fetched.status === "ok" && fetched.policy.filesUsed === true) state.files_used = true;
if (fetched.status === "ok") this.filesUsed.setLimits({ ...(fetched.policy.filesUsedMaxFileBytes ? { maxFileBytes: fetched.policy.filesUsedMaxFileBytes } : {}), ...(fetched.policy.filesUsedMaxSessionBytes ? { maxSessionBytes: fetched.policy.filesUsedMaxSessionBytes } : {}) });
if (touched) this.dropPrescan(sessionId);
this.touched.track(sessionId);
diff --git a/docs/project-archive.md b/docs/project-archive.md
index ac2b1dd7..dfe56262 100644
--- a/docs/project-archive.md
+++ b/docs/project-archive.md
@@ -198,9 +198,11 @@ session (including temporary files and a few allowlisted config files, with
secrets removed), so the session can be replayed.
It runs whenever omnirush.ai has it on for your account (its server
-setting), next to the project archive. The app shows the line above once,
-as a "what's new" notice. A change on omnirush.ai reaches a running app
-within five minutes.
+setting), next to the project archive. A chat records them when the
+setting is on as the chat starts; the app shows the line above once, as a
+"what's new" notice, when the first such chat opens. Turning the setting
+off on omnirush.ai stops recording in running chats too, within five
+minutes. There is no client override.
The files come only from what the agent itself did: the paths of its file
tools, the files named in the shell commands it ran, a look over the project
@@ -221,8 +223,9 @@ What is saved and what is not:
`.yarnrc`, `pip.conf`, `uv.toml`, editor and linter configs) are saved, as
copies with credentials, tokens and URL passwords removed. `.npmrc` and
`.pypirc` are credential files and are never saved. Other dotfiles and
- settings folders are listed but never saved. Other files in the home folder
- the agent used (a dataset in Downloads) are saved as they are.
+ settings folders are listed but never saved, and so are all other files in
+ the home folder the agent used (a dataset in Downloads, documents, another
+ project's files): listed, never saved.
- Never saved: `.env` files, keys, credential stores, tokens, caches and
package stores. Dependency folders (`node_modules`, `.venv`, `vendor`) and
build output (`dist`, `build`, `target`) are listed with their hash only.