latticesql 0.5.4 → 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/index.cjs +37 -14
- package/dist/index.d.cts +63 -12
- package/dist/index.d.ts +63 -12
- package/dist/index.js +34 -14
- package/package.json +3 -2
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,
|
|
@@ -1634,7 +1637,7 @@ function parseBlock(block) {
|
|
|
1634
1637
|
|
|
1635
1638
|
// src/session/entries.ts
|
|
1636
1639
|
var import_node_crypto4 = require("crypto");
|
|
1637
|
-
var
|
|
1640
|
+
var DEFAULT_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
1638
1641
|
"event",
|
|
1639
1642
|
"learning",
|
|
1640
1643
|
"status",
|
|
@@ -1644,7 +1647,7 @@ var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
|
1644
1647
|
"handoff",
|
|
1645
1648
|
"write"
|
|
1646
1649
|
]);
|
|
1647
|
-
var
|
|
1650
|
+
var DEFAULT_TYPE_ALIASES = {
|
|
1648
1651
|
task_completion: "event",
|
|
1649
1652
|
completion: "event",
|
|
1650
1653
|
heartbeat: "status",
|
|
@@ -1654,7 +1657,7 @@ var TYPE_ALIASES = {
|
|
|
1654
1657
|
note: "event"
|
|
1655
1658
|
};
|
|
1656
1659
|
var FIELD_NAME_RE2 = /^[a-zA-Z0-9_]+$/;
|
|
1657
|
-
function parseSessionMD(content, startOffset = 0) {
|
|
1660
|
+
function parseSessionMD(content, startOffset = 0, options) {
|
|
1658
1661
|
const entries = [];
|
|
1659
1662
|
const errors = [];
|
|
1660
1663
|
const text = content.slice(startOffset);
|
|
@@ -1710,7 +1713,7 @@ function parseSessionMD(content, startOffset = 0) {
|
|
|
1710
1713
|
}
|
|
1711
1714
|
const body = bodyLines.join("\n").trim();
|
|
1712
1715
|
const rawType = headers["type"] ?? "";
|
|
1713
|
-
const resolvedType = normalizeType(rawType);
|
|
1716
|
+
const resolvedType = normalizeType(rawType, options);
|
|
1714
1717
|
if (!resolvedType) {
|
|
1715
1718
|
errors.push({ line: entryStartLine + 1, message: `Unknown entry type: ${rawType}` });
|
|
1716
1719
|
continue;
|
|
@@ -1760,7 +1763,7 @@ function parseSessionMD(content, startOffset = 0) {
|
|
|
1760
1763
|
}
|
|
1761
1764
|
return { entries, errors, lastOffset: currentByteOffset };
|
|
1762
1765
|
}
|
|
1763
|
-
function parseMarkdownEntries(content, agentName, startOffset = 0) {
|
|
1766
|
+
function parseMarkdownEntries(content, agentName, startOffset = 0, options) {
|
|
1764
1767
|
const entries = [];
|
|
1765
1768
|
const errors = [];
|
|
1766
1769
|
const text = content.slice(startOffset);
|
|
@@ -1802,7 +1805,7 @@ function parseMarkdownEntries(content, agentName, startOffset = 0) {
|
|
|
1802
1805
|
continue;
|
|
1803
1806
|
}
|
|
1804
1807
|
const rawType = bodyType ?? start.headingType ?? "event";
|
|
1805
|
-
const resolvedType = normalizeType(rawType) ?? "event";
|
|
1808
|
+
const resolvedType = normalizeType(rawType, options) ?? "event";
|
|
1806
1809
|
const id = generateEntryId(start.timestamp, agentName, body);
|
|
1807
1810
|
entries.push({
|
|
1808
1811
|
id,
|
|
@@ -1825,13 +1828,25 @@ function validateEntryId(id, body) {
|
|
|
1825
1828
|
const expectedHash = (0, import_node_crypto4.createHash)("sha256").update(body).digest("hex").slice(0, 6);
|
|
1826
1829
|
return hash === expectedHash;
|
|
1827
1830
|
}
|
|
1828
|
-
function normalizeType(raw) {
|
|
1831
|
+
function normalizeType(raw, options) {
|
|
1829
1832
|
const lower = raw.toLowerCase().trim();
|
|
1830
|
-
if (
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
if (
|
|
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
|
+
}
|
|
1835
1850
|
}
|
|
1836
1851
|
return null;
|
|
1837
1852
|
}
|
|
@@ -1895,17 +1910,25 @@ function applyWriteEntry(db, entry) {
|
|
|
1895
1910
|
}
|
|
1896
1911
|
|
|
1897
1912
|
// src/session/constants.ts
|
|
1898
|
-
|
|
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.
|
|
1899
1917
|
To update data in Lattice: write entries to SESSION.md in this directory.
|
|
1900
1918
|
Format: type: write | op: create/update/delete | table: <name> | target: <id>
|
|
1901
|
-
See
|
|
1919
|
+
See ${docsRef} for the SESSION.md format spec. -->
|
|
1902
1920
|
|
|
1903
1921
|
`;
|
|
1922
|
+
}
|
|
1923
|
+
var READ_ONLY_HEADER = createReadOnlyHeader();
|
|
1904
1924
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1905
1925
|
0 && (module.exports = {
|
|
1926
|
+
DEFAULT_ENTRY_TYPES,
|
|
1927
|
+
DEFAULT_TYPE_ALIASES,
|
|
1906
1928
|
Lattice,
|
|
1907
1929
|
READ_ONLY_HEADER,
|
|
1908
1930
|
applyWriteEntry,
|
|
1931
|
+
createReadOnlyHeader,
|
|
1909
1932
|
generateEntryId,
|
|
1910
1933
|
generateWriteEntryId,
|
|
1911
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.
|
|
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
|
|
949
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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.
|
|
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
|
|
949
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
@@ -1585,7 +1585,7 @@ function parseBlock(block) {
|
|
|
1585
1585
|
|
|
1586
1586
|
// src/session/entries.ts
|
|
1587
1587
|
import { createHash as createHash3 } from "crypto";
|
|
1588
|
-
var
|
|
1588
|
+
var DEFAULT_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
1589
1589
|
"event",
|
|
1590
1590
|
"learning",
|
|
1591
1591
|
"status",
|
|
@@ -1595,7 +1595,7 @@ var VALID_TYPES = /* @__PURE__ */ new Set([
|
|
|
1595
1595
|
"handoff",
|
|
1596
1596
|
"write"
|
|
1597
1597
|
]);
|
|
1598
|
-
var
|
|
1598
|
+
var DEFAULT_TYPE_ALIASES = {
|
|
1599
1599
|
task_completion: "event",
|
|
1600
1600
|
completion: "event",
|
|
1601
1601
|
heartbeat: "status",
|
|
@@ -1605,7 +1605,7 @@ var TYPE_ALIASES = {
|
|
|
1605
1605
|
note: "event"
|
|
1606
1606
|
};
|
|
1607
1607
|
var FIELD_NAME_RE2 = /^[a-zA-Z0-9_]+$/;
|
|
1608
|
-
function parseSessionMD(content, startOffset = 0) {
|
|
1608
|
+
function parseSessionMD(content, startOffset = 0, options) {
|
|
1609
1609
|
const entries = [];
|
|
1610
1610
|
const errors = [];
|
|
1611
1611
|
const text = content.slice(startOffset);
|
|
@@ -1661,7 +1661,7 @@ function parseSessionMD(content, startOffset = 0) {
|
|
|
1661
1661
|
}
|
|
1662
1662
|
const body = bodyLines.join("\n").trim();
|
|
1663
1663
|
const rawType = headers["type"] ?? "";
|
|
1664
|
-
const resolvedType = normalizeType(rawType);
|
|
1664
|
+
const resolvedType = normalizeType(rawType, options);
|
|
1665
1665
|
if (!resolvedType) {
|
|
1666
1666
|
errors.push({ line: entryStartLine + 1, message: `Unknown entry type: ${rawType}` });
|
|
1667
1667
|
continue;
|
|
@@ -1711,7 +1711,7 @@ function parseSessionMD(content, startOffset = 0) {
|
|
|
1711
1711
|
}
|
|
1712
1712
|
return { entries, errors, lastOffset: currentByteOffset };
|
|
1713
1713
|
}
|
|
1714
|
-
function parseMarkdownEntries(content, agentName, startOffset = 0) {
|
|
1714
|
+
function parseMarkdownEntries(content, agentName, startOffset = 0, options) {
|
|
1715
1715
|
const entries = [];
|
|
1716
1716
|
const errors = [];
|
|
1717
1717
|
const text = content.slice(startOffset);
|
|
@@ -1753,7 +1753,7 @@ function parseMarkdownEntries(content, agentName, startOffset = 0) {
|
|
|
1753
1753
|
continue;
|
|
1754
1754
|
}
|
|
1755
1755
|
const rawType = bodyType ?? start.headingType ?? "event";
|
|
1756
|
-
const resolvedType = normalizeType(rawType) ?? "event";
|
|
1756
|
+
const resolvedType = normalizeType(rawType, options) ?? "event";
|
|
1757
1757
|
const id = generateEntryId(start.timestamp, agentName, body);
|
|
1758
1758
|
entries.push({
|
|
1759
1759
|
id,
|
|
@@ -1776,13 +1776,25 @@ function validateEntryId(id, body) {
|
|
|
1776
1776
|
const expectedHash = createHash3("sha256").update(body).digest("hex").slice(0, 6);
|
|
1777
1777
|
return hash === expectedHash;
|
|
1778
1778
|
}
|
|
1779
|
-
function normalizeType(raw) {
|
|
1779
|
+
function normalizeType(raw, options) {
|
|
1780
1780
|
const lower = raw.toLowerCase().trim();
|
|
1781
|
-
if (
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
if (
|
|
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
|
+
}
|
|
1786
1798
|
}
|
|
1787
1799
|
return null;
|
|
1788
1800
|
}
|
|
@@ -1846,16 +1858,24 @@ function applyWriteEntry(db, entry) {
|
|
|
1846
1858
|
}
|
|
1847
1859
|
|
|
1848
1860
|
// src/session/constants.ts
|
|
1849
|
-
|
|
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.
|
|
1850
1865
|
To update data in Lattice: write entries to SESSION.md in this directory.
|
|
1851
1866
|
Format: type: write | op: create/update/delete | table: <name> | target: <id>
|
|
1852
|
-
See
|
|
1867
|
+
See ${docsRef} for the SESSION.md format spec. -->
|
|
1853
1868
|
|
|
1854
1869
|
`;
|
|
1870
|
+
}
|
|
1871
|
+
var READ_ONLY_HEADER = createReadOnlyHeader();
|
|
1855
1872
|
export {
|
|
1873
|
+
DEFAULT_ENTRY_TYPES,
|
|
1874
|
+
DEFAULT_TYPE_ALIASES,
|
|
1856
1875
|
Lattice,
|
|
1857
1876
|
READ_ONLY_HEADER,
|
|
1858
1877
|
applyWriteEntry,
|
|
1878
|
+
createReadOnlyHeader,
|
|
1859
1879
|
generateEntryId,
|
|
1860
1880
|
generateWriteEntryId,
|
|
1861
1881
|
manifestPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latticesql",
|
|
3
|
-
"version": "0.5.
|
|
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",
|