Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions frontend/app/view/term/termwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ function handleOsc7Command(data: string, blockId: string, loaded: boolean): bool
await RpcApi.SetRTInfoCommand(TabRpcClient, rtInfoData).catch((e) =>
console.log("error setting RT info", e)
);

// Smart auto-detection: Update tab basedir if not locked
const tabAtom = globalStore.get(atoms.activeTabAtom);
const currentBasedir = tabAtom?.meta?.["tab:basedir"];
const basedirLocked = tabAtom?.meta?.["tab:basedirlock"];

// Set tab basedir if not set yet, or if not locked and this is the first meaningful directory
if (!basedirLocked && (!currentBasedir || currentBasedir === "~")) {
await services.ObjectService.UpdateObjectMeta(
WOS.makeORef("tab", tabAtom.oid),
{
"tab:basedir": pathPart,
}
);
}
Comment on lines +191 to +205
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

atoms is not imported — runtime error.

The atoms object is referenced on line 193 but is not imported in this file. The imports from @/store/global (line 9) include WOS, fetchWaveFile, getApi, getSettingsKeyAtom, globalStore, openLink, recordTEvent but not atoms. This will cause a ReferenceError at runtime.

Additionally, tabAtom.oid on line 200 lacks a null guard despite tabAtom being accessed with optional chaining earlier.

🐛 Proposed fix

Update the import on line 9:

-import { WOS, fetchWaveFile, getApi, getSettingsKeyAtom, globalStore, openLink, recordTEvent } from "@/store/global";
+import { WOS, atoms, fetchWaveFile, getApi, getSettingsKeyAtom, globalStore, openLink, recordTEvent } from "@/store/global";

Add null guard before accessing tabAtom.oid:

             // Set tab basedir if not set yet, or if not locked and this is the first meaningful directory
-            if (!basedirLocked && (!currentBasedir || currentBasedir === "~")) {
+            if (tabAtom && !basedirLocked && (!currentBasedir || currentBasedir === "~")) {
                 await services.ObjectService.UpdateObjectMeta(
                     WOS.makeORef("tab", tabAtom.oid),
🤖 Prompt for AI Agents
In `@frontend/app/view/term/termwrap.ts` around lines 191 - 205, The file
references atoms and accesses tabAtom.oid without guarding; import atoms from
the same module as globalStore (add atoms to the existing import list from
"@/store/global") and add a null guard before calling
services.ObjectService.UpdateObjectMeta so it only runs when tabAtom is non-null
and tabAtom.oid is defined (e.g., check tabAtom and tabAtom.oid before
WOS.makeORef("tab", tabAtom.oid) and the update call).

});
}, 0);
return true;
Expand Down Expand Up @@ -702,6 +717,7 @@ export class TermWrap {
let startTs = Date.now();
const { data: cacheData, fileInfo: cacheFile } = await fetchWaveFile(this.blockId, TermCacheFileName);
let ptyOffset = 0;
let loadedFromCache = false;
if (cacheFile != null) {
ptyOffset = cacheFile.meta["ptyoffset"] ?? 0;
if (cacheData.byteLength > 0) {
Expand All @@ -720,13 +736,22 @@ export class TermWrap {
if (didResize) {
this.terminal.resize(curTermSize.cols, curTermSize.rows);
}
loadedFromCache = true;
}
}
const { data: mainData, fileInfo: mainFile } = await fetchWaveFile(this.blockId, TermFileName, ptyOffset);
// Only load main file data if we didn't load from cache, or load only NEW data after cache
// The cache contains the fully rendered terminal state, so loading from ptyOffset would duplicate data
const { data: mainData, fileInfo: mainFile } = await fetchWaveFile(
this.blockId,
TermFileName,
loadedFromCache ? ptyOffset : 0
);
console.log(
`terminal loaded cachefile:${cacheData?.byteLength ?? 0} main:${mainData?.byteLength ?? 0} bytes, ${Date.now() - startTs}ms`
`terminal loaded cachefile:${cacheData?.byteLength ?? 0} main:${mainData?.byteLength ?? 0} bytes (cached=${loadedFromCache}, offset=${ptyOffset}), ${Date.now() - startTs}ms`
);
if (mainFile != null) {
// If we loaded from cache, only append new data that arrived after the cache was saved
// If no cache, load all data from the beginning
if (mainFile != null && mainData != null && mainData.byteLength > 0) {
await this.doTerminalWrite(mainData, null);
}
}
Expand Down