@cesarus777/opencode-cgp 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/cli.js +1411 -0
- package/dist/core.js +1247 -0
- package/dist/index.js +2565 -0
- package/dist/rpc.js +332 -0
- package/dist/tui.js +2286 -0
- package/dist/types/adapter.d.ts +20 -0
- package/dist/types/chartreport.d.ts +14 -0
- package/dist/types/charts.d.ts +54 -0
- package/dist/types/config.d.ts +2 -0
- package/dist/types/core.d.ts +10 -0
- package/dist/types/estimate.d.ts +1 -0
- package/dist/types/family.d.ts +39 -0
- package/dist/types/history.d.ts +59 -0
- package/dist/types/historycharts.d.ts +17 -0
- package/dist/types/historyserver.d.ts +7 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/monitor.d.ts +20 -0
- package/dist/types/performance.d.ts +57 -0
- package/dist/types/policy.d.ts +12 -0
- package/dist/types/recovery.d.ts +22 -0
- package/dist/types/rpc.d.ts +129 -0
- package/dist/types/scheduler.d.ts +18 -0
- package/dist/types/snapshot.d.ts +98 -0
- package/dist/types/snapshotserver.d.ts +7 -0
- package/dist/types/telemetry.d.ts +17 -0
- package/dist/types/tui/chartformat.d.ts +11 -0
- package/dist/types/tui/charts.d.ts +10 -0
- package/dist/types/tui/compact.d.ts +10 -0
- package/dist/types/tui/compactformat.d.ts +28 -0
- package/dist/types/tui/format.d.ts +8 -0
- package/dist/types/tui/inventory.d.ts +18 -0
- package/dist/types/tui/panel.d.ts +8 -0
- package/dist/types/tui/sidebar.d.ts +13 -0
- package/dist/types/tui/state.d.ts +30 -0
- package/dist/types/tui/transport.d.ts +40 -0
- package/dist/types/tui.d.ts +3 -0
- package/dist/types/types.d.ts +153 -0
- package/package.json +110 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type HistoryRpcPort } from "./historyserver.js";
|
|
2
|
+
import { type SnapshotRpcPort } from "./snapshotserver.js";
|
|
3
|
+
import type { Plugin } from "@opencode/plugin";
|
|
4
|
+
import type { TelemetrySink } from "./types.js";
|
|
5
|
+
export interface Host {
|
|
6
|
+
rpc?: SnapshotRpcPort;
|
|
7
|
+
historyRpc?: HistoryRpcPort;
|
|
8
|
+
app: {
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
options: unknown;
|
|
12
|
+
location: {
|
|
13
|
+
directory: string;
|
|
14
|
+
};
|
|
15
|
+
session: Pick<Plugin.Context["session"], "get" | "compact" | "hook">;
|
|
16
|
+
model: Pick<Plugin.Context["model"], "list">;
|
|
17
|
+
event: Plugin.Context["event"];
|
|
18
|
+
storage: Pick<Plugin.Context["storage"], "get" | "set">;
|
|
19
|
+
}
|
|
20
|
+
export declare function setup(ctx: Host, injectedSink?: TelemetrySink): Promise<() => Promise<void>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ChartData } from "./charts.js";
|
|
2
|
+
import type { readPerformanceHistory } from "./history.js";
|
|
3
|
+
type ReportMetadata = Awaited<ReturnType<typeof readPerformanceHistory>>["metadata"];
|
|
4
|
+
interface ChartReport {
|
|
5
|
+
data: ChartData;
|
|
6
|
+
metadata: ReportMetadata;
|
|
7
|
+
agent?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
from?: number;
|
|
10
|
+
to?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Offline, self-contained SVG report. Generated identities only enter text nodes or escaped JSON. */
|
|
13
|
+
export declare function renderChartReport(report: ChartReport): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HistoryRecord } from "./history.js";
|
|
2
|
+
export interface ChartPoint {
|
|
3
|
+
time: number;
|
|
4
|
+
agent?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
breakBefore: boolean;
|
|
7
|
+
partial: boolean;
|
|
8
|
+
liveTps?: number;
|
|
9
|
+
averageModelTps?: number;
|
|
10
|
+
averageSessionTps?: number;
|
|
11
|
+
sessionOutputTokens?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ChartRequest {
|
|
14
|
+
time: number;
|
|
15
|
+
requestId: string;
|
|
16
|
+
started: number;
|
|
17
|
+
agent?: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
ttftMs?: number;
|
|
20
|
+
outputTokens?: number;
|
|
21
|
+
durationMs?: number;
|
|
22
|
+
tps?: number;
|
|
23
|
+
partial: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ChartSeries {
|
|
26
|
+
sessionId: string;
|
|
27
|
+
parentId?: string;
|
|
28
|
+
agents: string[];
|
|
29
|
+
models: string[];
|
|
30
|
+
points: ChartPoint[];
|
|
31
|
+
requests: ChartRequest[];
|
|
32
|
+
originalPoints: number;
|
|
33
|
+
}
|
|
34
|
+
export interface ChartGap {
|
|
35
|
+
time: number;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
reason: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ChartData {
|
|
40
|
+
schema: 1;
|
|
41
|
+
series: ChartSeries[];
|
|
42
|
+
gaps: ChartGap[];
|
|
43
|
+
omittedSessions: number;
|
|
44
|
+
omittedGaps?: number;
|
|
45
|
+
maxPoints: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ChartOptions {
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
maxPoints?: number;
|
|
50
|
+
maxSessions?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Preserve actual timestamps and extrema; never average a bucket's rates or bridge a gap. */
|
|
53
|
+
export declare function downsamplePoints(points: readonly ChartPoint[], limit: number): ChartPoint[];
|
|
54
|
+
export declare function buildChartData(records: readonly HistoryRecord[], options?: ChartOptions): ChartData;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./config.js";
|
|
3
|
+
export * from "./policy.js";
|
|
4
|
+
export * from "./monitor.js";
|
|
5
|
+
export * from "./scheduler.js";
|
|
6
|
+
export * from "./estimate.js";
|
|
7
|
+
export * from "./snapshot.js";
|
|
8
|
+
export * from "./family.js";
|
|
9
|
+
export * from "./performance.js";
|
|
10
|
+
export * from "./charts.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function estimate(value: unknown, maxChars?: number): number | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ContextSnapshot } from "./snapshot.js";
|
|
2
|
+
export type ExecutionStatus = "running" | "idle" | "completed" | "failed" | "unknown";
|
|
3
|
+
export interface SessionNode {
|
|
4
|
+
readonly sessionId: string;
|
|
5
|
+
readonly parentId?: string;
|
|
6
|
+
readonly agent?: string;
|
|
7
|
+
readonly model?: string;
|
|
8
|
+
readonly status: ExecutionStatus;
|
|
9
|
+
readonly interrupted?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface GuardRow {
|
|
12
|
+
readonly node: SessionNode;
|
|
13
|
+
readonly snapshot?: ContextSnapshot;
|
|
14
|
+
readonly depth: number;
|
|
15
|
+
readonly current: boolean;
|
|
16
|
+
readonly freshness: "fresh" | "stale" | "missing" | "invalid";
|
|
17
|
+
readonly pressure: "normal" | "near" | "crossed" | "unknown";
|
|
18
|
+
readonly pressureRatio?: number;
|
|
19
|
+
readonly utilizationPercent?: number;
|
|
20
|
+
readonly triggerDeltaTokens?: number;
|
|
21
|
+
readonly hidden: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function metric(snapshot: ContextSnapshot | undefined, now: number, staleMs: number): {
|
|
24
|
+
readonly triggerDeltaTokens?: number;
|
|
25
|
+
readonly utilizationPercent?: number;
|
|
26
|
+
readonly pressureRatio?: number;
|
|
27
|
+
readonly freshness: "invalid" | "fresh" | "stale" | "missing";
|
|
28
|
+
readonly pressure: "unknown" | "crossed" | "normal" | "near";
|
|
29
|
+
};
|
|
30
|
+
export declare function familyRows(nodes: readonly SessionNode[], snapshots: ReadonlyMap<string, ContextSnapshot>, current: string, now: number, staleMs: number, expanded?: ReadonlySet<string>, limit?: number, timing?: (id: string) => {
|
|
31
|
+
now: number;
|
|
32
|
+
staleMs: number;
|
|
33
|
+
}, stableOrder?: readonly string[]): GuardRow[];
|
|
34
|
+
export interface ExecutionEvidence {
|
|
35
|
+
readonly startedAt?: number;
|
|
36
|
+
readonly terminalAt?: number;
|
|
37
|
+
readonly outcome?: "succeeded" | "failed" | "interrupted";
|
|
38
|
+
}
|
|
39
|
+
export declare function executionStatus(known: boolean, nativeRunning: boolean, evidence: ExecutionEvidence): ExecutionStatus;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Identity, Config } from "./types.js";
|
|
2
|
+
import type { PerformanceSnapshot } from "./performance.js";
|
|
3
|
+
export interface HistoryRecord extends Identity {
|
|
4
|
+
schema: 1;
|
|
5
|
+
recordId: string;
|
|
6
|
+
time: number;
|
|
7
|
+
type: "sample" | "request" | "lifecycle" | "gap" | "terminal";
|
|
8
|
+
performance?: PerformanceSnapshot;
|
|
9
|
+
event?: string;
|
|
10
|
+
droppedRecords?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Separate bounded journal; the API accepts only projected scalar measurements. */
|
|
13
|
+
export declare class PerformanceHistory {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
private readonly config;
|
|
16
|
+
private readonly now;
|
|
17
|
+
private readonly report;
|
|
18
|
+
private pending;
|
|
19
|
+
private working;
|
|
20
|
+
private active;
|
|
21
|
+
private bytes;
|
|
22
|
+
private started;
|
|
23
|
+
private disabled;
|
|
24
|
+
private dropped;
|
|
25
|
+
private droppedTotal;
|
|
26
|
+
constructor(path: string, config: Config["history"], now?: () => number, report?: (event: string) => void);
|
|
27
|
+
emit(record: HistoryRecord): void;
|
|
28
|
+
private kick;
|
|
29
|
+
private prune;
|
|
30
|
+
private gapLine;
|
|
31
|
+
private drain;
|
|
32
|
+
health(): {
|
|
33
|
+
unavailable: boolean;
|
|
34
|
+
droppedRecords: number;
|
|
35
|
+
};
|
|
36
|
+
flush(): Promise<void>;
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export declare function scalarPerformance(p: PerformanceSnapshot): PerformanceSnapshot;
|
|
40
|
+
export interface HistoryFilter {
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
agent?: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
from?: number;
|
|
45
|
+
to?: number;
|
|
46
|
+
maxBytes?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface HistoryMetadata {
|
|
49
|
+
schema: number;
|
|
50
|
+
retainedFrom?: number;
|
|
51
|
+
retainedBytes: number;
|
|
52
|
+
skippedBytes: number;
|
|
53
|
+
malformedRecords: number;
|
|
54
|
+
completeness: string;
|
|
55
|
+
}
|
|
56
|
+
export declare function readPerformanceHistory(directory: string, filter?: HistoryFilter): Promise<{
|
|
57
|
+
metadata: HistoryMetadata;
|
|
58
|
+
records: HistoryRecord[];
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ChartData } from "./charts.js";
|
|
2
|
+
import type { readPerformanceHistory } from "./history.js";
|
|
3
|
+
export interface HistoryChartRead {
|
|
4
|
+
schemaVersion: 1;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
maxPoints: number;
|
|
9
|
+
}
|
|
10
|
+
export interface HistoryChartResult {
|
|
11
|
+
schemaVersion: 1;
|
|
12
|
+
generatedAt: number;
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
metadata: Awaited<ReturnType<typeof readPerformanceHistory>>["metadata"];
|
|
16
|
+
data: ChartData;
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { historyRpc } from "./rpc.js";
|
|
2
|
+
import type { RpcHandlers, RpcRegistration } from "@opencode/plugin/promise/rpc";
|
|
3
|
+
export interface HistoryRpcPort {
|
|
4
|
+
register(definition: typeof historyRpc, handlers: RpcHandlers<typeof historyRpc>): Promise<Pick<RpcRegistration<typeof historyRpc>, "dispose">>;
|
|
5
|
+
}
|
|
6
|
+
/** Read-only archive service. Clients can select an ID/time range, never a filesystem path. */
|
|
7
|
+
export declare function serveHistory(rpc: HistoryRpcPort | undefined, path: string, enabled: boolean, now?: () => number, authorize?: (sessionId: string, signal: AbortSignal) => Promise<boolean>): Promise<() => void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CompactionScheduler } from "./scheduler.js";
|
|
2
|
+
import { type BudgetController, type Config, type ContextUsage, type ContextUsageProvider, type Identity, type Measurement, type ModelLimits, type SessionState, type TelemetrySink, type Tokens } from "./types.js";
|
|
3
|
+
export declare function promptTokens(t: Tokens): number | undefined;
|
|
4
|
+
export declare class ContextMonitor implements ContextUsageProvider {
|
|
5
|
+
private readonly config;
|
|
6
|
+
readonly scheduler: CompactionScheduler;
|
|
7
|
+
private readonly sink;
|
|
8
|
+
private readonly now;
|
|
9
|
+
private readonly budget;
|
|
10
|
+
readonly sessions: Map<string, SessionState>;
|
|
11
|
+
private readonly resolver;
|
|
12
|
+
constructor(config: Config, scheduler: CompactionScheduler, sink: TelemetrySink, now?: () => number, budget?: BudgetController);
|
|
13
|
+
touch(identity: Identity, limits?: ModelLimits): SessionState | undefined;
|
|
14
|
+
accept(s: SessionState, sequence: number): boolean;
|
|
15
|
+
measure(s: SessionState, measurement: Measurement, cumulative?: Tokens): void;
|
|
16
|
+
evaluate(s: SessionState): void;
|
|
17
|
+
remove(id: string): void;
|
|
18
|
+
cleanup(): void;
|
|
19
|
+
getUsage(id: string): Promise<ContextUsage>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Tokens } from "./types.js";
|
|
2
|
+
export interface PerformanceSnapshot {
|
|
3
|
+
readonly sessionCreatedAt: number;
|
|
4
|
+
readonly sessionOutputTokens?: number;
|
|
5
|
+
readonly observedSince: number;
|
|
6
|
+
readonly at: number;
|
|
7
|
+
readonly status: "waiting" | "streaming" | "idle" | "unavailable";
|
|
8
|
+
readonly partial: boolean;
|
|
9
|
+
readonly liveTps?: number;
|
|
10
|
+
readonly averageModelTps?: number;
|
|
11
|
+
readonly averageSessionTps?: number;
|
|
12
|
+
readonly ttftMs?: number;
|
|
13
|
+
readonly latestRequestTps?: number;
|
|
14
|
+
readonly requestId?: string;
|
|
15
|
+
readonly requestAgent?: string;
|
|
16
|
+
readonly requestModel?: string;
|
|
17
|
+
readonly requestOutputTokens?: number;
|
|
18
|
+
readonly requestStartedAt?: number;
|
|
19
|
+
readonly firstOutputAt?: number;
|
|
20
|
+
readonly streamEndedAt?: number;
|
|
21
|
+
readonly estimatedOutputTokens: number;
|
|
22
|
+
readonly modelOutputTokens: number;
|
|
23
|
+
readonly modelDurationMs: number;
|
|
24
|
+
readonly completedRequests: number;
|
|
25
|
+
readonly tokenSource: "estimated" | "reported" | "unavailable";
|
|
26
|
+
}
|
|
27
|
+
export interface PerformanceCheckpoint {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
observedSince: number;
|
|
30
|
+
created: number;
|
|
31
|
+
output: number;
|
|
32
|
+
duration: number;
|
|
33
|
+
completed: number;
|
|
34
|
+
sequence: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function outputTokens(tokens: Pick<Tokens, "output" | "reasoning">): number | undefined;
|
|
37
|
+
/** Scalar-only collection. No harness types or generated content are retained. */
|
|
38
|
+
export declare class PerformanceTracker {
|
|
39
|
+
private readonly maxSessions;
|
|
40
|
+
private readonly windowMs;
|
|
41
|
+
private readonly now;
|
|
42
|
+
private rows;
|
|
43
|
+
constructor(maxSessions: number, windowMs?: number, now?: () => number);
|
|
44
|
+
observe(id: string, created: number, cumulative: number | undefined): void;
|
|
45
|
+
accept(id: string, sequence: number): boolean;
|
|
46
|
+
start(id: string, requestId: string, agent: string, model: string, started: number): void;
|
|
47
|
+
delta(id: string, requestId: string, eventId: string, at: number, characters: number): void;
|
|
48
|
+
streamed(id: string, requestId: string, at: number): void;
|
|
49
|
+
settle(id: string, requestId: string, tokens: number | undefined): void;
|
|
50
|
+
gap(id?: string): void;
|
|
51
|
+
private prune;
|
|
52
|
+
snapshot(id: string): PerformanceSnapshot | undefined;
|
|
53
|
+
checkpoint(): PerformanceCheckpoint[];
|
|
54
|
+
restore(value: unknown): void;
|
|
55
|
+
remove(id: string): void;
|
|
56
|
+
ids(): MapIterator<string>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config, Identity, Measurement, ModelLimits, Threshold, Decision } from "./types.js";
|
|
2
|
+
export declare function glob(pattern: string, text: string): boolean;
|
|
3
|
+
export declare class PolicyResolver {
|
|
4
|
+
private readonly config;
|
|
5
|
+
constructor(config: Config);
|
|
6
|
+
resolve(identity: Identity): {
|
|
7
|
+
threshold: Threshold;
|
|
8
|
+
policy: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function usableInput(limits?: ModelLimits, reserve?: number): number | undefined;
|
|
12
|
+
export declare function evaluateThreshold(threshold: Threshold, measurement: Measurement | undefined, limits: ModelLimits | undefined, now: number, staleMs: number, model: string | undefined, policy: string, reserve?: number): Decision;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CompactionState } from "./types.js";
|
|
2
|
+
export interface Recovery {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
compaction: CompactionState;
|
|
5
|
+
sequence?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function decodeRecovery(v: unknown, max: number): Recovery[];
|
|
8
|
+
export declare function encodeRecovery(rows: Recovery[]): {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
sequence: number;
|
|
11
|
+
compaction: {
|
|
12
|
+
requestId: string | null;
|
|
13
|
+
phase: import("./types.js").CompactionPhase;
|
|
14
|
+
armed: boolean;
|
|
15
|
+
count: number;
|
|
16
|
+
failures: number;
|
|
17
|
+
consecutiveFailures: number;
|
|
18
|
+
lastAttempt: number | null;
|
|
19
|
+
lastCompleted: number | null;
|
|
20
|
+
blockedReason: string | null;
|
|
21
|
+
};
|
|
22
|
+
}[];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { SnapshotBatch, SnapshotRead, SnapshotReadResult } from "./snapshot.js";
|
|
2
|
+
export declare const readSchema: {
|
|
3
|
+
type: "object";
|
|
4
|
+
properties: Record<string, object>;
|
|
5
|
+
required: string[];
|
|
6
|
+
additionalProperties: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const batchSchema: {
|
|
9
|
+
type: "object";
|
|
10
|
+
properties: Record<string, object>;
|
|
11
|
+
required: string[];
|
|
12
|
+
additionalProperties: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const resultSchema: {
|
|
15
|
+
type: "object";
|
|
16
|
+
properties: Record<string, object>;
|
|
17
|
+
required: string[];
|
|
18
|
+
additionalProperties: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare const monitorRpc: {
|
|
21
|
+
readonly id: "context-guard.monitor.v1";
|
|
22
|
+
readonly methods: {
|
|
23
|
+
readonly read: {
|
|
24
|
+
readonly input: {
|
|
25
|
+
type: "object";
|
|
26
|
+
properties: Record<string, object>;
|
|
27
|
+
required: string[];
|
|
28
|
+
additionalProperties: boolean;
|
|
29
|
+
};
|
|
30
|
+
readonly output: {
|
|
31
|
+
type: "object";
|
|
32
|
+
properties: Record<string, object>;
|
|
33
|
+
required: string[];
|
|
34
|
+
additionalProperties: boolean;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly events: {
|
|
39
|
+
readonly changed: {
|
|
40
|
+
readonly schema: {
|
|
41
|
+
type: "object";
|
|
42
|
+
properties: Record<string, object>;
|
|
43
|
+
required: string[];
|
|
44
|
+
additionalProperties: boolean;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export declare const performanceSchema: {
|
|
50
|
+
type: "object";
|
|
51
|
+
properties: Record<string, object>;
|
|
52
|
+
required: string[];
|
|
53
|
+
additionalProperties: boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare const performanceBatchSchema: {
|
|
56
|
+
type: "object";
|
|
57
|
+
properties: Record<string, object>;
|
|
58
|
+
required: string[];
|
|
59
|
+
additionalProperties: boolean;
|
|
60
|
+
};
|
|
61
|
+
export declare const performanceResultSchema: {
|
|
62
|
+
type: "object";
|
|
63
|
+
properties: Record<string, object>;
|
|
64
|
+
required: string[];
|
|
65
|
+
additionalProperties: boolean;
|
|
66
|
+
};
|
|
67
|
+
export declare const performanceRpc: {
|
|
68
|
+
readonly id: "context-guard.monitor.v2";
|
|
69
|
+
readonly methods: {
|
|
70
|
+
readonly read: {
|
|
71
|
+
readonly input: {
|
|
72
|
+
type: "object";
|
|
73
|
+
properties: Record<string, object>;
|
|
74
|
+
required: string[];
|
|
75
|
+
additionalProperties: boolean;
|
|
76
|
+
};
|
|
77
|
+
readonly output: {
|
|
78
|
+
type: "object";
|
|
79
|
+
properties: Record<string, object>;
|
|
80
|
+
required: string[];
|
|
81
|
+
additionalProperties: boolean;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
readonly events: {
|
|
86
|
+
readonly changed: {
|
|
87
|
+
readonly schema: {
|
|
88
|
+
type: "object";
|
|
89
|
+
properties: Record<string, object>;
|
|
90
|
+
required: string[];
|
|
91
|
+
additionalProperties: boolean;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export declare function isPerformanceBatch(value: unknown): value is SnapshotBatch;
|
|
97
|
+
export declare function isPerformanceResult(value: unknown): value is SnapshotReadResult;
|
|
98
|
+
export declare function isPerformanceSnapshot(value: unknown): value is import("./performance.js").PerformanceSnapshot;
|
|
99
|
+
export declare const historyReadSchema: {
|
|
100
|
+
type: "object";
|
|
101
|
+
properties: Record<string, object>;
|
|
102
|
+
required: string[];
|
|
103
|
+
additionalProperties: boolean;
|
|
104
|
+
};
|
|
105
|
+
export declare const historyRpc: {
|
|
106
|
+
readonly id: "context-guard.history.v1";
|
|
107
|
+
readonly methods: {
|
|
108
|
+
readonly read: {
|
|
109
|
+
readonly input: {
|
|
110
|
+
type: "object";
|
|
111
|
+
properties: Record<string, object>;
|
|
112
|
+
required: string[];
|
|
113
|
+
additionalProperties: boolean;
|
|
114
|
+
};
|
|
115
|
+
readonly output: {
|
|
116
|
+
type: "object";
|
|
117
|
+
properties: Record<string, object>;
|
|
118
|
+
required: string[];
|
|
119
|
+
additionalProperties: boolean;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
readonly events: {};
|
|
124
|
+
};
|
|
125
|
+
export declare function isHistoryRead(value: unknown): value is import("./historycharts.js").HistoryChartRead;
|
|
126
|
+
export declare function isHistoryResult(value: unknown): value is import("./historycharts.js").HistoryChartResult;
|
|
127
|
+
export declare function isRead(value: unknown): value is SnapshotRead;
|
|
128
|
+
export declare function isBatch(value: unknown): value is SnapshotBatch;
|
|
129
|
+
export declare function isResult(value: unknown): value is SnapshotReadResult;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CompactionPort, Config, SessionState, TelemetrySink } from "./types.js";
|
|
2
|
+
export declare class CompactionScheduler {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private readonly port;
|
|
5
|
+
private readonly sink;
|
|
6
|
+
private readonly now;
|
|
7
|
+
private readonly id;
|
|
8
|
+
private stopped;
|
|
9
|
+
private readonly jobs;
|
|
10
|
+
constructor(config: Config, port: CompactionPort, sink: TelemetrySink, now?: () => number, id?: () => string);
|
|
11
|
+
consider(s: SessionState): void;
|
|
12
|
+
lifecycle(s: SessionState, event: "started" | "ended" | "failed", at: number): void;
|
|
13
|
+
measured(s: SessionState): void;
|
|
14
|
+
tick(s: SessionState): void;
|
|
15
|
+
private emit;
|
|
16
|
+
flush(): Promise<void>;
|
|
17
|
+
stop(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { PerformanceSnapshot } from "./performance.js";
|
|
2
|
+
import type { Config, SessionState, Measurement, ModelLimits, Threshold, Tokens, CompactionPhase } from "./types.js";
|
|
3
|
+
export interface ContextSnapshot {
|
|
4
|
+
readonly performance?: PerformanceSnapshot;
|
|
5
|
+
readonly sessionId: string;
|
|
6
|
+
readonly revision: number;
|
|
7
|
+
readonly observedAt: number;
|
|
8
|
+
readonly parentId?: string;
|
|
9
|
+
readonly agent?: string;
|
|
10
|
+
readonly model?: string;
|
|
11
|
+
readonly measurement?: Readonly<Measurement>;
|
|
12
|
+
readonly limits?: Readonly<ModelLimits>;
|
|
13
|
+
readonly capacityTokens?: number;
|
|
14
|
+
readonly outputReserveTokens?: number;
|
|
15
|
+
/** Peak prompt tokens observed during monitor residency. */
|
|
16
|
+
readonly peakTokens?: number;
|
|
17
|
+
readonly policy: {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly configured: Readonly<Threshold>;
|
|
20
|
+
readonly triggerTokens?: number;
|
|
21
|
+
readonly comparison: ">=" | ">";
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
readonly crossed: boolean;
|
|
24
|
+
};
|
|
25
|
+
readonly compaction: {
|
|
26
|
+
readonly phase: CompactionPhase;
|
|
27
|
+
/** Completed lifecycle events observed by the monitor, never admissions. */
|
|
28
|
+
readonly count?: number;
|
|
29
|
+
readonly armed: boolean;
|
|
30
|
+
readonly blockedReason?: string;
|
|
31
|
+
readonly lastAttempt?: number;
|
|
32
|
+
readonly lastCompleted?: number;
|
|
33
|
+
readonly cooldownUntil?: number;
|
|
34
|
+
};
|
|
35
|
+
readonly cumulative?: Readonly<Omit<Tokens, "cache">> & {
|
|
36
|
+
readonly cache: Readonly<Tokens["cache"]>;
|
|
37
|
+
};
|
|
38
|
+
readonly cumulativeScope: "session" | "unknown";
|
|
39
|
+
readonly lastObservedActive: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface MonitorHealth {
|
|
42
|
+
readonly enabled: boolean;
|
|
43
|
+
readonly mode: "observe" | "enforce";
|
|
44
|
+
readonly enforcement: "observing" | "available" | "suspended" | "disabled";
|
|
45
|
+
readonly reasons: readonly string[];
|
|
46
|
+
readonly staleMs: number;
|
|
47
|
+
readonly maxSessions: number;
|
|
48
|
+
}
|
|
49
|
+
export interface SnapshotBatch {
|
|
50
|
+
readonly schemaVersion: 1;
|
|
51
|
+
readonly epoch: string;
|
|
52
|
+
readonly sequence: number;
|
|
53
|
+
readonly generatedAt: number;
|
|
54
|
+
readonly health: MonitorHealth;
|
|
55
|
+
readonly upserts: readonly ContextSnapshot[];
|
|
56
|
+
readonly removed: readonly {
|
|
57
|
+
readonly sessionId: string;
|
|
58
|
+
readonly revision: number;
|
|
59
|
+
readonly reason: "deleted" | "evicted";
|
|
60
|
+
}[];
|
|
61
|
+
}
|
|
62
|
+
export interface SnapshotRead {
|
|
63
|
+
readonly schemaVersion: 1;
|
|
64
|
+
readonly sessionIds: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
export interface SnapshotReadResult extends SnapshotBatch {
|
|
67
|
+
readonly unavailable: readonly {
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
readonly reason: "not-monitored";
|
|
70
|
+
}[];
|
|
71
|
+
}
|
|
72
|
+
export declare function project(s: SessionState, config: Config, now: number, revision?: number): ContextSnapshot;
|
|
73
|
+
export declare class SnapshotStore {
|
|
74
|
+
private readonly config;
|
|
75
|
+
private readonly sessions;
|
|
76
|
+
private readonly now;
|
|
77
|
+
private readonly performanceSnapshot?;
|
|
78
|
+
readonly epoch: string;
|
|
79
|
+
private sequence;
|
|
80
|
+
private revision;
|
|
81
|
+
private rows;
|
|
82
|
+
private deleted;
|
|
83
|
+
private dirty;
|
|
84
|
+
private listeners;
|
|
85
|
+
private healthKey;
|
|
86
|
+
private reasons;
|
|
87
|
+
constructor(config: Config, sessions: () => ReadonlyMap<string, SessionState>, now?: () => number, epoch?: string, performanceSnapshot?: ((id: string) => PerformanceSnapshot | undefined) | undefined);
|
|
88
|
+
health(): MonitorHealth;
|
|
89
|
+
degrade(reason: "event-stream-gap" | "persistence-unavailable" | "capacity-exceeded" | "model-metadata-unavailable"): void;
|
|
90
|
+
recover(reason: "capacity-exceeded" | "model-metadata-unavailable"): void;
|
|
91
|
+
mark(id: string): void;
|
|
92
|
+
markAll(): void;
|
|
93
|
+
remove(id: string): void;
|
|
94
|
+
listen(fn: (batch: SnapshotBatch) => void): () => void;
|
|
95
|
+
private batch;
|
|
96
|
+
flush(): void;
|
|
97
|
+
read(input: SnapshotRead): SnapshotReadResult;
|
|
98
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RpcHandlers, RpcRegistration } from "@opencode/plugin/promise/rpc";
|
|
2
|
+
export interface SnapshotRpcPort {
|
|
3
|
+
register(definition: typeof monitorRpc | typeof performanceRpc, handlers: RpcHandlers<typeof monitorRpc>): Promise<RpcRegistration<typeof monitorRpc>>;
|
|
4
|
+
}
|
|
5
|
+
import { monitorRpc, performanceRpc } from "./rpc.js";
|
|
6
|
+
import type { SnapshotStore } from "./snapshot.js";
|
|
7
|
+
export declare function serveSnapshots(rpc: SnapshotRpcPort | undefined, store: SnapshotStore, performance?: boolean): Promise<() => void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Config, TelemetryEvent, TelemetrySink } from "./types.js";
|
|
2
|
+
export declare function defaultPath(directory: string): string;
|
|
3
|
+
export declare class JsonlTelemetrySink implements TelemetrySink {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
private readonly config;
|
|
6
|
+
private pending;
|
|
7
|
+
private working;
|
|
8
|
+
private disabled;
|
|
9
|
+
private bytes;
|
|
10
|
+
private ready;
|
|
11
|
+
constructor(path: string, config: Config["telemetry"]);
|
|
12
|
+
emit(event: TelemetryEvent): void;
|
|
13
|
+
private kick;
|
|
14
|
+
private drain;
|
|
15
|
+
flush(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare function readJournal(path: string, maxBytes?: number): Promise<unknown[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HistoryChartResult } from "../historycharts.js";
|
|
2
|
+
/** Each cell contains an observed peak, never an interpolated or invented zero. */
|
|
3
|
+
export declare function sparkline(points: readonly {
|
|
4
|
+
time: number;
|
|
5
|
+
value?: number;
|
|
6
|
+
}[], from: number, to: number, width: number, gaps?: readonly number[]): {
|
|
7
|
+
line: string;
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function historyChartLines(result: HistoryChartResult, width: number, from: number, to: number): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import type { GuardState } from "./state.js";
|
|
3
|
+
export declare function HistoryCharts(props: {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
windowMs: number;
|
|
6
|
+
refresh: number;
|
|
7
|
+
width: number;
|
|
8
|
+
state: GuardState;
|
|
9
|
+
context: Plugin.Context;
|
|
10
|
+
}): import("solid-js").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import type { GuardRow } from "../family.js";
|
|
3
|
+
import type { GuardState } from "./state.js";
|
|
4
|
+
export declare function CompactSidebar(props: {
|
|
5
|
+
sessionID: string;
|
|
6
|
+
rows: readonly GuardRow[];
|
|
7
|
+
state: GuardState;
|
|
8
|
+
context: Plugin.Context;
|
|
9
|
+
width: number;
|
|
10
|
+
}): import("solid-js").JSX.Element;
|