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/README.md +105 -525
- package/dist/core.d.ts +7 -46
- package/dist/detail-lines.d.ts +17 -0
- package/dist/gui-experimental.cjs +29 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2282 -71
- package/dist/index.js.map +15 -5
- package/dist/log/body.d.ts +41 -0
- package/dist/log/errors.d.ts +5 -0
- package/dist/log/limits.d.ts +30 -0
- package/dist/log/paths.d.ts +42 -0
- package/dist/log/sanitize.d.ts +16 -0
- package/dist/log/summary.d.ts +3 -0
- package/dist/log/types.d.ts +58 -0
- package/dist/log/v2.d.ts +155 -0
- package/dist/logging-indicator.d.ts +31 -0
- package/dist/rpc-client.d.ts +27 -0
- package/dist/rpc-client.js +585 -0
- package/dist/rpc-client.js.map +14 -0
- package/dist/rpc.d.ts +1437 -0
- package/dist/rpc.js +446 -0
- package/dist/rpc.js.map +12 -0
- package/dist/runtime-state.d.ts +35 -0
- package/dist/session-scope-client.d.ts +8 -0
- package/dist/session-scope.d.ts +65 -0
- package/dist/settings.d.ts +46 -0
- package/dist/tui-panel/detail.d.ts +28 -0
- package/dist/tui-panel/panel.d.ts +21 -0
- package/dist/tui-status.d.ts +25 -0
- package/dist/tui.d.ts +15 -0
- package/dist/tui.js +2571 -0
- package/dist/tui.js.map +25 -0
- package/dist/ui-support.d.ts +3 -0
- package/dist/view-model.d.ts +76 -0
- package/package.json +53 -10
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** The provider, model and optional variant of one request. */
|
|
2
|
+
export type ModelRef = {
|
|
3
|
+
readonly providerID?: string;
|
|
4
|
+
readonly id?: string;
|
|
5
|
+
readonly variant?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Index entry for one model request. It carries only what the list and the
|
|
9
|
+
* filters need - never the prompt, the messages or the HTTP body.
|
|
10
|
+
*/
|
|
11
|
+
export type LogSummary = {
|
|
12
|
+
/** Opaque key of the v2 request. */
|
|
13
|
+
readonly key: string;
|
|
14
|
+
/** Stable pagination cursor: request time plus request ID. */
|
|
15
|
+
readonly cursor: string;
|
|
16
|
+
/** Logical size of the request: system prompt, messages and tools. */
|
|
17
|
+
readonly bytes: number;
|
|
18
|
+
readonly at: string | null;
|
|
19
|
+
readonly type: string | null;
|
|
20
|
+
readonly kind: string | null;
|
|
21
|
+
readonly sessionID: string | null;
|
|
22
|
+
readonly agent: string | null;
|
|
23
|
+
readonly model: ModelRef | null;
|
|
24
|
+
/** Request URL, when the request has an HTTP body. */
|
|
25
|
+
readonly url: string | null;
|
|
26
|
+
/** Message count on an assembled request. */
|
|
27
|
+
readonly messages?: number;
|
|
28
|
+
/** Wire body size on a request with an HTTP body. */
|
|
29
|
+
readonly bodyBytes?: number;
|
|
30
|
+
readonly hasBody?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type LogFilters = {
|
|
33
|
+
readonly sessionID?: string;
|
|
34
|
+
readonly type?: string;
|
|
35
|
+
readonly kind?: string;
|
|
36
|
+
readonly agent?: string;
|
|
37
|
+
readonly model?: string;
|
|
38
|
+
/** Metadata filter; never searches prompt content. */
|
|
39
|
+
readonly query?: string;
|
|
40
|
+
};
|
|
41
|
+
export type SearchInput = LogFilters & {
|
|
42
|
+
readonly query: string;
|
|
43
|
+
readonly limit?: number;
|
|
44
|
+
readonly ignoreCase?: boolean;
|
|
45
|
+
readonly budgetBytes?: number;
|
|
46
|
+
readonly budgetMs?: number;
|
|
47
|
+
};
|
|
48
|
+
export type SearchMatch = {
|
|
49
|
+
readonly entry: LogSummary;
|
|
50
|
+
readonly snippet: string;
|
|
51
|
+
};
|
|
52
|
+
export type SearchOutput = {
|
|
53
|
+
readonly matches: readonly SearchMatch[];
|
|
54
|
+
readonly partial: boolean;
|
|
55
|
+
readonly scannedBytes: number;
|
|
56
|
+
readonly skipped: number;
|
|
57
|
+
readonly error: string | null;
|
|
58
|
+
};
|
package/dist/log/v2.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AssembledEvent, HttpEvent } from "../core";
|
|
2
|
+
import { type BodyEncoding } from "./body";
|
|
3
|
+
import type { LogFilters, LogSummary, ModelRef, SearchInput, SearchOutput } from "./types";
|
|
4
|
+
export type V2Retention = {
|
|
5
|
+
readonly maxTotalBytes: number;
|
|
6
|
+
readonly maxAgeDays: number;
|
|
7
|
+
readonly maxSessions: number;
|
|
8
|
+
};
|
|
9
|
+
/** The retention policy derived from the effective settings. */
|
|
10
|
+
export declare function resolveRetention(settings: {
|
|
11
|
+
readonly diskBudget: number;
|
|
12
|
+
readonly retentionMaxAgeDays: number;
|
|
13
|
+
readonly retentionMaxSessions: number;
|
|
14
|
+
}): V2Retention;
|
|
15
|
+
type V2AssembledLine = {
|
|
16
|
+
readonly v: number;
|
|
17
|
+
readonly type: "assembled";
|
|
18
|
+
readonly requestID: string;
|
|
19
|
+
readonly at: string;
|
|
20
|
+
readonly kind: string;
|
|
21
|
+
readonly sessionID: string;
|
|
22
|
+
readonly agent?: string;
|
|
23
|
+
readonly model?: unknown;
|
|
24
|
+
readonly systemHash: string;
|
|
25
|
+
readonly messageHashes: readonly string[];
|
|
26
|
+
readonly tools: readonly string[];
|
|
27
|
+
readonly messages: number;
|
|
28
|
+
readonly bytes: number;
|
|
29
|
+
};
|
|
30
|
+
type V2HttpLine = {
|
|
31
|
+
readonly v: number;
|
|
32
|
+
readonly type: "http";
|
|
33
|
+
readonly requestID: string;
|
|
34
|
+
readonly at: string;
|
|
35
|
+
readonly kind: string;
|
|
36
|
+
readonly sessionID: string;
|
|
37
|
+
readonly agent?: string;
|
|
38
|
+
readonly model?: unknown;
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly bodyHash: string;
|
|
41
|
+
readonly bodyEncoding: BodyEncoding;
|
|
42
|
+
readonly contentType?: string | null;
|
|
43
|
+
readonly bodyBytes: number;
|
|
44
|
+
readonly decodedBytes?: number | null;
|
|
45
|
+
readonly truncated?: true;
|
|
46
|
+
readonly bytes: number;
|
|
47
|
+
};
|
|
48
|
+
type V2Entry = {
|
|
49
|
+
readonly key: string;
|
|
50
|
+
readonly cursor: string;
|
|
51
|
+
readonly sessionDir: string;
|
|
52
|
+
readonly sessionID: string;
|
|
53
|
+
readonly requestID: string;
|
|
54
|
+
at: string;
|
|
55
|
+
kind: string;
|
|
56
|
+
type: "assembled" | "http";
|
|
57
|
+
agent: string | null;
|
|
58
|
+
model: ModelRef | null;
|
|
59
|
+
bytes: number;
|
|
60
|
+
messages: number | null;
|
|
61
|
+
hasBody: boolean;
|
|
62
|
+
bodyBytes: number | null;
|
|
63
|
+
assembled: V2AssembledLine | null;
|
|
64
|
+
http: V2HttpLine | null;
|
|
65
|
+
};
|
|
66
|
+
type SessionCache = {
|
|
67
|
+
readonly dir: string;
|
|
68
|
+
readonly file: string;
|
|
69
|
+
size: number;
|
|
70
|
+
entries: Map<string, V2Entry>;
|
|
71
|
+
};
|
|
72
|
+
type Cache = {
|
|
73
|
+
readonly root: string;
|
|
74
|
+
sessions: Map<string, SessionCache>;
|
|
75
|
+
byKey: Map<string, V2Entry>;
|
|
76
|
+
sorted: V2Entry[];
|
|
77
|
+
requestBytes: number;
|
|
78
|
+
lastScanMs: number;
|
|
79
|
+
error: string | null;
|
|
80
|
+
};
|
|
81
|
+
/** A viewer has read from this store; writes may now emit change events. */
|
|
82
|
+
export declare function armV2(root: string): void;
|
|
83
|
+
export declare function isV2Armed(root: string): boolean;
|
|
84
|
+
export declare function disarmV2(root: string): void;
|
|
85
|
+
export type V2Writer = {
|
|
86
|
+
readonly writeAssembled: (kind: string, event: AssembledEvent) => void;
|
|
87
|
+
readonly writeHttp: (event: HttpEvent) => Promise<void>;
|
|
88
|
+
readonly active: Set<string>;
|
|
89
|
+
};
|
|
90
|
+
export type V2WriterOptions = {
|
|
91
|
+
readonly onWrite?: (written: {
|
|
92
|
+
readonly at: string;
|
|
93
|
+
}) => void;
|
|
94
|
+
readonly onError?: (error: unknown) => void;
|
|
95
|
+
};
|
|
96
|
+
export declare function createV2Writer(root: string, options?: V2WriterOptions): V2Writer;
|
|
97
|
+
export declare function invalidateV2(root: string): void;
|
|
98
|
+
export declare function ensureV2(root: string): Cache;
|
|
99
|
+
export type V2ListInput = LogFilters & {
|
|
100
|
+
readonly limit?: number;
|
|
101
|
+
readonly cursor?: string;
|
|
102
|
+
};
|
|
103
|
+
export type V2ListOutput = {
|
|
104
|
+
readonly entries: readonly LogSummary[];
|
|
105
|
+
readonly hasMore: boolean;
|
|
106
|
+
readonly records: number;
|
|
107
|
+
readonly error: string | null;
|
|
108
|
+
};
|
|
109
|
+
export declare function v2List(root: string, input: V2ListInput): V2ListOutput;
|
|
110
|
+
/**
|
|
111
|
+
* Bounded content search over the v2 store. Metadata is checked first, then the
|
|
112
|
+
* system prompt, the message bodies and finally the raw HTTP body. Body blobs
|
|
113
|
+
* are decoded only when their entry is reached, and both a byte and a time
|
|
114
|
+
* budget stop the scan early.
|
|
115
|
+
*/
|
|
116
|
+
export declare function v2Search(root: string, input: SearchInput, signal?: AbortSignal): SearchOutput;
|
|
117
|
+
export type V2ReadOutput = {
|
|
118
|
+
readonly record: Record<string, unknown> | null;
|
|
119
|
+
readonly bytes: number;
|
|
120
|
+
readonly truncated: boolean;
|
|
121
|
+
/** A larger `maxBytes` could return more of the same request. */
|
|
122
|
+
readonly moreAvailable: boolean;
|
|
123
|
+
/** Logical size of the complete request, including the decoded body. */
|
|
124
|
+
readonly fullBytes: number;
|
|
125
|
+
readonly notFound: boolean;
|
|
126
|
+
readonly paths?: {
|
|
127
|
+
readonly session: string;
|
|
128
|
+
readonly requests: string;
|
|
129
|
+
readonly body?: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export type V2ReadOptions = {
|
|
133
|
+
/** Test hook: force the streaming path with a value below the session size. */
|
|
134
|
+
readonly maxMapBytes?: number;
|
|
135
|
+
};
|
|
136
|
+
export declare function v2Read(root: string, key: string, maxBytes?: number, options?: V2ReadOptions): V2ReadOutput;
|
|
137
|
+
export type V2Status = {
|
|
138
|
+
readonly bytes: number;
|
|
139
|
+
readonly sessions: number;
|
|
140
|
+
readonly requests: number;
|
|
141
|
+
readonly requestBytes: number;
|
|
142
|
+
readonly lastScanMs: number;
|
|
143
|
+
readonly error: string | null;
|
|
144
|
+
readonly warnings: readonly string[];
|
|
145
|
+
};
|
|
146
|
+
export declare function v2Status(root: string): V2Status;
|
|
147
|
+
export declare function v2Delete(root: string, target: "current" | "all", sessionID?: string): number;
|
|
148
|
+
export type V2PruneResult = {
|
|
149
|
+
readonly removed: number;
|
|
150
|
+
readonly bytesFreed: number;
|
|
151
|
+
};
|
|
152
|
+
export declare function v2Prune(root: string, retention: V2Retention, active: ReadonlySet<string>): V2PruneResult;
|
|
153
|
+
/** Exposed for tests. */
|
|
154
|
+
export declare function v2SessionDir(root: string, sessionID: string): string;
|
|
155
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type SessionScope } from "./session-scope";
|
|
2
|
+
/** The effective logging state a viewer knows about. */
|
|
3
|
+
export type LoggingState = {
|
|
4
|
+
readonly enabled: boolean;
|
|
5
|
+
readonly scope: SessionScope | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type LoggingIndicatorTone = "recording" | "paused" | "off";
|
|
8
|
+
/**
|
|
9
|
+
* A short, viewer-independent description of the logging state.
|
|
10
|
+
*
|
|
11
|
+
* The TUI renders `label` in its footer; the desktop uses `detail` in a
|
|
12
|
+
* tooltip and the tone to pick an icon. Keeping the decision here means the
|
|
13
|
+
* two clients cannot disagree about what "paused" means.
|
|
14
|
+
*/
|
|
15
|
+
export type LoggingIndicator = {
|
|
16
|
+
readonly tone: LoggingIndicatorTone;
|
|
17
|
+
/** Compact label for a status bar, e.g. `log: all`. */
|
|
18
|
+
readonly label: string;
|
|
19
|
+
/** Full sentence for a tooltip or accessible name. */
|
|
20
|
+
readonly detail: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the state for one session, or for Home when `sessionID` is omitted.
|
|
24
|
+
*
|
|
25
|
+
* `enabled` is the master switch. When it is on, a limited scope can still
|
|
26
|
+
* exclude this session: that is `paused`, not `off`, and the distinction is
|
|
27
|
+
* the reason the indicator exists.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loggingIndicator(state: LoggingState & {
|
|
30
|
+
readonly sessionID?: string;
|
|
31
|
+
}): LoggingIndicator;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OpenCodeClient } from "@opencode/client";
|
|
2
|
+
import { type ChangedEvent, type ListRequest, type ListResponse, type ReadRequest, type ReadResponse, type SearchRequest, type SearchResponse, type SettingsChangedEvent, type SettingsResponse, type StatusResponse, type TruncateResponse, type UpdateSessionScopeRequest, type UpdateSessionScopeResponse } from "./rpc";
|
|
3
|
+
import { type Settings } from "./settings";
|
|
4
|
+
export type RpcLocation = {
|
|
5
|
+
readonly directory?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Typed client for the prompt-logger RPC, shared by the TUI and the desktop
|
|
9
|
+
* GUI. JSON Schema returns `unknown`; this is the one place it is cast back to
|
|
10
|
+
* the declared types, after the same clamps the server applies. Defence in
|
|
11
|
+
* depth: a stale client cannot ask for an unbounded page.
|
|
12
|
+
*/
|
|
13
|
+
export declare function promptLogApi(client: OpenCodeClient, location?: RpcLocation): {
|
|
14
|
+
status(signal?: AbortSignal): Promise<StatusResponse>;
|
|
15
|
+
list(input?: ListRequest, signal?: AbortSignal): Promise<ListResponse>;
|
|
16
|
+
read(input: ReadRequest, signal?: AbortSignal): Promise<ReadResponse>;
|
|
17
|
+
search(input: SearchRequest, signal?: AbortSignal): Promise<SearchResponse>;
|
|
18
|
+
truncate(target: "current" | "all", sessionID?: string): Promise<TruncateResponse>;
|
|
19
|
+
getSettings(): Promise<SettingsResponse>;
|
|
20
|
+
setSettings(settings: Settings): Promise<SettingsResponse>;
|
|
21
|
+
resetSettings(): Promise<SettingsResponse>;
|
|
22
|
+
updateSessionScope(input: UpdateSessionScopeRequest): Promise<UpdateSessionScopeResponse>;
|
|
23
|
+
onChanged(handler: (event: ChangedEvent) => void, signal?: AbortSignal): () => void;
|
|
24
|
+
onSettingsChanged(handler: (event: SettingsChangedEvent) => void, signal?: AbortSignal): () => void;
|
|
25
|
+
contractVersion: number;
|
|
26
|
+
};
|
|
27
|
+
export type PromptLogApi = ReturnType<typeof promptLogApi>;
|