@jmtrin/opencode-kevin 0.6.0 → 0.8.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 +771 -580
- package/dist/migrations/001_initial.sql +91 -91
- package/dist/migrations/003_v02_signal.sql +57 -57
- package/dist/migrations/004_v03_knowledge.sql +138 -138
- package/dist/migrations/005_v04_signal.sql +57 -57
- package/dist/migrations/006_v05_glassbox.sql +118 -118
- package/dist/migrations/007_v06_pull.sql +144 -144
- package/dist/migrations/008_v07_truth.sql +124 -0
- package/dist/migrations/009_v08_team.sql +100 -0
- package/dist/plugin/ArtifactWriter.d.ts +28 -0
- package/dist/plugin/ArtifactWriter.js +35 -2
- package/dist/plugin/ArtifactWriter.js.map +1 -1
- package/dist/plugin/ConflictDetector.d.ts +35 -0
- package/dist/plugin/ConflictDetector.js +283 -0
- package/dist/plugin/ConflictDetector.js.map +1 -0
- package/dist/plugin/ContextInjector.d.ts +9 -0
- package/dist/plugin/ContextInjector.js +14 -3
- package/dist/plugin/ContextInjector.js.map +1 -1
- package/dist/plugin/ConventionMiner.d.ts +35 -0
- package/dist/plugin/ConventionMiner.js +243 -0
- package/dist/plugin/ConventionMiner.js.map +1 -0
- package/dist/plugin/Curator.d.ts +22 -2
- package/dist/plugin/Curator.js +101 -28
- package/dist/plugin/Curator.js.map +1 -1
- package/dist/plugin/InjectionLedger.d.ts +6 -0
- package/dist/plugin/InjectionLedger.js +6 -0
- package/dist/plugin/InjectionLedger.js.map +1 -1
- package/dist/plugin/Materializer.d.ts +4 -5
- package/dist/plugin/Materializer.js +9 -6
- package/dist/plugin/Materializer.js.map +1 -1
- package/dist/plugin/MemoryService.d.ts +49 -2
- package/dist/plugin/MemoryService.js +306 -8
- package/dist/plugin/MemoryService.js.map +1 -1
- package/dist/plugin/Migrate.js +61 -2
- package/dist/plugin/Migrate.js.map +1 -1
- package/dist/plugin/Reflector.js +13 -0
- package/dist/plugin/Reflector.js.map +1 -1
- package/dist/plugin/RepoIdentity.d.ts +113 -0
- package/dist/plugin/RepoIdentity.js +266 -0
- package/dist/plugin/RepoIdentity.js.map +1 -0
- package/dist/plugin/RepoTruth.d.ts +80 -0
- package/dist/plugin/RepoTruth.js +600 -0
- package/dist/plugin/RepoTruth.js.map +1 -0
- package/dist/plugin/Retrospective.js +17 -0
- package/dist/plugin/Retrospective.js.map +1 -1
- package/dist/plugin/SharedLayer.d.ts +159 -0
- package/dist/plugin/SharedLayer.js +463 -0
- package/dist/plugin/SharedLayer.js.map +1 -0
- package/dist/plugin/index.d.ts +36 -2
- package/dist/plugin/index.js +591 -10
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/kevin_approve.js +7 -4
- package/dist/plugin/kevin_approve.js.map +1 -1
- package/dist/plugin/kevin_audit.d.ts +59 -1
- package/dist/plugin/kevin_audit.js +190 -3
- package/dist/plugin/kevin_audit.js.map +1 -1
- package/dist/plugin/kevin_conflicts.d.ts +9 -0
- package/dist/plugin/kevin_conflicts.js +51 -0
- package/dist/plugin/kevin_conflicts.js.map +1 -0
- package/dist/plugin/kevin_facts.d.ts +42 -0
- package/dist/plugin/kevin_facts.js +37 -0
- package/dist/plugin/kevin_facts.js.map +1 -0
- package/dist/plugin/metrics.d.ts +3 -3
- package/dist/plugin/metrics.js +21 -2
- package/dist/plugin/metrics.js.map +1 -1
- package/dist/plugin/okf-export.d.ts +2 -2
- package/dist/plugin/okf-export.js +15 -7
- package/dist/plugin/okf-export.js.map +1 -1
- package/dist/plugin/okf.d.ts +107 -0
- package/dist/plugin/okf.js +304 -0
- package/dist/plugin/okf.js.map +1 -0
- package/dist/plugin/replay-types.d.ts +29 -287
- package/dist/plugin/replay-types.js +145 -53
- package/dist/plugin/replay-types.js.map +1 -1
- package/migrations/001_initial.sql +91 -91
- package/migrations/003_v02_signal.sql +57 -57
- package/migrations/004_v03_knowledge.sql +138 -138
- package/migrations/005_v04_signal.sql +57 -57
- package/migrations/006_v05_glassbox.sql +118 -118
- package/migrations/007_v06_pull.sql +144 -144
- package/migrations/008_v07_truth.sql +124 -0
- package/migrations/009_v08_team.sql +100 -0
- package/package.json +4 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MemoryService } from "./MemoryService.js";
|
|
2
|
+
import type { RepoTruth } from "./RepoTruth.js";
|
|
3
|
+
import type { Store } from "./Store.js";
|
|
4
|
+
/**
|
|
5
|
+
* v0.7.0 (K7-009 / plan §5.7) — `kevin_facts`.
|
|
6
|
+
*
|
|
7
|
+
* The user-facing answer to "why did Kevin stop suggesting that?". Lists the
|
|
8
|
+
* repository facts the current project was scanned for and every memory that
|
|
9
|
+
* was de-ranked by a contradiction, with its `truth_penalty`, `contradicted_at`
|
|
10
|
+
* and the human-readable reasons. Pure read apart from the optional re-scan. No
|
|
11
|
+
* LLM, no network, no hot-path cost.
|
|
12
|
+
*/
|
|
13
|
+
export interface KevinFactsDeps {
|
|
14
|
+
store: Store;
|
|
15
|
+
memoryService: MemoryService;
|
|
16
|
+
repoTruth: RepoTruth;
|
|
17
|
+
projectId: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PenalizedMemory {
|
|
20
|
+
id: string;
|
|
21
|
+
type: string;
|
|
22
|
+
truth_penalty: number;
|
|
23
|
+
contradicted_at: string | null;
|
|
24
|
+
reasons: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface KevinFactsResult {
|
|
27
|
+
project_id: string;
|
|
28
|
+
scanned_at: string | null;
|
|
29
|
+
truncated: {
|
|
30
|
+
is_truncated: true;
|
|
31
|
+
count: number;
|
|
32
|
+
} | {
|
|
33
|
+
is_truncated: false;
|
|
34
|
+
};
|
|
35
|
+
facts: {
|
|
36
|
+
file: string;
|
|
37
|
+
key_path: string;
|
|
38
|
+
value: string;
|
|
39
|
+
}[];
|
|
40
|
+
penalized: PenalizedMemory[];
|
|
41
|
+
}
|
|
42
|
+
export declare function buildKevinFacts(deps: KevinFactsDeps, refresh: boolean): KevinFactsResult;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function buildKevinFacts(deps, refresh) {
|
|
2
|
+
if (refresh)
|
|
3
|
+
deps.repoTruth.scan();
|
|
4
|
+
// Penalized memories: scoped to the project, only those with a penalty.
|
|
5
|
+
const rows = deps.store
|
|
6
|
+
.prepare(`SELECT id, type, truth_penalty, contradicted_at
|
|
7
|
+
FROM memories
|
|
8
|
+
WHERE project_id = ? AND truth_penalty > 0
|
|
9
|
+
ORDER BY created_at`)
|
|
10
|
+
.all(deps.projectId);
|
|
11
|
+
const penalized = rows.map((r) => {
|
|
12
|
+
const mem = deps.memoryService.getById(r.id);
|
|
13
|
+
return {
|
|
14
|
+
id: r.id,
|
|
15
|
+
type: r.type,
|
|
16
|
+
truth_penalty: r.truth_penalty,
|
|
17
|
+
contradicted_at: r.contradicted_at,
|
|
18
|
+
reasons: mem ? deps.repoTruth.contradictions(mem) : [],
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const stored = deps.repoTruth.facts();
|
|
22
|
+
const truncatedFact = stored.find((f) => f.keyPath === "_truncated");
|
|
23
|
+
const facts = stored
|
|
24
|
+
.filter((f) => f.keyPath !== "_truncated")
|
|
25
|
+
.map((f) => ({ file: f.file, key_path: f.keyPath, value: f.value }));
|
|
26
|
+
const scanned_at = deps.repoTruth.scannedAt();
|
|
27
|
+
return {
|
|
28
|
+
project_id: deps.projectId,
|
|
29
|
+
scanned_at,
|
|
30
|
+
truncated: truncatedFact
|
|
31
|
+
? { is_truncated: true, count: Number(truncatedFact.value) || 0 }
|
|
32
|
+
: { is_truncated: false },
|
|
33
|
+
facts,
|
|
34
|
+
penalized,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=kevin_facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kevin_facts.js","sourceRoot":"","sources":["../../plugin/kevin_facts.ts"],"names":[],"mappings":"AAoCA,MAAM,UAAU,eAAe,CAC9B,IAAoB,EACpB,OAAgB;I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AE9C,OAAO;QACN,UAAU,EAAE,IAAI,CAAC,SAAS;QAC1B,UAAU;QACV,SAAS,EAAE,aAAa;YACvB,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACjE,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE;QAC1B,KAAK;QACL,SAAS;KACT,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", "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"];
|
|
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", "repo_facts_scanned", "memories_contradicted", "conventions_mined", "conflicts_detected", "error_lessons_suppressed", "shared_entries_total", "shared_entries_imported", "shared_entries_exported", "okf_merge_folds", "rekey_events", "injections_from_shared"];
|
|
10
10
|
export type MetricKey = (typeof METRIC_KEYS)[number];
|
|
11
11
|
/**
|
|
12
12
|
* Cheap token estimate used when bumping the `tokens_injected_*` counters.
|
|
@@ -37,8 +37,8 @@ export declare class Metrics {
|
|
|
37
37
|
incr(key: MetricKey, by?: number): void;
|
|
38
38
|
/**
|
|
39
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
|
|
41
|
-
* (
|
|
40
|
+
* counters. These live OUTSIDE `METRIC_KEYS`, which is frozen at 33
|
|
41
|
+
* (K7-004 acceptance, the verified cumulative ladder), but persist to
|
|
42
42
|
* the same `kevin_metrics` table so `kevin_audit`'s channels block can
|
|
43
43
|
* read them by SQL (K6-023). They are written immediately (no debounce):
|
|
44
44
|
* they change at most twice per process, on session start.
|
package/dist/plugin/metrics.js
CHANGED
|
@@ -38,6 +38,25 @@ export const METRIC_KEYS = [
|
|
|
38
38
|
"artifact_writes_total",
|
|
39
39
|
"artifact_writes_noop",
|
|
40
40
|
"injections_blocked_confidence",
|
|
41
|
+
// v0.7.0 (K7-004 / plan §8.3) — order matches migration 008's seed block.
|
|
42
|
+
// These are the Project Truth counters. No per-type precision helper is
|
|
43
|
+
// exported here: the per-type split of plan §5.6 lives in `kevin_audit`
|
|
44
|
+
// as pure SQL, not as a `Metrics` method, so there is never a second
|
|
45
|
+
// definition of precision to drift from the first (D7-14).
|
|
46
|
+
"repo_facts_scanned",
|
|
47
|
+
"memories_contradicted",
|
|
48
|
+
"conventions_mined",
|
|
49
|
+
"conflicts_detected",
|
|
50
|
+
"error_lessons_suppressed",
|
|
51
|
+
// v0.8.0 (K8-003 / plan §8.3) — order matches migration 009's seed block.
|
|
52
|
+
// These are the Team counters. shared_entries_total is re-derived from
|
|
53
|
+
// the table by the 009 post-apply hook, never trusted from increments.
|
|
54
|
+
"shared_entries_total",
|
|
55
|
+
"shared_entries_imported",
|
|
56
|
+
"shared_entries_exported",
|
|
57
|
+
"okf_merge_folds",
|
|
58
|
+
"rekey_events",
|
|
59
|
+
"injections_from_shared",
|
|
41
60
|
];
|
|
42
61
|
const DEFAULT_FLUSH_MS = 1000;
|
|
43
62
|
function zeroCache() {
|
|
@@ -107,8 +126,8 @@ export class Metrics {
|
|
|
107
126
|
}
|
|
108
127
|
/**
|
|
109
128
|
* v0.6.0 (K6-018/019 / plan §5.8) — the pull-channel registration
|
|
110
|
-
* counters. These live OUTSIDE `METRIC_KEYS`, which is frozen at
|
|
111
|
-
* (
|
|
129
|
+
* counters. These live OUTSIDE `METRIC_KEYS`, which is frozen at 33
|
|
130
|
+
* (K7-004 acceptance, the verified cumulative ladder), but persist to
|
|
112
131
|
* the same `kevin_metrics` table so `kevin_audit`'s channels block can
|
|
113
132
|
* read them by SQL (K6-023). They are written immediately (no debounce):
|
|
114
133
|
* they change at most twice per process, on session start.
|
|
@@ -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;IACvB,0EAA0E;IAC1E,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,+BAA+B;IAC/B,0BAA0B;IAC1B,4BAA4B;IAC5B,yBAAyB;IACzB,yBAAyB;IACzB,mBAAmB;IACnB,0EAA0E;IAC1E,mEAAmE;IACnE,iEAAiE;IACjE,mBAAmB;IACnB,oBAAoB;IACpB,oBAAoB;IACpB,uBAAuB;IACvB,sBAAsB;IACtB,+BAA+B;
|
|
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;IAC1B,4BAA4B;IAC5B,yBAAyB;IACzB,yBAAyB;IACzB,mBAAmB;IACnB,0EAA0E;IAC1E,mEAAmE;IACnE,iEAAiE;IACjE,mBAAmB;IACnB,oBAAoB;IACpB,oBAAoB;IACpB,uBAAuB;IACvB,sBAAsB;IACtB,+BAA+B;IAC/B,0EAA0E;IAC1E,wEAAwE;IACxE,wEAAwE;IACxE,qEAAqE;IACrE,2DAA2D;IAC3D,oBAAoB;IACpB,uBAAuB;IACvB,mBAAmB;IACnB,oBAAoB;IACpB,0BAA0B;IAC1B,0EAA0E;IAC1E,uEAAuE;IACvE,uEAAuE;IACvE,sBAAsB;IACtB,yBAAyB;IACzB,yBAAyB;IACzB,iBAAiB;IACjB,cAAc;IACd,wBAAwB;CACf,CAAC;AAIX,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,SAAS,SAAS;IACjB,MAAM,CAAC,GAAG,IAAI,GAAG,EAAqB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,WAAW;QAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,CAAC,CAAC;AACV,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,GAA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AAC;IACb,CAAC;IAEO,UAAU;QACjB,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC9B,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACxB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Store } from "./Store.js";
|
|
2
|
-
export declare function exportOkf(store: Store): string;
|
|
3
|
-
export declare function exportMarkdown(store: Store): string;
|
|
2
|
+
export declare function exportOkf(store: Store, projectId?: string | null): string;
|
|
3
|
+
export declare function exportMarkdown(store: Store, projectId?: string | null): string;
|
|
@@ -16,8 +16,14 @@ function formatTimestamp(ts) {
|
|
|
16
16
|
* demotion signal, column from migration 005). DBs that predate 005 have
|
|
17
17
|
* no such column; the SELECT is retried without it and recurrences
|
|
18
18
|
* degrade to 0 (legacy confidence formula applies — see below).
|
|
19
|
+
*
|
|
20
|
+
* v0.8.0 (K8-027) — the v1 export is scoped to one project: the global
|
|
21
|
+
* database may hold several projects' memories, and once an export lands
|
|
22
|
+
* in a committed file a cross-project leak becomes permanent history.
|
|
23
|
+
* A `project_id` of null keeps the legacy unscoped behaviour for direct
|
|
24
|
+
* callers that predate the fix; the kevin_export tool always threads it.
|
|
19
25
|
*/
|
|
20
|
-
function selectExportRows(store) {
|
|
26
|
+
function selectExportRows(store, projectId) {
|
|
21
27
|
try {
|
|
22
28
|
return {
|
|
23
29
|
hasRecurrence: true,
|
|
@@ -27,8 +33,9 @@ function selectExportRows(store) {
|
|
|
27
33
|
source_tool, source_session, created_at, updated_at
|
|
28
34
|
FROM memories
|
|
29
35
|
WHERE status = 'active'
|
|
36
|
+
AND project_id = ?
|
|
30
37
|
ORDER BY type, created_at DESC`)
|
|
31
|
-
.all(),
|
|
38
|
+
.all(projectId),
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
catch {
|
|
@@ -38,8 +45,9 @@ function selectExportRows(store) {
|
|
|
38
45
|
source_tool, source_session, created_at, updated_at
|
|
39
46
|
FROM memories
|
|
40
47
|
WHERE status = 'active'
|
|
48
|
+
AND project_id = ?
|
|
41
49
|
ORDER BY type, created_at DESC`)
|
|
42
|
-
.all();
|
|
50
|
+
.all(projectId);
|
|
43
51
|
return {
|
|
44
52
|
hasRecurrence: false,
|
|
45
53
|
rows: legacy.map((r) => ({ ...r, recurrence_count: 0 })),
|
|
@@ -57,8 +65,8 @@ function exportConfidence(row, hasRecurrence) {
|
|
|
57
65
|
: Math.min(1, 0.5 + 0.1 * row.evidence_count);
|
|
58
66
|
return confidence.toFixed(2);
|
|
59
67
|
}
|
|
60
|
-
export function exportOkf(store) {
|
|
61
|
-
const { rows: allRows, hasRecurrence } = selectExportRows(store);
|
|
68
|
+
export function exportOkf(store, projectId = null) {
|
|
69
|
+
const { rows: allRows, hasRecurrence } = selectExportRows(store, projectId);
|
|
62
70
|
const filtered = allRows.filter((r) => EXPORT_TYPES.has(r.type));
|
|
63
71
|
if (filtered.length === 0)
|
|
64
72
|
return "<!-- No exportable memories found. -->\n";
|
|
@@ -88,8 +96,8 @@ export function exportOkf(store) {
|
|
|
88
96
|
}
|
|
89
97
|
return `${blocks.join("\n\n")}\n`;
|
|
90
98
|
}
|
|
91
|
-
export function exportMarkdown(store) {
|
|
92
|
-
const { rows: allRows, hasRecurrence } = selectExportRows(store);
|
|
99
|
+
export function exportMarkdown(store, projectId = null) {
|
|
100
|
+
const { rows: allRows, hasRecurrence } = selectExportRows(store, projectId);
|
|
93
101
|
const filtered = allRows.filter((r) => EXPORT_TYPES.has(r.type));
|
|
94
102
|
if (filtered.length === 0)
|
|
95
103
|
return "# Kevin Knowledge Export\n\n_No exportable memories found._\n";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"okf-export.js","sourceRoot":"","sources":["../../plugin/okf-export.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;A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IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** OKF v2 format version marker, written on the first header line. */
|
|
2
|
+
export declare const OKF_VERSION = 2;
|
|
3
|
+
/** A single canonicalized entry line may not exceed this many bytes. */
|
|
4
|
+
export declare const MAX_LINE_BYTES = 4096;
|
|
5
|
+
/** A serialized corpus may not exceed this many entries. */
|
|
6
|
+
export declare const MAX_ENTRIES = 2000;
|
|
7
|
+
export type OkfOp = "assert" | "tombstone";
|
|
8
|
+
/**
|
|
9
|
+
* A v2 entry. The field set is plan §5.3/§5.4: the two integer
|
|
10
|
+
* counters (`evidence`, `recurrence`) are transported and
|
|
11
|
+
* `confidence` is DERIVED at read time — the file contains no
|
|
12
|
+
* floats at all, so two machines computing a confidence slightly
|
|
13
|
+
* differently still emit byte-identical lines.
|
|
14
|
+
*/
|
|
15
|
+
export interface OkfEntry {
|
|
16
|
+
entry_id: string;
|
|
17
|
+
type: "decision" | "rule" | "pattern" | "solution";
|
|
18
|
+
statement: string;
|
|
19
|
+
scope: string | null;
|
|
20
|
+
evidence: number;
|
|
21
|
+
recurrence: number;
|
|
22
|
+
origin: string;
|
|
23
|
+
author_hash: string | null;
|
|
24
|
+
op: OkfOp;
|
|
25
|
+
created_at: string;
|
|
26
|
+
supersedes: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Canonical JSON of an entry: keys in alphabetical order, no space
|
|
30
|
+
* argument, integers only (no float is ever written — plan §5.3).
|
|
31
|
+
* The object is constructed explicitly so the source object's
|
|
32
|
+
* insertion order can never leak into the bytes.
|
|
33
|
+
*/
|
|
34
|
+
export declare function canonicalize(e: OkfEntry): string;
|
|
35
|
+
/**
|
|
36
|
+
* Emit the v2 file: three `#` header lines, then every entry sorted
|
|
37
|
+
* ascending by `entry_id`, one per line, LF endings, exactly one
|
|
38
|
+
* terminating newline. Entries over MAX_LINE_BYTES (measured in
|
|
39
|
+
* BYTES — a Japanese statement passes a `.length` check and fails a
|
|
40
|
+
* byte check) and corpora over MAX_ENTRIES are refused, not
|
|
41
|
+
* truncated (plan §5.3, physical rules).
|
|
42
|
+
*/
|
|
43
|
+
export declare function serialize(entries: OkfEntry[], repoId: string, version: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Group both corpora by `entry_id`, fold each group through `join()`,
|
|
46
|
+
* and return the result sorted ascending by `entry_id`. Order of the
|
|
47
|
+
* inputs does not matter: join() is commutative, and the fold order is
|
|
48
|
+
* the only place input order could leak in — it cannot, by algebra.
|
|
49
|
+
*/
|
|
50
|
+
export declare function merge(a: OkfEntry[], b: OkfEntry[]): OkfEntry[];
|
|
51
|
+
/**
|
|
52
|
+
* Derived, never serialized — reuses the v0.4.0 two-sided confidence
|
|
53
|
+
* formula verbatim (plan §5.4). A lesson that keeps recurring is
|
|
54
|
+
* DEMOTED rather than merely un-promoted; shared and local memories
|
|
55
|
+
* are repriced identically by the same formula.
|
|
56
|
+
*/
|
|
57
|
+
export declare function deriveConfidence(e: OkfEntry): number;
|
|
58
|
+
export interface RejectedLine {
|
|
59
|
+
line: number;
|
|
60
|
+
reason: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ParseResult {
|
|
63
|
+
version: number;
|
|
64
|
+
repoId: string | null;
|
|
65
|
+
/** Folded via join() and sorted ascending by entry_id. */
|
|
66
|
+
entries: OkfEntry[];
|
|
67
|
+
/** parse never throws; bad lines are reported. */
|
|
68
|
+
rejected: RejectedLine[];
|
|
69
|
+
/** Duplicate entry_ids collapsed by join(). */
|
|
70
|
+
folded: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* v0.8.0 (K8-013 / plan §5.4, D8-13) — the field lattice. Every field
|
|
74
|
+
* resolves through a max, a min, or an absorbing boolean OR over a
|
|
75
|
+
* totally ordered set; there is no "prefer the newer" anywhere.
|
|
76
|
+
* Precondition: `a.entry_id === b.entry_id`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function join(a: OkfEntry, b: OkfEntry): OkfEntry;
|
|
79
|
+
/**
|
|
80
|
+
* parse() is a TOTAL function — it never throws, on any input,
|
|
81
|
+
* including binary (D8-14). The file is expected to arrive damaged:
|
|
82
|
+
* a conflict resolution leaves `<<<<<<< HEAD` markers, an editor
|
|
83
|
+
* truncates the last line, a merge tool mangles an encoding. Every
|
|
84
|
+
* unusable line becomes a `RejectedLine`; the good entries survive.
|
|
85
|
+
*
|
|
86
|
+
* Reason taxonomy (closed): not_okf, version_ahead, bad_json,
|
|
87
|
+
* missing_field, wrong_type, id_mismatch, unknown_op, line_too_long,
|
|
88
|
+
* corpus_too_large.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parse(text: string): ParseResult;
|
|
91
|
+
/**
|
|
92
|
+
* Compute the identity of an OKF entry: `fnv1a64("okf:v2\0" + type +
|
|
93
|
+
* "\0" + statement + "\0" + (scope ?? ""))`.
|
|
94
|
+
*
|
|
95
|
+
* D8-05 — deliberately NOT `fingerprint()`:
|
|
96
|
+
* - it salts with `project_id`, so every clone would produce a
|
|
97
|
+
* different id for the same rule, the shared file would accumulate
|
|
98
|
+
* one entry per developer per rule, and the merge fold would never
|
|
99
|
+
* once fire;
|
|
100
|
+
* - it runs `normalize()`, which lowercases and rewrites
|
|
101
|
+
* `path.ext:line:col` — both destructive for a curated statement,
|
|
102
|
+
* where casing and file paths carry meaning.
|
|
103
|
+
*
|
|
104
|
+
* NUL separators keep (`rule`, "ab", "c") distinct from
|
|
105
|
+
* ("rule", "a", "bc") — plain concatenation could never.
|
|
106
|
+
*/
|
|
107
|
+
export declare function computeEntryId(type: string, statement: string, scope?: string | null): string;
|