@oscharko-dev/keiko-evidence 0.2.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.
Files changed (92) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/aggregate.d.ts +4 -0
  3. package/dist/aggregate.d.ts.map +1 -0
  4. package/dist/aggregate.js +21 -0
  5. package/dist/build.d.ts +3 -0
  6. package/dist/build.d.ts.map +1 -0
  7. package/dist/build.js +227 -0
  8. package/dist/connected-context-evidence.d.ts +47 -0
  9. package/dist/connected-context-evidence.d.ts.map +1 -0
  10. package/dist/connected-context-evidence.js +197 -0
  11. package/dist/errors.d.ts +3 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +4 -0
  14. package/dist/index-api.d.ts +15 -0
  15. package/dist/index-api.d.ts.map +1 -0
  16. package/dist/index-api.js +136 -0
  17. package/dist/index.d.ts +20 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +34 -0
  20. package/dist/persist.d.ts +9 -0
  21. package/dist/persist.d.ts.map +1 -0
  22. package/dist/persist.js +40 -0
  23. package/dist/promptEnhancement/index.d.ts +7 -0
  24. package/dist/promptEnhancement/index.d.ts.map +1 -0
  25. package/dist/promptEnhancement/index.js +10 -0
  26. package/dist/promptEnhancement/manifestSchema.d.ts +71 -0
  27. package/dist/promptEnhancement/manifestSchema.d.ts.map +1 -0
  28. package/dist/promptEnhancement/manifestSchema.js +307 -0
  29. package/dist/promptEnhancement/redaction.d.ts +17 -0
  30. package/dist/promptEnhancement/redaction.d.ts.map +1 -0
  31. package/dist/promptEnhancement/redaction.js +66 -0
  32. package/dist/promptEnhancement/store.d.ts +64 -0
  33. package/dist/promptEnhancement/store.d.ts.map +1 -0
  34. package/dist/promptEnhancement/store.js +409 -0
  35. package/dist/qualityIntelligence/candidatesArtifact.d.ts +74 -0
  36. package/dist/qualityIntelligence/candidatesArtifact.d.ts.map +1 -0
  37. package/dist/qualityIntelligence/candidatesArtifact.js +258 -0
  38. package/dist/qualityIntelligence/companionStore.d.ts +37 -0
  39. package/dist/qualityIntelligence/companionStore.d.ts.map +1 -0
  40. package/dist/qualityIntelligence/companionStore.js +158 -0
  41. package/dist/qualityIntelligence/figmaSnapshot/schema.d.ts +123 -0
  42. package/dist/qualityIntelligence/figmaSnapshot/schema.d.ts.map +1 -0
  43. package/dist/qualityIntelligence/figmaSnapshot/schema.js +163 -0
  44. package/dist/qualityIntelligence/figmaSnapshot/store.d.ts +144 -0
  45. package/dist/qualityIntelligence/figmaSnapshot/store.d.ts.map +1 -0
  46. package/dist/qualityIntelligence/figmaSnapshot/store.js +898 -0
  47. package/dist/qualityIntelligence/index.d.ts +18 -0
  48. package/dist/qualityIntelligence/index.d.ts.map +1 -0
  49. package/dist/qualityIntelligence/index.js +21 -0
  50. package/dist/qualityIntelligence/manifestSchema.d.ts +154 -0
  51. package/dist/qualityIntelligence/manifestSchema.d.ts.map +1 -0
  52. package/dist/qualityIntelligence/manifestSchema.js +70 -0
  53. package/dist/qualityIntelligence/redaction.d.ts +10 -0
  54. package/dist/qualityIntelligence/redaction.d.ts.map +1 -0
  55. package/dist/qualityIntelligence/redaction.js +103 -0
  56. package/dist/qualityIntelligence/retention.d.ts +71 -0
  57. package/dist/qualityIntelligence/retention.d.ts.map +1 -0
  58. package/dist/qualityIntelligence/retention.js +287 -0
  59. package/dist/qualityIntelligence/retentionPolicy.d.ts +10 -0
  60. package/dist/qualityIntelligence/retentionPolicy.d.ts.map +1 -0
  61. package/dist/qualityIntelligence/retentionPolicy.js +38 -0
  62. package/dist/qualityIntelligence/store.d.ts +95 -0
  63. package/dist/qualityIntelligence/store.d.ts.map +1 -0
  64. package/dist/qualityIntelligence/store.js +483 -0
  65. package/dist/redaction.d.ts +2 -0
  66. package/dist/redaction.d.ts.map +1 -0
  67. package/dist/redaction.js +4 -0
  68. package/dist/report.d.ts +17 -0
  69. package/dist/report.d.ts.map +1 -0
  70. package/dist/report.js +50 -0
  71. package/dist/retention.d.ts +4 -0
  72. package/dist/retention.d.ts.map +1 -0
  73. package/dist/retention.js +95 -0
  74. package/dist/runid.d.ts +2 -0
  75. package/dist/runid.d.ts.map +1 -0
  76. package/dist/runid.js +4 -0
  77. package/dist/side-file.d.ts +9 -0
  78. package/dist/side-file.d.ts.map +1 -0
  79. package/dist/side-file.js +102 -0
  80. package/dist/store.d.ts +8 -0
  81. package/dist/store.d.ts.map +1 -0
  82. package/dist/store.js +332 -0
  83. package/dist/types.d.ts +3 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +5 -0
  86. package/dist/version.d.ts +2 -0
  87. package/dist/version.d.ts.map +1 -0
  88. package/dist/version.js +1 -0
  89. package/dist/workflow-evidence.d.ts +36 -0
  90. package/dist/workflow-evidence.d.ts.map +1 -0
  91. package/dist/workflow-evidence.js +158 -0
  92. package/package.json +32 -0
@@ -0,0 +1,197 @@
1
+ // Connected-context evidence persistence (Issue #187). This records what Keiko inspected and
2
+ // what metadata reached the model without persisting query text or excerpt content.
3
+ import { createHash } from "node:crypto";
4
+ import { HARNESS_VERSION, } from "@oscharko-dev/keiko-contracts";
5
+ import { buildEvidenceReport } from "./report.js";
6
+ import { createAuditRedactor, deepRedactStrings } from "./redaction.js";
7
+ import { applyRetention } from "./retention.js";
8
+ import { DEFAULT_RETENTION, EVIDENCE_SCHEMA_VERSION, } from "./types.js";
9
+ function sha256Hex(value) {
10
+ return createHash("sha256").update(value).digest("hex");
11
+ }
12
+ function redactString(redact, value) {
13
+ return redact(value);
14
+ }
15
+ function byteLength(value) {
16
+ return Buffer.byteLength(value, "utf8");
17
+ }
18
+ function numberRecord(value) {
19
+ const out = {};
20
+ for (const [key, entry] of Object.entries(value)) {
21
+ if (typeof entry === "number") {
22
+ out[key] = entry;
23
+ }
24
+ }
25
+ return out;
26
+ }
27
+ function workspaceRootAuditId(workspaceRoot, redact) {
28
+ return `connected-context-root-${sha256Hex(redactString(redact, workspaceRoot)).slice(0, 16)}`;
29
+ }
30
+ function contextOf(input, redact) {
31
+ return {
32
+ workspaceRoot: workspaceRootAuditId(input.workspaceRoot, redact),
33
+ totalCandidates: input.pack.files.length + input.pack.omitted.length,
34
+ usedBytes: input.pack.usage.excerptBytes,
35
+ budgetBytes: input.pack.budget.excerptBytesMax,
36
+ droppedForBudget: input.pack.omitted.filter((entry) => entry.reason === "budget-exhausted")
37
+ .length,
38
+ entries: [],
39
+ };
40
+ }
41
+ function excerptOf(excerpt, redact) {
42
+ const redactedContent = redactString(redact, excerpt.content);
43
+ return {
44
+ atomStableId: redactString(redact, excerpt.atom.stableId),
45
+ scopePath: redactString(redact, excerpt.atom.scopePath),
46
+ ...(excerpt.atom.lineRange === undefined ? {} : { lineRange: excerpt.atom.lineRange }),
47
+ score: excerpt.atom.score,
48
+ provenanceKind: excerpt.atom.provenance.kind,
49
+ tool: redactString(redact, excerpt.atom.provenance.tool),
50
+ queryFingerprint: redactString(redact, excerpt.atom.provenance.queryFingerprint),
51
+ redactionState: excerpt.atom.redactionState,
52
+ contentBytes: excerpt.contentBytes,
53
+ contentSha256: sha256Hex(redactedContent),
54
+ };
55
+ }
56
+ function fileOf(file, redact) {
57
+ const excerpts = file.excerpts.map((excerpt) => excerptOf(excerpt, redact));
58
+ return {
59
+ scopePath: redactString(redact, file.scopePath),
60
+ role: file.role,
61
+ selectionReason: redactString(redact, file.selectionReason),
62
+ excerptCount: file.excerpts.length,
63
+ excerptBytes: file.excerpts.reduce((total, excerpt) => total + excerpt.contentBytes, 0),
64
+ excerpts,
65
+ };
66
+ }
67
+ function toolsUsed(pack, redact) {
68
+ const tools = new Set(["model-gateway"]);
69
+ for (const file of pack.files) {
70
+ for (const excerpt of file.excerpts) {
71
+ tools.add(redactString(redact, excerpt.atom.provenance.tool));
72
+ }
73
+ }
74
+ return [...tools].sort();
75
+ }
76
+ function scopeOf(input, redact) {
77
+ return {
78
+ schemaVersion: input.pack.scope.schemaVersion,
79
+ scopeIdHash: sha256Hex(redactString(redact, input.pack.scope.scopeId)),
80
+ scopeKind: input.pack.scope.kind,
81
+ selectedPathCount: input.pack.scope.relativePaths.length,
82
+ selectedPaths: input.pack.scope.relativePaths.map((path) => redactString(redact, path)),
83
+ };
84
+ }
85
+ function queryOf(input, redact) {
86
+ const safeQueryText = redactString(redact, input.pack.query.text);
87
+ return {
88
+ kind: input.pack.query.kind,
89
+ queryTextHash: sha256Hex(safeQueryText),
90
+ queryTextBytes: byteLength(safeQueryText),
91
+ maxResults: input.pack.query.maxResults,
92
+ caseSensitive: input.pack.query.caseSensitive,
93
+ };
94
+ }
95
+ function planOf(input, redact) {
96
+ if (input.plan === undefined || typeof input.plan.planId !== "string") {
97
+ return undefined;
98
+ }
99
+ const anchors = input.plan.anchors ?? [];
100
+ const rings = input.plan.rings ?? [];
101
+ const anchorKinds = {};
102
+ const anchorTermHashes = anchors
103
+ .map((anchor) => {
104
+ anchorKinds[anchor.kind] = (anchorKinds[anchor.kind] ?? 0) + 1;
105
+ return sha256Hex(redactString(redact, anchor.term));
106
+ })
107
+ .sort();
108
+ return {
109
+ planIdHash: sha256Hex(redactString(redact, input.plan.planId)),
110
+ state: input.plan.state,
111
+ createdAtMs: typeof input.plan.createdAtMs === "number" ? Math.max(0, input.plan.createdAtMs) : undefined,
112
+ anchorCount: anchorTermHashes.length,
113
+ anchorKinds,
114
+ anchorTermHashes,
115
+ ringKinds: rings.map((ring) => ring.kind).sort(),
116
+ clarificationReason: typeof input.plan.clarification?.reason === "string"
117
+ ? input.plan.clarification.reason
118
+ : undefined,
119
+ };
120
+ }
121
+ function summaryOf(input) {
122
+ return {
123
+ fileCount: input.pack.files.length,
124
+ citationCount: input.citationCount,
125
+ omittedCount: input.pack.omitted.length,
126
+ uncertaintyCount: input.pack.uncertainty.length,
127
+ elapsedMs: input.elapsedMs,
128
+ };
129
+ }
130
+ function connectedContextOf(input, redact) {
131
+ return {
132
+ packSchemaVersion: input.pack.schemaVersion,
133
+ packStableIdHash: sha256Hex(redactString(redact, input.pack.stableId)),
134
+ chatIdHash: input.chatId === undefined ? undefined : sha256Hex(redactString(redact, input.chatId)),
135
+ modelRequest: {
136
+ sentToModel: true,
137
+ excerptContentPersisted: false,
138
+ },
139
+ scope: scopeOf(input, redact),
140
+ query: queryOf(input, redact),
141
+ plan: planOf(input, redact),
142
+ budget: {
143
+ usage: numberRecord(input.pack.usage),
144
+ limits: numberRecord(input.pack.budget),
145
+ },
146
+ files: input.pack.files.map((file) => fileOf(file, redact)),
147
+ omitted: input.pack.omitted.map((entry) => ({
148
+ scopePath: redactString(redact, entry.scopePath),
149
+ reason: entry.reason,
150
+ })),
151
+ uncertainty: input.pack.uncertainty.map((entry) => ({
152
+ kind: entry.kind,
153
+ impactedAtomCount: entry.impactedAtomIds.length,
154
+ })),
155
+ toolsUsed: toolsUsed(input.pack, redact),
156
+ summary: summaryOf(input),
157
+ };
158
+ }
159
+ function buildConnectedContextEvidenceManifest(input, costClassResolver, redact = (value) => value) {
160
+ const identityDurationMs = Math.max(0, input.finishedAt - input.startedAt);
161
+ return {
162
+ evidenceSchemaVersion: EVIDENCE_SCHEMA_VERSION,
163
+ run: {
164
+ runId: input.runId,
165
+ fingerprint: sha256Hex(redactString(redact, input.pack.stableId)),
166
+ harnessVersion: HARNESS_VERSION,
167
+ taskType: "connected-context",
168
+ outcome: "completed",
169
+ startedAt: input.startedAt,
170
+ finishedAt: input.finishedAt,
171
+ durationMs: identityDurationMs,
172
+ },
173
+ model: {
174
+ modelId: input.modelId,
175
+ costClass: costClassResolver?.(input.modelId) ?? "unknown",
176
+ },
177
+ usageTotals: {
178
+ promptTokens: input.pack.usage.modelInputTokens,
179
+ completionTokens: input.pack.usage.modelOutputTokens,
180
+ requestCount: 1,
181
+ totalLatencyMs: input.elapsedMs,
182
+ },
183
+ context: contextOf(input, redact),
184
+ stateTransitions: [],
185
+ toolCalls: [],
186
+ commandExecutions: [],
187
+ connectedContext: connectedContextOf(input, redact),
188
+ };
189
+ }
190
+ export function persistConnectedContextEvidence(input, ctx) {
191
+ const redactor = createAuditRedactor({ additionalSecrets: ctx.additionalSecrets ?? [] }, ctx.env);
192
+ const manifest = buildConnectedContextEvidenceManifest(input, ctx.costClassResolver, redactor);
193
+ const safeManifest = deepRedactStrings(manifest, redactor);
194
+ const location = ctx.store.put(safeManifest.run.runId, JSON.stringify(safeManifest, null, 2));
195
+ applyRetention(ctx.store, ctx.retention ?? DEFAULT_RETENTION);
196
+ return { manifest: safeManifest, location, report: buildEvidenceReport(safeManifest, location) };
197
+ }
@@ -0,0 +1,3 @@
1
+ export { AUDIT_CODES, AuditError, InvalidRunIdError, EvidenceWriteError, EvidenceReadError, EvidenceSchemaError, } from "@oscharko-dev/keiko-security/errors/audit";
2
+ export type { AuditCode } from "@oscharko-dev/keiko-security/errors/audit";
3
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2CAA2C,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,4 @@
1
+ // Re-export shim: the audit error taxonomy now lives in @oscharko-dev/keiko-security
2
+ // (issue #159, ADR-0019). All existing import sites (`from "./errors.js"`) keep resolving
3
+ // unchanged via this barrel.
4
+ export { AUDIT_CODES, AuditError, InvalidRunIdError, EvidenceWriteError, EvidenceReadError, EvidenceSchemaError, } from "@oscharko-dev/keiko-security/errors/audit";
@@ -0,0 +1,15 @@
1
+ import type { RunOutcome } from "@oscharko-dev/keiko-contracts";
2
+ import type { EvidenceStore } from "./store.js";
3
+ import type { EvidenceManifest, EvidenceTaskType } from "./types.js";
4
+ export interface EvidenceListEntry {
5
+ readonly runId: string;
6
+ readonly taskType: EvidenceTaskType;
7
+ readonly outcome: RunOutcome;
8
+ readonly startedAt: number;
9
+ readonly finishedAt: number;
10
+ readonly modelId: string;
11
+ readonly workspaceRoot?: string | undefined;
12
+ }
13
+ export declare function listEvidence(store: EvidenceStore): readonly EvidenceListEntry[];
14
+ export declare function loadEvidence(store: EvidenceStore, runId: string): EvidenceManifest | undefined;
15
+ //# sourceMappingURL=index-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-api.d.ts","sourceRoot":"","sources":["../src/index-api.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C;AA4ID,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,iBAAiB,EAAE,CAc/E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAM9F"}
@@ -0,0 +1,136 @@
1
+ // Evidence index/list API (ADR-0010 D5). listEvidence enumerates and loadEvidence loads past runs
2
+ // reading ONLY the contained base dir via the EvidenceStore — never scanning arbitrary workspace
3
+ // files. Because the persisted JSON is redacted by construction (D3), the loaded data is
4
+ // redacted-by-construction: there is no un-redaction path. A manifest whose evidenceSchemaVersion is
5
+ // not a recognised version is reported with a typed error (D5), not silently coerced. This is the
6
+ // #13 UI seam.
7
+ import { EvidenceReadError, EvidenceSchemaError } from "./errors.js";
8
+ import { EVIDENCE_SCHEMA_VERSION } from "./types.js";
9
+ // Parses raw JSON and verifies the schema version before trusting the shape. We narrow on the
10
+ // version discriminant exactly as harness consumers narrow on the event schemaVersion (D2).
11
+ // JSON.parse can throw a raw SyntaxError on a truncated/hand-edited manifest; the parse is a system
12
+ // boundary (reading developer-writable files), so catching it and re-throwing a typed AuditError is
13
+ // correct — the CLI maps AuditError to an exit code instead of leaking an unhandled stack (C1).
14
+ function parseJson(json, runId) {
15
+ try {
16
+ return JSON.parse(json);
17
+ }
18
+ catch {
19
+ throw new EvidenceReadError(`evidence manifest is not valid JSON: ${runId}`);
20
+ }
21
+ }
22
+ function isRecord(value) {
23
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24
+ }
25
+ function requireRecord(parent, key, runId) {
26
+ const value = parent[key];
27
+ if (!isRecord(value)) {
28
+ throw new EvidenceSchemaError(`evidence manifest is missing object field ${key}: ${runId}`, "1");
29
+ }
30
+ return value;
31
+ }
32
+ function requireArray(parent, key, runId) {
33
+ if (!Array.isArray(parent[key])) {
34
+ throw new EvidenceSchemaError(`evidence manifest is missing array field ${key}: ${runId}`, "1");
35
+ }
36
+ }
37
+ function requireString(parent, key, runId) {
38
+ if (typeof parent[key] !== "string") {
39
+ throw new EvidenceSchemaError(`evidence manifest is missing string field ${key}: ${runId}`, "1");
40
+ }
41
+ }
42
+ function requireNumber(parent, key, runId) {
43
+ if (typeof parent[key] !== "number" || !Number.isFinite(parent[key])) {
44
+ throw new EvidenceSchemaError(`evidence manifest is missing numeric field ${key}: ${runId}`, "1");
45
+ }
46
+ }
47
+ function requireOptionalRecord(parent, key, runId) {
48
+ const value = parent[key];
49
+ if (value !== undefined && !isRecord(value)) {
50
+ throw new EvidenceSchemaError(`evidence manifest has invalid object field ${key}: ${runId}`, "1");
51
+ }
52
+ }
53
+ function requireOptionalArray(parent, key, runId) {
54
+ const value = parent[key];
55
+ if (value !== undefined && !Array.isArray(value)) {
56
+ throw new EvidenceSchemaError(`evidence manifest has invalid array field ${key}: ${runId}`, "1");
57
+ }
58
+ }
59
+ function validateManifestShape(parsed, runId) {
60
+ const run = requireRecord(parsed, "run", runId);
61
+ requireString(run, "runId", runId);
62
+ requireString(run, "fingerprint", runId);
63
+ requireString(run, "harnessVersion", runId);
64
+ requireString(run, "taskType", runId);
65
+ requireString(run, "outcome", runId);
66
+ requireNumber(run, "startedAt", runId);
67
+ requireNumber(run, "finishedAt", runId);
68
+ requireNumber(run, "durationMs", runId);
69
+ const model = requireRecord(parsed, "model", runId);
70
+ requireString(model, "modelId", runId);
71
+ requireString(model, "costClass", runId);
72
+ const usage = requireRecord(parsed, "usageTotals", runId);
73
+ requireNumber(usage, "promptTokens", runId);
74
+ requireNumber(usage, "completionTokens", runId);
75
+ requireNumber(usage, "requestCount", runId);
76
+ requireNumber(usage, "totalLatencyMs", runId);
77
+ requireArray(parsed, "stateTransitions", runId);
78
+ requireArray(parsed, "toolCalls", runId);
79
+ requireArray(parsed, "commandExecutions", runId);
80
+ requireOptionalArray(parsed, "sandboxConfigurations", runId);
81
+ requireOptionalArray(parsed, "verificationResults", runId);
82
+ requireOptionalArray(parsed, "reasoning", runId);
83
+ requireOptionalRecord(parsed, "context", runId);
84
+ requireOptionalRecord(parsed, "patch", runId);
85
+ requireOptionalRecord(parsed, "verification", runId);
86
+ requireOptionalRecord(parsed, "failure", runId);
87
+ requireOptionalRecord(parsed, "browser", runId);
88
+ requireOptionalRecord(parsed, "connectedContext", runId);
89
+ }
90
+ function parseManifest(json, runId) {
91
+ const parsed = parseJson(json, runId);
92
+ if (!isRecord(parsed)) {
93
+ throw new EvidenceSchemaError(`evidence manifest is not an object: ${runId}`, "none");
94
+ }
95
+ const version = parsed.evidenceSchemaVersion;
96
+ if (version !== EVIDENCE_SCHEMA_VERSION) {
97
+ throw new EvidenceSchemaError(`unrecognised evidence schema version for ${runId}`, typeof version === "string" ? version : "none");
98
+ }
99
+ validateManifestShape(parsed, runId);
100
+ return parsed;
101
+ }
102
+ function toListEntry(manifest) {
103
+ return {
104
+ runId: manifest.run.runId,
105
+ taskType: manifest.run.taskType,
106
+ outcome: manifest.run.outcome,
107
+ startedAt: manifest.run.startedAt,
108
+ finishedAt: manifest.run.finishedAt,
109
+ modelId: manifest.model.modelId,
110
+ ...(manifest.context?.workspaceRoot === undefined
111
+ ? {}
112
+ : { workspaceRoot: manifest.context.workspaceRoot }),
113
+ };
114
+ }
115
+ export function listEvidence(store) {
116
+ const entries = [];
117
+ for (const runId of store.list()) {
118
+ const json = store.get(runId);
119
+ if (json === undefined) {
120
+ continue;
121
+ }
122
+ const parsed = parseJson(json, runId);
123
+ if (!isRecord(parsed) || typeof parsed.evidenceSchemaVersion !== "string") {
124
+ continue;
125
+ }
126
+ entries.push(toListEntry(parseManifest(json, runId)));
127
+ }
128
+ return entries;
129
+ }
130
+ export function loadEvidence(store, runId) {
131
+ const json = store.get(runId);
132
+ if (json === undefined) {
133
+ return undefined;
134
+ }
135
+ return parseManifest(json, runId);
136
+ }
@@ -0,0 +1,20 @@
1
+ export { KEIKO_EVIDENCE_VERSION } from "./version.js";
2
+ export { buildEvidenceManifest } from "./build.js";
3
+ export { persistEvidence, type PersistResult } from "./persist.js";
4
+ export { createAuditRedactor, deepRedactStrings } from "./redaction.js";
5
+ export { aggregateUsage } from "./aggregate.js";
6
+ export { listEvidence, loadEvidence, type EvidenceListEntry } from "./index-api.js";
7
+ export { applyRetention } from "./retention.js";
8
+ export { buildEvidenceReport, renderEvidenceReport, type EvidenceReport } from "./report.js";
9
+ export { assertValidRunId } from "./runid.js";
10
+ export { buildWorkflowManifest, foldWorkflowUsage, persistWorkflowEvidence, type EvidencePersistContext, type WorkflowEventLike, type WorkflowRunIdentity, type WorkflowRunKind, type WorkflowTerminalStatus, } from "./workflow-evidence.js";
11
+ export { persistConnectedContextEvidence, type ConnectedContextEvidenceContext, type ConnectedContextEvidenceInput, type ConnectedContextEvidencePersistResult, } from "./connected-context-evidence.js";
12
+ export { createInMemoryEvidenceStore, createNodeEvidenceStore, DEFAULT_EVIDENCE_DIR, resolveEvidenceDir, type EvidenceStore, } from "./store.js";
13
+ export { writeSideFile, type SideFileWriteResult, type SideFileWriterOptions, } from "./side-file.js";
14
+ export { AUDIT_CODES, AuditError, EvidenceReadError, EvidenceSchemaError, EvidenceWriteError, InvalidRunIdError, type AuditCode, } from "./errors.js";
15
+ export * as QualityIntelligence from "./qualityIntelligence/index.js";
16
+ export { QUALITY_INTELLIGENCE_DEFAULT_RETENTION_PROFILE_ID, QUALITY_INTELLIGENCE_EVIDENCE_SCHEMA_VERSION, QUALITY_INTELLIGENCE_RETENTION_PROFILES, appendQualityIntelligenceExportRow, applyQualityIntelligenceRetention, createInMemoryQualityIntelligenceLocalStore, createNodeQualityIntelligenceLocalStore, deleteQualityIntelligenceRun, enforceQualityIntelligenceRetentionPolicy, getQualityIntelligenceRetentionProfile, listQualityIntelligenceRuns, loadQualityIntelligenceRun, quarantineCorruptQualityIntelligenceManifest, recordQualityIntelligenceRun, recordQualityIntelligenceCandidates, loadQualityIntelligenceCandidates, deleteQualityIntelligenceCandidates, applyQualityIntelligenceCandidateEdit, QUALITY_INTELLIGENCE_CANDIDATES_SCHEMA_VERSION, createNodeContainedJsonArtifactStore, redactQualityIntelligenceEvidence, snapshotQualityIntelligenceRunsForRecovery, validateQualityIntelligenceEvidenceManifest, FIGMA_SNAPSHOT_SCHEMA_VERSION, validateFigmaSnapshotRecord, createNodeFigmaSnapshotStore, enforceFigmaSnapshotRetention, DEFAULT_FIGMA_SNAPSHOT_MAX_RECORDS, type FigmaSnapshotImageRef, type FigmaSnapshotLinkRow, type FigmaSnapshotProvenanceRow, type FigmaSnapshotRecord, type FigmaSnapshotRedactionSummary, type FigmaSnapshotScreenRow, type FigmaSnapshotSkipReason, type FigmaSnapshotSkippedScreenRow, type FigmaSnapshotStructuralScreenRow, type FigmaSnapshotImageBytes, type FigmaSnapshotRetentionProfile, type FigmaSnapshotStore, type FigmaSnapshotStoreOptions, type FigmaSnapshotUserMetadata, type FigmaSnapshotValidationResult, type DeleteFigmaSnapshotResult, type RecordFigmaSnapshotInput, type RecordFigmaSnapshotResult, type RecordFigmaSnapshotScreenInput, type RecordFigmaSnapshotStructuralScreenInput, type UpdateFigmaSnapshotUserMetadataInput, type QualityIntelligenceCandidateRow, type QualityIntelligenceCandidatesArtifact, type RecordQualityIntelligenceCandidatesInput, type ApplyQualityIntelligenceCandidateEditInput, type ApplyQualityIntelligenceCandidateEditResult, type QualityIntelligenceCandidateEditErrorReason, type ContainedJsonArtifactStore, type ContainedJsonArtifactStoreOptions, type QualityIntelligenceDeleteOptions, type QualityIntelligenceDeletionReceipt, type QualityIntelligenceDeletionStatus, type QualityIntelligenceEvidenceManifest, type QualityIntelligenceBinaryExportMode, type QualityIntelligenceTraceabilityExportMode, type QualityIntelligenceEvidenceRefRow, type QualityIntelligenceExportEvidenceInput, type QualityIntelligenceExportRow, type QualityIntelligenceExportTarget, type QualityIntelligenceFindingRow, type QualityIntelligenceIntegrityHashes, type QualityIntelligenceLoadOptions, type QualityIntelligenceLocalStore, type QualityIntelligenceManifestTotals, type QualityIntelligenceNodeStoreOptions, type QualityIntelligenceProvenanceRefs, type QualityIntelligenceQuarantineOptions, type QualityIntelligenceQuarantineReceipt, type QualityIntelligenceRecordInput, type QualityIntelligenceRecordOptions, type QualityIntelligenceRecordResult, type QualityIntelligenceRecoverySnapshot, type QualityIntelligenceRedactionOptions, type QualityIntelligenceRedactionResult, type QualityIntelligenceRedactionSummary, type QualityIntelligenceRetentionDecision, type QualityIntelligenceRetentionDecisionInput, type QualityIntelligenceRetentionDeletionFailure, type QualityIntelligenceRetentionEnforcementOptions, type QualityIntelligenceRetentionEnforcementResult, type QualityIntelligenceRetentionResult, type QualityIntelligenceRunDeletedEvent, type QualityIntelligenceRunSnapshotEntry, type QualityIntelligenceSchemaValidationResult, type QualityIntelligenceCoverageMatrixRow, type QualityIntelligenceSourceFingerprintRow, } from "./qualityIntelligence/index.js";
17
+ export * as PromptEnhancement from "./promptEnhancement/index.js";
18
+ export { PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION, PE_SUBDIR, validatePromptEnhancementEvidenceManifest, redactPromptEnhancementEvidence, buildPromptEnhancementEvidenceManifest, createInMemoryPromptEnhancementLocalStore, createNodePromptEnhancementLocalStore, recordPromptEnhancementRun, loadPromptEnhancementRun, listPromptEnhancementRuns, type PromptEnhancementEvidenceStatus, type PromptEnhancementRedactionSummary, type PromptEnhancementRedactionOptions, type PromptEnhancementRedactionResult, type PromptEnhancementCandidateScoreRow, type PromptEnhancementSafetyRecord, type PromptEnhancementModelMetadata, type PromptEnhancementIntegrityHashes, type PromptEnhancementManifestTotals, type PromptEnhancementEvidenceManifest, type PromptEnhancementSchemaValidationResult, type PromptEnhancementRecordInput, type PromptEnhancementRecordOptions, type PromptEnhancementRecordResult, type PromptEnhancementLocalStore, type PromptEnhancementNodeStoreOptions, type PromptEnhancementLoadOptions, } from "./promptEnhancement/index.js";
19
+ export { EVIDENCE_SCHEMA_VERSION, DEFAULT_RETENTION, type AuditRedactionConfig, type BuildOptions, type EvidenceBuildInput, type EvidenceCommandExecution, type EvidenceDeps, type EvidenceFailure, type EvidenceManifest, type EvidenceModel, type EvidenceBrowserCapture, type EvidenceBrowserContentCapture, type EvidenceBrowserEvent, type EvidenceBrowserEventType, type EvidenceBrowserScreenshot, type EvidenceBrowserViewportPx, type EvidenceConnectedContextAudit, type EvidenceConnectedContextExcerpt, type EvidenceConnectedContextFile, type EvidenceConnectedContextOmitted, type EvidenceConnectedContextQuery, type EvidenceConnectedContextScope, type EvidenceConnectedContextUncertainty, type EvidencePatch, type EvidenceReasoningEntry, type EvidenceRunIdentity, type EvidenceStateTransition, type EvidenceTaskType, type EvidenceToolCall, type EvidenceUsageTotals, type EvidenceVerificationResult, type RetentionPolicy, } from "./types.js";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,+BAA+B,EAC/B,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,qCAAqC,GAC3C,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,UAAU,EACV,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AClC,KAAK,2BAA2B,EAChC,KAAK,iCAAiC,EACtC,KAAK,4BAA4B,GAClC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,6BAA6B,EAClC,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EACjC,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,KAAK,mCAAmC,EACxC,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ // Public surface of @oscharko-dev/keiko-evidence (ADR-0010 D12 + ADR-0019). Re-exports the public
2
+ // evidence surface — the builder, the persist orchestration, the redactor, the store port +
3
+ // adapters, aggregation, the index/list API, retention, the report, runId validation, side-file
4
+ // writing, and the workflow-evidence mapping — alongside the package version constant. The layer
5
+ // does NOT export a bare `summarizeForAudit` or `redact` (it composes them internally).
6
+ export { KEIKO_EVIDENCE_VERSION } from "./version.js";
7
+ export { buildEvidenceManifest } from "./build.js";
8
+ export { persistEvidence } from "./persist.js";
9
+ export { createAuditRedactor, deepRedactStrings } from "./redaction.js";
10
+ export { aggregateUsage } from "./aggregate.js";
11
+ export { listEvidence, loadEvidence } from "./index-api.js";
12
+ export { applyRetention } from "./retention.js";
13
+ export { buildEvidenceReport, renderEvidenceReport } from "./report.js";
14
+ export { assertValidRunId } from "./runid.js";
15
+ export { buildWorkflowManifest, foldWorkflowUsage, persistWorkflowEvidence, } from "./workflow-evidence.js";
16
+ export { persistConnectedContextEvidence, } from "./connected-context-evidence.js";
17
+ export { createInMemoryEvidenceStore, createNodeEvidenceStore, DEFAULT_EVIDENCE_DIR, resolveEvidenceDir, } from "./store.js";
18
+ export { writeSideFile, } from "./side-file.js";
19
+ export { AUDIT_CODES, AuditError, EvidenceReadError, EvidenceSchemaError, EvidenceWriteError, InvalidRunIdError, } from "./errors.js";
20
+ // QualityIntelligence sub-module (Issue #274, ADR-0023 D8). Mirrors the contracts barrel layout —
21
+ // callers may use it either as a namespace import
22
+ // (`import { QualityIntelligence } from '@oscharko-dev/keiko-evidence'`) OR as a flat
23
+ // import of the public surface (`import { recordQualityIntelligenceRun, ... } from
24
+ // '@oscharko-dev/keiko-evidence'`). The flat re-exports below mirror what the
25
+ // `QualityIntelligence` namespace exposes — flat-named symbols are added per ADR-0019
26
+ // trust rule 6 to let downstream consumers (Issue #273 workflow runners, future
27
+ // orchestrators) avoid namespace plumbing in hot paths.
28
+ export * as QualityIntelligence from "./qualityIntelligence/index.js";
29
+ export { QUALITY_INTELLIGENCE_DEFAULT_RETENTION_PROFILE_ID, QUALITY_INTELLIGENCE_EVIDENCE_SCHEMA_VERSION, QUALITY_INTELLIGENCE_RETENTION_PROFILES, appendQualityIntelligenceExportRow, applyQualityIntelligenceRetention, createInMemoryQualityIntelligenceLocalStore, createNodeQualityIntelligenceLocalStore, deleteQualityIntelligenceRun, enforceQualityIntelligenceRetentionPolicy, getQualityIntelligenceRetentionProfile, listQualityIntelligenceRuns, loadQualityIntelligenceRun, quarantineCorruptQualityIntelligenceManifest, recordQualityIntelligenceRun, recordQualityIntelligenceCandidates, loadQualityIntelligenceCandidates, deleteQualityIntelligenceCandidates, applyQualityIntelligenceCandidateEdit, QUALITY_INTELLIGENCE_CANDIDATES_SCHEMA_VERSION, createNodeContainedJsonArtifactStore, redactQualityIntelligenceEvidence, snapshotQualityIntelligenceRunsForRecovery, validateQualityIntelligenceEvidenceManifest, FIGMA_SNAPSHOT_SCHEMA_VERSION, validateFigmaSnapshotRecord, createNodeFigmaSnapshotStore, enforceFigmaSnapshotRetention, DEFAULT_FIGMA_SNAPSHOT_MAX_RECORDS, } from "./qualityIntelligence/index.js";
30
+ // PromptEnhancement sub-module (Epic #1307, Issue #1313; ADR-0044 §1/§5). Same dual surface as the
31
+ // QualityIntelligence module: a `PromptEnhancement` namespace import plus flat-named re-exports.
32
+ export * as PromptEnhancement from "./promptEnhancement/index.js";
33
+ export { PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION, PE_SUBDIR, validatePromptEnhancementEvidenceManifest, redactPromptEnhancementEvidence, buildPromptEnhancementEvidenceManifest, createInMemoryPromptEnhancementLocalStore, createNodePromptEnhancementLocalStore, recordPromptEnhancementRun, loadPromptEnhancementRun, listPromptEnhancementRuns, } from "./promptEnhancement/index.js";
34
+ export { EVIDENCE_SCHEMA_VERSION, DEFAULT_RETENTION, } from "./types.js";
@@ -0,0 +1,9 @@
1
+ import { type EvidenceReport } from "./report.js";
2
+ import type { EvidenceBuildInput, EvidenceDeps, EvidenceManifest, RetentionPolicy } from "./types.js";
3
+ export interface PersistResult {
4
+ readonly manifest: EvidenceManifest;
5
+ readonly location: string;
6
+ readonly report: EvidenceReport;
7
+ }
8
+ export declare function persistEvidence(input: EvidenceBuildInput, deps: EvidenceDeps, retention?: RetentionPolicy): PersistResult;
9
+ //# sourceMappingURL=persist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../src/persist.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EAChB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC;AAOD,wBAAgB,eAAe,CAC7B,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,YAAY,EAClB,SAAS,GAAE,eAAmC,GAC7C,aAAa,CAgBf"}
@@ -0,0 +1,40 @@
1
+ // Top-level orchestration (ADR-0010 D11, D9): build -> deep re-redact (defense in depth) ->
2
+ // store.put -> applyRetention -> buildEvidenceReport. This is the single entry the CLI and the SDK
3
+ // call to write evidence. It is the supported SDK persist entry (the harness is NOT modified — the
4
+ // reuse-unchanged rule is absolute; AC #6 "SDK runs write evidence" is satisfied here and at the CLI
5
+ // layer, not by editing runAgent).
6
+ //
7
+ // Defense-in-depth redaction (coordinator refinement, replacing the ADR's serialized-string pass):
8
+ // the builder is redacted-by-construction (primary), and this layer re-applies the redactor to EVERY
9
+ // STRING LEAF of the assembled manifest object via a generic deep walk BEFORE JSON.stringify. This is
10
+ // idempotent and cannot break JSON structure (a serialized-string re-redaction could miss
11
+ // JSON-escaped secrets and risk corrupting the document). It catches a secret smuggled in through a
12
+ // verbatim-embedded summary (context/verification) that the builder does not itself redact.
13
+ import { isAbsolute, resolve } from "node:path";
14
+ import { buildEvidenceManifest } from "./build.js";
15
+ import { createAuditRedactor, deepRedactStrings } from "./redaction.js";
16
+ import { buildEvidenceReport } from "./report.js";
17
+ import { applyRetention } from "./retention.js";
18
+ import { createNodeEvidenceStore, resolveEvidenceDir } from "./store.js";
19
+ import { DEFAULT_RETENTION } from "./types.js";
20
+ function defaultEvidenceDir(input, env) {
21
+ const configured = resolveEvidenceDir(undefined, env);
22
+ return isAbsolute(configured) ? configured : resolve(input.manifest.workingDirectory, configured);
23
+ }
24
+ export function persistEvidence(input, deps, retention = DEFAULT_RETENTION) {
25
+ const env = deps.env ?? {};
26
+ // The builder is already redacted-by-construction (incl. the deep-redact of embedded summaries);
27
+ // re-apply the redactor over every string leaf here as IDEMPOTENT defense in depth, so a builder
28
+ // bug that missed a field still cannot persist a secret.
29
+ const manifest = buildEvidenceManifest(input, deps);
30
+ const redact = createAuditRedactor(input.redaction ?? {}, env);
31
+ const safeManifest = deepRedactStrings(manifest, redact);
32
+ const json = JSON.stringify(safeManifest, null, 2);
33
+ // C5/AC#6: with no explicit store, persist to the predictable local node store (resolved dir incl.
34
+ // KEIKO_EVIDENCE_DIR), NOT an in-memory store that would silently discard the evidence. Tests
35
+ // inject createInMemoryEvidenceStore explicitly so they never write to the repository tree.
36
+ const store = deps.store ?? createNodeEvidenceStore(defaultEvidenceDir(input, deps.env));
37
+ const location = store.put(safeManifest.run.runId, json);
38
+ applyRetention(store, retention);
39
+ return { manifest: safeManifest, location, report: buildEvidenceReport(safeManifest, location) };
40
+ }
@@ -0,0 +1,7 @@
1
+ export { PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION, validatePromptEnhancementEvidenceManifest, } from "./manifestSchema.js";
2
+ export type { PromptEnhancementEvidenceStatus, PromptEnhancementRedactionSummary, PromptEnhancementCandidateScoreRow, PromptEnhancementSafetyRecord, PromptEnhancementModelMetadata, PromptEnhancementIntegrityHashes, PromptEnhancementManifestTotals, PromptEnhancementEvidenceManifest, PromptEnhancementSchemaValidationResult, } from "./manifestSchema.js";
3
+ export { redactPromptEnhancementEvidence } from "./redaction.js";
4
+ export type { PromptEnhancementRedactionOptions, PromptEnhancementRedactionResult, } from "./redaction.js";
5
+ export { PE_SUBDIR, buildPromptEnhancementEvidenceManifest, createInMemoryPromptEnhancementLocalStore, createNodePromptEnhancementLocalStore, recordPromptEnhancementRun, loadPromptEnhancementRun, listPromptEnhancementRuns, } from "./store.js";
6
+ export type { PromptEnhancementRecordInput, PromptEnhancementRecordOptions, PromptEnhancementRecordResult, PromptEnhancementLocalStore, PromptEnhancementNodeStoreOptions, PromptEnhancementLoadOptions, } from "./store.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/promptEnhancement/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,0CAA0C,EAC1C,yCAAyC,GAC1C,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,kCAAkC,EAClC,6BAA6B,EAC7B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,iCAAiC,EACjC,uCAAuC,GACxC,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EACV,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,SAAS,EACT,sCAAsC,EACtC,yCAAyC,EACzC,qCAAqC,EACrC,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,4BAA4B,EAC5B,8BAA8B,EAC9B,6BAA6B,EAC7B,2BAA2B,EAC3B,iCAAiC,EACjC,4BAA4B,GAC7B,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ // Public barrel for the PromptEnhancement sub-module of `@oscharko-dev/keiko-evidence`
2
+ // (Epic #1307, Issue #1313; ADR-0044 §1/§5). Re-exports the manifest schema, the redactor, and the
3
+ // local-store + builder API. The package barrel re-exports this directory under the
4
+ // `PromptEnhancement` namespace plus flat-named symbols, mirroring the QualityIntelligence layout.
5
+ // ─── Manifest schema ─────────────────────────────────────────────────────────────────
6
+ export { PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION, validatePromptEnhancementEvidenceManifest, } from "./manifestSchema.js";
7
+ // ─── Redaction ───────────────────────────────────────────────────────────────────────
8
+ export { redactPromptEnhancementEvidence } from "./redaction.js";
9
+ // ─── Local-state store + builder + CRUD ────────────────────────────────────────────
10
+ export { PE_SUBDIR, buildPromptEnhancementEvidenceManifest, createInMemoryPromptEnhancementLocalStore, createNodePromptEnhancementLocalStore, recordPromptEnhancementRun, loadPromptEnhancementRun, listPromptEnhancementRuns, } from "./store.js";
@@ -0,0 +1,71 @@
1
+ import type { GroundingDirective, LeastPrivilegeConstraint, PromptSafetyDecision, PromptSafetyVerificationStatus, PromptSafetyViolationCode } from "@oscharko-dev/keiko-contracts";
2
+ export declare const PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION: 2;
3
+ export type PromptEnhancementEvidenceStatus = "validated" | "requires-human-review" | "rejected";
4
+ export interface PromptEnhancementRedactionSummary {
5
+ readonly totalStringsScanned: number;
6
+ readonly stringsRedacted: number;
7
+ readonly patternsMatched: Readonly<Record<string, number>>;
8
+ }
9
+ export interface PromptEnhancementCandidateScoreRow {
10
+ readonly candidateId: string;
11
+ readonly profile: string;
12
+ readonly aggregateScore: number;
13
+ readonly estimatedTokens: number;
14
+ readonly selected: boolean;
15
+ }
16
+ export interface PromptEnhancementSafetyRecord {
17
+ readonly decision: PromptSafetyDecision;
18
+ readonly verificationStatus: PromptSafetyVerificationStatus;
19
+ readonly requiresHumanReview: boolean;
20
+ readonly findingCodes: readonly PromptSafetyViolationCode[];
21
+ readonly leastPrivilege: readonly LeastPrivilegeConstraint[];
22
+ }
23
+ export interface PromptEnhancementModelMetadata {
24
+ readonly deterministic: boolean;
25
+ readonly modelId?: string;
26
+ readonly profile?: string;
27
+ }
28
+ export interface PromptEnhancementIntegrityHashes {
29
+ readonly enhancedOutput: string;
30
+ readonly appliedRules: string;
31
+ readonly candidateScores: string;
32
+ readonly record: string;
33
+ }
34
+ export interface PromptEnhancementManifestTotals {
35
+ readonly candidateScores: number;
36
+ readonly appliedSafetyRules: number;
37
+ readonly assumptions: number;
38
+ readonly safetyFindings: number;
39
+ }
40
+ export interface PromptEnhancementEvidenceManifest {
41
+ readonly peEvidenceSchemaVersion: typeof PROMPT_ENHANCEMENT_EVIDENCE_SCHEMA_VERSION;
42
+ readonly runId: string;
43
+ readonly recordedAt: string;
44
+ readonly requestId: string;
45
+ readonly status: PromptEnhancementEvidenceStatus;
46
+ readonly inputRedactedFingerprintSha256: string;
47
+ readonly inputExcerptRedacted: string;
48
+ readonly enhancedPromptId: string;
49
+ readonly enhancedPromptTextRedacted: string;
50
+ readonly appliedSafetyRules: readonly string[];
51
+ readonly appliedGroundingDirectives: readonly GroundingDirective[];
52
+ readonly assumptions: readonly string[];
53
+ readonly candidateScores: readonly PromptEnhancementCandidateScoreRow[];
54
+ readonly safety: PromptEnhancementSafetyRecord;
55
+ readonly modelMetadata: PromptEnhancementModelMetadata;
56
+ readonly redactionSummary: PromptEnhancementRedactionSummary;
57
+ readonly integrityHashes: PromptEnhancementIntegrityHashes;
58
+ readonly totals: PromptEnhancementManifestTotals;
59
+ }
60
+ export interface PromptEnhancementSchemaValidationResult {
61
+ readonly ok: boolean;
62
+ readonly reason: string | undefined;
63
+ }
64
+ /**
65
+ * Strict-schema gate for a deserialised Prompt Enhancement evidence record. Validates the
66
+ * schema-version literal, the closed set of top-level keys, and the status enum. Counts/integrity
67
+ * correctness is orthogonally enforced by the builder before persist and re-checked on read by the
68
+ * store.
69
+ */
70
+ export declare function validatePromptEnhancementEvidenceManifest(value: unknown): PromptEnhancementSchemaValidationResult;
71
+ //# sourceMappingURL=manifestSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifestSchema.d.ts","sourceRoot":"","sources":["../../src/promptEnhancement/manifestSchema.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,8BAA8B,EAC9B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AASvC,eAAO,MAAM,0CAA0C,EAAG,CAAU,CAAC;AAGrE,MAAM,MAAM,+BAA+B,GAAG,WAAW,GAAG,uBAAuB,GAAG,UAAU,CAAC;AA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