Skip to content

Commit 1b1fc0c

Browse files
authored
refactor: functional Janitor architecture with unified notifications
* refactor: convert Janitor class and notifications to functional components - Extract notification logic from Janitor into lib/notification.ts - Convert Janitor class to pure functions with JanitorContext - Extract message parsing and LLM analysis into separate functions - Rename notification functions to match config (sendPruningSummary, sendMinimalSummary, sendDetailedSummary) - Update callers (index.ts, hooks.ts, pruning-tool.ts) to use functional API * refactor: make batch a protected tool, remove cascade pruning - Add 'batch' to default protectedTools in config - Remove batchToolChildren tracking from parseMessages() - Remove expandBatchIds() function - Batch children are now pruned individually by LLM decision * chore: remove dead batch checks from notification.ts * chore: remove batch display logic from display-utils * refactor: reorganize lib/ into core/, state/, api-formats/, ui/ subdirectories * refactor: add strategies infrastructure and migrate deduplication * chore: update opencode-auth-provider to 0.1.7 * feat: unified notification system with GC tracking - Add GCStats type and gcPending state to track deduplication activity - Accumulate GC stats during fetch when runStrategies prunes duplicates - Rewrite notification system to combine AI analysis and GC in one display - Show GC-only notifications when AI prunes nothing but deduplication occurred - Track totalGCTokens in session stats for lifetime GC contribution - Display format: '🧹 DCP: ~20K saved (10 tools, ♻️ ~500) │ Session: ...' - GC-only format: '♻️ DCP: ~500 collected │ Session: ...' * fix: show combined AI + GC tokens in notification headline * chore: change GC icon from recycle to wastebasket * fix: include GC tokens in session total and improve icon placement
1 parent ca2b7e3 commit 1b1fc0c

25 files changed

+1127
-881
lines changed

index.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { Plugin } from "@opencode-ai/plugin"
22
import { getConfig } from "./lib/config"
33
import { Logger } from "./lib/logger"
4-
import { Janitor } from "./lib/janitor"
4+
import { createJanitorContext } from "./lib/core/janitor"
55
import { checkForUpdates } from "./lib/version-checker"
66
import { createPluginState } from "./lib/state"
77
import { installFetchWrapper } from "./lib/fetch-wrapper"
88
import { createPruningTool } from "./lib/pruning-tool"
99
import { createEventHandler, createChatParamsHandler } from "./lib/hooks"
10-
import { createToolTracker } from "./lib/synth-instruction"
11-
import { loadPrompt } from "./lib/prompt"
10+
import { createToolTracker } from "./lib/api-formats/synth-instruction"
11+
import { loadPrompt } from "./lib/core/prompt"
1212

1313
const plugin: Plugin = (async (ctx) => {
1414
const { config, migrations } = getConfig(ctx)
@@ -26,16 +26,18 @@ const plugin: Plugin = (async (ctx) => {
2626
const logger = new Logger(config.debug)
2727
const state = createPluginState()
2828

29-
const janitor = new Janitor(
29+
const janitorCtx = createJanitorContext(
3030
ctx.client,
3131
state,
3232
logger,
33-
config.protectedTools,
34-
config.model,
35-
config.showModelErrorToasts,
36-
config.strictModelSelection,
37-
config.pruning_summary,
38-
ctx.directory
33+
{
34+
protectedTools: config.protectedTools,
35+
model: config.model,
36+
showModelErrorToasts: config.showModelErrorToasts ?? true,
37+
strictModelSelection: config.strictModelSelection ?? false,
38+
pruningSummary: config.pruning_summary,
39+
workingDirectory: ctx.directory
40+
}
3941
)
4042

4143
// Create tool tracker and load prompts for synthetic instruction injection
@@ -85,10 +87,10 @@ const plugin: Plugin = (async (ctx) => {
8587
}
8688

8789
return {
88-
event: createEventHandler(ctx.client, janitor, logger, config, toolTracker),
90+
event: createEventHandler(ctx.client, janitorCtx, logger, config, toolTracker),
8991
"chat.params": createChatParamsHandler(ctx.client, state, logger),
9092
tool: config.strategies.onTool.length > 0 ? {
91-
prune: createPruningTool(ctx.client, janitor, config, toolTracker),
93+
prune: createPruningTool(ctx.client, janitorCtx, config, toolTracker),
9294
} : undefined,
9395
}
9496
}) satisfies Plugin

lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface ConfigResult {
3030
const defaultConfig: PluginConfig = {
3131
enabled: true,
3232
debug: false,
33-
protectedTools: ['task', 'todowrite', 'todoread', 'prune'],
33+
protectedTools: ['task', 'todowrite', 'todoread', 'prune', 'batch'],
3434
showModelErrorToasts: true,
3535
strictModelSelection: false,
3636
pruning_summary: 'detailed',

0 commit comments

Comments
 (0)