opencode-prompt-logger 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rpc.js ADDED
@@ -0,0 +1,446 @@
1
+ // @bun
2
+ // src/rpc.ts
3
+ import { Rpc } from "@opencode/plugin/rpc";
4
+
5
+ // src/core.ts
6
+ var DEFAULT_DISK_BUDGET = 256 * 1024 * 1024;
7
+ var CONTEXT_KINDS = ["context", "compaction", "generate", "title"];
8
+
9
+ // src/settings.ts
10
+ var SETTINGS_KEY = "settings";
11
+ var MAX_SETTINGS_DISK_BUDGET = 8 * 1024 * 1024 * 1024;
12
+ var MAX_SETTINGS_RETENTION_DAYS = 3650;
13
+ var MAX_SETTINGS_RETENTION_SESSIONS = 1e4;
14
+ var MAX_SETTINGS_DIRECTORY = 4096;
15
+ var DEFAULT_SETTINGS = {
16
+ enabled: true,
17
+ http: false,
18
+ diskBudget: DEFAULT_DISK_BUDGET,
19
+ retentionMaxAgeDays: 30,
20
+ retentionMaxSessions: 200,
21
+ directory: "",
22
+ maintenance: true
23
+ };
24
+ function defaultSettings() {
25
+ return { ...DEFAULT_SETTINGS };
26
+ }
27
+ function isRecord(value) {
28
+ return value !== null && typeof value === "object" && !Array.isArray(value);
29
+ }
30
+ function isBoundedInteger(value, max) {
31
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && Math.floor(value) === value && value <= max;
32
+ }
33
+ function boundedInteger(value, max, fallback) {
34
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
35
+ return fallback;
36
+ return Math.min(max, Math.floor(value));
37
+ }
38
+ function directoryValue(value) {
39
+ if (typeof value !== "string")
40
+ return;
41
+ return value.trim().slice(0, MAX_SETTINGS_DIRECTORY);
42
+ }
43
+ function overlay(target, value) {
44
+ if (!isRecord(value))
45
+ return target;
46
+ const next = { ...target };
47
+ if (typeof value.enabled === "boolean")
48
+ next.enabled = value.enabled;
49
+ if (typeof value.http === "boolean")
50
+ next.http = value.http;
51
+ next.diskBudget = boundedInteger(value.diskBudget, MAX_SETTINGS_DISK_BUDGET, next.diskBudget);
52
+ next.retentionMaxAgeDays = boundedInteger(value.retentionMaxAgeDays, MAX_SETTINGS_RETENTION_DAYS, next.retentionMaxAgeDays);
53
+ next.retentionMaxSessions = boundedInteger(value.retentionMaxSessions, MAX_SETTINGS_RETENTION_SESSIONS, next.retentionMaxSessions);
54
+ const directory = directoryValue(value.directory);
55
+ if (directory !== undefined)
56
+ next.directory = directory;
57
+ if (typeof value.maintenance === "boolean")
58
+ next.maintenance = value.maintenance;
59
+ return next;
60
+ }
61
+ function sanitizeSettings(value) {
62
+ return overlay(defaultSettings(), value);
63
+ }
64
+ function isValidSettings(value) {
65
+ if (!isRecord(value))
66
+ return false;
67
+ if (typeof value.enabled !== "boolean" || typeof value.http !== "boolean")
68
+ return false;
69
+ if (typeof value.maintenance !== "boolean")
70
+ return false;
71
+ if (typeof value.directory !== "string" || value.directory.length > MAX_SETTINGS_DIRECTORY)
72
+ return false;
73
+ return isBoundedInteger(value.diskBudget, MAX_SETTINGS_DISK_BUDGET) && isBoundedInteger(value.retentionMaxAgeDays, MAX_SETTINGS_RETENTION_DAYS) && isBoundedInteger(value.retentionMaxSessions, MAX_SETTINGS_RETENTION_SESSIONS);
74
+ }
75
+ function settingsFromEnvelope(value) {
76
+ return sanitizeSettings(isRecord(value) ? value.settings : undefined);
77
+ }
78
+ function pickSettings(value) {
79
+ return {
80
+ enabled: value.enabled,
81
+ http: value.http,
82
+ diskBudget: value.diskBudget,
83
+ retentionMaxAgeDays: value.retentionMaxAgeDays,
84
+ retentionMaxSessions: value.retentionMaxSessions,
85
+ directory: value.directory,
86
+ maintenance: value.maintenance
87
+ };
88
+ }
89
+
90
+ // src/rpc.ts
91
+ var CONTRACT_VERSION = 6;
92
+ var nullableString = { type: ["string", "null"] };
93
+ var modelSchema = {
94
+ anyOf: [
95
+ { type: "null" },
96
+ {
97
+ type: "object",
98
+ properties: {
99
+ providerID: { type: "string" },
100
+ id: { type: "string" },
101
+ variant: { type: "string" }
102
+ },
103
+ additionalProperties: false
104
+ }
105
+ ]
106
+ };
107
+ var summarySchema = {
108
+ type: "object",
109
+ properties: {
110
+ key: { type: "string" },
111
+ cursor: { type: "string" },
112
+ bytes: { type: "number" },
113
+ at: nullableString,
114
+ type: nullableString,
115
+ kind: nullableString,
116
+ sessionID: nullableString,
117
+ agent: nullableString,
118
+ model: modelSchema,
119
+ url: nullableString,
120
+ messages: { type: "number" },
121
+ bodyBytes: { type: "number" },
122
+ hasBody: { type: "boolean" }
123
+ },
124
+ required: ["key", "cursor", "bytes", "at", "type", "kind", "sessionID", "agent", "model", "url"],
125
+ additionalProperties: false
126
+ };
127
+ var storeStatusSchema = {
128
+ type: "object",
129
+ properties: {
130
+ path: { type: "string" },
131
+ exists: { type: "boolean" },
132
+ bytes: { type: "number" },
133
+ mtimeMs: { anyOf: [{ type: "number" }, { type: "null" }] },
134
+ directory: { type: "boolean" },
135
+ symlink: { type: "boolean" },
136
+ mode: { anyOf: [{ type: "number" }, { type: "null" }] },
137
+ directoryMode: { anyOf: [{ type: "number" }, { type: "null" }] },
138
+ warnings: { type: "array", items: { type: "string" } }
139
+ },
140
+ required: ["path", "exists", "bytes", "mtimeMs", "directory", "symlink", "mode", "directoryMode", "warnings"],
141
+ additionalProperties: false
142
+ };
143
+ var cacheSchema = {
144
+ type: "object",
145
+ properties: {
146
+ requests: { type: "number" },
147
+ requestBytes: { type: "number" },
148
+ lastScanMs: { type: "number" },
149
+ error: nullableString
150
+ },
151
+ required: ["requests", "requestBytes", "lastScanMs", "error"],
152
+ additionalProperties: false
153
+ };
154
+ var settingsSchema = {
155
+ type: "object",
156
+ properties: {
157
+ enabled: { type: "boolean" },
158
+ http: { type: "boolean" },
159
+ diskBudget: { type: "number", minimum: 0, maximum: MAX_SETTINGS_DISK_BUDGET },
160
+ retentionMaxAgeDays: { type: "number", minimum: 0, maximum: MAX_SETTINGS_RETENTION_DAYS },
161
+ retentionMaxSessions: { type: "number", minimum: 0, maximum: MAX_SETTINGS_RETENTION_SESSIONS },
162
+ directory: { type: "string", maxLength: MAX_SETTINGS_DIRECTORY },
163
+ maintenance: { type: "boolean" }
164
+ },
165
+ required: [
166
+ "enabled",
167
+ "http",
168
+ "diskBudget",
169
+ "retentionMaxAgeDays",
170
+ "retentionMaxSessions",
171
+ "directory",
172
+ "maintenance"
173
+ ],
174
+ additionalProperties: false
175
+ };
176
+ var statusSettingsSchema = {
177
+ type: "object",
178
+ properties: {
179
+ ...settingsSchema.properties,
180
+ retention: {
181
+ type: "object",
182
+ properties: {
183
+ maxTotalBytes: { anyOf: [{ type: "number" }, { type: "null" }] },
184
+ maxAgeDays: { type: "number" },
185
+ maxSessions: { anyOf: [{ type: "number" }, { type: "null" }] }
186
+ },
187
+ required: ["maxTotalBytes", "maxAgeDays", "maxSessions"],
188
+ additionalProperties: false
189
+ }
190
+ },
191
+ required: [...settingsSchema.required, "retention"],
192
+ additionalProperties: false
193
+ };
194
+ var sessionScopeSchema = {
195
+ type: "object",
196
+ properties: {
197
+ mode: { type: "string", enum: ["all", "only"] },
198
+ sessions: { type: "array", items: { type: "string", maxLength: 200 } },
199
+ max: { type: "number" }
200
+ },
201
+ required: ["mode", "sessions", "max"],
202
+ additionalProperties: false
203
+ };
204
+ var settingsResponseSchema = {
205
+ type: "object",
206
+ properties: {
207
+ settings: settingsSchema,
208
+ sessionScope: sessionScopeSchema
209
+ },
210
+ required: ["settings", "sessionScope"],
211
+ additionalProperties: false
212
+ };
213
+ var errorSchema = {
214
+ type: "object",
215
+ properties: { message: { type: "string" } },
216
+ additionalProperties: false
217
+ };
218
+ var errors = {
219
+ io: errorSchema,
220
+ not_found: errorSchema,
221
+ bad_request: errorSchema,
222
+ forbidden: errorSchema
223
+ };
224
+ var filtersSchema = {
225
+ sessionID: { type: "string", maxLength: 200 },
226
+ type: { type: "string", maxLength: 80 },
227
+ kind: { type: "string", maxLength: 80 },
228
+ agent: { type: "string", maxLength: 200 },
229
+ model: { type: "string", maxLength: 200 },
230
+ query: { type: "string", maxLength: 200 }
231
+ };
232
+ var PromptLogger = Rpc.define({
233
+ id: "prompt-logger",
234
+ methods: {
235
+ status: {
236
+ input: { type: "object", properties: {}, additionalProperties: false },
237
+ output: {
238
+ type: "object",
239
+ properties: {
240
+ version: { type: "number" },
241
+ store: storeStatusSchema,
242
+ settings: statusSettingsSchema,
243
+ sessionScope: sessionScopeSchema,
244
+ cache: cacheSchema,
245
+ lastWriteAt: { anyOf: [{ type: "string" }, { type: "null" }] },
246
+ lastWriteError: {
247
+ anyOf: [
248
+ { type: "null" },
249
+ {
250
+ type: "object",
251
+ properties: {
252
+ at: { type: "string" },
253
+ code: { type: "string" },
254
+ message: { type: "string" }
255
+ },
256
+ required: ["at", "message"],
257
+ additionalProperties: false
258
+ }
259
+ ]
260
+ }
261
+ },
262
+ required: ["version", "store", "settings", "sessionScope", "cache", "lastWriteAt", "lastWriteError"],
263
+ additionalProperties: false
264
+ },
265
+ errors
266
+ },
267
+ list: {
268
+ input: {
269
+ type: "object",
270
+ properties: {
271
+ ...filtersSchema,
272
+ limit: { type: "number" },
273
+ cursor: { type: "string" }
274
+ },
275
+ additionalProperties: false
276
+ },
277
+ output: {
278
+ type: "object",
279
+ properties: {
280
+ entries: { type: "array", items: summarySchema },
281
+ hasMore: { type: "boolean" },
282
+ records: { type: "number" },
283
+ error: nullableString
284
+ },
285
+ required: ["entries", "hasMore", "records", "error"],
286
+ additionalProperties: false
287
+ },
288
+ errors
289
+ },
290
+ read: {
291
+ input: {
292
+ type: "object",
293
+ properties: {
294
+ key: { type: "string", maxLength: 300 },
295
+ maxBytes: { type: "number" }
296
+ },
297
+ required: ["key"],
298
+ additionalProperties: false
299
+ },
300
+ output: {
301
+ type: "object",
302
+ properties: {
303
+ record: {},
304
+ bytes: { type: "number" },
305
+ truncated: { type: "boolean" },
306
+ moreAvailable: { type: "boolean" },
307
+ fullBytes: { type: "number" },
308
+ paths: {
309
+ type: "object",
310
+ properties: {
311
+ session: { type: "string" },
312
+ requests: { type: "string" },
313
+ body: { type: "string" }
314
+ },
315
+ additionalProperties: false
316
+ }
317
+ },
318
+ required: ["record", "bytes", "truncated"],
319
+ additionalProperties: false
320
+ },
321
+ errors
322
+ },
323
+ search: {
324
+ input: {
325
+ type: "object",
326
+ properties: {
327
+ ...filtersSchema,
328
+ query: { type: "string", minLength: 1, maxLength: 500 },
329
+ limit: { type: "number" },
330
+ ignoreCase: { type: "boolean" },
331
+ budgetBytes: { type: "number" },
332
+ budgetMs: { type: "number" }
333
+ },
334
+ required: ["query"],
335
+ additionalProperties: false
336
+ },
337
+ output: {
338
+ type: "object",
339
+ properties: {
340
+ matches: {
341
+ type: "array",
342
+ items: {
343
+ type: "object",
344
+ properties: { entry: summarySchema, snippet: { type: "string" } },
345
+ required: ["entry", "snippet"],
346
+ additionalProperties: false
347
+ }
348
+ },
349
+ partial: { type: "boolean" },
350
+ scannedBytes: { type: "number" },
351
+ skipped: { type: "number" },
352
+ error: nullableString
353
+ },
354
+ required: ["matches", "partial", "scannedBytes", "skipped", "error"],
355
+ additionalProperties: false
356
+ },
357
+ errors
358
+ },
359
+ truncate: {
360
+ input: {
361
+ type: "object",
362
+ properties: {
363
+ target: { type: "string", enum: ["current", "all"] },
364
+ sessionID: { type: "string", maxLength: 200 },
365
+ confirm: { type: "boolean", enum: [true] }
366
+ },
367
+ required: ["target", "confirm"],
368
+ additionalProperties: false
369
+ },
370
+ output: {
371
+ type: "object",
372
+ properties: {
373
+ target: { type: "string", enum: ["current", "all"] },
374
+ bytesFreed: { type: "number" }
375
+ },
376
+ required: ["target", "bytesFreed"],
377
+ additionalProperties: false
378
+ },
379
+ errors
380
+ },
381
+ getSettings: {
382
+ input: { type: "object", properties: {}, additionalProperties: false },
383
+ output: settingsResponseSchema,
384
+ errors
385
+ },
386
+ setSettings: {
387
+ input: {
388
+ type: "object",
389
+ properties: { settings: settingsSchema },
390
+ required: ["settings"],
391
+ additionalProperties: false
392
+ },
393
+ output: settingsResponseSchema,
394
+ errors
395
+ },
396
+ resetSettings: {
397
+ input: { type: "object", properties: {}, additionalProperties: false },
398
+ output: settingsResponseSchema,
399
+ errors
400
+ },
401
+ updateSessionScope: {
402
+ input: {
403
+ type: "object",
404
+ properties: {
405
+ mode: { type: "string", enum: ["all", "only"] },
406
+ action: { type: "string", enum: ["only", "disarm", "clear"] },
407
+ sessionID: { type: "string", maxLength: 200 }
408
+ },
409
+ additionalProperties: false
410
+ },
411
+ output: {
412
+ type: "object",
413
+ properties: {
414
+ sessionScope: sessionScopeSchema,
415
+ settings: settingsSchema
416
+ },
417
+ required: ["sessionScope", "settings"],
418
+ additionalProperties: false
419
+ },
420
+ errors
421
+ }
422
+ },
423
+ events: {
424
+ changed: {
425
+ schema: {
426
+ type: "object",
427
+ properties: {
428
+ store: { type: "string" },
429
+ reason: { type: "string", enum: ["append", "truncate", "error"] },
430
+ at: { type: "string" }
431
+ },
432
+ required: ["store", "reason", "at"],
433
+ additionalProperties: false
434
+ }
435
+ },
436
+ settingsChanged: {
437
+ schema: settingsResponseSchema
438
+ }
439
+ }
440
+ });
441
+ export {
442
+ CONTRACT_VERSION,
443
+ PromptLogger
444
+ };
445
+
446
+ //# debugId=EC5AB6ECF4DE51D064756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/rpc.ts", "../src/core.ts", "../src/settings.ts"],
4
+ "sourcesContent": [
5
+ "import { Rpc } from \"@opencode/plugin/rpc\"\nimport type { SessionScope, SessionScopeChange } from \"./session-scope\"\nimport {\n MAX_SETTINGS_DIRECTORY,\n MAX_SETTINGS_DISK_BUDGET,\n MAX_SETTINGS_RETENTION_DAYS,\n MAX_SETTINGS_RETENTION_SESSIONS,\n type Settings,\n} from \"./settings\"\nimport type { LogSummary, SearchMatch } from \"./log/types\"\n\nexport const CONTRACT_VERSION = 6\n\nexport type StoreStatusView = {\n readonly path: string\n readonly exists: boolean\n readonly bytes: number\n readonly mtimeMs: number | null\n /** True when the store root is a directory. */\n readonly directory: boolean\n readonly symlink: boolean\n readonly mode: number | null\n readonly directoryMode: number | null\n readonly warnings: readonly string[]\n}\n\nexport type CacheView = {\n readonly requests: number\n readonly requestBytes: number\n readonly lastScanMs: number\n readonly error: string | null\n}\n\n/** Settings plus the computed retention policy. */\nexport type StatusSettings = Settings & {\n /** Effective retention policy. `null` means unlimited. */\n readonly retention: {\n readonly maxTotalBytes: number | null\n readonly maxAgeDays: number\n readonly maxSessions: number | null\n }\n}\n\nexport type StatusResponse = {\n readonly version: number\n readonly store: StoreStatusView\n readonly settings: StatusSettings\n /** Which sessions are written while logging is enabled. */\n readonly sessionScope: SessionScope\n readonly cache: CacheView\n readonly lastWriteAt: string | null\n readonly lastWriteError: { readonly at: string; readonly code?: string; readonly message: string } | null\n}\n\nexport type ListRequest = {\n readonly sessionID?: string\n readonly type?: string\n readonly kind?: string\n readonly agent?: string\n readonly model?: string\n readonly query?: string\n readonly limit?: number\n readonly cursor?: string\n}\n\nexport type ListResponse = {\n readonly entries: readonly LogSummary[]\n readonly hasMore: boolean\n readonly records: number\n readonly error: string | null\n}\n\nexport type ReadRequest = {\n /** Opaque v2 request key from the list. */\n readonly key: string\n /**\n * Read budget in bytes. Omit for the preview budget; an explicit\n * \"load complete entry\" may ask for up to `MAX_FULL_RECORD_BYTES`.\n */\n readonly maxBytes?: number\n}\n\nexport type ReadResponse = {\n readonly record: unknown\n readonly bytes: number\n readonly truncated: boolean\n /** A larger `maxBytes` could return more of the same request. */\n readonly moreAvailable?: boolean\n /** Logical size of the complete request, including the decoded body. */\n readonly fullBytes?: number\n /** Concrete files backing this record, for \"Reveal\" actions. */\n readonly paths?: {\n readonly session?: string\n readonly requests?: string\n readonly body?: string\n }\n}\n\nexport type SearchRequest = {\n readonly sessionID?: string\n readonly type?: string\n readonly kind?: string\n readonly agent?: string\n readonly model?: string\n readonly query: string\n readonly limit?: number\n readonly ignoreCase?: boolean\n readonly budgetBytes?: number\n readonly budgetMs?: number\n}\n\nexport type SearchResponse = {\n readonly matches: readonly SearchMatch[]\n readonly partial: boolean\n readonly scannedBytes: number\n readonly skipped: number\n readonly error: string | null\n}\n\nexport type TruncateTarget = \"current\" | \"all\"\n\nexport type TruncateRequest = {\n readonly target: TruncateTarget\n /** The session whose directory is deleted by `current`. */\n readonly sessionID?: string\n readonly confirm: true\n}\n\nexport type TruncateResponse = {\n readonly target: TruncateTarget\n readonly bytesFreed: number\n}\n\nexport type SettingsResponse = {\n readonly settings: Settings\n readonly sessionScope: SessionScope\n}\n\nexport type SetSettingsRequest = {\n readonly settings: Settings\n}\n\n/** The scope transition accepted by `updateSessionScope`. */\nexport type UpdateSessionScopeRequest = SessionScopeChange\n\nexport type UpdateSessionScopeResponse = {\n readonly sessionScope: SessionScope\n /** Selecting a session while logging is off turns the master switch on. */\n readonly settings: Settings\n}\n\nexport type SettingsChangedEvent = SettingsResponse\n\nexport type ChangedReason = \"append\" | \"truncate\" | \"error\"\n\nexport type ChangedEvent = {\n /** The store root, not a single file. */\n readonly store: string\n readonly reason: ChangedReason\n readonly at: string\n}\n\nconst nullableString = { type: [\"string\", \"null\"] } as const\nconst modelSchema = {\n anyOf: [\n { type: \"null\" },\n {\n type: \"object\",\n properties: {\n providerID: { type: \"string\" },\n id: { type: \"string\" },\n variant: { type: \"string\" },\n },\n additionalProperties: false,\n },\n ],\n} as const\n\nconst summarySchema = {\n type: \"object\",\n properties: {\n key: { type: \"string\" },\n cursor: { type: \"string\" },\n bytes: { type: \"number\" },\n at: nullableString,\n type: nullableString,\n kind: nullableString,\n sessionID: nullableString,\n agent: nullableString,\n model: modelSchema,\n url: nullableString,\n messages: { type: \"number\" },\n bodyBytes: { type: \"number\" },\n hasBody: { type: \"boolean\" },\n },\n required: [\"key\", \"cursor\", \"bytes\", \"at\", \"type\", \"kind\", \"sessionID\", \"agent\", \"model\", \"url\"],\n additionalProperties: false,\n} as const\n\nconst storeStatusSchema = {\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n exists: { type: \"boolean\" },\n bytes: { type: \"number\" },\n mtimeMs: { anyOf: [{ type: \"number\" }, { type: \"null\" }] },\n directory: { type: \"boolean\" },\n symlink: { type: \"boolean\" },\n mode: { anyOf: [{ type: \"number\" }, { type: \"null\" }] },\n directoryMode: { anyOf: [{ type: \"number\" }, { type: \"null\" }] },\n warnings: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"path\", \"exists\", \"bytes\", \"mtimeMs\", \"directory\", \"symlink\", \"mode\", \"directoryMode\", \"warnings\"],\n additionalProperties: false,\n} as const\n\nconst cacheSchema = {\n type: \"object\",\n properties: {\n requests: { type: \"number\" },\n requestBytes: { type: \"number\" },\n lastScanMs: { type: \"number\" },\n error: nullableString,\n },\n required: [\"requests\", \"requestBytes\", \"lastScanMs\", \"error\"],\n additionalProperties: false,\n} as const\n\nconst settingsSchema = {\n type: \"object\",\n properties: {\n enabled: { type: \"boolean\" },\n http: { type: \"boolean\" },\n diskBudget: { type: \"number\", minimum: 0, maximum: MAX_SETTINGS_DISK_BUDGET },\n retentionMaxAgeDays: { type: \"number\", minimum: 0, maximum: MAX_SETTINGS_RETENTION_DAYS },\n retentionMaxSessions: { type: \"number\", minimum: 0, maximum: MAX_SETTINGS_RETENTION_SESSIONS },\n directory: { type: \"string\", maxLength: MAX_SETTINGS_DIRECTORY },\n maintenance: { type: \"boolean\" },\n },\n required: [\n \"enabled\",\n \"http\",\n \"diskBudget\",\n \"retentionMaxAgeDays\",\n \"retentionMaxSessions\",\n \"directory\",\n \"maintenance\",\n ],\n additionalProperties: false,\n} as const\n\nconst statusSettingsSchema = {\n type: \"object\",\n properties: {\n ...settingsSchema.properties,\n retention: {\n type: \"object\",\n properties: {\n maxTotalBytes: { anyOf: [{ type: \"number\" }, { type: \"null\" }] },\n maxAgeDays: { type: \"number\" },\n maxSessions: { anyOf: [{ type: \"number\" }, { type: \"null\" }] },\n },\n required: [\"maxTotalBytes\", \"maxAgeDays\", \"maxSessions\"],\n additionalProperties: false,\n },\n },\n required: [...settingsSchema.required, \"retention\"],\n additionalProperties: false,\n} as const\n\nconst sessionScopeSchema = {\n type: \"object\",\n properties: {\n mode: { type: \"string\", enum: [\"all\", \"only\"] },\n sessions: { type: \"array\", items: { type: \"string\", maxLength: 200 } },\n max: { type: \"number\" },\n },\n required: [\"mode\", \"sessions\", \"max\"],\n additionalProperties: false,\n} as const\n\nconst settingsResponseSchema = {\n type: \"object\",\n properties: {\n settings: settingsSchema,\n sessionScope: sessionScopeSchema,\n },\n required: [\"settings\", \"sessionScope\"],\n additionalProperties: false,\n} as const\n\nconst errorSchema = {\n type: \"object\",\n properties: { message: { type: \"string\" } },\n additionalProperties: false,\n} as const\n\nconst errors = {\n io: errorSchema,\n not_found: errorSchema,\n bad_request: errorSchema,\n forbidden: errorSchema,\n} as const\n\nconst filtersSchema = {\n sessionID: { type: \"string\", maxLength: 200 },\n type: { type: \"string\", maxLength: 80 },\n kind: { type: \"string\", maxLength: 80 },\n agent: { type: \"string\", maxLength: 200 },\n model: { type: \"string\", maxLength: 200 },\n query: { type: \"string\", maxLength: 200 },\n} as const\n\nexport const PromptLogger = Rpc.define({\n id: \"prompt-logger\",\n methods: {\n status: {\n input: { type: \"object\", properties: {}, additionalProperties: false },\n output: {\n type: \"object\",\n properties: {\n version: { type: \"number\" },\n store: storeStatusSchema,\n settings: statusSettingsSchema,\n sessionScope: sessionScopeSchema,\n cache: cacheSchema,\n lastWriteAt: { anyOf: [{ type: \"string\" }, { type: \"null\" }] },\n lastWriteError: {\n anyOf: [\n { type: \"null\" },\n {\n type: \"object\",\n properties: {\n at: { type: \"string\" },\n code: { type: \"string\" },\n message: { type: \"string\" },\n },\n required: [\"at\", \"message\"],\n additionalProperties: false,\n },\n ],\n },\n },\n required: [\"version\", \"store\", \"settings\", \"sessionScope\", \"cache\", \"lastWriteAt\", \"lastWriteError\"],\n additionalProperties: false,\n },\n errors,\n },\n list: {\n input: {\n type: \"object\",\n properties: {\n ...filtersSchema,\n limit: { type: \"number\" },\n cursor: { type: \"string\" },\n },\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n entries: { type: \"array\", items: summarySchema },\n hasMore: { type: \"boolean\" },\n records: { type: \"number\" },\n error: nullableString,\n },\n required: [\"entries\", \"hasMore\", \"records\", \"error\"],\n additionalProperties: false,\n },\n errors,\n },\n read: {\n input: {\n type: \"object\",\n properties: {\n key: { type: \"string\", maxLength: 300 },\n maxBytes: { type: \"number\" },\n },\n required: [\"key\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n record: {},\n bytes: { type: \"number\" },\n truncated: { type: \"boolean\" },\n moreAvailable: { type: \"boolean\" },\n fullBytes: { type: \"number\" },\n paths: {\n type: \"object\",\n properties: {\n session: { type: \"string\" },\n requests: { type: \"string\" },\n body: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n required: [\"record\", \"bytes\", \"truncated\"],\n additionalProperties: false,\n },\n errors,\n },\n search: {\n input: {\n type: \"object\",\n properties: {\n ...filtersSchema,\n query: { type: \"string\", minLength: 1, maxLength: 500 },\n limit: { type: \"number\" },\n ignoreCase: { type: \"boolean\" },\n budgetBytes: { type: \"number\" },\n budgetMs: { type: \"number\" },\n },\n required: [\"query\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n matches: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: { entry: summarySchema, snippet: { type: \"string\" } },\n required: [\"entry\", \"snippet\"],\n additionalProperties: false,\n },\n },\n partial: { type: \"boolean\" },\n scannedBytes: { type: \"number\" },\n skipped: { type: \"number\" },\n error: nullableString,\n },\n required: [\"matches\", \"partial\", \"scannedBytes\", \"skipped\", \"error\"],\n additionalProperties: false,\n },\n errors,\n },\n truncate: {\n input: {\n type: \"object\",\n properties: {\n target: { type: \"string\", enum: [\"current\", \"all\"] },\n sessionID: { type: \"string\", maxLength: 200 },\n confirm: { type: \"boolean\", enum: [true] },\n },\n required: [\"target\", \"confirm\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n target: { type: \"string\", enum: [\"current\", \"all\"] },\n bytesFreed: { type: \"number\" },\n },\n required: [\"target\", \"bytesFreed\"],\n additionalProperties: false,\n },\n errors,\n },\n getSettings: {\n input: { type: \"object\", properties: {}, additionalProperties: false },\n output: settingsResponseSchema,\n errors,\n },\n setSettings: {\n input: {\n type: \"object\",\n properties: { settings: settingsSchema },\n required: [\"settings\"],\n additionalProperties: false,\n },\n output: settingsResponseSchema,\n errors,\n },\n resetSettings: {\n input: { type: \"object\", properties: {}, additionalProperties: false },\n output: settingsResponseSchema,\n errors,\n },\n updateSessionScope: {\n input: {\n type: \"object\",\n properties: {\n mode: { type: \"string\", enum: [\"all\", \"only\"] },\n action: { type: \"string\", enum: [\"only\", \"disarm\", \"clear\"] },\n sessionID: { type: \"string\", maxLength: 200 },\n },\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n sessionScope: sessionScopeSchema,\n settings: settingsSchema,\n },\n required: [\"sessionScope\", \"settings\"],\n additionalProperties: false,\n },\n errors,\n },\n },\n events: {\n changed: {\n schema: {\n type: \"object\",\n properties: {\n store: { type: \"string\" },\n reason: { type: \"string\", enum: [\"append\", \"truncate\", \"error\"] },\n at: { type: \"string\" },\n },\n required: [\"store\", \"reason\", \"at\"],\n additionalProperties: false,\n },\n },\n settingsChanged: {\n schema: settingsResponseSchema,\n },\n },\n})\n",
6
+ "/** Default disk budget when no setting is configured: 256 MiB. */\nexport const DEFAULT_DISK_BUDGET = 256 * 1024 * 1024\n\n/** Model request kinds captured through one hook each. */\nexport const CONTEXT_KINDS = [\"context\", \"compaction\", \"generate\", \"title\"] as const\n\nexport type ContextKind = (typeof CONTEXT_KINDS)[number]\n\n/**\n * Structural view of the `context`, `compaction`, `generate` and `title` hook\n * events. `agent` and `tools` are only present on the kinds that carry them\n * (`title` has neither), so every field accepts the shape of the event it\n * actually receives.\n */\nexport type AssembledEvent = {\n readonly sessionID: string\n readonly model?: unknown\n readonly system?: unknown\n readonly messages?: unknown\n readonly agent?: unknown\n readonly tools?: Record<string, unknown>\n}\n\n/** Structural view of the `http.request` hook event. */\nexport type HttpEvent = {\n readonly sessionID: string\n readonly agent: unknown\n readonly model: unknown\n readonly kind: string\n readonly request: Request\n}\n\nexport type WriteError = {\n readonly at: string\n readonly code?: string\n readonly message: string\n}\n",
7
+ "import { DEFAULT_DISK_BUDGET } from \"./core\"\n\n/**\n * Every setting. The plugin's server storage is the only source of truth: the\n * configuration file registers the plugin, but it never carries settings.\n */\nexport type Settings = {\n readonly enabled: boolean\n readonly http: boolean\n /** Total store budget in bytes. Zero means no byte budget. */\n readonly diskBudget: number\n /** Remove sessions inactive for longer than this. Zero means unlimited. */\n readonly retentionMaxAgeDays: number\n /** Keep at most this many sessions. Zero means unlimited. */\n readonly retentionMaxSessions: number\n /** Store root. Empty means the platform default. */\n readonly directory: string\n /** Allow destructive actions from the viewer. */\n readonly maintenance: boolean\n}\n\n/** Settings live under this key. */\nexport const SETTINGS_KEY = \"settings\"\n\n/** A setting must stay sane; the UI offers presets well below these limits. */\nexport const MAX_SETTINGS_DISK_BUDGET = 8 * 1024 * 1024 * 1024\nexport const MAX_SETTINGS_RETENTION_DAYS = 3650\nexport const MAX_SETTINGS_RETENTION_SESSIONS = 10_000\nexport const MAX_SETTINGS_DIRECTORY = 4096\n\nexport const DEFAULT_SETTINGS: Settings = {\n enabled: true,\n http: false,\n diskBudget: DEFAULT_DISK_BUDGET,\n retentionMaxAgeDays: 30,\n retentionMaxSessions: 200,\n directory: \"\",\n maintenance: true,\n}\n\n/** A fresh copy of the built-in settings, safe for an editor to mutate. */\nexport function defaultSettings(): Settings {\n return { ...DEFAULT_SETTINGS }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n}\n\nfunction isBoundedInteger(value: unknown, max: number): value is number {\n return (\n typeof value === \"number\" &&\n Number.isFinite(value) &&\n value >= 0 &&\n Math.floor(value) === value &&\n value <= max\n )\n}\n\nfunction boundedInteger(value: unknown, max: number, fallback: number): number {\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) return fallback\n return Math.min(max, Math.floor(value))\n}\n\nfunction directoryValue(value: unknown): string | undefined {\n if (typeof value !== \"string\") return undefined\n return value.trim().slice(0, MAX_SETTINGS_DIRECTORY)\n}\n\nfunction overlay(target: Settings, value: unknown): Settings {\n if (!isRecord(value)) return target\n const next: { -readonly [K in keyof Settings]: Settings[K] } = { ...target }\n if (typeof value.enabled === \"boolean\") next.enabled = value.enabled\n if (typeof value.http === \"boolean\") next.http = value.http\n next.diskBudget = boundedInteger(value.diskBudget, MAX_SETTINGS_DISK_BUDGET, next.diskBudget)\n next.retentionMaxAgeDays = boundedInteger(\n value.retentionMaxAgeDays,\n MAX_SETTINGS_RETENTION_DAYS,\n next.retentionMaxAgeDays,\n )\n next.retentionMaxSessions = boundedInteger(\n value.retentionMaxSessions,\n MAX_SETTINGS_RETENTION_SESSIONS,\n next.retentionMaxSessions,\n )\n const directory = directoryValue(value.directory)\n if (directory !== undefined) next.directory = directory\n if (typeof value.maintenance === \"boolean\") next.maintenance = value.maintenance\n return next\n}\n\n/**\n * Read a stored value defensively. A value written by a newer version, a\n * manual edit or a corrupted store is replaced field by field with a default\n * instead of breaking logging.\n */\nexport function sanitizeSettings(value: unknown): Settings {\n return overlay(defaultSettings(), value)\n}\n\n/**\n * Strict validation for a user action. Unlike `sanitizeSettings`, a malformed\n * request fails loudly instead of being silently repaired.\n */\nexport function isValidSettings(value: unknown): value is Settings {\n if (!isRecord(value)) return false\n if (typeof value.enabled !== \"boolean\" || typeof value.http !== \"boolean\") return false\n if (typeof value.maintenance !== \"boolean\") return false\n if (typeof value.directory !== \"string\" || value.directory.length > MAX_SETTINGS_DIRECTORY) return false\n return (\n isBoundedInteger(value.diskBudget, MAX_SETTINGS_DISK_BUDGET) &&\n isBoundedInteger(value.retentionMaxAgeDays, MAX_SETTINGS_RETENTION_DAYS) &&\n isBoundedInteger(value.retentionMaxSessions, MAX_SETTINGS_RETENTION_SESSIONS)\n )\n}\n\n/** Reads the `{ settings }` envelope used by the RPC methods and event. */\nexport function settingsFromEnvelope(value: unknown): Settings {\n return sanitizeSettings(isRecord(value) ? value.settings : undefined)\n}\n\n/**\n * Strip the computed `retention` policy that only exists in the status view\n * before writing a settings object back over the RPC.\n */\nexport function pickSettings(value: Settings): Settings {\n return {\n enabled: value.enabled,\n http: value.http,\n diskBudget: value.diskBudget,\n retentionMaxAgeDays: value.retentionMaxAgeDays,\n retentionMaxSessions: value.retentionMaxSessions,\n directory: value.directory,\n maintenance: value.maintenance,\n }\n}\n"
8
+ ],
9
+ "mappings": ";;AAAA;;;ACCO,IAAM,sBAAsB,MAAM,OAAO;AAGzC,IAAM,gBAAgB,CAAC,WAAW,cAAc,YAAY,OAAO;;;ACkBnE,IAAM,eAAe;AAGrB,IAAM,2BAA2B,IAAI,OAAO,OAAO;AACnD,IAAM,8BAA8B;AACpC,IAAM,kCAAkC;AACxC,IAAM,yBAAyB;AAE/B,IAAM,mBAA6B;AAAA,EACxC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,WAAW;AAAA,EACX,aAAa;AACf;AAGO,SAAS,eAAe,GAAa;AAAA,EAC1C,OAAO,KAAK,iBAAiB;AAAA;AAG/B,SAAS,QAAQ,CAAC,OAAkD;AAAA,EAClE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA;AAG5E,SAAS,gBAAgB,CAAC,OAAgB,KAA8B;AAAA,EACtE,OACE,OAAO,UAAU,YACjB,OAAO,SAAS,KAAK,KACrB,SAAS,KACT,KAAK,MAAM,KAAK,MAAM,SACtB,SAAS;AAAA;AAIb,SAAS,cAAc,CAAC,OAAgB,KAAa,UAA0B;AAAA,EAC7E,IAAI,OAAO,UAAU,YAAY,CAAC,OA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MAAM,UAAU,MAAM,CAAC,QAAQ,UAAU,OAAO,EAAE;AAAA,UAC5D,WAAW,EAAE,MAAM,UAAU,WAAW,IAAI;AAAA,QAC9C;AAAA,QACA,sBAAsB;AAAA,MACxB;AAAA,MACA,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,YAAY;AAAA,UACV,cAAc;AAAA,UACd,UAAU;AAAA,QACZ;AAAA,QACA,UAAU,CAAC,gBAAgB,UAAU;AAAA,QACrC,sBAAsB;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,MACP,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,YAAY;AAAA,UACV,OAAO,EAAE,MAAM,SAAS;AAAA,UACxB,QAAQ,EAAE,MAAM,UAAU,MAAM,CAAC,UAAU,YAAY,OAAO,EAAE;AAAA,UAChE,IAAI,EAAE,MAAM,SAAS;AAAA,QACvB;AAAA,QACA,UAAU,CAAC,SAAS,UAAU,IAAI;AAAA,QAClC,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,QAAQ;AAAA,IACV;AAAA,EACF;AACF,CAAC;",
10
+ "debugId": "EC5AB6ECF4DE51D064756E2164756E21",
11
+ "names": []
12
+ }
@@ -0,0 +1,35 @@
1
+ import { type Settings } from "./settings";
2
+ import { type SessionScope } from "./session-scope";
3
+ /**
4
+ * How often a running location re-reads the global runtime state. Settings and
5
+ * the session scope can be changed from any location (or another process
6
+ * sharing the same storage), so a cached value must expire eventually. A
7
+ * second keeps the hot path free of storage reads while a change still reaches
8
+ * every active session promptly.
9
+ */
10
+ export declare const RUNTIME_REFRESH_MS = 1000;
11
+ export type RuntimeReader = {
12
+ readonly settings: () => Promise<unknown>;
13
+ readonly scope: () => Promise<unknown>;
14
+ };
15
+ export type RuntimeStateOptions = {
16
+ readonly ttlMs?: number;
17
+ readonly now?: () => number;
18
+ readonly onError?: (source: "settings" | "scope", error: unknown) => void;
19
+ };
20
+ export type RuntimeState = {
21
+ readonly settings: Settings;
22
+ readonly scope: SessionScope;
23
+ refresh(force?: boolean): Promise<void>;
24
+ applySettings(settings: Settings): void;
25
+ applyScope(scope: SessionScope): void;
26
+ /** Back to the values this instance started with, not the built-in defaults. */
27
+ reset(): void;
28
+ };
29
+ /**
30
+ * The runtime state shared by every hook: the settings and the session scope.
31
+ * Both are global (stored in the plugin's server-side storage), but each
32
+ * location loads its own copy. The TTL is what lets a running location observe
33
+ * a change made by another one without reading storage on every request.
34
+ */
35
+ export declare function createRuntimeState(initial: Settings, read: RuntimeReader, state?: RuntimeStateOptions): RuntimeState;
@@ -0,0 +1,8 @@
1
+ import type { UpdateSessionScopeResponse } from "./rpc";
2
+ import type { PromptLogApi } from "./rpc-client";
3
+ /**
4
+ * Read the current scope, then arm or disarm exactly this session. The panel
5
+ * switch already knows the desired state; the keybind and slash commands do
6
+ * not, so they share this read-then-toggle path.
7
+ */
8
+ export declare function toggleSessionArmed(api: PromptLogApi, sessionID: string): Promise<UpdateSessionScopeResponse>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Session-scoped logging. `enabled` stays the master switch; this scope only
3
+ * decides which sessions are written while it is on.
4
+ *
5
+ * The scope is runtime state, persisted in the plugin's server storage next to
6
+ * the settings. `mode: "all"` keeps the historical behaviour.
7
+ * `mode: "only"` writes the listed sessions and nothing else; an empty list is
8
+ * a deliberate pause, not a fallback to every session.
9
+ */
10
+ export type SessionMode = "all" | "only";
11
+ export type SessionScope = {
12
+ readonly mode: SessionMode;
13
+ readonly sessions: readonly string[];
14
+ readonly max: number;
15
+ };
16
+ /**
17
+ * A validated transition request. `mode` and `action` are mutually exclusive:
18
+ * a mode switches the whole scope, an action changes the selected session.
19
+ */
20
+ export type SessionScopeChange = {
21
+ /** Switch every session back on, or keep the current selection limited. */
22
+ readonly mode?: SessionMode;
23
+ /**
24
+ * `only` records exactly this session and pauses the others; `disarm` drops
25
+ * this session from the selection (the scope stays limited); `clear` drops
26
+ * every selection and pauses logging.
27
+ */
28
+ readonly action?: "only" | "disarm" | "clear";
29
+ readonly sessionID?: string;
30
+ };
31
+ /** Runtime key. The settings key is "settings"; this is the same kind of state. */
32
+ export declare const SESSION_SCOPE_KEY = "sessionScope";
33
+ /** A bounded allowlist keeps stale session IDs from accumulating forever. */
34
+ export declare const MAX_SESSION_SCOPE = 50;
35
+ export declare function emptySessionScope(): SessionScope;
36
+ /**
37
+ * Read a stored scope defensively. A value written by a newer version, a
38
+ * manual edit or a corrupted store falls back to the default (all sessions)
39
+ * instead of breaking logging. Session IDs are bounded and deduplicated.
40
+ */
41
+ export declare function parseSessionScope(value: unknown): SessionScope;
42
+ /**
43
+ * What the hook gate asks: is this session written at all? Unlike
44
+ * `isSelected`, a session in `mode: "all"` is allowed even though it is not in
45
+ * the list.
46
+ */
47
+ export declare function sessionAllowed(scope: SessionScope, sessionID: string | undefined): boolean;
48
+ /** Whether the user explicitly selected this session in the limited scope. */
49
+ export declare function isSelected(scope: SessionScope | undefined, sessionID: string | undefined): boolean;
50
+ /** Short label shared by the TUI header, the desktop subtitle and toasts. */
51
+ export declare function scopeLabel(scope: SessionScope | undefined, enabled: boolean, sessionID?: string): string;
52
+ /** "Log only this session": an exclusive selection. */
53
+ export declare function onlySession(scope: SessionScope, sessionID: string): SessionScope;
54
+ /** Remove one selected session; the scope stays limited, possibly paused. */
55
+ export declare function removeSession(scope: SessionScope, sessionID: string): SessionScope;
56
+ /** Keep the limited scope but select nothing: logging is paused. */
57
+ export declare function clearSessions(scope: SessionScope): SessionScope;
58
+ /** Back to the historical behaviour: every session is written. */
59
+ export declare function allSessions(scope: SessionScope): SessionScope;
60
+ /**
61
+ * Apply a validated change. The handler rejects unknown or incomplete
62
+ * requests first; an empty ID here is a defensive no-op, never a selection
63
+ * with an empty string.
64
+ */
65
+ export declare function changeSessionScope(scope: SessionScope, change: SessionScopeChange): SessionScope;