@klickd/core 4.0.0-preview.1 → 4.0.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 CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Official JavaScript/TypeScript library for reading and writing `.klickd` portable AI context files.
4
4
 
5
- **One soul. Any model. Any body.**
5
+ **One soul. Any model. Any agent.** — open-source security and continuity layer for every actor in AI.
6
6
 
7
7
  Official page for the open `.klickd` format → **[klickd.app/klickdskill](https://klickd.app/klickdskill)**
8
8
 
9
9
  [![npm version](https://img.shields.io/npm/v/@klickd/core)](https://www.npmjs.com/package/@klickd/core)
10
10
  [![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-lightgrey.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
11
- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.20320480.svg)](https://doi.org/10.5281/zenodo.20320480)
11
+ [![DOI (v4.0.0)](https://zenodo.org/badge/DOI/10.5281/zenodo.20383133.svg)](https://doi.org/10.5281/zenodo.20383133)
12
12
 
13
13
  ---
14
14
 
@@ -144,12 +144,12 @@ See `SPEC.md §33` and `examples/v4-preview/` for preview-track details.
144
144
  - Format page: [klickd.app/klickdskill](https://klickd.app/klickdskill)
145
145
  - Specification: [SPEC.md](https://github.com/Davincc77/klickdskill/blob/main/SPEC.md)
146
146
  - Repository: [github.com/Davincc77/klickdskill](https://github.com/Davincc77/klickdskill)
147
- - DOI: [10.5281/zenodo.20320480](https://doi.org/10.5281/zenodo.20320480) (v3.5) · concept DOI (all versions): [10.5281/zenodo.20262530](https://doi.org/10.5281/zenodo.20262530)
148
- - Homepage: [klickd.app](https://klickd.app)
147
+ - DOI: [10.5281/zenodo.20383133](https://doi.org/10.5281/zenodo.20383133) (v4.0.0) · concept DOI (all versions): [10.5281/zenodo.20262530](https://doi.org/10.5281/zenodo.20262530)
148
+ - Homepage: [klickd.app/klickdskill](https://klickd.app/klickdskill)
149
149
 
150
150
  ---
151
151
 
152
152
  ## License
153
153
 
154
154
  [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) — Public Domain Dedication.
155
- Author: Vince C. (Luxlearn, Luxembourg)
155
+ Author: Vincenzo Cirilli (.klickd / klickd.app, Luxembourg)
package/dist/index.cjs CHANGED
@@ -32,8 +32,15 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  HTTP_STATUS: () => HTTP_STATUS,
34
34
  KlickdError: () => KlickdError,
35
+ getBundledSchema: () => getBundledSchema,
36
+ listBundledSchemas: () => listBundledSchemas,
35
37
  loadKlickd: () => loadKlickd,
36
- saveKlickd: () => saveKlickd
38
+ migratePayload: () => migratePayload,
39
+ migratePayloadIterWarnings: () => migratePayloadIterWarnings,
40
+ needsMigration: () => needsMigration,
41
+ saveKlickd: () => saveKlickd,
42
+ validate: () => validate,
43
+ validateIterErrors: () => validateIterErrors
37
44
  });
38
45
  module.exports = __toCommonJS(index_exports);
39
46
 
@@ -321,10 +328,265 @@ async function loadKlickd(input, options = {}) {
321
328
  }
322
329
  return payload;
323
330
  }
331
+
332
+ // src/validate.ts
333
+ var import_klickd_payload_v4_schema = __toESM(require("./klickd-payload-v4.schema-7UPTEJOY.json"), 1);
334
+ var import_klickd_payload_v4_preview_schema = __toESM(require("./klickd-payload-v4-preview.schema-W7RY72VP.json"), 1);
335
+ var import_klickd_v4_schema = __toESM(require("./klickd-v4.schema-ZZGRYTLY.json"), 1);
336
+ var import_klickd_v4_preview_schema = __toESM(require("./klickd-v4-preview.schema-QHITWMK6.json"), 1);
337
+ var SCHEMAS = {
338
+ "payload-strict": import_klickd_payload_v4_schema.default,
339
+ "payload-preview": import_klickd_payload_v4_preview_schema.default,
340
+ "unified-strict": import_klickd_v4_schema.default,
341
+ "unified-preview": import_klickd_v4_preview_schema.default
342
+ };
343
+ function getBundledSchema(key) {
344
+ const s = SCHEMAS[key];
345
+ if (!s) {
346
+ throw new Error(`Unknown schema key: ${String(key)}`);
347
+ }
348
+ return JSON.parse(JSON.stringify(s));
349
+ }
350
+ function listBundledSchemas() {
351
+ return Object.keys(SCHEMAS);
352
+ }
353
+ var ajvBundle = null;
354
+ async function getAjv() {
355
+ if (ajvBundle) return ajvBundle;
356
+ let AjvCtor;
357
+ try {
358
+ const mod = await import("ajv/dist/2020.js");
359
+ AjvCtor = mod.default ?? mod;
360
+ } catch (e) {
361
+ throw new KlickdError(
362
+ "KLICKD_E_SCHEMA",
363
+ "validate() requires the optional 'ajv' dependency (>=8.12, Draft 2020-12). Install it with: npm install ajv",
364
+ HTTP_STATUS["KLICKD_E_SCHEMA"]
365
+ );
366
+ }
367
+ const ajv = new AjvCtor({ allErrors: true, strict: false, validateFormats: false });
368
+ for (const key of listBundledSchemas()) {
369
+ ajv.addSchema(SCHEMAS[key], `klickd:${key}`);
370
+ }
371
+ const validators = /* @__PURE__ */ new Map();
372
+ for (const key of listBundledSchemas()) {
373
+ validators.set(key, ajv.compile(SCHEMAS[key]));
374
+ }
375
+ ajvBundle = { validators };
376
+ return ajvBundle;
377
+ }
378
+ function keyFor(target, strict) {
379
+ return `${target}-${strict ? "strict" : "preview"}`;
380
+ }
381
+ function formatPath(instancePath) {
382
+ if (!instancePath || instancePath === "") return "<root>";
383
+ return instancePath.replace(/^\//, "");
384
+ }
385
+ async function validate(payload, options = {}) {
386
+ const strict = options.strict ?? true;
387
+ const target = options.target ?? "payload";
388
+ if (target !== "payload" && target !== "unified") {
389
+ throw new Error(`target must be 'payload' or 'unified', got ${String(target)}`);
390
+ }
391
+ const { validators } = await getAjv();
392
+ const validator = validators.get(keyFor(target, strict));
393
+ if (!validator) {
394
+ throw new Error(`No bundled validator for ${target}-${strict ? "strict" : "preview"}`);
395
+ }
396
+ if (validator(payload)) return;
397
+ const errors = validator.errors ?? [];
398
+ const summary = errors.slice(0, 8).map((e) => `${formatPath(e.instancePath)}: ${(e.message ?? "").slice(0, 200)}`);
399
+ const extra = errors.length > 8 ? ` (+${errors.length - 8} more)` : "";
400
+ throw new KlickdError(
401
+ "KLICKD_E_SCHEMA",
402
+ `v4 ${strict ? "strict" : "preview"} ${target} validation failed${extra}: ${summary.join(" | ")}`,
403
+ HTTP_STATUS["KLICKD_E_SCHEMA"]
404
+ );
405
+ }
406
+ async function validateIterErrors(payload, options = {}) {
407
+ const strict = options.strict ?? true;
408
+ const target = options.target ?? "payload";
409
+ if (target !== "payload" && target !== "unified") {
410
+ throw new Error(`target must be 'payload' or 'unified', got ${String(target)}`);
411
+ }
412
+ const { validators } = await getAjv();
413
+ const validator = validators.get(keyFor(target, strict));
414
+ if (!validator) {
415
+ throw new Error(`No bundled validator for ${target}-${strict ? "strict" : "preview"}`);
416
+ }
417
+ if (validator(payload)) return [];
418
+ return (validator.errors ?? []).map((e) => ({
419
+ path: formatPath(e.instancePath),
420
+ message: e.message ?? ""
421
+ }));
422
+ }
423
+
424
+ // src/migrate.ts
425
+ var V3_SCHEMA_VERSIONS = /* @__PURE__ */ new Set([
426
+ "3.0",
427
+ "3.1",
428
+ "3.2",
429
+ "3.3",
430
+ "3.4",
431
+ "3.5"
432
+ ]);
433
+ var V4_SCHEMA_VERSIONS = /* @__PURE__ */ new Set(["4.0", "4.0.0-preview.1"]);
434
+ var RESERVED_PROFILE_KINDS = /* @__PURE__ */ new Set([
435
+ "learner",
436
+ "agent",
437
+ "team",
438
+ "robot",
439
+ "creator"
440
+ ]);
441
+ function isPlainObject(value) {
442
+ return typeof value === "object" && value !== null && !Array.isArray(value);
443
+ }
444
+ function utcNowIso() {
445
+ const now = /* @__PURE__ */ new Date();
446
+ const pad = (n) => String(n).padStart(2, "0");
447
+ return `${now.getUTCFullYear()}-${pad(now.getUTCMonth() + 1)}-${pad(now.getUTCDate())}T${pad(now.getUTCHours())}:${pad(now.getUTCMinutes())}:${pad(now.getUTCSeconds())}Z`;
448
+ }
449
+ function deepClone(value) {
450
+ return structuredClone(value);
451
+ }
452
+ function needsMigration(payload) {
453
+ if (!isPlainObject(payload)) return false;
454
+ const ver = payload["payload_schema_version"];
455
+ if (ver === void 0 || ver === null) return true;
456
+ if (typeof ver !== "string") return false;
457
+ if (V4_SCHEMA_VERSIONS.has(ver)) return false;
458
+ if (V3_SCHEMA_VERSIONS.has(ver)) return true;
459
+ return false;
460
+ }
461
+ function migratePayload(payload, options = {}) {
462
+ if (!isPlainObject(payload)) {
463
+ throw new KlickdError(
464
+ "KLICKD_E_SCHEMA",
465
+ `migratePayload requires a plain object payload; got ${typeof payload}`,
466
+ HTTP_STATUS["KLICKD_E_SCHEMA"]
467
+ );
468
+ }
469
+ const incomingVersion = payload["payload_schema_version"];
470
+ if (incomingVersion !== void 0 && typeof incomingVersion === "string" && !V3_SCHEMA_VERSIONS.has(incomingVersion) && !V4_SCHEMA_VERSIONS.has(incomingVersion)) {
471
+ throw new KlickdError(
472
+ "KLICKD_E_SCHEMA",
473
+ `migratePayload does not recognize payload_schema_version=${JSON.stringify(incomingVersion)}; expected v3.x (3.0..3.5) or v4 (4.0 / 4.0.0-preview.1)`,
474
+ HTTP_STATUS["KLICKD_E_SCHEMA"]
475
+ );
476
+ }
477
+ const out = deepClone(payload);
478
+ const {
479
+ sourceVersion,
480
+ migratedAt,
481
+ profileKind = "learner",
482
+ migrationReportRef,
483
+ backupRef
484
+ } = options;
485
+ if (typeof incomingVersion === "string" && V4_SCHEMA_VERSIONS.has(incomingVersion)) {
486
+ if (migrationReportRef === void 0 && backupRef === void 0) {
487
+ return out;
488
+ }
489
+ const existing = isPlainObject(out["migration"]) ? out["migration"] : {};
490
+ if (migrationReportRef !== void 0) {
491
+ existing["migration_report_ref"] = migrationReportRef;
492
+ }
493
+ if (backupRef !== void 0) {
494
+ existing["backup_ref"] = backupRef;
495
+ }
496
+ if (existing["source_version"] === void 0) {
497
+ existing["source_version"] = incomingVersion;
498
+ }
499
+ existing["migrated_at"] = migratedAt ?? utcNowIso();
500
+ out["migration"] = existing;
501
+ return out;
502
+ }
503
+ out["payload_schema_version"] = "4.0";
504
+ if (out["profile_kind"] === void 0) {
505
+ out["profile_kind"] = profileKind;
506
+ }
507
+ const migrationBlock = {
508
+ source_version: sourceVersion ?? (typeof incomingVersion === "string" ? incomingVersion : "3.x"),
509
+ migrated_at: migratedAt ?? utcNowIso()
510
+ };
511
+ if (migrationReportRef !== void 0) {
512
+ migrationBlock["migration_report_ref"] = migrationReportRef;
513
+ }
514
+ if (backupRef !== void 0) {
515
+ migrationBlock["backup_ref"] = backupRef;
516
+ }
517
+ out["migration"] = migrationBlock;
518
+ return out;
519
+ }
520
+ function migratePayloadIterWarnings(payload) {
521
+ const warnings = [];
522
+ if (!isPlainObject(payload)) {
523
+ warnings.push({ path: "<root>", message: "payload is not a JSON object" });
524
+ return warnings;
525
+ }
526
+ const ver = payload["payload_schema_version"];
527
+ if (ver === void 0) {
528
+ if (payload["domain_schema_version"] === void 0) {
529
+ warnings.push({
530
+ path: "<root>",
531
+ message: "no payload_schema_version and no domain_schema_version; pin sourceVersion explicitly when migrating"
532
+ });
533
+ }
534
+ } else if (typeof ver === "string" && !V3_SCHEMA_VERSIONS.has(ver) && !V4_SCHEMA_VERSIONS.has(ver)) {
535
+ warnings.push({
536
+ path: "/payload_schema_version",
537
+ message: `unknown payload_schema_version ${JSON.stringify(ver)}; migrator will refuse`
538
+ });
539
+ }
540
+ const ctx = payload["context"];
541
+ if (isPlainObject(ctx)) {
542
+ const decisions = ctx["decisions_locked"];
543
+ if (Array.isArray(decisions)) {
544
+ decisions.forEach((d, i) => {
545
+ if (typeof d === "string" && d.length > 1024) {
546
+ warnings.push({
547
+ path: `/context/decisions_locked/${i}`,
548
+ message: `entry exceeds 1024 chars (${d.length}); some readers will truncate`
549
+ });
550
+ }
551
+ });
552
+ }
553
+ }
554
+ const ethics = payload["ethics"];
555
+ const veto = payload["human_veto_policy"];
556
+ if (isPlainObject(ethics) && isPlainObject(veto)) {
557
+ const locked = ethics["locked_actions"];
558
+ const appliesTo = veto["applies_to"];
559
+ if (Array.isArray(locked) && Array.isArray(appliesTo)) {
560
+ const lockedSet = new Set(locked.filter((x) => typeof x === "string"));
561
+ const overlap = appliesTo.filter((x) => typeof x === "string" && lockedSet.has(x)).sort();
562
+ if (overlap.length > 0) {
563
+ warnings.push({
564
+ path: "/human_veto_policy/applies_to",
565
+ message: "overlaps with /ethics/locked_actions: " + overlap.map((x) => JSON.stringify(x)).join(", ")
566
+ });
567
+ }
568
+ }
569
+ }
570
+ const pk = payload["profile_kind"];
571
+ if (typeof pk === "string" && !RESERVED_PROFILE_KINDS.has(pk)) {
572
+ warnings.push({
573
+ path: "/profile_kind",
574
+ message: `non-reserved profile_kind ${JSON.stringify(pk)}; readers MAY treat as extension`
575
+ });
576
+ }
577
+ return warnings;
578
+ }
324
579
  // Annotate the CommonJS export names for ESM import in node:
325
580
  0 && (module.exports = {
326
581
  HTTP_STATUS,
327
582
  KlickdError,
583
+ getBundledSchema,
584
+ listBundledSchemas,
328
585
  loadKlickd,
329
- saveKlickd
586
+ migratePayload,
587
+ migratePayloadIterWarnings,
588
+ needsMigration,
589
+ saveKlickd,
590
+ validate,
591
+ validateIterErrors
330
592
  });
package/dist/index.d.cts CHANGED
@@ -84,9 +84,80 @@ interface KlickdPayload {
84
84
  context?: KlickdContext;
85
85
  knowledge?: KlickdKnowledge;
86
86
  memory?: KlickdMemoryEntry[];
87
+ profile_kind?: string;
88
+ preview?: string;
89
+ onboarding_trigger?: string;
90
+ media_profile?: KlickdMediaProfileV1 | Record<string, unknown> | null;
91
+ verification_gates?: KlickdVerificationGatesV1 | Record<string, KlickdGateLevel> | null;
92
+ human_veto_policy?: KlickdHumanVetoPolicy | null;
93
+ claim_sources?: KlickdClaimSources | null;
94
+ migration?: KlickdMigrationV1 | null;
95
+ risk_thresholds?: Record<string, unknown> | null;
96
+ preflight_checks?: unknown[] | null;
97
+ error_journal?: unknown[] | null;
98
+ verification_artifacts?: unknown[] | null;
99
+ contract_tests?: unknown[] | null;
100
+ success_criteria?: unknown;
101
+ reversibility?: Record<string, unknown> | null;
102
+ blast_radius?: Record<string, unknown> | null;
103
+ context_cost?: Record<string, unknown> | null;
104
+ gaming_profile?: Record<string, unknown> | null;
105
+ deprecated_fields?: Array<Record<string, unknown>> | null;
87
106
  /** Domain extension fields */
88
107
  [key: string]: unknown;
89
108
  }
109
+ type KlickdMediaModality = 'voice' | 'image' | 'document' | 'embedding';
110
+ interface KlickdMediaProfileEntryHash {
111
+ algo: 'blake3';
112
+ value: string;
113
+ }
114
+ interface KlickdMediaProfileEntry {
115
+ id: string;
116
+ modality: KlickdMediaModality;
117
+ hash: KlickdMediaProfileEntryHash;
118
+ label?: string;
119
+ language?: string;
120
+ uri?: string;
121
+ media_type?: string;
122
+ byte_size?: number;
123
+ duration_ms?: number;
124
+ bytes_b64?: string;
125
+ producer?: Record<string, unknown>;
126
+ consent?: Record<string, unknown>;
127
+ }
128
+ interface KlickdMediaProfileV1 {
129
+ version: 1;
130
+ entries: KlickdMediaProfileEntry[];
131
+ }
132
+ type KlickdGateLevel = 'silent' | 'warn' | 'confirm' | 'block' | 'require-owner';
133
+ interface KlickdGateEntry {
134
+ action_class: string;
135
+ level: KlickdGateLevel;
136
+ id?: string;
137
+ reason?: string;
138
+ }
139
+ interface KlickdVerificationGatesV1 {
140
+ version: 1;
141
+ gates: KlickdGateEntry[];
142
+ user_default?: KlickdGateLevel;
143
+ }
144
+ interface KlickdHumanVetoPolicy {
145
+ applies_to?: string[];
146
+ second_party?: string | null;
147
+ min_level?: KlickdGateLevel;
148
+ rationale?: string;
149
+ }
150
+ interface KlickdClaimSources {
151
+ prefer?: string[];
152
+ require_citation_for?: string[];
153
+ records?: Array<Record<string, unknown>>;
154
+ }
155
+ interface KlickdMigrationV1 {
156
+ source_version?: string;
157
+ migrated_at?: string;
158
+ migration_report_ref?: string;
159
+ backup_ref?: string;
160
+ }
90
161
  interface LoadKlickdOptions {
91
162
  passphrase?: string;
92
163
  /** Enable legacy v2.x PBKDF2-SHA256/600k reading. Default: false */
@@ -129,4 +200,94 @@ declare function saveKlickd(payload: KlickdPayload, options: SaveKlickdOptions):
129
200
  */
130
201
  declare function loadKlickd(input: string | Uint8Array, options?: LoadKlickdOptions): Promise<KlickdPayload>;
131
202
 
132
- export { type CipherName, HTTP_STATUS, type KdfName, type KlickdCipher, type KlickdContext, type KlickdDomain, type KlickdEnvelope, KlickdError, type KlickdErrorCode, type KlickdIdentity, type KlickdKdf, type KlickdKdfArgon2id, type KlickdKdfPbkdf2, type KlickdKnowledge, type KlickdMemoryEntry, type KlickdPayload, type LoadKlickdOptions, type MemoryModality, type MemoryRole, type SaveKlickdOptions, loadKlickd, saveKlickd };
203
+ type ValidationTarget = 'payload' | 'unified';
204
+ interface ValidateOptions {
205
+ /** True (default) = v4 GA strict schema; false = permissive preview. */
206
+ strict?: boolean;
207
+ /**
208
+ * "payload" (default) validates the inner payload schema.
209
+ * "unified" validates against the unified envelope+payload schema.
210
+ */
211
+ target?: ValidationTarget;
212
+ }
213
+ interface ValidationIssue {
214
+ /** JSON-pointer-like path ("" / "<root>" when at root). */
215
+ path: string;
216
+ /** Validator-produced human-readable message. */
217
+ message: string;
218
+ }
219
+ declare const SCHEMAS: {
220
+ readonly 'payload-strict': Record<string, unknown>;
221
+ readonly 'payload-preview': Record<string, unknown>;
222
+ readonly 'unified-strict': Record<string, unknown>;
223
+ readonly 'unified-preview': Record<string, unknown>;
224
+ };
225
+ type SchemaKey = keyof typeof SCHEMAS;
226
+ /**
227
+ * Return a parsed copy of one of the four bundled v4 schemas. Provides the
228
+ * same affordance as Python `klickd.validate._load_schema` — useful for
229
+ * tooling that wants to introspect the bundled JSON without reaching back
230
+ * into the repo.
231
+ */
232
+ declare function getBundledSchema(key: SchemaKey): Record<string, unknown>;
233
+ /** List of bundled schema keys (parity with Python `_SCHEMA_FILES`). */
234
+ declare function listBundledSchemas(): SchemaKey[];
235
+ /**
236
+ * Validate a .klickd payload (or unified envelope+payload) against the v4
237
+ * JSON schema bundled with this package. Throws KlickdError(KLICKD_E_SCHEMA)
238
+ * on validation failure or when the optional `ajv` peer is missing.
239
+ *
240
+ * Mirrors Python `klickd.validate`. See packages/pypi/klickd/src/klickd/validate.py.
241
+ */
242
+ declare function validate(payload: unknown, options?: ValidateOptions): Promise<void>;
243
+ /**
244
+ * Non-throwing variant. Returns an array of {path, message} issues — empty
245
+ * when the payload is valid. Mirrors Python `validate_iter_errors`.
246
+ */
247
+ declare function validateIterErrors(payload: unknown, options?: ValidateOptions): Promise<ValidationIssue[]>;
248
+
249
+ interface MigrateOptions {
250
+ /** Override the recorded source_version. Defaults to the input's
251
+ * payload_schema_version, or "3.x" when absent. */
252
+ sourceVersion?: string;
253
+ /** RFC 3339 UTC timestamp (must end with `Z`). Defaults to now().
254
+ * Tests SHOULD pin this for reproducibility. */
255
+ migratedAt?: string;
256
+ /** Default "learner" (v3.x is implicitly "learner"). */
257
+ profileKind?: string;
258
+ /** Optional pointer (URI / path) to a human-authored migration report. */
259
+ migrationReportRef?: string;
260
+ /** Optional pointer to a backup of the pre-migration file. */
261
+ backupRef?: string;
262
+ }
263
+ interface MigrationWarning {
264
+ /** JSON-pointer-ish path; `<root>` for the top-level object. */
265
+ path: string;
266
+ /** Human-readable warning message. */
267
+ message: string;
268
+ }
269
+ type JsonObject = Record<string, unknown>;
270
+ /**
271
+ * Return true iff `payload` is a v3.x payload that should be lifted to v4 GA.
272
+ *
273
+ * Mirrors Python `needs_migration`.
274
+ */
275
+ declare function needsMigration(payload: unknown): boolean;
276
+ /**
277
+ * Lift a v3.x .klickd payload to the v4 GA payload shape.
278
+ *
279
+ * Pure: the input is never mutated; a structurally cloned result is
280
+ * returned. Idempotent on already-v4 inputs (unchanged unless the caller
281
+ * passes pointer refs).
282
+ *
283
+ * Throws `KlickdError(KLICKD_E_SCHEMA)` when the input is not a plain
284
+ * object or carries an unrecognized `payload_schema_version`.
285
+ */
286
+ declare function migratePayload(payload: unknown, options?: MigrateOptions): JsonObject;
287
+ /**
288
+ * Return manual-review warnings without mutating `payload`. Mirrors
289
+ * Python `migrate_payload_iter_warnings`.
290
+ */
291
+ declare function migratePayloadIterWarnings(payload: unknown): MigrationWarning[];
292
+
293
+ export { type CipherName, HTTP_STATUS, type KdfName, type KlickdCipher, type KlickdClaimSources, type KlickdContext, type KlickdDomain, type KlickdEnvelope, KlickdError, type KlickdErrorCode, type KlickdGateEntry, type KlickdGateLevel, type KlickdHumanVetoPolicy, type KlickdIdentity, type KlickdKdf, type KlickdKdfArgon2id, type KlickdKdfPbkdf2, type KlickdKnowledge, type KlickdMediaModality, type KlickdMediaProfileEntry, type KlickdMediaProfileEntryHash, type KlickdMediaProfileV1, type KlickdMemoryEntry, type KlickdMigrationV1, type KlickdPayload, type KlickdVerificationGatesV1, type LoadKlickdOptions, type MemoryModality, type MemoryRole, type MigrateOptions, type MigrationWarning, type SaveKlickdOptions, type ValidateOptions, type ValidationIssue, type ValidationTarget, getBundledSchema, listBundledSchemas, loadKlickd, migratePayload, migratePayloadIterWarnings, needsMigration, saveKlickd, validate, validateIterErrors };
package/dist/index.d.ts CHANGED
@@ -84,9 +84,80 @@ interface KlickdPayload {
84
84
  context?: KlickdContext;
85
85
  knowledge?: KlickdKnowledge;
86
86
  memory?: KlickdMemoryEntry[];
87
+ profile_kind?: string;
88
+ preview?: string;
89
+ onboarding_trigger?: string;
90
+ media_profile?: KlickdMediaProfileV1 | Record<string, unknown> | null;
91
+ verification_gates?: KlickdVerificationGatesV1 | Record<string, KlickdGateLevel> | null;
92
+ human_veto_policy?: KlickdHumanVetoPolicy | null;
93
+ claim_sources?: KlickdClaimSources | null;
94
+ migration?: KlickdMigrationV1 | null;
95
+ risk_thresholds?: Record<string, unknown> | null;
96
+ preflight_checks?: unknown[] | null;
97
+ error_journal?: unknown[] | null;
98
+ verification_artifacts?: unknown[] | null;
99
+ contract_tests?: unknown[] | null;
100
+ success_criteria?: unknown;
101
+ reversibility?: Record<string, unknown> | null;
102
+ blast_radius?: Record<string, unknown> | null;
103
+ context_cost?: Record<string, unknown> | null;
104
+ gaming_profile?: Record<string, unknown> | null;
105
+ deprecated_fields?: Array<Record<string, unknown>> | null;
87
106
  /** Domain extension fields */
88
107
  [key: string]: unknown;
89
108
  }
109
+ type KlickdMediaModality = 'voice' | 'image' | 'document' | 'embedding';
110
+ interface KlickdMediaProfileEntryHash {
111
+ algo: 'blake3';
112
+ value: string;
113
+ }
114
+ interface KlickdMediaProfileEntry {
115
+ id: string;
116
+ modality: KlickdMediaModality;
117
+ hash: KlickdMediaProfileEntryHash;
118
+ label?: string;
119
+ language?: string;
120
+ uri?: string;
121
+ media_type?: string;
122
+ byte_size?: number;
123
+ duration_ms?: number;
124
+ bytes_b64?: string;
125
+ producer?: Record<string, unknown>;
126
+ consent?: Record<string, unknown>;
127
+ }
128
+ interface KlickdMediaProfileV1 {
129
+ version: 1;
130
+ entries: KlickdMediaProfileEntry[];
131
+ }
132
+ type KlickdGateLevel = 'silent' | 'warn' | 'confirm' | 'block' | 'require-owner';
133
+ interface KlickdGateEntry {
134
+ action_class: string;
135
+ level: KlickdGateLevel;
136
+ id?: string;
137
+ reason?: string;
138
+ }
139
+ interface KlickdVerificationGatesV1 {
140
+ version: 1;
141
+ gates: KlickdGateEntry[];
142
+ user_default?: KlickdGateLevel;
143
+ }
144
+ interface KlickdHumanVetoPolicy {
145
+ applies_to?: string[];
146
+ second_party?: string | null;
147
+ min_level?: KlickdGateLevel;
148
+ rationale?: string;
149
+ }
150
+ interface KlickdClaimSources {
151
+ prefer?: string[];
152
+ require_citation_for?: string[];
153
+ records?: Array<Record<string, unknown>>;
154
+ }
155
+ interface KlickdMigrationV1 {
156
+ source_version?: string;
157
+ migrated_at?: string;
158
+ migration_report_ref?: string;
159
+ backup_ref?: string;
160
+ }
90
161
  interface LoadKlickdOptions {
91
162
  passphrase?: string;
92
163
  /** Enable legacy v2.x PBKDF2-SHA256/600k reading. Default: false */
@@ -129,4 +200,94 @@ declare function saveKlickd(payload: KlickdPayload, options: SaveKlickdOptions):
129
200
  */
130
201
  declare function loadKlickd(input: string | Uint8Array, options?: LoadKlickdOptions): Promise<KlickdPayload>;
131
202
 
132
- export { type CipherName, HTTP_STATUS, type KdfName, type KlickdCipher, type KlickdContext, type KlickdDomain, type KlickdEnvelope, KlickdError, type KlickdErrorCode, type KlickdIdentity, type KlickdKdf, type KlickdKdfArgon2id, type KlickdKdfPbkdf2, type KlickdKnowledge, type KlickdMemoryEntry, type KlickdPayload, type LoadKlickdOptions, type MemoryModality, type MemoryRole, type SaveKlickdOptions, loadKlickd, saveKlickd };
203
+ type ValidationTarget = 'payload' | 'unified';
204
+ interface ValidateOptions {
205
+ /** True (default) = v4 GA strict schema; false = permissive preview. */
206
+ strict?: boolean;
207
+ /**
208
+ * "payload" (default) validates the inner payload schema.
209
+ * "unified" validates against the unified envelope+payload schema.
210
+ */
211
+ target?: ValidationTarget;
212
+ }
213
+ interface ValidationIssue {
214
+ /** JSON-pointer-like path ("" / "<root>" when at root). */
215
+ path: string;
216
+ /** Validator-produced human-readable message. */
217
+ message: string;
218
+ }
219
+ declare const SCHEMAS: {
220
+ readonly 'payload-strict': Record<string, unknown>;
221
+ readonly 'payload-preview': Record<string, unknown>;
222
+ readonly 'unified-strict': Record<string, unknown>;
223
+ readonly 'unified-preview': Record<string, unknown>;
224
+ };
225
+ type SchemaKey = keyof typeof SCHEMAS;
226
+ /**
227
+ * Return a parsed copy of one of the four bundled v4 schemas. Provides the
228
+ * same affordance as Python `klickd.validate._load_schema` — useful for
229
+ * tooling that wants to introspect the bundled JSON without reaching back
230
+ * into the repo.
231
+ */
232
+ declare function getBundledSchema(key: SchemaKey): Record<string, unknown>;
233
+ /** List of bundled schema keys (parity with Python `_SCHEMA_FILES`). */
234
+ declare function listBundledSchemas(): SchemaKey[];
235
+ /**
236
+ * Validate a .klickd payload (or unified envelope+payload) against the v4
237
+ * JSON schema bundled with this package. Throws KlickdError(KLICKD_E_SCHEMA)
238
+ * on validation failure or when the optional `ajv` peer is missing.
239
+ *
240
+ * Mirrors Python `klickd.validate`. See packages/pypi/klickd/src/klickd/validate.py.
241
+ */
242
+ declare function validate(payload: unknown, options?: ValidateOptions): Promise<void>;
243
+ /**
244
+ * Non-throwing variant. Returns an array of {path, message} issues — empty
245
+ * when the payload is valid. Mirrors Python `validate_iter_errors`.
246
+ */
247
+ declare function validateIterErrors(payload: unknown, options?: ValidateOptions): Promise<ValidationIssue[]>;
248
+
249
+ interface MigrateOptions {
250
+ /** Override the recorded source_version. Defaults to the input's
251
+ * payload_schema_version, or "3.x" when absent. */
252
+ sourceVersion?: string;
253
+ /** RFC 3339 UTC timestamp (must end with `Z`). Defaults to now().
254
+ * Tests SHOULD pin this for reproducibility. */
255
+ migratedAt?: string;
256
+ /** Default "learner" (v3.x is implicitly "learner"). */
257
+ profileKind?: string;
258
+ /** Optional pointer (URI / path) to a human-authored migration report. */
259
+ migrationReportRef?: string;
260
+ /** Optional pointer to a backup of the pre-migration file. */
261
+ backupRef?: string;
262
+ }
263
+ interface MigrationWarning {
264
+ /** JSON-pointer-ish path; `<root>` for the top-level object. */
265
+ path: string;
266
+ /** Human-readable warning message. */
267
+ message: string;
268
+ }
269
+ type JsonObject = Record<string, unknown>;
270
+ /**
271
+ * Return true iff `payload` is a v3.x payload that should be lifted to v4 GA.
272
+ *
273
+ * Mirrors Python `needs_migration`.
274
+ */
275
+ declare function needsMigration(payload: unknown): boolean;
276
+ /**
277
+ * Lift a v3.x .klickd payload to the v4 GA payload shape.
278
+ *
279
+ * Pure: the input is never mutated; a structurally cloned result is
280
+ * returned. Idempotent on already-v4 inputs (unchanged unless the caller
281
+ * passes pointer refs).
282
+ *
283
+ * Throws `KlickdError(KLICKD_E_SCHEMA)` when the input is not a plain
284
+ * object or carries an unrecognized `payload_schema_version`.
285
+ */
286
+ declare function migratePayload(payload: unknown, options?: MigrateOptions): JsonObject;
287
+ /**
288
+ * Return manual-review warnings without mutating `payload`. Mirrors
289
+ * Python `migrate_payload_iter_warnings`.
290
+ */
291
+ declare function migratePayloadIterWarnings(payload: unknown): MigrationWarning[];
292
+
293
+ export { type CipherName, HTTP_STATUS, type KdfName, type KlickdCipher, type KlickdClaimSources, type KlickdContext, type KlickdDomain, type KlickdEnvelope, KlickdError, type KlickdErrorCode, type KlickdGateEntry, type KlickdGateLevel, type KlickdHumanVetoPolicy, type KlickdIdentity, type KlickdKdf, type KlickdKdfArgon2id, type KlickdKdfPbkdf2, type KlickdKnowledge, type KlickdMediaModality, type KlickdMediaProfileEntry, type KlickdMediaProfileEntryHash, type KlickdMediaProfileV1, type KlickdMemoryEntry, type KlickdMigrationV1, type KlickdPayload, type KlickdVerificationGatesV1, type LoadKlickdOptions, type MemoryModality, type MemoryRole, type MigrateOptions, type MigrationWarning, type SaveKlickdOptions, type ValidateOptions, type ValidationIssue, type ValidationTarget, getBundledSchema, listBundledSchemas, loadKlickd, migratePayload, migratePayloadIterWarnings, needsMigration, saveKlickd, validate, validateIterErrors };