mindcache 2.0.0 → 2.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.
package/dist/index.js CHANGED
@@ -299,11 +299,16 @@ var init_CloudAdapter = __esm({
299
299
 
300
300
  // src/core/types.ts
301
301
  var DEFAULT_KEY_ATTRIBUTES = {
302
+ type: "text",
303
+ contentTags: [],
304
+ systemTags: ["prompt"],
305
+ // visible by default
306
+ zIndex: 0,
307
+ // Legacy - derived from systemTags
302
308
  readonly: false,
303
309
  visible: true,
304
310
  hardcoded: false,
305
311
  template: false,
306
- type: "text",
307
312
  tags: []
308
313
  };
309
314
 
@@ -320,7 +325,12 @@ var MindCache = class {
320
325
  _isLoaded = true;
321
326
  // Default true for local mode
322
327
  _cloudConfig = null;
328
+ // Access level for system operations
329
+ _accessLevel = "user";
323
330
  constructor(options) {
331
+ if (options?.accessLevel) {
332
+ this._accessLevel = options.accessLevel;
333
+ }
324
334
  if (options?.cloud) {
325
335
  this._cloudConfig = options.cloud;
326
336
  this._isLoaded = false;
@@ -328,6 +338,18 @@ var MindCache = class {
328
338
  this._initCloud();
329
339
  }
330
340
  }
341
+ /**
342
+ * Get the current access level
343
+ */
344
+ get accessLevel() {
345
+ return this._accessLevel;
346
+ }
347
+ /**
348
+ * Check if this instance has system-level access
349
+ */
350
+ get hasSystemAccess() {
351
+ return this._accessLevel === "system";
352
+ }
331
353
  async _initCloud() {
332
354
  if (!this._cloudConfig) {
333
355
  return;
@@ -491,11 +513,16 @@ var MindCache = class {
491
513
  get_attributes(key) {
492
514
  if (key === "$date" || key === "$time") {
493
515
  return {
516
+ type: "text",
517
+ contentTags: [],
518
+ systemTags: ["prompt", "readonly", "protected"],
519
+ zIndex: 999999,
520
+ // System keys appear last
521
+ // Legacy attributes
494
522
  readonly: true,
495
523
  visible: true,
496
524
  hardcoded: true,
497
525
  template: false,
498
- type: "text",
499
526
  tags: []
500
527
  };
501
528
  }
@@ -508,18 +535,98 @@ var MindCache = class {
508
535
  return;
509
536
  }
510
537
  const existingEntry = this.stm[key];
511
- const baseAttributes = existingEntry ? existingEntry.attributes : { ...DEFAULT_KEY_ATTRIBUTES };
538
+ const wasHardcoded = existingEntry?.attributes.hardcoded || existingEntry?.attributes.systemTags?.includes("protected");
539
+ const baseAttributes = existingEntry ? {
540
+ ...existingEntry.attributes,
541
+ contentTags: [...existingEntry.attributes.contentTags || []],
542
+ systemTags: [...existingEntry.attributes.systemTags || []],
543
+ tags: [...existingEntry.attributes.tags || []],
544
+ zIndex: existingEntry.attributes.zIndex ?? 0
545
+ } : {
546
+ ...DEFAULT_KEY_ATTRIBUTES,
547
+ contentTags: [],
548
+ // Fresh array
549
+ systemTags: ["prompt"],
550
+ // Fresh array with default
551
+ tags: [],
552
+ // Fresh array
553
+ zIndex: 0
554
+ };
512
555
  const finalAttributes = attributes ? { ...baseAttributes, ...attributes } : baseAttributes;
513
- if (finalAttributes.hardcoded) {
514
- finalAttributes.readonly = true;
515
- finalAttributes.template = false;
556
+ if (attributes) {
557
+ let systemTags2 = [...finalAttributes.systemTags || []];
558
+ if ("readonly" in attributes) {
559
+ if (attributes.readonly && !systemTags2.includes("readonly")) {
560
+ systemTags2.push("readonly");
561
+ } else if (!attributes.readonly && !wasHardcoded) {
562
+ systemTags2 = systemTags2.filter((t) => t !== "readonly");
563
+ }
564
+ }
565
+ if ("visible" in attributes) {
566
+ if (attributes.visible && !systemTags2.includes("prompt")) {
567
+ systemTags2.push("prompt");
568
+ } else if (!attributes.visible) {
569
+ systemTags2 = systemTags2.filter((t) => t !== "prompt");
570
+ }
571
+ }
572
+ if ("hardcoded" in attributes) {
573
+ if (attributes.hardcoded && !systemTags2.includes("protected")) {
574
+ systemTags2.push("protected");
575
+ } else if (!attributes.hardcoded && !wasHardcoded) {
576
+ systemTags2 = systemTags2.filter((t) => t !== "protected");
577
+ }
578
+ if (wasHardcoded && !systemTags2.includes("protected")) {
579
+ systemTags2.push("protected");
580
+ }
581
+ } else if (wasHardcoded) {
582
+ if (!systemTags2.includes("protected")) {
583
+ systemTags2.push("protected");
584
+ }
585
+ }
586
+ if ("template" in attributes) {
587
+ if (attributes.template && !wasHardcoded && !systemTags2.includes("template")) {
588
+ systemTags2.push("template");
589
+ } else if (!attributes.template || wasHardcoded) {
590
+ systemTags2 = systemTags2.filter((t) => t !== "template");
591
+ }
592
+ }
593
+ finalAttributes.systemTags = systemTags2;
594
+ } else if (wasHardcoded) {
595
+ let systemTags2 = [...finalAttributes.systemTags || []];
596
+ if (!systemTags2.includes("protected")) {
597
+ systemTags2.push("protected");
598
+ }
599
+ if (!systemTags2.includes("readonly")) {
600
+ systemTags2.push("readonly");
601
+ }
602
+ systemTags2 = systemTags2.filter((t) => t !== "template");
603
+ finalAttributes.systemTags = systemTags2;
604
+ }
605
+ let systemTags = finalAttributes.systemTags || [];
606
+ if (wasHardcoded && !systemTags.includes("protected")) {
607
+ systemTags = [...systemTags, "protected"];
608
+ }
609
+ if (systemTags.includes("protected")) {
610
+ if (!systemTags.includes("readonly")) {
611
+ systemTags = [...systemTags, "readonly"];
612
+ }
613
+ systemTags = systemTags.filter((t) => t !== "template");
614
+ finalAttributes.systemTags = systemTags;
615
+ }
616
+ finalAttributes.readonly = systemTags.includes("readonly");
617
+ finalAttributes.visible = systemTags.includes("prompt");
618
+ finalAttributes.hardcoded = wasHardcoded || systemTags.includes("protected");
619
+ finalAttributes.template = systemTags.includes("template");
620
+ if (attributes && "tags" in attributes && attributes.tags) {
621
+ finalAttributes.contentTags = [...attributes.tags];
516
622
  }
623
+ finalAttributes.tags = [...finalAttributes.contentTags || []];
517
624
  this.stm[key] = {
518
625
  value,
519
626
  attributes: finalAttributes
520
627
  };
521
628
  if (this.listeners[key]) {
522
- this.listeners[key].forEach((listener) => listener());
629
+ this.listeners[key].forEach((listener) => listener(value));
523
630
  }
524
631
  this.notifyGlobalListeners();
525
632
  }
@@ -530,12 +637,38 @@ var MindCache = class {
530
637
  return;
531
638
  }
532
639
  this._isRemoteUpdate = true;
640
+ const systemTags = attributes.systemTags || [];
641
+ if (!attributes.systemTags) {
642
+ if (attributes.visible !== false) {
643
+ systemTags.push("prompt");
644
+ }
645
+ if (attributes.readonly) {
646
+ systemTags.push("readonly");
647
+ }
648
+ if (attributes.hardcoded) {
649
+ systemTags.push("protected");
650
+ }
651
+ if (attributes.template) {
652
+ systemTags.push("template");
653
+ }
654
+ }
655
+ const contentTags = attributes.contentTags || attributes.tags || [];
533
656
  this.stm[key] = {
534
657
  value,
535
- attributes
658
+ attributes: {
659
+ ...attributes,
660
+ contentTags,
661
+ systemTags,
662
+ zIndex: attributes.zIndex ?? 0,
663
+ tags: contentTags,
664
+ readonly: systemTags.includes("readonly"),
665
+ visible: systemTags.includes("prompt"),
666
+ hardcoded: systemTags.includes("protected"),
667
+ template: systemTags.includes("template")
668
+ }
536
669
  };
537
670
  if (this.listeners[key]) {
538
- this.listeners[key].forEach((listener) => listener());
671
+ this.listeners[key].forEach((listener) => listener(value));
539
672
  }
540
673
  this.notifyGlobalListeners();
541
674
  this._isRemoteUpdate = false;
@@ -553,7 +686,7 @@ var MindCache = class {
553
686
  if (key in this.stm) {
554
687
  delete this.stm[key];
555
688
  if (this.listeners[key]) {
556
- this.listeners[key].forEach((listener) => listener());
689
+ this.listeners[key].forEach((listener) => listener(void 0));
557
690
  }
558
691
  this.notifyGlobalListeners();
559
692
  }
@@ -575,12 +708,62 @@ var MindCache = class {
575
708
  if (!entry) {
576
709
  return false;
577
710
  }
578
- const { hardcoded: _hardcoded, ...allowedAttributes } = attributes;
711
+ const wasHardcoded = entry.attributes.hardcoded || entry.attributes.systemTags?.includes("protected");
712
+ const { hardcoded: _hardcoded, systemTags: _systemTags, ...allowedAttributes } = attributes;
713
+ if (wasHardcoded) {
714
+ if ("readonly" in allowedAttributes) {
715
+ delete allowedAttributes.readonly;
716
+ }
717
+ if ("template" in allowedAttributes) {
718
+ delete allowedAttributes.template;
719
+ }
720
+ }
579
721
  entry.attributes = { ...entry.attributes, ...allowedAttributes };
580
- if (entry.attributes.hardcoded) {
722
+ if ("readonly" in attributes || "visible" in attributes || "template" in attributes) {
723
+ let newSystemTags = [];
724
+ if (entry.attributes.readonly) {
725
+ newSystemTags.push("readonly");
726
+ }
727
+ if (entry.attributes.visible) {
728
+ newSystemTags.push("prompt");
729
+ }
730
+ if (entry.attributes.template) {
731
+ newSystemTags.push("template");
732
+ }
733
+ if (wasHardcoded || entry.attributes.hardcoded) {
734
+ newSystemTags.push("protected");
735
+ }
736
+ if (newSystemTags.includes("protected")) {
737
+ if (!newSystemTags.includes("readonly")) {
738
+ newSystemTags.push("readonly");
739
+ }
740
+ newSystemTags = newSystemTags.filter((t) => t !== "template");
741
+ entry.attributes.readonly = true;
742
+ entry.attributes.template = false;
743
+ }
744
+ entry.attributes.systemTags = newSystemTags;
745
+ } else if (wasHardcoded) {
746
+ let systemTags = [...entry.attributes.systemTags || []];
747
+ if (!systemTags.includes("protected")) {
748
+ systemTags.push("protected");
749
+ }
750
+ if (!systemTags.includes("readonly")) {
751
+ systemTags.push("readonly");
752
+ }
753
+ systemTags = systemTags.filter((t) => t !== "template");
754
+ entry.attributes.systemTags = systemTags;
755
+ }
756
+ if (wasHardcoded) {
757
+ entry.attributes.hardcoded = true;
758
+ if (!entry.attributes.systemTags?.includes("protected")) {
759
+ entry.attributes.systemTags = [...entry.attributes.systemTags || [], "protected"];
760
+ }
581
761
  entry.attributes.readonly = true;
582
762
  entry.attributes.template = false;
583
763
  }
764
+ if ("contentTags" in attributes) {
765
+ entry.attributes.tags = [...entry.attributes.contentTags || []];
766
+ }
584
767
  this.notifyGlobalListeners();
585
768
  return true;
586
769
  }
@@ -652,7 +835,7 @@ var MindCache = class {
652
835
  if (deleted) {
653
836
  this.notifyGlobalListeners();
654
837
  if (this.listeners[key]) {
655
- this.listeners[key].forEach((listener) => listener());
838
+ this.listeners[key].forEach((listener) => listener(void 0));
656
839
  }
657
840
  }
658
841
  return deleted;
@@ -661,12 +844,26 @@ var MindCache = class {
661
844
  this.stm = {};
662
845
  this.notifyGlobalListeners();
663
846
  }
847
+ /**
848
+ * Get keys sorted by zIndex (ascending), then by key name
849
+ */
850
+ getSortedKeys() {
851
+ return Object.entries(this.stm).sort(([keyA, entryA], [keyB, entryB]) => {
852
+ const zIndexA = entryA.attributes.zIndex ?? 0;
853
+ const zIndexB = entryB.attributes.zIndex ?? 0;
854
+ if (zIndexA !== zIndexB) {
855
+ return zIndexA - zIndexB;
856
+ }
857
+ return keyA.localeCompare(keyB);
858
+ }).map(([key]) => key);
859
+ }
664
860
  keys() {
665
- return [...Object.keys(this.stm), "$date", "$time"];
861
+ return [...this.getSortedKeys(), "$date", "$time"];
666
862
  }
667
863
  values() {
668
864
  const now = /* @__PURE__ */ new Date();
669
- const stmValues = Object.values(this.stm).map((entry) => entry.value);
865
+ const sortedKeys = this.getSortedKeys();
866
+ const stmValues = sortedKeys.map((key) => this.stm[key].value);
670
867
  return [
671
868
  ...stmValues,
672
869
  now.toISOString().split("T")[0],
@@ -675,8 +872,9 @@ var MindCache = class {
675
872
  }
676
873
  entries() {
677
874
  const now = /* @__PURE__ */ new Date();
678
- const stmEntries = Object.entries(this.stm).map(
679
- ([key, entry]) => [key, entry.value]
875
+ const sortedKeys = this.getSortedKeys();
876
+ const stmEntries = sortedKeys.map(
877
+ (key) => [key, this.stm[key].value]
680
878
  );
681
879
  return [
682
880
  ...stmEntries,
@@ -690,8 +888,9 @@ var MindCache = class {
690
888
  getAll() {
691
889
  const now = /* @__PURE__ */ new Date();
692
890
  const result = {};
693
- Object.entries(this.stm).forEach(([key, entry]) => {
694
- result[key] = entry.value;
891
+ const sortedKeys = this.getSortedKeys();
892
+ sortedKeys.forEach((key) => {
893
+ result[key] = this.stm[key].value;
695
894
  });
696
895
  result["$date"] = now.toISOString().split("T")[0];
697
896
  result["$time"] = now.toTimeString().split(" ")[0];
@@ -705,7 +904,7 @@ var MindCache = class {
705
904
  attributes: { ...DEFAULT_KEY_ATTRIBUTES }
706
905
  };
707
906
  if (this.listeners[key]) {
708
- this.listeners[key].forEach((listener) => listener());
907
+ this.listeners[key].forEach((listener) => listener(this.stm[key]?.value));
709
908
  }
710
909
  }
711
910
  });
@@ -774,7 +973,9 @@ var MindCache = class {
774
973
  getSTM() {
775
974
  const now = /* @__PURE__ */ new Date();
776
975
  const entries = [];
777
- Object.entries(this.stm).forEach(([key, entry]) => {
976
+ const sortedKeys = this.getSortedKeys();
977
+ sortedKeys.forEach((key) => {
978
+ const entry = this.stm[key];
778
979
  if (entry.attributes.visible) {
779
980
  entries.push([key, this.get_value(key)]);
780
981
  }
@@ -789,7 +990,9 @@ var MindCache = class {
789
990
  getSTMForAPI() {
790
991
  const now = /* @__PURE__ */ new Date();
791
992
  const apiData = [];
792
- Object.entries(this.stm).forEach(([key, entry]) => {
993
+ const sortedKeys = this.getSortedKeys();
994
+ sortedKeys.forEach((key) => {
995
+ const entry = this.stm[key];
793
996
  if (entry.attributes.visible) {
794
997
  const processedValue = entry.attributes.template ? this.get_value(key) : entry.value;
795
998
  apiData.push({
@@ -814,7 +1017,9 @@ var MindCache = class {
814
1017
  }
815
1018
  getVisibleImages() {
816
1019
  const imageParts = [];
817
- Object.entries(this.stm).forEach(([key, entry]) => {
1020
+ const sortedKeys = this.getSortedKeys();
1021
+ sortedKeys.forEach((key) => {
1022
+ const entry = this.stm[key];
818
1023
  if (entry.attributes.visible && entry.attributes.type === "image" && entry.attributes.contentType) {
819
1024
  const dataUrl = this.createDataUrl(entry.value, entry.attributes.contentType);
820
1025
  imageParts.push({
@@ -840,7 +1045,9 @@ var MindCache = class {
840
1045
  }
841
1046
  serialize() {
842
1047
  const result = {};
843
- Object.entries(this.stm).forEach(([key, entry]) => {
1048
+ const sortedKeys = this.getSortedKeys();
1049
+ sortedKeys.forEach((key) => {
1050
+ const entry = this.stm[key];
844
1051
  if (!entry.attributes.hardcoded) {
845
1052
  result[key] = {
846
1053
  value: entry.value,
@@ -855,11 +1062,40 @@ var MindCache = class {
855
1062
  this.clear();
856
1063
  Object.entries(data).forEach(([key, entry]) => {
857
1064
  if (entry && typeof entry === "object" && "value" in entry && "attributes" in entry) {
1065
+ const attrs = entry.attributes;
1066
+ if (attrs.hardcoded === true || attrs.systemTags?.includes("protected")) {
1067
+ return;
1068
+ }
1069
+ let systemTags = attrs.systemTags || [];
1070
+ if (!attrs.systemTags) {
1071
+ systemTags = [];
1072
+ if (attrs.visible !== false) {
1073
+ systemTags.push("prompt");
1074
+ }
1075
+ if (attrs.readonly) {
1076
+ systemTags.push("readonly");
1077
+ }
1078
+ if (attrs.hardcoded) {
1079
+ systemTags.push("protected");
1080
+ }
1081
+ if (attrs.template) {
1082
+ systemTags.push("template");
1083
+ }
1084
+ }
1085
+ const contentTags = attrs.contentTags || attrs.tags || [];
858
1086
  this.stm[key] = {
859
1087
  value: entry.value,
860
1088
  attributes: {
861
- ...entry.attributes,
862
- tags: entry.attributes.tags || []
1089
+ ...attrs,
1090
+ contentTags,
1091
+ systemTags,
1092
+ zIndex: attrs.zIndex ?? 0,
1093
+ // Sync legacy attributes
1094
+ tags: contentTags,
1095
+ readonly: systemTags.includes("readonly"),
1096
+ visible: systemTags.includes("prompt"),
1097
+ hardcoded: systemTags.includes("protected"),
1098
+ template: systemTags.includes("template")
863
1099
  }
864
1100
  };
865
1101
  }
@@ -870,7 +1106,9 @@ var MindCache = class {
870
1106
  get_system_prompt() {
871
1107
  const now = /* @__PURE__ */ new Date();
872
1108
  const promptLines = [];
873
- Object.entries(this.stm).forEach(([key, entry]) => {
1109
+ const sortedKeys = this.getSortedKeys();
1110
+ sortedKeys.forEach((key) => {
1111
+ const entry = this.stm[key];
874
1112
  if (entry.attributes.visible) {
875
1113
  if (entry.attributes.type === "image") {
876
1114
  promptLines.push(`image ${key} available`);
@@ -905,14 +1143,18 @@ var MindCache = class {
905
1143
  return void 0;
906
1144
  }
907
1145
  const sanitizedKey = toolName.replace("write_", "");
908
- const allKeys = Object.keys(this.stm);
909
- return allKeys.find(
1146
+ const sortedKeys = this.getSortedKeys();
1147
+ return sortedKeys.find(
910
1148
  (k) => k.replace(/[^a-zA-Z0-9_-]/g, "_") === sanitizedKey
911
1149
  );
912
1150
  }
913
1151
  get_aisdk_tools() {
914
1152
  const tools = {};
915
- const writableKeys = Object.entries(this.stm).filter(([, entry]) => !entry.attributes.readonly).map(([key]) => key);
1153
+ const sortedKeys = this.getSortedKeys();
1154
+ const writableKeys = sortedKeys.filter((key) => {
1155
+ const entry = this.stm[key];
1156
+ return !entry.attributes.readonly;
1157
+ });
916
1158
  writableKeys.forEach((key) => {
917
1159
  const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
918
1160
  const toolName = `write_${sanitizedKey}`;
@@ -996,6 +1238,12 @@ var MindCache = class {
996
1238
  value
997
1239
  };
998
1240
  }
1241
+ // ============================================
1242
+ // Content Tag Methods (available to all access levels)
1243
+ // ============================================
1244
+ /**
1245
+ * Add a content tag to a key (user-level organization)
1246
+ */
999
1247
  addTag(key, tag) {
1000
1248
  if (key === "$date" || key === "$time") {
1001
1249
  return false;
@@ -1004,64 +1252,231 @@ var MindCache = class {
1004
1252
  if (!entry) {
1005
1253
  return false;
1006
1254
  }
1007
- if (!entry.attributes.tags) {
1008
- entry.attributes.tags = [];
1255
+ if (!entry.attributes.contentTags) {
1256
+ entry.attributes.contentTags = [];
1009
1257
  }
1010
- if (!entry.attributes.tags.includes(tag)) {
1011
- entry.attributes.tags.push(tag);
1258
+ if (!entry.attributes.contentTags.includes(tag)) {
1259
+ entry.attributes.contentTags.push(tag);
1260
+ entry.attributes.tags = [...entry.attributes.contentTags];
1012
1261
  this.notifyGlobalListeners();
1013
1262
  return true;
1014
1263
  }
1015
1264
  return false;
1016
1265
  }
1266
+ /**
1267
+ * Remove a content tag from a key
1268
+ */
1017
1269
  removeTag(key, tag) {
1018
1270
  if (key === "$date" || key === "$time") {
1019
1271
  return false;
1020
1272
  }
1021
1273
  const entry = this.stm[key];
1022
- if (!entry || !entry.attributes.tags) {
1274
+ if (!entry || !entry.attributes.contentTags) {
1023
1275
  return false;
1024
1276
  }
1025
- const tagIndex = entry.attributes.tags.indexOf(tag);
1277
+ const tagIndex = entry.attributes.contentTags.indexOf(tag);
1026
1278
  if (tagIndex > -1) {
1027
- entry.attributes.tags.splice(tagIndex, 1);
1279
+ entry.attributes.contentTags.splice(tagIndex, 1);
1280
+ entry.attributes.tags = [...entry.attributes.contentTags];
1028
1281
  this.notifyGlobalListeners();
1029
1282
  return true;
1030
1283
  }
1031
1284
  return false;
1032
1285
  }
1286
+ /**
1287
+ * Get all content tags for a key
1288
+ */
1033
1289
  getTags(key) {
1034
1290
  if (key === "$date" || key === "$time") {
1035
1291
  return [];
1036
1292
  }
1037
1293
  const entry = this.stm[key];
1038
- return entry?.attributes.tags || [];
1294
+ return entry?.attributes.contentTags || [];
1039
1295
  }
1296
+ /**
1297
+ * Get all unique content tags across all keys
1298
+ */
1040
1299
  getAllTags() {
1041
1300
  const allTags = /* @__PURE__ */ new Set();
1042
1301
  Object.values(this.stm).forEach((entry) => {
1043
- if (entry.attributes.tags) {
1044
- entry.attributes.tags.forEach((tag) => allTags.add(tag));
1302
+ if (entry.attributes.contentTags) {
1303
+ entry.attributes.contentTags.forEach((tag) => allTags.add(tag));
1045
1304
  }
1046
1305
  });
1047
1306
  return Array.from(allTags);
1048
1307
  }
1308
+ /**
1309
+ * Check if a key has a specific content tag
1310
+ */
1049
1311
  hasTag(key, tag) {
1050
1312
  if (key === "$date" || key === "$time") {
1051
1313
  return false;
1052
1314
  }
1053
1315
  const entry = this.stm[key];
1054
- return entry?.attributes.tags?.includes(tag) || false;
1316
+ return entry?.attributes.contentTags?.includes(tag) || false;
1055
1317
  }
1318
+ /**
1319
+ * Get all keys with a specific content tag as formatted string
1320
+ */
1056
1321
  getTagged(tag) {
1057
1322
  const entries = [];
1058
- Object.entries(this.stm).forEach(([key, entry]) => {
1059
- if (entry.attributes.tags?.includes(tag)) {
1323
+ const sortedKeys = this.getSortedKeys();
1324
+ sortedKeys.forEach((key) => {
1325
+ const entry = this.stm[key];
1326
+ if (entry.attributes.contentTags?.includes(tag)) {
1060
1327
  entries.push([key, this.get_value(key)]);
1061
1328
  }
1062
1329
  });
1063
1330
  return entries.map(([key, value]) => `${key}: ${value}`).join(", ");
1064
1331
  }
1332
+ /**
1333
+ * Get all keys with a specific content tag
1334
+ */
1335
+ getKeysByTag(tag) {
1336
+ const sortedKeys = this.getSortedKeys();
1337
+ return sortedKeys.filter((key) => {
1338
+ const entry = this.stm[key];
1339
+ return entry.attributes.contentTags?.includes(tag);
1340
+ });
1341
+ }
1342
+ // ============================================
1343
+ // System Tag Methods (requires system access level)
1344
+ // ============================================
1345
+ /**
1346
+ * Add a system tag to a key (requires system access)
1347
+ * System tags: 'prompt', 'readonly', 'protected', 'template'
1348
+ */
1349
+ systemAddTag(key, tag) {
1350
+ if (!this.hasSystemAccess) {
1351
+ console.warn("MindCache: systemAddTag requires system access level");
1352
+ return false;
1353
+ }
1354
+ if (key === "$date" || key === "$time") {
1355
+ return false;
1356
+ }
1357
+ const entry = this.stm[key];
1358
+ if (!entry) {
1359
+ return false;
1360
+ }
1361
+ if (!entry.attributes.systemTags) {
1362
+ entry.attributes.systemTags = [];
1363
+ }
1364
+ if (!entry.attributes.systemTags.includes(tag)) {
1365
+ entry.attributes.systemTags.push(tag);
1366
+ this.syncLegacyFromSystemTags(entry);
1367
+ this.notifyGlobalListeners();
1368
+ return true;
1369
+ }
1370
+ return false;
1371
+ }
1372
+ /**
1373
+ * Remove a system tag from a key (requires system access)
1374
+ */
1375
+ systemRemoveTag(key, tag) {
1376
+ if (!this.hasSystemAccess) {
1377
+ console.warn("MindCache: systemRemoveTag requires system access level");
1378
+ return false;
1379
+ }
1380
+ if (key === "$date" || key === "$time") {
1381
+ return false;
1382
+ }
1383
+ const entry = this.stm[key];
1384
+ if (!entry || !entry.attributes.systemTags) {
1385
+ return false;
1386
+ }
1387
+ const isHardcoded = entry.attributes.hardcoded || entry.attributes.systemTags.includes("protected");
1388
+ if (tag === "protected" && isHardcoded) {
1389
+ return false;
1390
+ }
1391
+ const tagIndex = entry.attributes.systemTags.indexOf(tag);
1392
+ if (tagIndex > -1) {
1393
+ entry.attributes.systemTags.splice(tagIndex, 1);
1394
+ this.syncLegacyFromSystemTags(entry);
1395
+ if (isHardcoded) {
1396
+ if (!entry.attributes.systemTags.includes("protected")) {
1397
+ entry.attributes.systemTags.push("protected");
1398
+ }
1399
+ entry.attributes.hardcoded = true;
1400
+ entry.attributes.readonly = true;
1401
+ entry.attributes.template = false;
1402
+ }
1403
+ this.notifyGlobalListeners();
1404
+ return true;
1405
+ }
1406
+ return false;
1407
+ }
1408
+ /**
1409
+ * Get all system tags for a key (requires system access)
1410
+ */
1411
+ systemGetTags(key) {
1412
+ if (!this.hasSystemAccess) {
1413
+ console.warn("MindCache: systemGetTags requires system access level");
1414
+ return [];
1415
+ }
1416
+ if (key === "$date" || key === "$time") {
1417
+ return [];
1418
+ }
1419
+ const entry = this.stm[key];
1420
+ return entry?.attributes.systemTags || [];
1421
+ }
1422
+ /**
1423
+ * Check if a key has a specific system tag (requires system access)
1424
+ */
1425
+ systemHasTag(key, tag) {
1426
+ if (!this.hasSystemAccess) {
1427
+ console.warn("MindCache: systemHasTag requires system access level");
1428
+ return false;
1429
+ }
1430
+ if (key === "$date" || key === "$time") {
1431
+ return false;
1432
+ }
1433
+ const entry = this.stm[key];
1434
+ return entry?.attributes.systemTags?.includes(tag) || false;
1435
+ }
1436
+ /**
1437
+ * Set all system tags for a key at once (requires system access)
1438
+ */
1439
+ systemSetTags(key, tags) {
1440
+ if (!this.hasSystemAccess) {
1441
+ console.warn("MindCache: systemSetTags requires system access level");
1442
+ return false;
1443
+ }
1444
+ if (key === "$date" || key === "$time") {
1445
+ return false;
1446
+ }
1447
+ const entry = this.stm[key];
1448
+ if (!entry) {
1449
+ return false;
1450
+ }
1451
+ entry.attributes.systemTags = [...tags];
1452
+ this.syncLegacyFromSystemTags(entry);
1453
+ this.notifyGlobalListeners();
1454
+ return true;
1455
+ }
1456
+ /**
1457
+ * Get all keys with a specific system tag (requires system access)
1458
+ */
1459
+ systemGetKeysByTag(tag) {
1460
+ if (!this.hasSystemAccess) {
1461
+ console.warn("MindCache: systemGetKeysByTag requires system access level");
1462
+ return [];
1463
+ }
1464
+ const sortedKeys = this.getSortedKeys();
1465
+ return sortedKeys.filter((key) => {
1466
+ const entry = this.stm[key];
1467
+ return entry.attributes.systemTags?.includes(tag);
1468
+ });
1469
+ }
1470
+ /**
1471
+ * Helper to sync legacy boolean attributes from system tags
1472
+ */
1473
+ syncLegacyFromSystemTags(entry) {
1474
+ const tags = entry.attributes.systemTags || [];
1475
+ entry.attributes.readonly = tags.includes("readonly");
1476
+ entry.attributes.visible = tags.includes("prompt");
1477
+ entry.attributes.hardcoded = tags.includes("protected");
1478
+ entry.attributes.template = tags.includes("template");
1479
+ }
1065
1480
  toMarkdown() {
1066
1481
  const now = /* @__PURE__ */ new Date();
1067
1482
  const lines = [];
@@ -1075,7 +1490,9 @@ var MindCache = class {
1075
1490
  lines.push("");
1076
1491
  lines.push("## STM Entries");
1077
1492
  lines.push("");
1078
- Object.entries(this.stm).forEach(([key, entry]) => {
1493
+ const sortedKeys = this.getSortedKeys();
1494
+ sortedKeys.forEach((key) => {
1495
+ const entry = this.stm[key];
1079
1496
  if (entry.attributes.hardcoded) {
1080
1497
  return;
1081
1498
  }
@@ -1085,6 +1502,7 @@ var MindCache = class {
1085
1502
  lines.push(`- **Readonly**: \`${entry.attributes.readonly}\``);
1086
1503
  lines.push(`- **Visible**: \`${entry.attributes.visible}\``);
1087
1504
  lines.push(`- **Template**: \`${entry.attributes.template}\``);
1505
+ lines.push(`- **Z-Index**: \`${entry.attributes.zIndex ?? 0}\``);
1088
1506
  if (entry.attributes.tags && entry.attributes.tags.length > 0) {
1089
1507
  lines.push(`- **Tags**: \`${entry.attributes.tags.join("`, `")}\``);
1090
1508
  }
@@ -1197,11 +1615,9 @@ var MindCache = class {
1197
1615
  currentEntry = {
1198
1616
  value: void 0,
1199
1617
  attributes: {
1200
- readonly: false,
1201
- visible: true,
1202
- hardcoded: false,
1203
- template: false,
1204
- type: "text",
1618
+ ...DEFAULT_KEY_ATTRIBUTES,
1619
+ contentTags: [],
1620
+ systemTags: ["prompt"],
1205
1621
  tags: []
1206
1622
  }
1207
1623
  };
@@ -1225,6 +1641,14 @@ var MindCache = class {
1225
1641
  if (currentEntry) {
1226
1642
  currentEntry.attributes.template = value;
1227
1643
  }
1644
+ } else if (trimmed.startsWith("- **Z-Index**: `")) {
1645
+ const zIndexStr = trimmed.match(/`([^`]+)`/)?.[1];
1646
+ if (currentEntry && zIndexStr) {
1647
+ const zIndex = parseInt(zIndexStr, 10);
1648
+ if (!isNaN(zIndex)) {
1649
+ currentEntry.attributes.zIndex = zIndex;
1650
+ }
1651
+ }
1228
1652
  } else if (trimmed.startsWith("- **Tags**: `")) {
1229
1653
  const tagsStr = trimmed.substring(13, trimmed.length - 1);
1230
1654
  if (currentEntry) {
@@ -1281,9 +1705,35 @@ var MindCache = class {
1281
1705
  }
1282
1706
  }
1283
1707
  if (entry.value !== void 0 && entry.attributes) {
1708
+ const attrs = entry.attributes;
1709
+ if (attrs.tags && attrs.tags.length > 0 && (!attrs.contentTags || attrs.contentTags.length === 0)) {
1710
+ attrs.contentTags = [...attrs.tags];
1711
+ }
1712
+ if (!attrs.systemTags || attrs.systemTags.length === 0) {
1713
+ const systemTags = [];
1714
+ if (attrs.visible !== false) {
1715
+ systemTags.push("prompt");
1716
+ }
1717
+ if (attrs.readonly) {
1718
+ systemTags.push("readonly");
1719
+ }
1720
+ if (attrs.hardcoded) {
1721
+ systemTags.push("protected");
1722
+ }
1723
+ if (attrs.template) {
1724
+ systemTags.push("template");
1725
+ }
1726
+ attrs.systemTags = systemTags;
1727
+ }
1728
+ if (!attrs.contentTags) {
1729
+ attrs.contentTags = [];
1730
+ }
1731
+ if (!attrs.tags) {
1732
+ attrs.tags = [...attrs.contentTags];
1733
+ }
1284
1734
  this.stm[key] = {
1285
1735
  value: entry.value,
1286
- attributes: entry.attributes
1736
+ attributes: attrs
1287
1737
  };
1288
1738
  }
1289
1739
  });