@jmtrin/opencode-kevin 0.4.0 → 0.5.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 +87 -11
- package/dist/migrations/006_v05_glassbox.sql +118 -0
- package/dist/plugin/Archiver.d.ts +42 -0
- package/dist/plugin/Archiver.js +98 -0
- package/dist/plugin/Archiver.js.map +1 -0
- package/dist/plugin/ContextInjector.d.ts +72 -0
- package/dist/plugin/ContextInjector.js +177 -44
- package/dist/plugin/ContextInjector.js.map +1 -1
- package/dist/plugin/Feedback.d.ts +67 -0
- package/dist/plugin/Feedback.js +137 -0
- package/dist/plugin/Feedback.js.map +1 -0
- package/dist/plugin/InjectionLedger.d.ts +9 -2
- package/dist/plugin/InjectionLedger.js +63 -9
- package/dist/plugin/InjectionLedger.js.map +1 -1
- package/dist/plugin/MemoryService.d.ts +19 -0
- package/dist/plugin/MemoryService.js +119 -15
- package/dist/plugin/MemoryService.js.map +1 -1
- package/dist/plugin/Migrate.js +21 -0
- package/dist/plugin/Migrate.js.map +1 -1
- package/dist/plugin/QualityGate.d.ts +39 -0
- package/dist/plugin/QualityGate.js +38 -8
- package/dist/plugin/QualityGate.js.map +1 -1
- package/dist/plugin/Retrospective.js +12 -0
- package/dist/plugin/Retrospective.js.map +1 -1
- package/dist/plugin/confidence.d.ts +3 -1
- package/dist/plugin/confidence.js +14 -2
- package/dist/plugin/confidence.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.js +152 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/kevin_audit.d.ts +49 -0
- package/dist/plugin/kevin_audit.js +141 -0
- package/dist/plugin/kevin_audit.js.map +1 -0
- package/dist/plugin/kevin_why.js +23 -2
- package/dist/plugin/kevin_why.js.map +1 -1
- package/dist/plugin/metrics.d.ts +21 -1
- package/dist/plugin/metrics.js +47 -2
- package/dist/plugin/metrics.js.map +1 -1
- package/dist/plugin/replay-types.d.ts +327 -0
- package/dist/plugin/replay-types.js +65 -0
- package/dist/plugin/replay-types.js.map +1 -0
- package/dist/plugin/replay.d.ts +36 -0
- package/dist/plugin/replay.js +193 -0
- package/dist/plugin/replay.js.map +1 -0
- package/migrations/006_v05_glassbox.sql +118 -0
- package/package.json +3 -2
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
function groupCounts(store, column) {
|
|
2
|
+
const rows = store
|
|
3
|
+
.prepare(`SELECT ${column} AS k, COUNT(*) AS n FROM memories GROUP BY ${column}`)
|
|
4
|
+
.all();
|
|
5
|
+
const out = {};
|
|
6
|
+
for (const r of rows) {
|
|
7
|
+
out[r.k ?? "unknown"] = r.n;
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
function scalar(store, sql) {
|
|
12
|
+
const row = store.prepare(sql).get();
|
|
13
|
+
return row.n ?? 0;
|
|
14
|
+
}
|
|
15
|
+
export function buildAudit(store, metrics) {
|
|
16
|
+
let partial = false;
|
|
17
|
+
// Memories block: `total` + the three GROUP BYs are pre-006 safe; the
|
|
18
|
+
// lifecycle counters need the 006 columns and fall back separately.
|
|
19
|
+
let memories = {
|
|
20
|
+
total: 0,
|
|
21
|
+
by_status: {},
|
|
22
|
+
by_origin: {},
|
|
23
|
+
by_type: {},
|
|
24
|
+
ignored: 0,
|
|
25
|
+
archived: 0,
|
|
26
|
+
with_feedback: 0,
|
|
27
|
+
superseded_with_target: 0,
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
memories = {
|
|
31
|
+
...memories,
|
|
32
|
+
total: scalar(store, "SELECT COUNT(*) AS n FROM memories"),
|
|
33
|
+
by_status: groupCounts(store, "status"),
|
|
34
|
+
by_origin: groupCounts(store, "origin"),
|
|
35
|
+
by_type: groupCounts(store, "type"),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
partial = true;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
memories = {
|
|
43
|
+
...memories,
|
|
44
|
+
ignored: scalar(store, "SELECT COUNT(*) AS n FROM memories WHERE ignored = 1"),
|
|
45
|
+
archived: scalar(store, "SELECT COUNT(*) AS n FROM memories WHERE status = 'archived'"),
|
|
46
|
+
with_feedback: scalar(store, "SELECT COUNT(*) AS n FROM memories WHERE feedback_positive > 0 OR feedback_negative > 0"),
|
|
47
|
+
superseded_with_target: scalar(store, "SELECT COUNT(*) AS n FROM memories WHERE status = 'superseded' AND superseded_by IS NOT NULL"),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
partial = true;
|
|
52
|
+
}
|
|
53
|
+
// Injections block: grouped rollup over the ledger (same query the
|
|
54
|
+
// InjectionLedger.outcomeCounts() runs), rates from the metric cache.
|
|
55
|
+
let injections = {
|
|
56
|
+
total: 0,
|
|
57
|
+
effective: 0,
|
|
58
|
+
ineffective: 0,
|
|
59
|
+
inconclusive: 0,
|
|
60
|
+
unmeasured: 0,
|
|
61
|
+
precision_rate: 0,
|
|
62
|
+
coverage_rate: 0,
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
const rows = store
|
|
66
|
+
.prepare("SELECT outcome, COUNT(*) AS n FROM kevin_injections GROUP BY outcome")
|
|
67
|
+
.all();
|
|
68
|
+
const counts = {
|
|
69
|
+
unmeasured: 0,
|
|
70
|
+
effective: 0,
|
|
71
|
+
ineffective: 0,
|
|
72
|
+
inconclusive: 0,
|
|
73
|
+
};
|
|
74
|
+
for (const r of rows) {
|
|
75
|
+
counts[r.outcome] = r.n;
|
|
76
|
+
}
|
|
77
|
+
injections = {
|
|
78
|
+
total: rows.reduce((acc, r) => acc + r.n, 0),
|
|
79
|
+
effective: counts.effective,
|
|
80
|
+
ineffective: counts.ineffective,
|
|
81
|
+
inconclusive: counts.inconclusive,
|
|
82
|
+
unmeasured: counts.unmeasured,
|
|
83
|
+
precision_rate: metrics.precisionRate(),
|
|
84
|
+
coverage_rate: metrics.coverageRate(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
partial = true;
|
|
89
|
+
}
|
|
90
|
+
// Feedback block: verdict rollup from the table, totals from the cache.
|
|
91
|
+
let feedback = {
|
|
92
|
+
positive: 0,
|
|
93
|
+
negative: 0,
|
|
94
|
+
by_verdict: {},
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
const rows = store
|
|
98
|
+
.prepare("SELECT verdict, COUNT(*) AS n FROM memory_feedback GROUP BY verdict")
|
|
99
|
+
.all();
|
|
100
|
+
const byVerdict = {};
|
|
101
|
+
for (const r of rows) {
|
|
102
|
+
byVerdict[r.verdict] = r.n;
|
|
103
|
+
}
|
|
104
|
+
feedback = {
|
|
105
|
+
positive: metrics.get("feedback_positive_total"),
|
|
106
|
+
negative: metrics.get("feedback_negative_total"),
|
|
107
|
+
by_verdict: byVerdict,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
partial = true;
|
|
112
|
+
}
|
|
113
|
+
const blocked = metrics.blockedSnapshot();
|
|
114
|
+
const tokens = {
|
|
115
|
+
pre_prompt: metrics.get("tokens_injected_pre_prompt"),
|
|
116
|
+
compacting: metrics.get("tokens_injected_compacting"),
|
|
117
|
+
};
|
|
118
|
+
let settings = {};
|
|
119
|
+
try {
|
|
120
|
+
const rows = store
|
|
121
|
+
.prepare("SELECT key, value FROM kevin_settings")
|
|
122
|
+
.all();
|
|
123
|
+
settings = {};
|
|
124
|
+
for (const r of rows) {
|
|
125
|
+
settings[r.key] = r.value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
partial = true;
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
memories,
|
|
133
|
+
injections,
|
|
134
|
+
blocked,
|
|
135
|
+
feedback,
|
|
136
|
+
tokens,
|
|
137
|
+
settings,
|
|
138
|
+
partial,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=kev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AM,IAAI,GAAG,KAAK;aAChB,OAAO,CAAC,uCAAuC,CAAC;aAChD,GAAG,EAAsC,CAAC;QAC5C,QAAQ,GAAG,EAAE,CAAC;QACd,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACtB,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;QAC3B,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACN,QAAQ;QACR,UAAU;QACV,OAAO;QACP,QAAQ;QACR,MAAM;QACN,QAAQ;QACR,OAAO;KACP,CAAC;AACH,CAAC"}
|
package/dist/plugin/kevin_why.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { TS_CODE_RULES } from "./Reflector.js";
|
|
2
2
|
import { computeConfidence } from "./confidence.js";
|
|
3
3
|
import { toMatchClause, tokenizeQuery } from "./query-tokenizer.js";
|
|
4
|
+
// v0.5.0 (K5-010 / plan §5.3) — pre-006 DBs lack the feedback columns;
|
|
5
|
+
// kevin_why must not reference them (it degrades via the try/catch below,
|
|
6
|
+
// which is for missing ROWS, not missing COLUMNS). Probe once per store.
|
|
7
|
+
const feedbackColumnCache = new WeakMap();
|
|
8
|
+
function hasFeedbackColumns(store) {
|
|
9
|
+
const cached = feedbackColumnCache.get(store);
|
|
10
|
+
if (cached !== undefined)
|
|
11
|
+
return cached;
|
|
12
|
+
try {
|
|
13
|
+
store.prepare("SELECT feedback_positive FROM memories LIMIT 1").get();
|
|
14
|
+
feedbackColumnCache.set(store, true);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
feedbackColumnCache.set(store, false);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
4
22
|
export function kevinWhy(store, query) {
|
|
5
23
|
// v0.3.0 fix (bug #7) — the old code wrapped the WHOLE query in a
|
|
6
24
|
// single quoted phrase, so it only matched the exact full-string
|
|
@@ -17,7 +35,9 @@ export function kevinWhy(store, query) {
|
|
|
17
35
|
try {
|
|
18
36
|
patternRows = store
|
|
19
37
|
.prepare(`SELECT m.id, m.content, m.fingerprint, m.evidence_count,
|
|
20
|
-
m.recurrence_count, m.fix_args, m.last_verified_at, m.created_at
|
|
38
|
+
m.recurrence_count, m.fix_args, m.last_verified_at, m.created_at${hasFeedbackColumns(store)
|
|
39
|
+
? ", m.feedback_positive, m.feedback_negative"
|
|
40
|
+
: ""}
|
|
21
41
|
FROM memories_fts
|
|
22
42
|
JOIN memories m ON m.rowid = memories_fts.rowid
|
|
23
43
|
WHERE memories_fts MATCH ?
|
|
@@ -36,7 +56,8 @@ export function kevinWhy(store, query) {
|
|
|
36
56
|
const pattern = patternRows[0];
|
|
37
57
|
const fp = pattern.fingerprint;
|
|
38
58
|
// v0.4.0 (K4-010) — two-sided confidence shared with promoteToPattern.
|
|
39
|
-
|
|
59
|
+
// v0.5.0 (K5-010) — human feedback terms nudge it (D5-02).
|
|
60
|
+
const confidence = computeConfidence(pattern.evidence_count ?? 0, pattern.recurrence_count ?? 0, pattern.feedback_positive ?? 0, pattern.feedback_negative ?? 0);
|
|
40
61
|
// BUG-007 — the trace is built from the error-memory sessions below;
|
|
41
62
|
// the legacy `traceRows` probe (executed but unused, with a
|
|
42
63
|
// never-matching `tc.fingerprint LIKE '%<8-hex>%'` branch against the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kevin_why.js","sourceRoot":"","sources":["../../plugin/kevin_why.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"kevin_why.js","sourceRoot":"","sources":["../../plugin/kevin_why.ts"],"names":[],"mappings":"A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ACL,CAAC;IAED,OAAO;QACN,OAAO;QACP,UAAU;QACV,cAAc,EAAE,aAAa;QAC7B,gBAAgB,EAAE,UAAU;QAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;QAClC,aAAa,EAAE,OAAO,CAAC,gBAAgB,IAAI,IAAI;QAC/C,KAAK;QACL,aAAa,EAAE,YAAY;KAC3B,CAAC;AACH,CAAC"}
|
package/dist/plugin/metrics.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Store } from "./Store.js";
|
|
|
6
6
|
* underlying table is empty (e.g., before 003 is applied, on a fresh
|
|
7
7
|
* :memory: test DB, or after a manual wipe).
|
|
8
8
|
*/
|
|
9
|
-
export declare const METRIC_KEYS: readonly ["tokens_injected_pre_prompt", "tokens_injected_compacting", "reflections_throttled", "duplicate_suppressions", "tool_calls_deduped", "patterns_mined", "patterns_causal", "causal_links", "memories_superseded", "injections_total", "injections_effective", "injections_ineffective", "patterns_promoted_new"];
|
|
9
|
+
export declare const METRIC_KEYS: readonly ["tokens_injected_pre_prompt", "tokens_injected_compacting", "reflections_throttled", "duplicate_suppressions", "tool_calls_deduped", "patterns_mined", "patterns_causal", "causal_links", "memories_superseded", "injections_total", "injections_effective", "injections_ineffective", "patterns_promoted_new", "injections_inconclusive", "injections_blocked_seen", "injections_blocked_weak", "injections_blocked_recurrence", "injections_blocked_stale", "injections_blocked_ignored", "feedback_positive_total", "feedback_negative_total", "memories_archived"];
|
|
10
10
|
export type MetricKey = (typeof METRIC_KEYS)[number];
|
|
11
11
|
/**
|
|
12
12
|
* Cheap token estimate used when bumping the `tokens_injected_*` counters.
|
|
@@ -48,8 +48,28 @@ export declare class Metrics {
|
|
|
48
48
|
* v0.4.0 (K4-008): injection precision = effective / total settled
|
|
49
49
|
* injections. 0 when the ledger has no entries yet (no division by zero).
|
|
50
50
|
* Computed from the cached counters — does NOT flush.
|
|
51
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the denominator is now
|
|
52
|
+
* `effective + ineffective` only. `inconclusive` (the new majority
|
|
53
|
+
* bucket) must not inflate precision: absence of recurrence is not
|
|
54
|
+
* evidence of effect. An idle session therefore no longer drives
|
|
55
|
+
* precision toward 1.0 — expect the reported rate to fall sharply on
|
|
56
|
+
* real databases; that is the intended result.
|
|
51
57
|
*/
|
|
52
58
|
precisionRate(): number;
|
|
59
|
+
/**
|
|
60
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the share of injections that
|
|
61
|
+
* were actually measured (effective + ineffective) of all injections.
|
|
62
|
+
* Reported alongside `precisionRate` so a low measurable fraction is
|
|
63
|
+
* visible rather than hidden behind a large `total`. 0 when the ledger
|
|
64
|
+
* is empty. Computed from the cached counters — does NOT flush.
|
|
65
|
+
*/
|
|
66
|
+
coverageRate(): number;
|
|
67
|
+
/**
|
|
68
|
+
* v0.5.0 (K5-004 / plan §5.2, D5-02) — the five `injections_blocked_*`
|
|
69
|
+
* counters keyed by their short names. Consumed by `kevin_audit`.
|
|
70
|
+
* Computed from the cached counters — does NOT flush.
|
|
71
|
+
*/
|
|
72
|
+
blockedSnapshot(): Record<string, number>;
|
|
53
73
|
/** True iff a debounced flush is scheduled. Useful for tests. */
|
|
54
74
|
isFlushScheduled(): boolean;
|
|
55
75
|
/**
|
package/dist/plugin/metrics.js
CHANGED
|
@@ -19,6 +19,16 @@ export const METRIC_KEYS = [
|
|
|
19
19
|
"injections_effective",
|
|
20
20
|
"injections_ineffective",
|
|
21
21
|
"patterns_promoted_new",
|
|
22
|
+
// v0.5.0 (K5-004 / plan §8.3) — order matches migration 006's seed block.
|
|
23
|
+
"injections_inconclusive",
|
|
24
|
+
"injections_blocked_seen",
|
|
25
|
+
"injections_blocked_weak",
|
|
26
|
+
"injections_blocked_recurrence",
|
|
27
|
+
"injections_blocked_stale",
|
|
28
|
+
"injections_blocked_ignored",
|
|
29
|
+
"feedback_positive_total",
|
|
30
|
+
"feedback_negative_total",
|
|
31
|
+
"memories_archived",
|
|
22
32
|
];
|
|
23
33
|
const DEFAULT_FLUSH_MS = 1000;
|
|
24
34
|
function zeroCache() {
|
|
@@ -106,13 +116,48 @@ export class Metrics {
|
|
|
106
116
|
* v0.4.0 (K4-008): injection precision = effective / total settled
|
|
107
117
|
* injections. 0 when the ledger has no entries yet (no division by zero).
|
|
108
118
|
* Computed from the cached counters — does NOT flush.
|
|
119
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the denominator is now
|
|
120
|
+
* `effective + ineffective` only. `inconclusive` (the new majority
|
|
121
|
+
* bucket) must not inflate precision: absence of recurrence is not
|
|
122
|
+
* evidence of effect. An idle session therefore no longer drives
|
|
123
|
+
* precision toward 1.0 — expect the reported rate to fall sharply on
|
|
124
|
+
* real databases; that is the intended result.
|
|
109
125
|
*/
|
|
110
126
|
precisionRate() {
|
|
127
|
+
const effective = this.cache.get("injections_effective") ?? 0;
|
|
128
|
+
const measured = effective + (this.cache.get("injections_ineffective") ?? 0);
|
|
129
|
+
if (measured <= 0)
|
|
130
|
+
return 0;
|
|
131
|
+
return Math.min(1, effective / measured);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the share of injections that
|
|
135
|
+
* were actually measured (effective + ineffective) of all injections.
|
|
136
|
+
* Reported alongside `precisionRate` so a low measurable fraction is
|
|
137
|
+
* visible rather than hidden behind a large `total`. 0 when the ledger
|
|
138
|
+
* is empty. Computed from the cached counters — does NOT flush.
|
|
139
|
+
*/
|
|
140
|
+
coverageRate() {
|
|
111
141
|
const total = this.cache.get("injections_total") ?? 0;
|
|
112
142
|
if (total <= 0)
|
|
113
143
|
return 0;
|
|
114
|
-
const
|
|
115
|
-
|
|
144
|
+
const measured = (this.cache.get("injections_effective") ?? 0) +
|
|
145
|
+
(this.cache.get("injections_ineffective") ?? 0);
|
|
146
|
+
return Math.min(1, measured / total);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* v0.5.0 (K5-004 / plan §5.2, D5-02) — the five `injections_blocked_*`
|
|
150
|
+
* counters keyed by their short names. Consumed by `kevin_audit`.
|
|
151
|
+
* Computed from the cached counters — does NOT flush.
|
|
152
|
+
*/
|
|
153
|
+
blockedSnapshot() {
|
|
154
|
+
return {
|
|
155
|
+
seen: this.cache.get("injections_blocked_seen") ?? 0,
|
|
156
|
+
weak: this.cache.get("injections_blocked_weak") ?? 0,
|
|
157
|
+
recurrence: this.cache.get("injections_blocked_recurrence") ?? 0,
|
|
158
|
+
stale: this.cache.get("injections_blocked_stale") ?? 0,
|
|
159
|
+
ignored: this.cache.get("injections_blocked_ignored") ?? 0,
|
|
160
|
+
};
|
|
116
161
|
}
|
|
117
162
|
/** True iff a debounced flush is scheduled. Useful for tests. */
|
|
118
163
|
isFlushScheduled() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../plugin/metrics.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,4BAA4B;IAC5B,4BAA4B;IAC5B,uBAAuB;IACvB,wBAAwB;IACxB,oBAAoB;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,uBAAuB;
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../plugin/metrics.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,4BAA4B;IAC5B,4BAA4B;IAC5B,uBAAuB;IACvB,wBAAwB;IACxB,oBAAoB;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,uBAAuB;IACvB,0EAA0E;IAC1E,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,+BAA+B;IAC/B,0BAA0B;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AAE,CAAC;YAC9B,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACxB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* v0.5.0 (K5-018 / plan §5.8) — replay transcript format.
|
|
4
|
+
*
|
|
5
|
+
* A hermetic, deterministic way to run a recorded session through the
|
|
6
|
+
* plugin's components and read the outcome distribution. `at` is an
|
|
7
|
+
* ISO-8601 string and is the ONLY source of time during replay:
|
|
8
|
+
* `Date.now()` must not be called anywhere in the replay path.
|
|
9
|
+
*/
|
|
10
|
+
export declare const replayEventSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
11
|
+
kind: z.ZodLiteral<"session.created">;
|
|
12
|
+
at: z.ZodString;
|
|
13
|
+
sessionId: z.ZodString;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
at: string;
|
|
16
|
+
sessionId: string;
|
|
17
|
+
kind: "session.created";
|
|
18
|
+
}, {
|
|
19
|
+
at: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
kind: "session.created";
|
|
22
|
+
}>, z.ZodObject<{
|
|
23
|
+
kind: z.ZodLiteral<"chat.message">;
|
|
24
|
+
at: z.ZodString;
|
|
25
|
+
sessionId: z.ZodString;
|
|
26
|
+
text: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
at: string;
|
|
29
|
+
sessionId: string;
|
|
30
|
+
text: string;
|
|
31
|
+
kind: "chat.message";
|
|
32
|
+
}, {
|
|
33
|
+
at: string;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
text: string;
|
|
36
|
+
kind: "chat.message";
|
|
37
|
+
}>, z.ZodObject<{
|
|
38
|
+
kind: z.ZodLiteral<"tool.before">;
|
|
39
|
+
at: z.ZodString;
|
|
40
|
+
sessionId: z.ZodString;
|
|
41
|
+
callId: z.ZodString;
|
|
42
|
+
tool: z.ZodString;
|
|
43
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
at: string;
|
|
46
|
+
sessionId: string;
|
|
47
|
+
tool: string;
|
|
48
|
+
kind: "tool.before";
|
|
49
|
+
callId: string;
|
|
50
|
+
args: Record<string, unknown>;
|
|
51
|
+
}, {
|
|
52
|
+
at: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
tool: string;
|
|
55
|
+
kind: "tool.before";
|
|
56
|
+
callId: string;
|
|
57
|
+
args: Record<string, unknown>;
|
|
58
|
+
}>, z.ZodObject<{
|
|
59
|
+
kind: z.ZodLiteral<"tool.after">;
|
|
60
|
+
at: z.ZodString;
|
|
61
|
+
sessionId: z.ZodString;
|
|
62
|
+
callId: z.ZodString;
|
|
63
|
+
success: z.ZodBoolean;
|
|
64
|
+
stdout: z.ZodOptional<z.ZodString>;
|
|
65
|
+
stderr: z.ZodOptional<z.ZodString>;
|
|
66
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
at: string;
|
|
69
|
+
sessionId: string;
|
|
70
|
+
success: boolean;
|
|
71
|
+
kind: "tool.after";
|
|
72
|
+
callId: string;
|
|
73
|
+
exitCode?: number | undefined;
|
|
74
|
+
stderr?: string | undefined;
|
|
75
|
+
stdout?: string | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
at: string;
|
|
78
|
+
sessionId: string;
|
|
79
|
+
success: boolean;
|
|
80
|
+
kind: "tool.after";
|
|
81
|
+
callId: string;
|
|
82
|
+
exitCode?: number | undefined;
|
|
83
|
+
stderr?: string | undefined;
|
|
84
|
+
stdout?: string | undefined;
|
|
85
|
+
}>, z.ZodObject<{
|
|
86
|
+
kind: z.ZodLiteral<"system.transform">;
|
|
87
|
+
at: z.ZodString;
|
|
88
|
+
sessionId: z.ZodString;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
at: string;
|
|
91
|
+
sessionId: string;
|
|
92
|
+
kind: "system.transform";
|
|
93
|
+
}, {
|
|
94
|
+
at: string;
|
|
95
|
+
sessionId: string;
|
|
96
|
+
kind: "system.transform";
|
|
97
|
+
}>, z.ZodObject<{
|
|
98
|
+
kind: z.ZodLiteral<"compacting">;
|
|
99
|
+
at: z.ZodString;
|
|
100
|
+
sessionId: z.ZodString;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
at: string;
|
|
103
|
+
sessionId: string;
|
|
104
|
+
kind: "compacting";
|
|
105
|
+
}, {
|
|
106
|
+
at: string;
|
|
107
|
+
sessionId: string;
|
|
108
|
+
kind: "compacting";
|
|
109
|
+
}>, z.ZodObject<{
|
|
110
|
+
kind: z.ZodLiteral<"session.idle">;
|
|
111
|
+
at: z.ZodString;
|
|
112
|
+
sessionId: z.ZodString;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
at: string;
|
|
115
|
+
sessionId: string;
|
|
116
|
+
kind: "session.idle";
|
|
117
|
+
}, {
|
|
118
|
+
at: string;
|
|
119
|
+
sessionId: string;
|
|
120
|
+
kind: "session.idle";
|
|
121
|
+
}>]>;
|
|
122
|
+
export type ReplayEvent = z.infer<typeof replayEventSchema>;
|
|
123
|
+
export declare const replayTranscriptSchema: z.ZodObject<{
|
|
124
|
+
version: z.ZodLiteral<1>;
|
|
125
|
+
name: z.ZodString;
|
|
126
|
+
events: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
127
|
+
kind: z.ZodLiteral<"session.created">;
|
|
128
|
+
at: z.ZodString;
|
|
129
|
+
sessionId: z.ZodString;
|
|
130
|
+
}, "strip", z.ZodTypeAny, {
|
|
131
|
+
at: string;
|
|
132
|
+
sessionId: string;
|
|
133
|
+
kind: "session.created";
|
|
134
|
+
}, {
|
|
135
|
+
at: string;
|
|
136
|
+
sessionId: string;
|
|
137
|
+
kind: "session.created";
|
|
138
|
+
}>, z.ZodObject<{
|
|
139
|
+
kind: z.ZodLiteral<"chat.message">;
|
|
140
|
+
at: z.ZodString;
|
|
141
|
+
sessionId: z.ZodString;
|
|
142
|
+
text: z.ZodString;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
at: string;
|
|
145
|
+
sessionId: string;
|
|
146
|
+
text: string;
|
|
147
|
+
kind: "chat.message";
|
|
148
|
+
}, {
|
|
149
|
+
at: string;
|
|
150
|
+
sessionId: string;
|
|
151
|
+
text: string;
|
|
152
|
+
kind: "chat.message";
|
|
153
|
+
}>, z.ZodObject<{
|
|
154
|
+
kind: z.ZodLiteral<"tool.before">;
|
|
155
|
+
at: z.ZodString;
|
|
156
|
+
sessionId: z.ZodString;
|
|
157
|
+
callId: z.ZodString;
|
|
158
|
+
tool: z.ZodString;
|
|
159
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
160
|
+
}, "strip", z.ZodTypeAny, {
|
|
161
|
+
at: string;
|
|
162
|
+
sessionId: string;
|
|
163
|
+
tool: string;
|
|
164
|
+
kind: "tool.before";
|
|
165
|
+
callId: string;
|
|
166
|
+
args: Record<string, unknown>;
|
|
167
|
+
}, {
|
|
168
|
+
at: string;
|
|
169
|
+
sessionId: string;
|
|
170
|
+
tool: string;
|
|
171
|
+
kind: "tool.before";
|
|
172
|
+
callId: string;
|
|
173
|
+
args: Record<string, unknown>;
|
|
174
|
+
}>, z.ZodObject<{
|
|
175
|
+
kind: z.ZodLiteral<"tool.after">;
|
|
176
|
+
at: z.ZodString;
|
|
177
|
+
sessionId: z.ZodString;
|
|
178
|
+
callId: z.ZodString;
|
|
179
|
+
success: z.ZodBoolean;
|
|
180
|
+
stdout: z.ZodOptional<z.ZodString>;
|
|
181
|
+
stderr: z.ZodOptional<z.ZodString>;
|
|
182
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
183
|
+
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
at: string;
|
|
185
|
+
sessionId: string;
|
|
186
|
+
success: boolean;
|
|
187
|
+
kind: "tool.after";
|
|
188
|
+
callId: string;
|
|
189
|
+
exitCode?: number | undefined;
|
|
190
|
+
stderr?: string | undefined;
|
|
191
|
+
stdout?: string | undefined;
|
|
192
|
+
}, {
|
|
193
|
+
at: string;
|
|
194
|
+
sessionId: string;
|
|
195
|
+
success: boolean;
|
|
196
|
+
kind: "tool.after";
|
|
197
|
+
callId: string;
|
|
198
|
+
exitCode?: number | undefined;
|
|
199
|
+
stderr?: string | undefined;
|
|
200
|
+
stdout?: string | undefined;
|
|
201
|
+
}>, z.ZodObject<{
|
|
202
|
+
kind: z.ZodLiteral<"system.transform">;
|
|
203
|
+
at: z.ZodString;
|
|
204
|
+
sessionId: z.ZodString;
|
|
205
|
+
}, "strip", z.ZodTypeAny, {
|
|
206
|
+
at: string;
|
|
207
|
+
sessionId: string;
|
|
208
|
+
kind: "system.transform";
|
|
209
|
+
}, {
|
|
210
|
+
at: string;
|
|
211
|
+
sessionId: string;
|
|
212
|
+
kind: "system.transform";
|
|
213
|
+
}>, z.ZodObject<{
|
|
214
|
+
kind: z.ZodLiteral<"compacting">;
|
|
215
|
+
at: z.ZodString;
|
|
216
|
+
sessionId: z.ZodString;
|
|
217
|
+
}, "strip", z.ZodTypeAny, {
|
|
218
|
+
at: string;
|
|
219
|
+
sessionId: string;
|
|
220
|
+
kind: "compacting";
|
|
221
|
+
}, {
|
|
222
|
+
at: string;
|
|
223
|
+
sessionId: string;
|
|
224
|
+
kind: "compacting";
|
|
225
|
+
}>, z.ZodObject<{
|
|
226
|
+
kind: z.ZodLiteral<"session.idle">;
|
|
227
|
+
at: z.ZodString;
|
|
228
|
+
sessionId: z.ZodString;
|
|
229
|
+
}, "strip", z.ZodTypeAny, {
|
|
230
|
+
at: string;
|
|
231
|
+
sessionId: string;
|
|
232
|
+
kind: "session.idle";
|
|
233
|
+
}, {
|
|
234
|
+
at: string;
|
|
235
|
+
sessionId: string;
|
|
236
|
+
kind: "session.idle";
|
|
237
|
+
}>]>, "many">;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
version: 1;
|
|
240
|
+
name: string;
|
|
241
|
+
events: ({
|
|
242
|
+
at: string;
|
|
243
|
+
sessionId: string;
|
|
244
|
+
kind: "session.created";
|
|
245
|
+
} | {
|
|
246
|
+
at: string;
|
|
247
|
+
sessionId: string;
|
|
248
|
+
text: string;
|
|
249
|
+
kind: "chat.message";
|
|
250
|
+
} | {
|
|
251
|
+
at: string;
|
|
252
|
+
sessionId: string;
|
|
253
|
+
tool: string;
|
|
254
|
+
kind: "tool.before";
|
|
255
|
+
callId: string;
|
|
256
|
+
args: Record<string, unknown>;
|
|
257
|
+
} | {
|
|
258
|
+
at: string;
|
|
259
|
+
sessionId: string;
|
|
260
|
+
success: boolean;
|
|
261
|
+
kind: "tool.after";
|
|
262
|
+
callId: string;
|
|
263
|
+
exitCode?: number | undefined;
|
|
264
|
+
stderr?: string | undefined;
|
|
265
|
+
stdout?: string | undefined;
|
|
266
|
+
} | {
|
|
267
|
+
at: string;
|
|
268
|
+
sessionId: string;
|
|
269
|
+
kind: "system.transform";
|
|
270
|
+
} | {
|
|
271
|
+
at: string;
|
|
272
|
+
sessionId: string;
|
|
273
|
+
kind: "compacting";
|
|
274
|
+
} | {
|
|
275
|
+
at: string;
|
|
276
|
+
sessionId: string;
|
|
277
|
+
kind: "session.idle";
|
|
278
|
+
})[];
|
|
279
|
+
}, {
|
|
280
|
+
version: 1;
|
|
281
|
+
name: string;
|
|
282
|
+
events: ({
|
|
283
|
+
at: string;
|
|
284
|
+
sessionId: string;
|
|
285
|
+
kind: "session.created";
|
|
286
|
+
} | {
|
|
287
|
+
at: string;
|
|
288
|
+
sessionId: string;
|
|
289
|
+
text: string;
|
|
290
|
+
kind: "chat.message";
|
|
291
|
+
} | {
|
|
292
|
+
at: string;
|
|
293
|
+
sessionId: string;
|
|
294
|
+
tool: string;
|
|
295
|
+
kind: "tool.before";
|
|
296
|
+
callId: string;
|
|
297
|
+
args: Record<string, unknown>;
|
|
298
|
+
} | {
|
|
299
|
+
at: string;
|
|
300
|
+
sessionId: string;
|
|
301
|
+
success: boolean;
|
|
302
|
+
kind: "tool.after";
|
|
303
|
+
callId: string;
|
|
304
|
+
exitCode?: number | undefined;
|
|
305
|
+
stderr?: string | undefined;
|
|
306
|
+
stdout?: string | undefined;
|
|
307
|
+
} | {
|
|
308
|
+
at: string;
|
|
309
|
+
sessionId: string;
|
|
310
|
+
kind: "system.transform";
|
|
311
|
+
} | {
|
|
312
|
+
at: string;
|
|
313
|
+
sessionId: string;
|
|
314
|
+
kind: "compacting";
|
|
315
|
+
} | {
|
|
316
|
+
at: string;
|
|
317
|
+
sessionId: string;
|
|
318
|
+
kind: "session.idle";
|
|
319
|
+
})[];
|
|
320
|
+
}>;
|
|
321
|
+
export interface ReplayTranscript {
|
|
322
|
+
readonly version: 1;
|
|
323
|
+
readonly name: string;
|
|
324
|
+
readonly events: readonly ReplayEvent[];
|
|
325
|
+
}
|
|
326
|
+
/** Validates an unknown payload (e.g. a parsed JSON file) as a transcript. */
|
|
327
|
+
export declare function parseTranscript(json: unknown): ReplayTranscript;
|