mindcache 2.0.0-alpha.1 → 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.
@@ -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;
@@ -345,18 +367,17 @@ var MindCache = class {
345
367
  if (this._cloudConfig.tokenEndpoint) {
346
368
  const tokenEndpoint = this._cloudConfig.tokenEndpoint;
347
369
  const instanceId = this._cloudConfig.instanceId;
348
- const resolveUrl = (endpoint) => {
349
- if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
350
- return endpoint;
351
- }
352
- if (typeof window !== "undefined" && window.location?.origin) {
353
- return `${window.location.origin}${endpoint.startsWith("/") ? "" : "/"}${endpoint}`;
354
- }
355
- return endpoint;
356
- };
370
+ let resolvedBaseUrl;
371
+ if (tokenEndpoint.startsWith("http://") || tokenEndpoint.startsWith("https://")) {
372
+ resolvedBaseUrl = tokenEndpoint;
373
+ } else if (typeof window !== "undefined" && window.location?.origin) {
374
+ resolvedBaseUrl = `${window.location.origin}${tokenEndpoint.startsWith("/") ? "" : "/"}${tokenEndpoint}`;
375
+ } else {
376
+ console.warn("MindCache: Cannot resolve tokenEndpoint to absolute URL - window.location not available");
377
+ resolvedBaseUrl = tokenEndpoint;
378
+ }
357
379
  adapter.setTokenProvider(async () => {
358
- const baseUrl2 = resolveUrl(tokenEndpoint);
359
- const url = baseUrl2.includes("?") ? `${baseUrl2}&instanceId=${instanceId}` : `${baseUrl2}?instanceId=${instanceId}`;
380
+ const url = resolvedBaseUrl.includes("?") ? `${resolvedBaseUrl}&instanceId=${instanceId}` : `${resolvedBaseUrl}?instanceId=${instanceId}`;
360
381
  const response = await fetch(url);
361
382
  if (!response.ok) {
362
383
  const error = await response.json().catch(() => ({ error: "Failed to get token" }));
@@ -492,11 +513,16 @@ var MindCache = class {
492
513
  get_attributes(key) {
493
514
  if (key === "$date" || key === "$time") {
494
515
  return {
516
+ type: "text",
517
+ contentTags: [],
518
+ systemTags: ["prompt", "readonly", "protected"],
519
+ zIndex: 999999,
520
+ // System keys appear last
521
+ // Legacy attributes
495
522
  readonly: true,
496
523
  visible: true,
497
524
  hardcoded: true,
498
525
  template: false,
499
- type: "text",
500
526
  tags: []
501
527
  };
502
528
  }
@@ -509,18 +535,98 @@ var MindCache = class {
509
535
  return;
510
536
  }
511
537
  const existingEntry = this.stm[key];
512
- 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
+ };
513
555
  const finalAttributes = attributes ? { ...baseAttributes, ...attributes } : baseAttributes;
514
- if (finalAttributes.hardcoded) {
515
- finalAttributes.readonly = true;
516
- 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;
517
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];
622
+ }
623
+ finalAttributes.tags = [...finalAttributes.contentTags || []];
518
624
  this.stm[key] = {
519
625
  value,
520
626
  attributes: finalAttributes
521
627
  };
522
628
  if (this.listeners[key]) {
523
- this.listeners[key].forEach((listener) => listener());
629
+ this.listeners[key].forEach((listener) => listener(value));
524
630
  }
525
631
  this.notifyGlobalListeners();
526
632
  }
@@ -531,12 +637,38 @@ var MindCache = class {
531
637
  return;
532
638
  }
533
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 || [];
534
656
  this.stm[key] = {
535
657
  value,
536
- 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
+ }
537
669
  };
538
670
  if (this.listeners[key]) {
539
- this.listeners[key].forEach((listener) => listener());
671
+ this.listeners[key].forEach((listener) => listener(value));
540
672
  }
541
673
  this.notifyGlobalListeners();
542
674
  this._isRemoteUpdate = false;
@@ -554,7 +686,7 @@ var MindCache = class {
554
686
  if (key in this.stm) {
555
687
  delete this.stm[key];
556
688
  if (this.listeners[key]) {
557
- this.listeners[key].forEach((listener) => listener());
689
+ this.listeners[key].forEach((listener) => listener(void 0));
558
690
  }
559
691
  this.notifyGlobalListeners();
560
692
  }
@@ -576,12 +708,62 @@ var MindCache = class {
576
708
  if (!entry) {
577
709
  return false;
578
710
  }
579
- 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
+ }
580
721
  entry.attributes = { ...entry.attributes, ...allowedAttributes };
581
- 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
+ }
582
761
  entry.attributes.readonly = true;
583
762
  entry.attributes.template = false;
584
763
  }
764
+ if ("contentTags" in attributes) {
765
+ entry.attributes.tags = [...entry.attributes.contentTags || []];
766
+ }
585
767
  this.notifyGlobalListeners();
586
768
  return true;
587
769
  }
@@ -653,7 +835,7 @@ var MindCache = class {
653
835
  if (deleted) {
654
836
  this.notifyGlobalListeners();
655
837
  if (this.listeners[key]) {
656
- this.listeners[key].forEach((listener) => listener());
838
+ this.listeners[key].forEach((listener) => listener(void 0));
657
839
  }
658
840
  }
659
841
  return deleted;
@@ -662,12 +844,26 @@ var MindCache = class {
662
844
  this.stm = {};
663
845
  this.notifyGlobalListeners();
664
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
+ }
665
860
  keys() {
666
- return [...Object.keys(this.stm), "$date", "$time"];
861
+ return [...this.getSortedKeys(), "$date", "$time"];
667
862
  }
668
863
  values() {
669
864
  const now = /* @__PURE__ */ new Date();
670
- 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);
671
867
  return [
672
868
  ...stmValues,
673
869
  now.toISOString().split("T")[0],
@@ -676,8 +872,9 @@ var MindCache = class {
676
872
  }
677
873
  entries() {
678
874
  const now = /* @__PURE__ */ new Date();
679
- const stmEntries = Object.entries(this.stm).map(
680
- ([key, entry]) => [key, entry.value]
875
+ const sortedKeys = this.getSortedKeys();
876
+ const stmEntries = sortedKeys.map(
877
+ (key) => [key, this.stm[key].value]
681
878
  );
682
879
  return [
683
880
  ...stmEntries,
@@ -691,8 +888,9 @@ var MindCache = class {
691
888
  getAll() {
692
889
  const now = /* @__PURE__ */ new Date();
693
890
  const result = {};
694
- Object.entries(this.stm).forEach(([key, entry]) => {
695
- result[key] = entry.value;
891
+ const sortedKeys = this.getSortedKeys();
892
+ sortedKeys.forEach((key) => {
893
+ result[key] = this.stm[key].value;
696
894
  });
697
895
  result["$date"] = now.toISOString().split("T")[0];
698
896
  result["$time"] = now.toTimeString().split(" ")[0];
@@ -706,7 +904,7 @@ var MindCache = class {
706
904
  attributes: { ...DEFAULT_KEY_ATTRIBUTES }
707
905
  };
708
906
  if (this.listeners[key]) {
709
- this.listeners[key].forEach((listener) => listener());
907
+ this.listeners[key].forEach((listener) => listener(this.stm[key]?.value));
710
908
  }
711
909
  }
712
910
  });
@@ -775,7 +973,9 @@ var MindCache = class {
775
973
  getSTM() {
776
974
  const now = /* @__PURE__ */ new Date();
777
975
  const entries = [];
778
- Object.entries(this.stm).forEach(([key, entry]) => {
976
+ const sortedKeys = this.getSortedKeys();
977
+ sortedKeys.forEach((key) => {
978
+ const entry = this.stm[key];
779
979
  if (entry.attributes.visible) {
780
980
  entries.push([key, this.get_value(key)]);
781
981
  }
@@ -790,7 +990,9 @@ var MindCache = class {
790
990
  getSTMForAPI() {
791
991
  const now = /* @__PURE__ */ new Date();
792
992
  const apiData = [];
793
- Object.entries(this.stm).forEach(([key, entry]) => {
993
+ const sortedKeys = this.getSortedKeys();
994
+ sortedKeys.forEach((key) => {
995
+ const entry = this.stm[key];
794
996
  if (entry.attributes.visible) {
795
997
  const processedValue = entry.attributes.template ? this.get_value(key) : entry.value;
796
998
  apiData.push({
@@ -815,7 +1017,9 @@ var MindCache = class {
815
1017
  }
816
1018
  getVisibleImages() {
817
1019
  const imageParts = [];
818
- Object.entries(this.stm).forEach(([key, entry]) => {
1020
+ const sortedKeys = this.getSortedKeys();
1021
+ sortedKeys.forEach((key) => {
1022
+ const entry = this.stm[key];
819
1023
  if (entry.attributes.visible && entry.attributes.type === "image" && entry.attributes.contentType) {
820
1024
  const dataUrl = this.createDataUrl(entry.value, entry.attributes.contentType);
821
1025
  imageParts.push({
@@ -841,7 +1045,9 @@ var MindCache = class {
841
1045
  }
842
1046
  serialize() {
843
1047
  const result = {};
844
- Object.entries(this.stm).forEach(([key, entry]) => {
1048
+ const sortedKeys = this.getSortedKeys();
1049
+ sortedKeys.forEach((key) => {
1050
+ const entry = this.stm[key];
845
1051
  if (!entry.attributes.hardcoded) {
846
1052
  result[key] = {
847
1053
  value: entry.value,
@@ -856,11 +1062,40 @@ var MindCache = class {
856
1062
  this.clear();
857
1063
  Object.entries(data).forEach(([key, entry]) => {
858
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 || [];
859
1086
  this.stm[key] = {
860
1087
  value: entry.value,
861
1088
  attributes: {
862
- ...entry.attributes,
863
- 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")
864
1099
  }
865
1100
  };
866
1101
  }
@@ -871,7 +1106,9 @@ var MindCache = class {
871
1106
  get_system_prompt() {
872
1107
  const now = /* @__PURE__ */ new Date();
873
1108
  const promptLines = [];
874
- Object.entries(this.stm).forEach(([key, entry]) => {
1109
+ const sortedKeys = this.getSortedKeys();
1110
+ sortedKeys.forEach((key) => {
1111
+ const entry = this.stm[key];
875
1112
  if (entry.attributes.visible) {
876
1113
  if (entry.attributes.type === "image") {
877
1114
  promptLines.push(`image ${key} available`);
@@ -906,14 +1143,18 @@ var MindCache = class {
906
1143
  return void 0;
907
1144
  }
908
1145
  const sanitizedKey = toolName.replace("write_", "");
909
- const allKeys = Object.keys(this.stm);
910
- return allKeys.find(
1146
+ const sortedKeys = this.getSortedKeys();
1147
+ return sortedKeys.find(
911
1148
  (k) => k.replace(/[^a-zA-Z0-9_-]/g, "_") === sanitizedKey
912
1149
  );
913
1150
  }
914
1151
  get_aisdk_tools() {
915
1152
  const tools = {};
916
- 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
+ });
917
1158
  writableKeys.forEach((key) => {
918
1159
  const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
919
1160
  const toolName = `write_${sanitizedKey}`;
@@ -997,6 +1238,12 @@ var MindCache = class {
997
1238
  value
998
1239
  };
999
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
+ */
1000
1247
  addTag(key, tag) {
1001
1248
  if (key === "$date" || key === "$time") {
1002
1249
  return false;
@@ -1005,64 +1252,231 @@ var MindCache = class {
1005
1252
  if (!entry) {
1006
1253
  return false;
1007
1254
  }
1008
- if (!entry.attributes.tags) {
1009
- entry.attributes.tags = [];
1255
+ if (!entry.attributes.contentTags) {
1256
+ entry.attributes.contentTags = [];
1010
1257
  }
1011
- if (!entry.attributes.tags.includes(tag)) {
1012
- 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];
1013
1261
  this.notifyGlobalListeners();
1014
1262
  return true;
1015
1263
  }
1016
1264
  return false;
1017
1265
  }
1266
+ /**
1267
+ * Remove a content tag from a key
1268
+ */
1018
1269
  removeTag(key, tag) {
1019
1270
  if (key === "$date" || key === "$time") {
1020
1271
  return false;
1021
1272
  }
1022
1273
  const entry = this.stm[key];
1023
- if (!entry || !entry.attributes.tags) {
1274
+ if (!entry || !entry.attributes.contentTags) {
1024
1275
  return false;
1025
1276
  }
1026
- const tagIndex = entry.attributes.tags.indexOf(tag);
1277
+ const tagIndex = entry.attributes.contentTags.indexOf(tag);
1027
1278
  if (tagIndex > -1) {
1028
- entry.attributes.tags.splice(tagIndex, 1);
1279
+ entry.attributes.contentTags.splice(tagIndex, 1);
1280
+ entry.attributes.tags = [...entry.attributes.contentTags];
1029
1281
  this.notifyGlobalListeners();
1030
1282
  return true;
1031
1283
  }
1032
1284
  return false;
1033
1285
  }
1286
+ /**
1287
+ * Get all content tags for a key
1288
+ */
1034
1289
  getTags(key) {
1035
1290
  if (key === "$date" || key === "$time") {
1036
1291
  return [];
1037
1292
  }
1038
1293
  const entry = this.stm[key];
1039
- return entry?.attributes.tags || [];
1294
+ return entry?.attributes.contentTags || [];
1040
1295
  }
1296
+ /**
1297
+ * Get all unique content tags across all keys
1298
+ */
1041
1299
  getAllTags() {
1042
1300
  const allTags = /* @__PURE__ */ new Set();
1043
1301
  Object.values(this.stm).forEach((entry) => {
1044
- if (entry.attributes.tags) {
1045
- entry.attributes.tags.forEach((tag) => allTags.add(tag));
1302
+ if (entry.attributes.contentTags) {
1303
+ entry.attributes.contentTags.forEach((tag) => allTags.add(tag));
1046
1304
  }
1047
1305
  });
1048
1306
  return Array.from(allTags);
1049
1307
  }
1308
+ /**
1309
+ * Check if a key has a specific content tag
1310
+ */
1050
1311
  hasTag(key, tag) {
1051
1312
  if (key === "$date" || key === "$time") {
1052
1313
  return false;
1053
1314
  }
1054
1315
  const entry = this.stm[key];
1055
- return entry?.attributes.tags?.includes(tag) || false;
1316
+ return entry?.attributes.contentTags?.includes(tag) || false;
1056
1317
  }
1318
+ /**
1319
+ * Get all keys with a specific content tag as formatted string
1320
+ */
1057
1321
  getTagged(tag) {
1058
1322
  const entries = [];
1059
- Object.entries(this.stm).forEach(([key, entry]) => {
1060
- 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)) {
1061
1327
  entries.push([key, this.get_value(key)]);
1062
1328
  }
1063
1329
  });
1064
1330
  return entries.map(([key, value]) => `${key}: ${value}`).join(", ");
1065
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
+ }
1066
1480
  toMarkdown() {
1067
1481
  const now = /* @__PURE__ */ new Date();
1068
1482
  const lines = [];
@@ -1076,7 +1490,9 @@ var MindCache = class {
1076
1490
  lines.push("");
1077
1491
  lines.push("## STM Entries");
1078
1492
  lines.push("");
1079
- Object.entries(this.stm).forEach(([key, entry]) => {
1493
+ const sortedKeys = this.getSortedKeys();
1494
+ sortedKeys.forEach((key) => {
1495
+ const entry = this.stm[key];
1080
1496
  if (entry.attributes.hardcoded) {
1081
1497
  return;
1082
1498
  }
@@ -1086,6 +1502,7 @@ var MindCache = class {
1086
1502
  lines.push(`- **Readonly**: \`${entry.attributes.readonly}\``);
1087
1503
  lines.push(`- **Visible**: \`${entry.attributes.visible}\``);
1088
1504
  lines.push(`- **Template**: \`${entry.attributes.template}\``);
1505
+ lines.push(`- **Z-Index**: \`${entry.attributes.zIndex ?? 0}\``);
1089
1506
  if (entry.attributes.tags && entry.attributes.tags.length > 0) {
1090
1507
  lines.push(`- **Tags**: \`${entry.attributes.tags.join("`, `")}\``);
1091
1508
  }
@@ -1198,11 +1615,9 @@ var MindCache = class {
1198
1615
  currentEntry = {
1199
1616
  value: void 0,
1200
1617
  attributes: {
1201
- readonly: false,
1202
- visible: true,
1203
- hardcoded: false,
1204
- template: false,
1205
- type: "text",
1618
+ ...DEFAULT_KEY_ATTRIBUTES,
1619
+ contentTags: [],
1620
+ systemTags: ["prompt"],
1206
1621
  tags: []
1207
1622
  }
1208
1623
  };
@@ -1226,6 +1641,14 @@ var MindCache = class {
1226
1641
  if (currentEntry) {
1227
1642
  currentEntry.attributes.template = value;
1228
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
+ }
1229
1652
  } else if (trimmed.startsWith("- **Tags**: `")) {
1230
1653
  const tagsStr = trimmed.substring(13, trimmed.length - 1);
1231
1654
  if (currentEntry) {
@@ -1282,9 +1705,35 @@ var MindCache = class {
1282
1705
  }
1283
1706
  }
1284
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
+ }
1285
1734
  this.stm[key] = {
1286
1735
  value: entry.value,
1287
- attributes: entry.attributes
1736
+ attributes: attrs
1288
1737
  };
1289
1738
  }
1290
1739
  });