Skip to content

Commit 4ba2710

Browse files
committed
Move prompt storage cleanup to extension activation, extend upload lifespan to 6 months, and limit prompt history to 25 items
- should remove old 'prompt text' and 'prompt images' when older than a month and not referenced by symbol e.g. #Image() #PastedText(), #Website() etc. in tasks.json and notes.json - prompt field's instructions history should be limited to 25 entries - finish cleanup implementation - should run only fom extension.ts ├── apps │ └── editor │ └── src │ ├── constants │ │ ├── state-keys.ts │ │ └── values.ts │ ├── extension.ts │ ├── utils │ │ └── global-workspace-storage.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-delete-task.ts │ │ │ ├── handle-get-history.ts │ │ │ ├── handle-get-instructions.ts │ │ │ ├── handle-paste-url.ts │ │ │ ├── handle-save-completed-tasks.ts │ │ │ ├── handle-save-history.ts │ │ │ ├── handle-save-instructions.ts │ │ │ ├── handle-save-notes.ts │ │ │ ├── handle-save-prompt-image.ts │ │ │ ├── handle-save-prompt-pasted-text.ts │ │ │ └── handle-save-tasks.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ ├── persistent-prompt-storage.ts │ │ └── symbols │ │ ├── image │ │ │ └── replace-image-symbol.ts │ │ ├── pasted-text │ │ │ └── replace-pasted-text-symbol.ts │ │ ├── replace-symbols.ts │ │ └── website │ │ └── replace-website-symbol.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-prompt │ │ └── hooks │ │ └── use-instructions.ts │ └── types │ └── messages.ts └── packages ├── shared │ └── src │ └── types │ └── task.ts └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.tsx └── hooks └── use-handlers └── handle-key-down.ts
1 parent 836fbf3 commit 4ba2710

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎apps/editor/src/constants/values.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const CHECKPOINT_LIFESPAN = 7 * 24 * 60 * 60 * 1000 // 7 days
2-
export const PROMPT_UPLOADS_LIFESPAN = 3 * 30 * 24 * 60 * 60 * 1000 // 3 months
2+
export const PROMPT_UPLOADS_LIFESPAN = 6 * 30 * 24 * 60 * 60 * 1000 // 6 months
33
export const MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE = 20000
44
export const MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE = 1000
55
export const GIT_LOG_SINCE_DURATION = '6 months ago'

‎apps/editor/src/extension.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { get_current_preview_url } from './views/prompt/backend/message-handlers
5858
import { AgenticSearchState } from './features/agentic-search'
5959
import { checkpoints_cleanup } from './features/checkpoints/utils'
6060
import { setup_apply_response } from './features/apply-response/apply-response'
61+
import { PersistentPromptStorage } from './views/prompt/backend/utils/persistent-prompt-storage'
6162

6263
let websocket_server_instance: WebSocketManager | null = null
6364

@@ -93,6 +94,7 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
9394
await migrations()
9495

9596
checkpoints_cleanup(extension_context).catch(() => {})
97+
PersistentPromptStorage.cleanup(extension_context).catch(() => {})
9698

9799
const agentic_search_state = new AgenticSearchState()
98100

‎apps/editor/src/views/prompt/backend/utils/persistent-prompt-storage.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export class PersistentPromptStorage<T extends 'text' | 'image'> {
4747
}
4848
}
4949

50-
await this.garbage_collect()
51-
5250
return id
5351
}
5452

@@ -69,6 +67,19 @@ export class PersistentPromptStorage<T extends 'text' | 'image'> {
6967
return path.join(this.dir_path, filename)
7068
}
7169

70+
static async cleanup(extension_context: vscode.ExtensionContext) {
71+
const text_storage = new PersistentPromptStorage(extension_context, 'text')
72+
const image_storage = new PersistentPromptStorage(
73+
extension_context,
74+
'image'
75+
)
76+
77+
await Promise.all([
78+
text_storage.garbage_collect(),
79+
image_storage.garbage_collect()
80+
])
81+
}
82+
7283
private async garbage_collect() {
7384
try {
7485
if (!fs.existsSync(this.dir_path)) {

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,7 @@ export const Main: React.FC<Props> = (props) => {
253253
history && history.length > 0 && history[0] === trimmed_instruction
254254

255255
if (!is_duplicate) {
256-
const new_history = [trimmed_instruction, ...(history || [])].slice(
257-
0,
258-
100
259-
)
256+
const new_history = [trimmed_instruction, ...(history || [])].slice(0, 25)
260257
set_history(new_history)
261258

262259
post_message(props.vscode, {

0 commit comments

Comments
 (0)