@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,28 @@
|
|
|
1
|
+
import type { GuardRow } from "../family.js";
|
|
2
|
+
export declare function tokens(value: number | undefined): string;
|
|
3
|
+
export declare function columns(left: string, right: string, width: number): string[];
|
|
4
|
+
export declare function progress(ratio: number | undefined, width: number): string;
|
|
5
|
+
export interface MainSection {
|
|
6
|
+
readonly tone: "base" | "execution" | "pressure" | "measurement";
|
|
7
|
+
readonly lines: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function mainSections(row: GuardRow | undefined, width: number, age: number): MainSection[];
|
|
10
|
+
export declare function mainLines(row: GuardRow | undefined, width: number, age: number): string[];
|
|
11
|
+
export declare const statusSymbol: {
|
|
12
|
+
readonly running: "●";
|
|
13
|
+
readonly idle: "◌";
|
|
14
|
+
readonly unknown: "◌";
|
|
15
|
+
readonly completed: "✓";
|
|
16
|
+
readonly failed: "✕";
|
|
17
|
+
};
|
|
18
|
+
export declare function agentHeading(row: GuardRow, width: number): string;
|
|
19
|
+
export declare function agentLines(row: GuardRow, width: number): string[];
|
|
20
|
+
export declare function subagentTree(rows: readonly GuardRow[], sessionID: string, collapsed: ReadonlySet<string>, hideCompleted: boolean, byPressure: boolean): {
|
|
21
|
+
all: GuardRow[];
|
|
22
|
+
visible: {
|
|
23
|
+
row: GuardRow;
|
|
24
|
+
depth: number;
|
|
25
|
+
hasChildren: boolean;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
export declare function statistics(rows: readonly GuardRow[], sessionID: string, complete: boolean, width: number): string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GuardRow } from "../family.js";
|
|
2
|
+
export declare function quantity(n: number | undefined): string;
|
|
3
|
+
export declare function cells(value: string): number;
|
|
4
|
+
export declare function clip(value: string, width: number): string;
|
|
5
|
+
export declare function rowLines(row: GuardRow, width: number): string[];
|
|
6
|
+
export declare function detailLines(row: GuardRow | undefined, width: number, expanded?: boolean, ageMs?: number): string[];
|
|
7
|
+
export declare function wrap(value: string, width: number): string[];
|
|
8
|
+
export declare function performanceLines(row: GuardRow, width: number): string[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OpenCodeClient, SessionInfo } from "@opencode/client";
|
|
2
|
+
interface Branch {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly depth: number;
|
|
5
|
+
readonly cursor?: string;
|
|
6
|
+
readonly cursors: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export interface Inventory {
|
|
9
|
+
readonly sessions: ReadonlyMap<string, SessionInfo>;
|
|
10
|
+
readonly complete: boolean;
|
|
11
|
+
readonly rootId: string;
|
|
12
|
+
readonly pages: number;
|
|
13
|
+
readonly pending: readonly Branch[];
|
|
14
|
+
readonly scanned: ReadonlySet<string>;
|
|
15
|
+
readonly damaged: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function discoverFamily(client: Pick<OpenCodeClient, "session">, currentId: string, signal: AbortSignal, cached: (id: string) => SessionInfo | undefined, maxNodes?: number, previous?: Inventory): Promise<Inventory>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import type { PanelInput } from "@opencode/plugin/tui/context";
|
|
3
|
+
import type { GuardState } from "./state.js";
|
|
4
|
+
export declare function GuardPanel(props: {
|
|
5
|
+
input: PanelInput;
|
|
6
|
+
state: GuardState;
|
|
7
|
+
context: Plugin.Context;
|
|
8
|
+
}): import("solid-js").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
import type { GuardState } from "./state.js";
|
|
3
|
+
import type { GuardRow } from "../family.js";
|
|
4
|
+
export declare function GuardView(props: {
|
|
5
|
+
sessionID: string;
|
|
6
|
+
state: GuardState;
|
|
7
|
+
context: Plugin.Context;
|
|
8
|
+
width: number;
|
|
9
|
+
expanded?: boolean;
|
|
10
|
+
family?: readonly GuardRow[];
|
|
11
|
+
selectedId?: string;
|
|
12
|
+
inspectId?: string | undefined;
|
|
13
|
+
}): import("solid-js").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/tui";
|
|
2
|
+
export declare function createGuardState(context: Plugin.Context): {
|
|
3
|
+
version: import("solid-js").Accessor<number>;
|
|
4
|
+
acquire: (id: string) => {
|
|
5
|
+
update(next: string): void;
|
|
6
|
+
release(): void;
|
|
7
|
+
};
|
|
8
|
+
history(id: string, from: number, to: number, signal: AbortSignal): Promise<import("../historycharts.js").HistoryChartResult>;
|
|
9
|
+
rows: (stableOrder?: readonly string[], allDescendants?: boolean) => import("../family.js").GuardRow[];
|
|
10
|
+
dispose: () => void;
|
|
11
|
+
age(id: string): number;
|
|
12
|
+
health(): import("../snapshot.js").MonitorHealth | undefined;
|
|
13
|
+
connection(): "unavailable" | "loading" | "live" | "reconnecting" | "incompatible";
|
|
14
|
+
complete(): boolean;
|
|
15
|
+
refresh(): void;
|
|
16
|
+
loadMore(): void;
|
|
17
|
+
expand(id: string): void;
|
|
18
|
+
};
|
|
19
|
+
export type GuardState = ReturnType<typeof createGuardState>;
|
|
20
|
+
export declare function locationKey(location: {
|
|
21
|
+
directory: string;
|
|
22
|
+
workspaceID?: string;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function sameLocation(a: {
|
|
25
|
+
directory: string;
|
|
26
|
+
workspaceID?: string;
|
|
27
|
+
}, b: {
|
|
28
|
+
directory: string;
|
|
29
|
+
workspaceID?: string;
|
|
30
|
+
}): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ContextSnapshot, MonitorHealth } from "../snapshot.js";
|
|
2
|
+
export interface SnapshotTransport {
|
|
3
|
+
read(location: string, ids: readonly string[], signal: AbortSignal): Promise<unknown>;
|
|
4
|
+
subscribe(location: string, signal: AbortSignal): AsyncIterable<unknown>;
|
|
5
|
+
}
|
|
6
|
+
export type Connection = "loading" | "live" | "reconnecting" | "unavailable" | "incompatible";
|
|
7
|
+
export declare class SnapshotClient {
|
|
8
|
+
private readonly transport;
|
|
9
|
+
private readonly changed;
|
|
10
|
+
private readonly elapsed;
|
|
11
|
+
readonly rows: Map<string, ContextSnapshot>;
|
|
12
|
+
health: MonitorHealth | undefined;
|
|
13
|
+
connection: Connection;
|
|
14
|
+
private epoch;
|
|
15
|
+
private sequence;
|
|
16
|
+
private revisions;
|
|
17
|
+
private baselines;
|
|
18
|
+
private controller;
|
|
19
|
+
private generation;
|
|
20
|
+
private ids;
|
|
21
|
+
private location;
|
|
22
|
+
private refreshTimer;
|
|
23
|
+
private reading;
|
|
24
|
+
private buffered;
|
|
25
|
+
private overflow;
|
|
26
|
+
private retryTimer;
|
|
27
|
+
private failures;
|
|
28
|
+
private serverAt;
|
|
29
|
+
private receivedAt;
|
|
30
|
+
private refreshAgain;
|
|
31
|
+
private subscriptionActive;
|
|
32
|
+
constructor(transport: SnapshotTransport, changed: () => void, elapsed?: () => number);
|
|
33
|
+
now(): number;
|
|
34
|
+
setIds(ids: readonly string[]): void;
|
|
35
|
+
start(location: string, ids: readonly string[]): void;
|
|
36
|
+
private merge;
|
|
37
|
+
refresh(): Promise<void>;
|
|
38
|
+
private supervise;
|
|
39
|
+
stop(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export type Threshold = {
|
|
2
|
+
type: "tokens" | "ratio" | "remaining";
|
|
3
|
+
value: number;
|
|
4
|
+
};
|
|
5
|
+
export interface Match {
|
|
6
|
+
role?: "main" | "subagent";
|
|
7
|
+
model?: string;
|
|
8
|
+
agent?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Policy {
|
|
11
|
+
match: Match;
|
|
12
|
+
threshold: Threshold;
|
|
13
|
+
}
|
|
14
|
+
export interface Config {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
mode: "observe" | "enforce";
|
|
17
|
+
defaults: {
|
|
18
|
+
threshold: Threshold;
|
|
19
|
+
};
|
|
20
|
+
policies: Policy[];
|
|
21
|
+
safety: {
|
|
22
|
+
cooldownMs: number;
|
|
23
|
+
minReclaimTokens: number;
|
|
24
|
+
maxConsecutiveFailures: number;
|
|
25
|
+
pendingTimeoutMs: number;
|
|
26
|
+
staleMs: number;
|
|
27
|
+
maxSessions: number;
|
|
28
|
+
sessionTtlMs: number;
|
|
29
|
+
outputReserveTokens?: number;
|
|
30
|
+
};
|
|
31
|
+
metrics: {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
sampleIntervalMs: number;
|
|
34
|
+
rollingWindowMs: number;
|
|
35
|
+
};
|
|
36
|
+
history: {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
retentionDays: number;
|
|
39
|
+
maxBytes: number;
|
|
40
|
+
path?: string;
|
|
41
|
+
};
|
|
42
|
+
telemetry: {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
jsonl: boolean;
|
|
45
|
+
path?: string;
|
|
46
|
+
maxBytes: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface ModelLimits {
|
|
50
|
+
context: number;
|
|
51
|
+
input?: number;
|
|
52
|
+
output: number;
|
|
53
|
+
}
|
|
54
|
+
export interface Identity {
|
|
55
|
+
sessionId: string;
|
|
56
|
+
parentId?: string;
|
|
57
|
+
agent?: string;
|
|
58
|
+
model?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface Tokens {
|
|
61
|
+
input: number;
|
|
62
|
+
output: number;
|
|
63
|
+
reasoning: number;
|
|
64
|
+
cache: {
|
|
65
|
+
read: number;
|
|
66
|
+
write: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export interface Measurement {
|
|
70
|
+
tokens: number;
|
|
71
|
+
at: number;
|
|
72
|
+
model: string;
|
|
73
|
+
requestId?: string;
|
|
74
|
+
provenance: "provider-normalized" | "serialized-estimate";
|
|
75
|
+
confidence: "reported" | "approximate";
|
|
76
|
+
scope: "completed-request" | "prepared-request";
|
|
77
|
+
}
|
|
78
|
+
export interface ContextUsage {
|
|
79
|
+
current?: Measurement;
|
|
80
|
+
cumulative?: Tokens;
|
|
81
|
+
cumulativeScope: "session" | "unknown";
|
|
82
|
+
peak: number;
|
|
83
|
+
modelRequests: number;
|
|
84
|
+
toolCalls: number;
|
|
85
|
+
countersSince: number;
|
|
86
|
+
}
|
|
87
|
+
export interface ContextUsageProvider {
|
|
88
|
+
getUsage(sessionId: string): Promise<ContextUsage>;
|
|
89
|
+
}
|
|
90
|
+
export type CompactionPhase = "idle" | "requesting" | "accepted" | "running" | "awaiting-measurement" | "blocked" | "uncertain";
|
|
91
|
+
export interface CompactionState {
|
|
92
|
+
phase: CompactionPhase;
|
|
93
|
+
count: number;
|
|
94
|
+
failures: number;
|
|
95
|
+
consecutiveFailures: number;
|
|
96
|
+
lastAttempt?: number;
|
|
97
|
+
lastCompleted?: number;
|
|
98
|
+
before?: number | undefined;
|
|
99
|
+
beforeModel?: string | undefined;
|
|
100
|
+
beforeConfidence?: Measurement["confidence"] | undefined;
|
|
101
|
+
requestId?: string;
|
|
102
|
+
blockedReason?: string;
|
|
103
|
+
armed: boolean;
|
|
104
|
+
}
|
|
105
|
+
export interface Decision {
|
|
106
|
+
crossed: boolean;
|
|
107
|
+
reason: string;
|
|
108
|
+
policy: string;
|
|
109
|
+
threshold?: number;
|
|
110
|
+
budget?: number;
|
|
111
|
+
percentage?: number;
|
|
112
|
+
}
|
|
113
|
+
export interface SessionState extends Identity {
|
|
114
|
+
usage: ContextUsage;
|
|
115
|
+
compaction: CompactionState;
|
|
116
|
+
limits?: ModelLimits;
|
|
117
|
+
decision?: Decision;
|
|
118
|
+
lastSeen: number;
|
|
119
|
+
lastExecutionEnd?: number;
|
|
120
|
+
sequence: number;
|
|
121
|
+
active: boolean;
|
|
122
|
+
}
|
|
123
|
+
export type BudgetAction = {
|
|
124
|
+
type: "continue";
|
|
125
|
+
} | {
|
|
126
|
+
type: "warn" | "compact" | "checkpoint" | "rotate" | "stop";
|
|
127
|
+
reason: string;
|
|
128
|
+
};
|
|
129
|
+
export interface BudgetInput {
|
|
130
|
+
session: Readonly<SessionState>;
|
|
131
|
+
now: number;
|
|
132
|
+
elapsedMs: number;
|
|
133
|
+
depth?: number;
|
|
134
|
+
inheritedTokenBudget?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface BudgetController {
|
|
137
|
+
evaluate(input: BudgetInput): BudgetAction;
|
|
138
|
+
}
|
|
139
|
+
export declare class NoopBudgetController implements BudgetController {
|
|
140
|
+
evaluate(_input: BudgetInput): BudgetAction;
|
|
141
|
+
}
|
|
142
|
+
export interface TelemetryEvent {
|
|
143
|
+
time: number;
|
|
144
|
+
type: string;
|
|
145
|
+
session?: SessionState;
|
|
146
|
+
detail?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface TelemetrySink {
|
|
149
|
+
emit(event: TelemetryEvent): void;
|
|
150
|
+
}
|
|
151
|
+
export interface CompactionPort {
|
|
152
|
+
compact(sessionId: string, requestId: string): Promise<void>;
|
|
153
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cesarus777/opencode-cgp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./core": {
|
|
12
|
+
"types": "./dist/types/core.d.ts",
|
|
13
|
+
"import": "./dist/core.js",
|
|
14
|
+
"default": "./dist/core.js"
|
|
15
|
+
},
|
|
16
|
+
"./rpc": {
|
|
17
|
+
"types": "./dist/types/rpc.d.ts",
|
|
18
|
+
"import": "./dist/rpc.js",
|
|
19
|
+
"default": "./dist/rpc.js"
|
|
20
|
+
},
|
|
21
|
+
"./tui": {
|
|
22
|
+
"types": "./dist/types/tui.d.ts",
|
|
23
|
+
"import": "./dist/tui.js",
|
|
24
|
+
"default": "./dist/tui.js"
|
|
25
|
+
},
|
|
26
|
+
"./server": {
|
|
27
|
+
"types": "./dist/types/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "bun test",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"inspect": "bun src/cli.ts",
|
|
36
|
+
"test:live": "bun scripts/live.ts",
|
|
37
|
+
"format": "prettier --write src tests scripts docs README.md examples package.json tsconfig.json server.ts tui.tsx rpc.ts tsconfig.build.json .github AGENTS.md",
|
|
38
|
+
"format:check": "prettier --check src tests scripts docs README.md examples package.json tsconfig.json server.ts tui.tsx rpc.ts tsconfig.build.json .github AGENTS.md",
|
|
39
|
+
"test:tui-live": "bun scripts/tui-live.ts",
|
|
40
|
+
"bench:tui": "bun scripts/tui-bench.ts",
|
|
41
|
+
"build": "bun scripts/build.ts",
|
|
42
|
+
"prepack": "bun run build",
|
|
43
|
+
"prepare": "bun run build",
|
|
44
|
+
"test:package": "bun scripts/package-smoke.ts",
|
|
45
|
+
"validate": "bun run format:check && bun run typecheck && bun test && bun run test:package",
|
|
46
|
+
"test:metrics-live": "bun scripts/metrics-live.ts",
|
|
47
|
+
"charts": "bun src/cli.ts charts",
|
|
48
|
+
"test:metrics-server-live": "bun scripts/metrics-server-live.ts"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@opencode/plugin": "2.0.29",
|
|
52
|
+
"@opencode/client": "2.0.29"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/bun": "1.3.11",
|
|
56
|
+
"typescript": "5.9.3",
|
|
57
|
+
"prettier": "3.6.2",
|
|
58
|
+
"solid-js": "1.9.15",
|
|
59
|
+
"@opentui/core": "0.5.17",
|
|
60
|
+
"@opentui/solid": "0.5.17",
|
|
61
|
+
"@opencode/theme": "2.0.29"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"bun": ">=1.1.34"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"solid-js": ">=1.9.0",
|
|
68
|
+
"@opentui/core": ">=0.5.17",
|
|
69
|
+
"@opentui/solid": ">=0.5.17"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"solid-js": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@opentui/core": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@opentui/solid": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"description": "Early native compaction policy and context monitoring for OpenCode V2 root and nested-agent sessions.",
|
|
83
|
+
"license": "MIT",
|
|
84
|
+
"repository": {
|
|
85
|
+
"type": "git",
|
|
86
|
+
"url": "git+https://github.com/cesarus777/opencode-cgp.git"
|
|
87
|
+
},
|
|
88
|
+
"homepage": "https://github.com/cesarus777/opencode-cgp#readme",
|
|
89
|
+
"bugs": {
|
|
90
|
+
"url": "https://github.com/cesarus777/opencode-cgp/issues"
|
|
91
|
+
},
|
|
92
|
+
"keywords": [
|
|
93
|
+
"opencode",
|
|
94
|
+
"opencode-plugin",
|
|
95
|
+
"context",
|
|
96
|
+
"compaction",
|
|
97
|
+
"tokens"
|
|
98
|
+
],
|
|
99
|
+
"publishConfig": {
|
|
100
|
+
"access": "public"
|
|
101
|
+
},
|
|
102
|
+
"main": "./dist/index.js",
|
|
103
|
+
"types": "./dist/types/index.d.ts",
|
|
104
|
+
"files": [
|
|
105
|
+
"dist",
|
|
106
|
+
"LICENSE",
|
|
107
|
+
"README.md"
|
|
108
|
+
],
|
|
109
|
+
"bin": {
|
|
110
|
+
"context-guard": "./dist/cli.js"
|
|
111
|
+
}
|
|
112
|
+
}
|