latticesql 0.5.3 → 0.5.5

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/dist/cli.js CHANGED
@@ -1172,7 +1172,6 @@ var Lattice = class {
1172
1172
  return this;
1173
1173
  }
1174
1174
  defineEntityContext(table, def) {
1175
- this._assertNotInit("defineEntityContext");
1176
1175
  this._schema.defineEntityContext(table, def);
1177
1176
  return this;
1178
1177
  }
package/dist/index.cjs CHANGED
@@ -30,9 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ DEFAULT_ENTRY_TYPES: () => DEFAULT_ENTRY_TYPES,
34
+ DEFAULT_TYPE_ALIASES: () => DEFAULT_TYPE_ALIASES,
33
35
  Lattice: () => Lattice,
34
36
  READ_ONLY_HEADER: () => READ_ONLY_HEADER,
35
37
  applyWriteEntry: () => applyWriteEntry,
38
+ createReadOnlyHeader: () => createReadOnlyHeader,
36
39
  generateEntryId: () => generateEntryId,
37
40
  generateWriteEntryId: () => generateWriteEntryId,
38
41
  manifestPath: () => manifestPath,
@@ -1132,7 +1135,6 @@ var Lattice = class {
1132
1135
  return this;
1133
1136
  }
1134
1137
  defineEntityContext(table, def) {
1135
- this._assertNotInit("defineEntityContext");
1136
1138
  this._schema.defineEntityContext(table, def);
1137
1139
  return this;
1138
1140
  }
@@ -1635,7 +1637,7 @@ function parseBlock(block) {
1635
1637
 
1636
1638
  // src/session/entries.ts
1637
1639
  var import_node_crypto4 = require("crypto");
1638
- var VALID_TYPES = /* @__PURE__ */ new Set([
1640
+ var DEFAULT_ENTRY_TYPES = /* @__PURE__ */ new Set([
1639
1641
  "event",
1640
1642
  "learning",
1641
1643
  "status",
@@ -1645,7 +1647,7 @@ var VALID_TYPES = /* @__PURE__ */ new Set([
1645
1647
  "handoff",
1646
1648
  "write"
1647
1649
  ]);
1648
- var TYPE_ALIASES = {
1650
+ var DEFAULT_TYPE_ALIASES = {
1649
1651
  task_completion: "event",
1650
1652
  completion: "event",
1651
1653
  heartbeat: "status",
@@ -1655,7 +1657,7 @@ var TYPE_ALIASES = {
1655
1657
  note: "event"
1656
1658
  };
1657
1659
  var FIELD_NAME_RE2 = /^[a-zA-Z0-9_]+$/;
1658
- function parseSessionMD(content, startOffset = 0) {
1660
+ function parseSessionMD(content, startOffset = 0, options) {
1659
1661
  const entries = [];
1660
1662
  const errors = [];
1661
1663
  const text = content.slice(startOffset);
@@ -1711,7 +1713,7 @@ function parseSessionMD(content, startOffset = 0) {
1711
1713
  }
1712
1714
  const body = bodyLines.join("\n").trim();
1713
1715
  const rawType = headers["type"] ?? "";
1714
- const resolvedType = normalizeType(rawType);
1716
+ const resolvedType = normalizeType(rawType, options);
1715
1717
  if (!resolvedType) {
1716
1718
  errors.push({ line: entryStartLine + 1, message: `Unknown entry type: ${rawType}` });
1717
1719
  continue;
@@ -1761,7 +1763,7 @@ function parseSessionMD(content, startOffset = 0) {
1761
1763
  }
1762
1764
  return { entries, errors, lastOffset: currentByteOffset };
1763
1765
  }
1764
- function parseMarkdownEntries(content, agentName, startOffset = 0) {
1766
+ function parseMarkdownEntries(content, agentName, startOffset = 0, options) {
1765
1767
  const entries = [];
1766
1768
  const errors = [];
1767
1769
  const text = content.slice(startOffset);
@@ -1803,7 +1805,7 @@ function parseMarkdownEntries(content, agentName, startOffset = 0) {
1803
1805
  continue;
1804
1806
  }
1805
1807
  const rawType = bodyType ?? start.headingType ?? "event";
1806
- const resolvedType = normalizeType(rawType) ?? "event";
1808
+ const resolvedType = normalizeType(rawType, options) ?? "event";
1807
1809
  const id = generateEntryId(start.timestamp, agentName, body);
1808
1810
  entries.push({
1809
1811
  id,
@@ -1826,13 +1828,25 @@ function validateEntryId(id, body) {
1826
1828
  const expectedHash = (0, import_node_crypto4.createHash)("sha256").update(body).digest("hex").slice(0, 6);
1827
1829
  return hash === expectedHash;
1828
1830
  }
1829
- function normalizeType(raw) {
1831
+ function normalizeType(raw, options) {
1830
1832
  const lower = raw.toLowerCase().trim();
1831
- if (VALID_TYPES.has(lower)) return lower;
1832
- const normalized = lower.replace(/-/g, "_");
1833
- if (TYPE_ALIASES[normalized]) return TYPE_ALIASES[normalized];
1834
- for (const alias of Object.keys(TYPE_ALIASES)) {
1835
- if (normalized.startsWith(alias)) return TYPE_ALIASES[alias];
1833
+ if (!lower) return null;
1834
+ const validTypes = options?.validTypes === void 0 ? DEFAULT_ENTRY_TYPES : options.validTypes;
1835
+ const aliases = options?.typeAliases === void 0 ? DEFAULT_TYPE_ALIASES : options.typeAliases;
1836
+ if (validTypes === null) {
1837
+ if (aliases) {
1838
+ const normalized = lower.replace(/-/g, "_");
1839
+ if (aliases[normalized]) return aliases[normalized];
1840
+ }
1841
+ return lower;
1842
+ }
1843
+ if (validTypes.has(lower)) return lower;
1844
+ if (aliases) {
1845
+ const normalized = lower.replace(/-/g, "_");
1846
+ if (aliases[normalized]) return aliases[normalized];
1847
+ for (const alias of Object.keys(aliases)) {
1848
+ if (normalized.startsWith(alias)) return aliases[alias];
1849
+ }
1836
1850
  }
1837
1851
  return null;
1838
1852
  }
@@ -1896,17 +1910,25 @@ function applyWriteEntry(db, entry) {
1896
1910
  }
1897
1911
 
1898
1912
  // src/session/constants.ts
1899
- var READ_ONLY_HEADER = `<!-- READ ONLY \u2014 generated by lattice-sync. Do not edit directly.
1913
+ function createReadOnlyHeader(options) {
1914
+ const generator = options?.generator ?? "Lattice";
1915
+ const docsRef = options?.docsRef ?? "the Lattice documentation";
1916
+ return `<!-- READ ONLY \u2014 generated by ${generator}. Do not edit directly.
1900
1917
  To update data in Lattice: write entries to SESSION.md in this directory.
1901
1918
  Format: type: write | op: create/update/delete | table: <name> | target: <id>
1902
- See agents/shared/SESSION-FORMAT.md for the full spec. -->
1919
+ See ${docsRef} for the SESSION.md format spec. -->
1903
1920
 
1904
1921
  `;
1922
+ }
1923
+ var READ_ONLY_HEADER = createReadOnlyHeader();
1905
1924
  // Annotate the CommonJS export names for ESM import in node:
1906
1925
  0 && (module.exports = {
1926
+ DEFAULT_ENTRY_TYPES,
1927
+ DEFAULT_TYPE_ALIASES,
1907
1928
  Lattice,
1908
1929
  READ_ONLY_HEADER,
1909
1930
  applyWriteEntry,
1931
+ createReadOnlyHeader,
1910
1932
  generateEntryId,
1911
1933
  generateWriteEntryId,
1912
1934
  manifestPath,
package/dist/index.d.cts CHANGED
@@ -896,9 +896,10 @@ declare function generateWriteEntryId(timestamp: string, agentName: string, op:
896
896
  declare function parseSessionWrites(content: string): SessionWriteParseResult;
897
897
 
898
898
  /**
899
- * A single parsed SESSION.md entry. Covers all entry types:
900
- * event, learning, status, correction, discovery, metric, handoff, write.
899
+ * A single parsed SESSION.md entry.
901
900
  *
901
+ * The `type` field holds the resolved entry type (from the built-in set or
902
+ * custom types supplied via {@link SessionParseOptions}).
902
903
  * When `type === 'write'`, the op/table/target/reason/fields fields are set.
903
904
  */
904
905
  interface SessionEntry {
@@ -929,6 +930,39 @@ interface ParseResult {
929
930
  /** Byte offset after the last fully parsed entry — used for incremental parsing. */
930
931
  lastOffset: number;
931
932
  }
933
+ /**
934
+ * Options for {@link parseSessionMD} and {@link parseMarkdownEntries}.
935
+ *
936
+ * All fields are optional — omitting them preserves the default behaviour
937
+ * (built-in type set + built-in aliases), so existing callers are unaffected.
938
+ */
939
+ interface SessionParseOptions {
940
+ /**
941
+ * Set of valid entry type names.
942
+ * - Omit (or `undefined`) → use {@link DEFAULT_ENTRY_TYPES}.
943
+ * - `null` → accept **any** type string without validation.
944
+ * - Provide a custom `Set<string>` to restrict to your own taxonomy.
945
+ */
946
+ validTypes?: Set<string> | null;
947
+ /**
948
+ * Map of non-standard type names to their canonical form.
949
+ * - Omit (or `undefined`) → use {@link DEFAULT_TYPE_ALIASES}.
950
+ * - `null` → disable alias resolution.
951
+ * - Provide a custom `Record<string, string>` for your own aliases.
952
+ */
953
+ typeAliases?: Record<string, string> | null;
954
+ }
955
+ /**
956
+ * Default set of valid entry types shipped with latticesql.
957
+ * Suitable for LLM-agent context systems; override via {@link SessionParseOptions.validTypes}.
958
+ */
959
+ declare const DEFAULT_ENTRY_TYPES: ReadonlySet<string>;
960
+ /**
961
+ * Default type aliases shipped with latticesql.
962
+ * Maps commonly-seen alternative names to their canonical type.
963
+ * Override via {@link SessionParseOptions.typeAliases}.
964
+ */
965
+ declare const DEFAULT_TYPE_ALIASES: Readonly<Record<string, string>>;
932
966
  /**
933
967
  * Parse SESSION.md YAML-delimited entries starting at `startOffset` bytes.
934
968
  *
@@ -942,15 +976,18 @@ interface ParseResult {
942
976
  * Entry body text here.
943
977
  * ===
944
978
  * ```
979
+ *
980
+ * Pass {@link SessionParseOptions} to customise which entry types are accepted
981
+ * and how aliases are resolved. Defaults match the built-in type set.
945
982
  */
946
- declare function parseSessionMD(content: string, startOffset?: number): ParseResult;
983
+ declare function parseSessionMD(content: string, startOffset?: number, options?: SessionParseOptions): ParseResult;
947
984
  /**
948
- * Parse free-form Markdown SESSION.md entries. Agents sometimes write entries
949
- * as `## {timestamp} — {description}` headings rather than YAML blocks.
985
+ * Parse free-form Markdown SESSION.md entries written as
986
+ * `## {timestamp} — {description}` headings rather than YAML blocks.
950
987
  *
951
988
  * Runs alongside `parseSessionMD`; the two parsers are merged by caller.
952
989
  */
953
- declare function parseMarkdownEntries(content: string, agentName: string, startOffset?: number): ParseResult;
990
+ declare function parseMarkdownEntries(content: string, agentName: string, startOffset?: number, options?: SessionParseOptions): ParseResult;
954
991
  /**
955
992
  * Generate a content-addressed entry ID.
956
993
  * Format: `{timestamp}-{agentName}-{6-char-sha256-prefix}`
@@ -988,12 +1025,26 @@ type ApplyWriteResult = {
988
1025
  declare function applyWriteEntry(db: Database.Database, entry: SessionWriteEntry): ApplyWriteResult;
989
1026
 
990
1027
  /**
991
- * Read-only header prepended to all Lattice-generated context files.
1028
+ * Options for {@link createReadOnlyHeader}.
1029
+ */
1030
+ interface ReadOnlyHeaderOptions {
1031
+ /** Name shown as the generator (default: `"Lattice"`). */
1032
+ generator?: string;
1033
+ /** Where to find the SESSION.md format spec (default: `"the Lattice documentation"`). */
1034
+ docsRef?: string;
1035
+ }
1036
+ /**
1037
+ * Build a read-only header for Lattice-generated context files.
1038
+ *
1039
+ * The header tells consumers (human or LLM) that the file is auto-generated
1040
+ * and that writes should go through SESSION.md instead.
1041
+ */
1042
+ declare function createReadOnlyHeader(options?: ReadOnlyHeaderOptions): string;
1043
+ /**
1044
+ * Default read-only header prepended to all Lattice-generated context files.
992
1045
  *
993
- * Directs agents to SESSION.md for writes rather than editing generated files
994
- * directly. Include at the top of every rendered markdown context file so
995
- * agents see it at the start of their context window.
1046
+ * For a customised header, use {@link createReadOnlyHeader} instead.
996
1047
  */
997
- declare const READ_ONLY_HEADER = "<!-- READ ONLY \u2014 generated by lattice-sync. Do not edit directly.\n To update data in Lattice: write entries to SESSION.md in this directory.\n Format: type: write | op: create/update/delete | table: <name> | target: <id>\n See agents/shared/SESSION-FORMAT.md for the full spec. -->\n\n";
1048
+ declare const READ_ONLY_HEADER: string;
998
1049
 
999
- export { type ApplyWriteResult, type AuditEvent, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileSource, type EntityFileSpec, type Filter, type FilterOp, type HasManyRelation, type HasManySource, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type ManyToManySource, type Migration, type MultiTableDefinition, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type Row, type SecurityOptions, type SelfSource, type SessionEntry, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type WatchOptions, type WritebackDefinition, applyWriteEntry, generateEntryId, generateWriteEntryId, manifestPath, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, validateEntryId, writeManifest };
1050
+ export { type ApplyWriteResult, type AuditEvent, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, DEFAULT_ENTRY_TYPES, DEFAULT_TYPE_ALIASES, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileSource, type EntityFileSpec, type Filter, type FilterOp, type HasManyRelation, type HasManySource, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type ManyToManySource, type Migration, type MultiTableDefinition, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReadOnlyHeaderOptions, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type Row, type SecurityOptions, type SelfSource, type SessionEntry, type SessionParseOptions, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type WatchOptions, type WritebackDefinition, applyWriteEntry, createReadOnlyHeader, generateEntryId, generateWriteEntryId, manifestPath, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, validateEntryId, writeManifest };
package/dist/index.d.ts CHANGED
@@ -896,9 +896,10 @@ declare function generateWriteEntryId(timestamp: string, agentName: string, op:
896
896
  declare function parseSessionWrites(content: string): SessionWriteParseResult;
897
897
 
898
898
  /**
899
- * A single parsed SESSION.md entry. Covers all entry types:
900
- * event, learning, status, correction, discovery, metric, handoff, write.
899
+ * A single parsed SESSION.md entry.
901
900
  *
901
+ * The `type` field holds the resolved entry type (from the built-in set or
902
+ * custom types supplied via {@link SessionParseOptions}).
902
903
  * When `type === 'write'`, the op/table/target/reason/fields fields are set.
903
904
  */
904
905
  interface SessionEntry {
@@ -929,6 +930,39 @@ interface ParseResult {
929
930
  /** Byte offset after the last fully parsed entry — used for incremental parsing. */
930
931
  lastOffset: number;
931
932
  }
933
+ /**
934
+ * Options for {@link parseSessionMD} and {@link parseMarkdownEntries}.
935
+ *
936
+ * All fields are optional — omitting them preserves the default behaviour
937
+ * (built-in type set + built-in aliases), so existing callers are unaffected.
938
+ */
939
+ interface SessionParseOptions {
940
+ /**
941
+ * Set of valid entry type names.
942
+ * - Omit (or `undefined`) → use {@link DEFAULT_ENTRY_TYPES}.
943
+ * - `null` → accept **any** type string without validation.
944
+ * - Provide a custom `Set<string>` to restrict to your own taxonomy.
945
+ */
946
+ validTypes?: Set<string> | null;
947
+ /**
948
+ * Map of non-standard type names to their canonical form.
949
+ * - Omit (or `undefined`) → use {@link DEFAULT_TYPE_ALIASES}.
950
+ * - `null` → disable alias resolution.
951
+ * - Provide a custom `Record<string, string>` for your own aliases.
952
+ */
953
+ typeAliases?: Record<string, string> | null;
954
+ }
955
+ /**
956
+ * Default set of valid entry types shipped with latticesql.
957
+ * Suitable for LLM-agent context systems; override via {@link SessionParseOptions.validTypes}.
958
+ */
959
+ declare const DEFAULT_ENTRY_TYPES: ReadonlySet<string>;
960
+ /**
961
+ * Default type aliases shipped with latticesql.
962
+ * Maps commonly-seen alternative names to their canonical type.
963
+ * Override via {@link SessionParseOptions.typeAliases}.
964
+ */
965
+ declare const DEFAULT_TYPE_ALIASES: Readonly<Record<string, string>>;
932
966
  /**
933
967
  * Parse SESSION.md YAML-delimited entries starting at `startOffset` bytes.
934
968
  *
@@ -942,15 +976,18 @@ interface ParseResult {
942
976
  * Entry body text here.
943
977
  * ===
944
978
  * ```
979
+ *
980
+ * Pass {@link SessionParseOptions} to customise which entry types are accepted
981
+ * and how aliases are resolved. Defaults match the built-in type set.
945
982
  */
946
- declare function parseSessionMD(content: string, startOffset?: number): ParseResult;
983
+ declare function parseSessionMD(content: string, startOffset?: number, options?: SessionParseOptions): ParseResult;
947
984
  /**
948
- * Parse free-form Markdown SESSION.md entries. Agents sometimes write entries
949
- * as `## {timestamp} — {description}` headings rather than YAML blocks.
985
+ * Parse free-form Markdown SESSION.md entries written as
986
+ * `## {timestamp} — {description}` headings rather than YAML blocks.
950
987
  *
951
988
  * Runs alongside `parseSessionMD`; the two parsers are merged by caller.
952
989
  */
953
- declare function parseMarkdownEntries(content: string, agentName: string, startOffset?: number): ParseResult;
990
+ declare function parseMarkdownEntries(content: string, agentName: string, startOffset?: number, options?: SessionParseOptions): ParseResult;
954
991
  /**
955
992
  * Generate a content-addressed entry ID.
956
993
  * Format: `{timestamp}-{agentName}-{6-char-sha256-prefix}`
@@ -988,12 +1025,26 @@ type ApplyWriteResult = {
988
1025
  declare function applyWriteEntry(db: Database.Database, entry: SessionWriteEntry): ApplyWriteResult;
989
1026
 
990
1027
  /**
991
- * Read-only header prepended to all Lattice-generated context files.
1028
+ * Options for {@link createReadOnlyHeader}.
1029
+ */
1030
+ interface ReadOnlyHeaderOptions {
1031
+ /** Name shown as the generator (default: `"Lattice"`). */
1032
+ generator?: string;
1033
+ /** Where to find the SESSION.md format spec (default: `"the Lattice documentation"`). */
1034
+ docsRef?: string;
1035
+ }
1036
+ /**
1037
+ * Build a read-only header for Lattice-generated context files.
1038
+ *
1039
+ * The header tells consumers (human or LLM) that the file is auto-generated
1040
+ * and that writes should go through SESSION.md instead.
1041
+ */
1042
+ declare function createReadOnlyHeader(options?: ReadOnlyHeaderOptions): string;
1043
+ /**
1044
+ * Default read-only header prepended to all Lattice-generated context files.
992
1045
  *
993
- * Directs agents to SESSION.md for writes rather than editing generated files
994
- * directly. Include at the top of every rendered markdown context file so
995
- * agents see it at the start of their context window.
1046
+ * For a customised header, use {@link createReadOnlyHeader} instead.
996
1047
  */
997
- declare const READ_ONLY_HEADER = "<!-- READ ONLY \u2014 generated by lattice-sync. Do not edit directly.\n To update data in Lattice: write entries to SESSION.md in this directory.\n Format: type: write | op: create/update/delete | table: <name> | target: <id>\n See agents/shared/SESSION-FORMAT.md for the full spec. -->\n\n";
1048
+ declare const READ_ONLY_HEADER: string;
998
1049
 
999
- export { type ApplyWriteResult, type AuditEvent, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileSource, type EntityFileSpec, type Filter, type FilterOp, type HasManyRelation, type HasManySource, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type ManyToManySource, type Migration, type MultiTableDefinition, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type Row, type SecurityOptions, type SelfSource, type SessionEntry, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type WatchOptions, type WritebackDefinition, applyWriteEntry, generateEntryId, generateWriteEntryId, manifestPath, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, validateEntryId, writeManifest };
1050
+ export { type ApplyWriteResult, type AuditEvent, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, DEFAULT_ENTRY_TYPES, DEFAULT_TYPE_ALIASES, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileSource, type EntityFileSpec, type Filter, type FilterOp, type HasManyRelation, type HasManySource, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type ManyToManySource, type Migration, type MultiTableDefinition, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReadOnlyHeaderOptions, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type Row, type SecurityOptions, type SelfSource, type SessionEntry, type SessionParseOptions, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type WatchOptions, type WritebackDefinition, applyWriteEntry, createReadOnlyHeader, generateEntryId, generateWriteEntryId, manifestPath, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, validateEntryId, writeManifest };
package/dist/index.js CHANGED
@@ -1083,7 +1083,6 @@ var Lattice = class {
1083
1083
  return this;
1084
1084
  }
1085
1085
  defineEntityContext(table, def) {
1086
- this._assertNotInit("defineEntityContext");
1087
1086
  this._schema.defineEntityContext(table, def);
1088
1087
  return this;
1089
1088
  }
@@ -1586,7 +1585,7 @@ function parseBlock(block) {
1586
1585
 
1587
1586
  // src/session/entries.ts
1588
1587
  import { createHash as createHash3 } from "crypto";
1589
- var VALID_TYPES = /* @__PURE__ */ new Set([
1588
+ var DEFAULT_ENTRY_TYPES = /* @__PURE__ */ new Set([
1590
1589
  "event",
1591
1590
  "learning",
1592
1591
  "status",
@@ -1596,7 +1595,7 @@ var VALID_TYPES = /* @__PURE__ */ new Set([
1596
1595
  "handoff",
1597
1596
  "write"
1598
1597
  ]);
1599
- var TYPE_ALIASES = {
1598
+ var DEFAULT_TYPE_ALIASES = {
1600
1599
  task_completion: "event",
1601
1600
  completion: "event",
1602
1601
  heartbeat: "status",
@@ -1606,7 +1605,7 @@ var TYPE_ALIASES = {
1606
1605
  note: "event"
1607
1606
  };
1608
1607
  var FIELD_NAME_RE2 = /^[a-zA-Z0-9_]+$/;
1609
- function parseSessionMD(content, startOffset = 0) {
1608
+ function parseSessionMD(content, startOffset = 0, options) {
1610
1609
  const entries = [];
1611
1610
  const errors = [];
1612
1611
  const text = content.slice(startOffset);
@@ -1662,7 +1661,7 @@ function parseSessionMD(content, startOffset = 0) {
1662
1661
  }
1663
1662
  const body = bodyLines.join("\n").trim();
1664
1663
  const rawType = headers["type"] ?? "";
1665
- const resolvedType = normalizeType(rawType);
1664
+ const resolvedType = normalizeType(rawType, options);
1666
1665
  if (!resolvedType) {
1667
1666
  errors.push({ line: entryStartLine + 1, message: `Unknown entry type: ${rawType}` });
1668
1667
  continue;
@@ -1712,7 +1711,7 @@ function parseSessionMD(content, startOffset = 0) {
1712
1711
  }
1713
1712
  return { entries, errors, lastOffset: currentByteOffset };
1714
1713
  }
1715
- function parseMarkdownEntries(content, agentName, startOffset = 0) {
1714
+ function parseMarkdownEntries(content, agentName, startOffset = 0, options) {
1716
1715
  const entries = [];
1717
1716
  const errors = [];
1718
1717
  const text = content.slice(startOffset);
@@ -1754,7 +1753,7 @@ function parseMarkdownEntries(content, agentName, startOffset = 0) {
1754
1753
  continue;
1755
1754
  }
1756
1755
  const rawType = bodyType ?? start.headingType ?? "event";
1757
- const resolvedType = normalizeType(rawType) ?? "event";
1756
+ const resolvedType = normalizeType(rawType, options) ?? "event";
1758
1757
  const id = generateEntryId(start.timestamp, agentName, body);
1759
1758
  entries.push({
1760
1759
  id,
@@ -1777,13 +1776,25 @@ function validateEntryId(id, body) {
1777
1776
  const expectedHash = createHash3("sha256").update(body).digest("hex").slice(0, 6);
1778
1777
  return hash === expectedHash;
1779
1778
  }
1780
- function normalizeType(raw) {
1779
+ function normalizeType(raw, options) {
1781
1780
  const lower = raw.toLowerCase().trim();
1782
- if (VALID_TYPES.has(lower)) return lower;
1783
- const normalized = lower.replace(/-/g, "_");
1784
- if (TYPE_ALIASES[normalized]) return TYPE_ALIASES[normalized];
1785
- for (const alias of Object.keys(TYPE_ALIASES)) {
1786
- if (normalized.startsWith(alias)) return TYPE_ALIASES[alias];
1781
+ if (!lower) return null;
1782
+ const validTypes = options?.validTypes === void 0 ? DEFAULT_ENTRY_TYPES : options.validTypes;
1783
+ const aliases = options?.typeAliases === void 0 ? DEFAULT_TYPE_ALIASES : options.typeAliases;
1784
+ if (validTypes === null) {
1785
+ if (aliases) {
1786
+ const normalized = lower.replace(/-/g, "_");
1787
+ if (aliases[normalized]) return aliases[normalized];
1788
+ }
1789
+ return lower;
1790
+ }
1791
+ if (validTypes.has(lower)) return lower;
1792
+ if (aliases) {
1793
+ const normalized = lower.replace(/-/g, "_");
1794
+ if (aliases[normalized]) return aliases[normalized];
1795
+ for (const alias of Object.keys(aliases)) {
1796
+ if (normalized.startsWith(alias)) return aliases[alias];
1797
+ }
1787
1798
  }
1788
1799
  return null;
1789
1800
  }
@@ -1847,16 +1858,24 @@ function applyWriteEntry(db, entry) {
1847
1858
  }
1848
1859
 
1849
1860
  // src/session/constants.ts
1850
- var READ_ONLY_HEADER = `<!-- READ ONLY \u2014 generated by lattice-sync. Do not edit directly.
1861
+ function createReadOnlyHeader(options) {
1862
+ const generator = options?.generator ?? "Lattice";
1863
+ const docsRef = options?.docsRef ?? "the Lattice documentation";
1864
+ return `<!-- READ ONLY \u2014 generated by ${generator}. Do not edit directly.
1851
1865
  To update data in Lattice: write entries to SESSION.md in this directory.
1852
1866
  Format: type: write | op: create/update/delete | table: <name> | target: <id>
1853
- See agents/shared/SESSION-FORMAT.md for the full spec. -->
1867
+ See ${docsRef} for the SESSION.md format spec. -->
1854
1868
 
1855
1869
  `;
1870
+ }
1871
+ var READ_ONLY_HEADER = createReadOnlyHeader();
1856
1872
  export {
1873
+ DEFAULT_ENTRY_TYPES,
1874
+ DEFAULT_TYPE_ALIASES,
1857
1875
  Lattice,
1858
1876
  READ_ONLY_HEADER,
1859
1877
  applyWriteEntry,
1878
+ createReadOnlyHeader,
1860
1879
  generateEntryId,
1861
1880
  generateWriteEntryId,
1862
1881
  manifestPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latticesql",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Persistent structured memory for AI agent systems — SQLite ↔ LLM context bridge",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,11 +34,12 @@
34
34
  "lint:fix": "eslint src tests --fix",
35
35
  "format": "prettier --write .",
36
36
  "format:check": "prettier --check .",
37
+ "check:generic": "bash scripts/check-generic.sh",
37
38
  "test": "vitest run",
38
39
  "test:watch": "vitest",
39
40
  "test:coverage": "vitest run --coverage",
40
41
  "docs": "typedoc --out docs-generated src/index.ts",
41
- "prepublishOnly": "npm run build && npm run typecheck && npm test"
42
+ "prepublishOnly": "npm run check:generic && npm run build && npm run typecheck && npm test"
42
43
  },
43
44
  "dependencies": {
44
45
  "better-sqlite3": "^12.8.0",