@jmtrin/opencode-kevin 0.4.0 → 0.6.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 +580 -360
- package/dist/migrations/006_v05_glassbox.sql +118 -0
- package/dist/migrations/007_v06_pull.sql +145 -0
- package/dist/plugin/Archiver.d.ts +42 -0
- package/dist/plugin/Archiver.js +99 -0
- package/dist/plugin/Archiver.js.map +1 -0
- package/dist/plugin/ArtifactWriter.d.ts +50 -0
- package/dist/plugin/ArtifactWriter.js +240 -0
- package/dist/plugin/ArtifactWriter.js.map +1 -0
- package/dist/plugin/ContextInjector.d.ts +87 -0
- package/dist/plugin/ContextInjector.js +212 -44
- package/dist/plugin/ContextInjector.js.map +1 -1
- package/dist/plugin/Curator.d.ts +96 -0
- package/dist/plugin/Curator.js +252 -0
- package/dist/plugin/Curator.js.map +1 -0
- package/dist/plugin/Feedback.d.ts +67 -0
- package/dist/plugin/Feedback.js +138 -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/Materializer.d.ts +59 -0
- package/dist/plugin/Materializer.js +237 -0
- package/dist/plugin/Materializer.js.map +1 -0
- package/dist/plugin/MemoryService.d.ts +38 -0
- package/dist/plugin/MemoryService.js +265 -30
- package/dist/plugin/MemoryService.js.map +1 -1
- package/dist/plugin/Migrate.js +41 -0
- package/dist/plugin/Migrate.js.map +1 -1
- package/dist/plugin/QualityGate.d.ts +53 -0
- package/dist/plugin/QualityGate.js +50 -8
- package/dist/plugin/QualityGate.js.map +1 -1
- package/dist/plugin/Retrospective.d.ts +1 -0
- package/dist/plugin/Retrospective.js +24 -1
- package/dist/plugin/Retrospective.js.map +1 -1
- package/dist/plugin/capabilities.d.ts +15 -0
- package/dist/plugin/capabilities.js +42 -0
- package/dist/plugin/capabilities.js.map +1 -0
- 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/diff.d.ts +8 -0
- package/dist/plugin/diff.js +183 -0
- package/dist/plugin/diff.js.map +1 -0
- package/dist/plugin/index.d.ts +3 -1
- package/dist/plugin/index.js +371 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/inferability.d.ts +32 -0
- package/dist/plugin/inferability.js +89 -0
- package/dist/plugin/inferability.js.map +1 -0
- package/dist/plugin/kevin_approve.d.ts +34 -0
- package/dist/plugin/kevin_approve.js +50 -0
- package/dist/plugin/kevin_approve.js.map +1 -0
- package/dist/plugin/kevin_audit.d.ts +95 -0
- package/dist/plugin/kevin_audit.js +233 -0
- package/dist/plugin/kevin_audit.js.map +1 -0
- package/dist/plugin/kevin_propose.d.ts +23 -0
- package/dist/plugin/kevin_propose.js +15 -0
- package/dist/plugin/kevin_propose.js.map +1 -0
- package/dist/plugin/kevin_publish.d.ts +38 -0
- package/dist/plugin/kevin_publish.js +19 -0
- package/dist/plugin/kevin_publish.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 +32 -1
- package/dist/plugin/metrics.js +86 -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 +203 -0
- package/dist/plugin/replay.js.map +1 -0
- package/migrations/006_v05_glassbox.sql +118 -0
- package/migrations/007_v06_pull.sql +145 -0
- package/package.json +3 -2
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":"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;AAEpE,uEAAuE;AACvE,0EAA0E;AAC1E,yEAAyE;AACzE,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAkB,CAAC;AAC1D,SAAS,kBAAkB,CAAC,KAAY;IACvC,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,IAAI,CAAC;QACJ,KAAK,CAAC,OAAO,CAAC,gDAAgD,CAAC,CAAC,GAAG,EAAE,CAAC;QACtE,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CA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AAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ;YAC3B,CAAC,CAAC,UAAU,OAAO,CAAC,QAAQ,EAAE;YAC9B,CAAC,CAAC,UACA,YAAY,CAAC,MAAM,GAAG,CAAC;gBACtB,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;gBACzB,CAAC,CAAC,sBACJ,EAAE,CAAC;QACL,OAAO,GAAG,wBAAwB,KAAK,iBAAiB,aAAa,OAAO,aAAa,GAAG,UAAU,gBAAgB,GAAG,GAAG,CAAC;IAC9H,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,wBAAwB,KAAK,KACtC,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OACtC,uBACC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,sBACrD,GAAG,CAAC;IACL,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", "proposals_created", "proposals_approved", "proposals_rejected", "artifact_writes_total", "artifact_writes_noop", "injections_blocked_confidence"];
|
|
10
10
|
export type MetricKey = (typeof METRIC_KEYS)[number];
|
|
11
11
|
/**
|
|
12
12
|
* Cheap token estimate used when bumping the `tokens_injected_*` counters.
|
|
@@ -35,6 +35,15 @@ export declare class Metrics {
|
|
|
35
35
|
constructor(store: Store, flushMs?: number);
|
|
36
36
|
private loadFromDb;
|
|
37
37
|
incr(key: MetricKey, by?: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* v0.6.0 (K6-018/019 / plan §5.8) — the pull-channel registration
|
|
40
|
+
* counters. These live OUTSIDE `METRIC_KEYS`, which is frozen at 28
|
|
41
|
+
* (K6-004 acceptance, the verified cumulative ladder), but persist to
|
|
42
|
+
* the same `kevin_metrics` table so `kevin_audit`'s channels block can
|
|
43
|
+
* read them by SQL (K6-023). They are written immediately (no debounce):
|
|
44
|
+
* they change at most twice per process, on session start.
|
|
45
|
+
*/
|
|
46
|
+
incrRegistered(key: "skills_registered" | "references_registered", by?: number): void;
|
|
38
47
|
/**
|
|
39
48
|
* Returns a snapshot of the cache. The returned object always contains all
|
|
40
49
|
* METRIC_KEYS, even if the DB has no rows yet. Does NOT flush.
|
|
@@ -48,8 +57,30 @@ export declare class Metrics {
|
|
|
48
57
|
* v0.4.0 (K4-008): injection precision = effective / total settled
|
|
49
58
|
* injections. 0 when the ledger has no entries yet (no division by zero).
|
|
50
59
|
* Computed from the cached counters — does NOT flush.
|
|
60
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the denominator is now
|
|
61
|
+
* `effective + ineffective` only. `inconclusive` (the new majority
|
|
62
|
+
* bucket) must not inflate precision: absence of recurrence is not
|
|
63
|
+
* evidence of effect. An idle session therefore no longer drives
|
|
64
|
+
* precision toward 1.0 — expect the reported rate to fall sharply on
|
|
65
|
+
* real databases; that is the intended result.
|
|
51
66
|
*/
|
|
52
67
|
precisionRate(): number;
|
|
68
|
+
/**
|
|
69
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the share of injections that
|
|
70
|
+
* were actually measured (effective + ineffective) of all injections.
|
|
71
|
+
* Reported alongside `precisionRate` so a low measurable fraction is
|
|
72
|
+
* visible rather than hidden behind a large `total`. 0 when the ledger
|
|
73
|
+
* is empty. Computed from the cached counters — does NOT flush.
|
|
74
|
+
*/
|
|
75
|
+
coverageRate(): number;
|
|
76
|
+
/**
|
|
77
|
+
* v0.5.0 (K5-004 / plan §5.2, D5-02) — the five `injections_blocked_*`
|
|
78
|
+
* counters keyed by their short names. Consumed by `kevin_audit`.
|
|
79
|
+
* v0.6.0 (K6-004 / plan §8.3) — sixth member keyed `confidence`
|
|
80
|
+
* (the low_confidence gate branch, K6-022).
|
|
81
|
+
* Computed from the cached counters — does NOT flush.
|
|
82
|
+
*/
|
|
83
|
+
blockedSnapshot(): Record<string, number>;
|
|
53
84
|
/** True iff a debounced flush is scheduled. Useful for tests. */
|
|
54
85
|
isFlushScheduled(): boolean;
|
|
55
86
|
/**
|
package/dist/plugin/metrics.js
CHANGED
|
@@ -19,6 +19,25 @@ 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",
|
|
32
|
+
// v0.6.0 (K6-004 / plan §8.3) — order matches migration 007's seed block.
|
|
33
|
+
// injections_blocked_confidence is the sixth member of the blocked
|
|
34
|
+
// family and MUST be counted like the other five (Principle 16).
|
|
35
|
+
"proposals_created",
|
|
36
|
+
"proposals_approved",
|
|
37
|
+
"proposals_rejected",
|
|
38
|
+
"artifact_writes_total",
|
|
39
|
+
"artifact_writes_noop",
|
|
40
|
+
"injections_blocked_confidence",
|
|
22
41
|
];
|
|
23
42
|
const DEFAULT_FLUSH_MS = 1000;
|
|
24
43
|
function zeroCache() {
|
|
@@ -86,6 +105,33 @@ export class Metrics {
|
|
|
86
105
|
this.dirty.add(key);
|
|
87
106
|
this.scheduleFlush();
|
|
88
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* v0.6.0 (K6-018/019 / plan §5.8) — the pull-channel registration
|
|
110
|
+
* counters. These live OUTSIDE `METRIC_KEYS`, which is frozen at 28
|
|
111
|
+
* (K6-004 acceptance, the verified cumulative ladder), but persist to
|
|
112
|
+
* the same `kevin_metrics` table so `kevin_audit`'s channels block can
|
|
113
|
+
* read them by SQL (K6-023). They are written immediately (no debounce):
|
|
114
|
+
* they change at most twice per process, on session start.
|
|
115
|
+
*/
|
|
116
|
+
incrRegistered(key, by = 1) {
|
|
117
|
+
if (this.closed)
|
|
118
|
+
return;
|
|
119
|
+
const store = this.store;
|
|
120
|
+
store.transaction(() => {
|
|
121
|
+
store.exec(`CREATE TABLE IF NOT EXISTS kevin_metrics (
|
|
122
|
+
key TEXT PRIMARY KEY,
|
|
123
|
+
value INTEGER NOT NULL DEFAULT 0,
|
|
124
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
125
|
+
)`);
|
|
126
|
+
store
|
|
127
|
+
.prepare(`INSERT INTO kevin_metrics (key, value, updated_at)
|
|
128
|
+
VALUES (?, ?, datetime('now'))
|
|
129
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
130
|
+
value = value + excluded.value,
|
|
131
|
+
updated_at = datetime('now')`)
|
|
132
|
+
.run(key, by);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
89
135
|
/**
|
|
90
136
|
* Returns a snapshot of the cache. The returned object always contains all
|
|
91
137
|
* METRIC_KEYS, even if the DB has no rows yet. Does NOT flush.
|
|
@@ -106,13 +152,51 @@ export class Metrics {
|
|
|
106
152
|
* v0.4.0 (K4-008): injection precision = effective / total settled
|
|
107
153
|
* injections. 0 when the ledger has no entries yet (no division by zero).
|
|
108
154
|
* Computed from the cached counters — does NOT flush.
|
|
155
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the denominator is now
|
|
156
|
+
* `effective + ineffective` only. `inconclusive` (the new majority
|
|
157
|
+
* bucket) must not inflate precision: absence of recurrence is not
|
|
158
|
+
* evidence of effect. An idle session therefore no longer drives
|
|
159
|
+
* precision toward 1.0 — expect the reported rate to fall sharply on
|
|
160
|
+
* real databases; that is the intended result.
|
|
109
161
|
*/
|
|
110
162
|
precisionRate() {
|
|
163
|
+
const effective = this.cache.get("injections_effective") ?? 0;
|
|
164
|
+
const measured = effective + (this.cache.get("injections_ineffective") ?? 0);
|
|
165
|
+
if (measured <= 0)
|
|
166
|
+
return 0;
|
|
167
|
+
return Math.min(1, effective / measured);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* v0.5.0 (K5-004 / plan §5.1, D5-02) — the share of injections that
|
|
171
|
+
* were actually measured (effective + ineffective) of all injections.
|
|
172
|
+
* Reported alongside `precisionRate` so a low measurable fraction is
|
|
173
|
+
* visible rather than hidden behind a large `total`. 0 when the ledger
|
|
174
|
+
* is empty. Computed from the cached counters — does NOT flush.
|
|
175
|
+
*/
|
|
176
|
+
coverageRate() {
|
|
111
177
|
const total = this.cache.get("injections_total") ?? 0;
|
|
112
178
|
if (total <= 0)
|
|
113
179
|
return 0;
|
|
114
|
-
const
|
|
115
|
-
|
|
180
|
+
const measured = (this.cache.get("injections_effective") ?? 0) +
|
|
181
|
+
(this.cache.get("injections_ineffective") ?? 0);
|
|
182
|
+
return Math.min(1, measured / total);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* v0.5.0 (K5-004 / plan §5.2, D5-02) — the five `injections_blocked_*`
|
|
186
|
+
* counters keyed by their short names. Consumed by `kevin_audit`.
|
|
187
|
+
* v0.6.0 (K6-004 / plan §8.3) — sixth member keyed `confidence`
|
|
188
|
+
* (the low_confidence gate branch, K6-022).
|
|
189
|
+
* Computed from the cached counters — does NOT flush.
|
|
190
|
+
*/
|
|
191
|
+
blockedSnapshot() {
|
|
192
|
+
return {
|
|
193
|
+
seen: this.cache.get("injections_blocked_seen") ?? 0,
|
|
194
|
+
weak: this.cache.get("injections_blocked_weak") ?? 0,
|
|
195
|
+
recurrence: this.cache.get("injections_blocked_recurrence") ?? 0,
|
|
196
|
+
stale: this.cache.get("injections_blocked_stale") ?? 0,
|
|
197
|
+
ignored: this.cache.get("injections_blocked_ignored") ?? 0,
|
|
198
|
+
confidence: this.cache.get("injections_blocked_confidence") ?? 0,
|
|
199
|
+
};
|
|
116
200
|
}
|
|
117
201
|
/** True iff a debounced flush is scheduled. Useful for tests. */
|
|
118
202
|
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":"metr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
*
|
|
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
|
+
kind: "chat.message";
|
|
31
|
+
text: string;
|
|
32
|
+
}, {
|
|
33
|
+
at: string;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
kind: "chat.message";
|
|
36
|
+
text: string;
|
|
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
|
+
kind: "chat.message";
|
|
147
|
+
text: string;
|
|
148
|
+
}, {
|
|
149
|
+
at: string;
|
|
150
|
+
sessionId: string;
|
|
151
|
+
kind: "chat.message";
|
|
152
|
+
text: string;
|
|
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
|
+
kind: "chat.message";
|
|
249
|
+
text: string;
|
|
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
|
+
kind: "chat.message";
|
|
290
|
+
text: string;
|
|
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;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 const replayEventSchema = z.discriminatedUnion("kind", [
|
|
11
|
+
z.object({
|
|
12
|
+
kind: z.literal("session.created"),
|
|
13
|
+
at: z.string().datetime(),
|
|
14
|
+
sessionId: z.string().min(1),
|
|
15
|
+
}),
|
|
16
|
+
z.object({
|
|
17
|
+
kind: z.literal("chat.message"),
|
|
18
|
+
at: z.string().datetime(),
|
|
19
|
+
sessionId: z.string().min(1),
|
|
20
|
+
text: z.string().min(1),
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
kind: z.literal("tool.before"),
|
|
24
|
+
at: z.string().datetime(),
|
|
25
|
+
sessionId: z.string().min(1),
|
|
26
|
+
callId: z.string().min(1),
|
|
27
|
+
tool: z.string().min(1),
|
|
28
|
+
args: z.record(z.string(), z.unknown()),
|
|
29
|
+
}),
|
|
30
|
+
z.object({
|
|
31
|
+
kind: z.literal("tool.after"),
|
|
32
|
+
at: z.string().datetime(),
|
|
33
|
+
sessionId: z.string().min(1),
|
|
34
|
+
callId: z.string().min(1),
|
|
35
|
+
success: z.boolean(),
|
|
36
|
+
stdout: z.string().optional(),
|
|
37
|
+
stderr: z.string().optional(),
|
|
38
|
+
exitCode: z.number().int().optional(),
|
|
39
|
+
}),
|
|
40
|
+
z.object({
|
|
41
|
+
kind: z.literal("system.transform"),
|
|
42
|
+
at: z.string().datetime(),
|
|
43
|
+
sessionId: z.string().min(1),
|
|
44
|
+
}),
|
|
45
|
+
z.object({
|
|
46
|
+
kind: z.literal("compacting"),
|
|
47
|
+
at: z.string().datetime(),
|
|
48
|
+
sessionId: z.string().min(1),
|
|
49
|
+
}),
|
|
50
|
+
z.object({
|
|
51
|
+
kind: z.literal("session.idle"),
|
|
52
|
+
at: z.string().datetime(),
|
|
53
|
+
sessionId: z.string().min(1),
|
|
54
|
+
}),
|
|
55
|
+
]);
|
|
56
|
+
export const replayTranscriptSchema = z.object({
|
|
57
|
+
version: z.literal(1),
|
|
58
|
+
name: z.string().min(1),
|
|
59
|
+
events: z.array(replayEventSchema).min(1),
|
|
60
|
+
});
|
|
61
|
+
/** Validates an unknown payload (e.g. a parsed JSON file) as a transcript. */
|
|
62
|
+
export function parseTranscript(json) {
|
|
63
|
+
return replayTranscriptSchema.parse(json);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=replay-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-types.js","sourceRoot":"","sources":["../../plugin/replay-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CA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