agenr 3.1.0 → 3.3.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.
@@ -37,8 +37,8 @@ function readOptionalTrimmedString(value) {
37
37
  function readOptionalFiniteNumber(value) {
38
38
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
39
39
  }
40
- function pushIssue(issues, path4, message) {
41
- issues.push({ path: path4, message });
40
+ function pushIssue(issues, path5, message) {
41
+ issues.push({ path: path5, message });
42
42
  }
43
43
  function pushUnexpectedFields(value, allowedKeys, basePath, issues) {
44
44
  for (const key of Object.keys(value)) {
@@ -48,68 +48,68 @@ function pushUnexpectedFields(value, allowedKeys, basePath, issues) {
48
48
  pushIssue(issues, joinPath(basePath, key), "Unexpected field.");
49
49
  }
50
50
  }
51
- function parseRequiredTrimmedString(value, path4, issues, message = "Expected a non-empty string.") {
51
+ function parseRequiredTrimmedString(value, path5, issues, message = "Expected a non-empty string.") {
52
52
  if (typeof value !== "string") {
53
- pushIssue(issues, path4, message);
53
+ pushIssue(issues, path5, message);
54
54
  return void 0;
55
55
  }
56
56
  const normalized = value.trim();
57
57
  if (normalized.length === 0) {
58
- pushIssue(issues, path4, message);
58
+ pushIssue(issues, path5, message);
59
59
  return void 0;
60
60
  }
61
61
  return normalized;
62
62
  }
63
- function parseOptionalTrimmedString(value, path4, issues, typeMessage = "Expected a string.", emptyMessage = "Expected a non-empty string.") {
63
+ function parseOptionalTrimmedString(value, path5, issues, typeMessage = "Expected a string.", emptyMessage = "Expected a non-empty string.") {
64
64
  if (value === void 0) {
65
65
  return void 0;
66
66
  }
67
67
  if (typeof value !== "string") {
68
- pushIssue(issues, path4, typeMessage);
68
+ pushIssue(issues, path5, typeMessage);
69
69
  return void 0;
70
70
  }
71
71
  const normalized = value.trim();
72
72
  if (normalized.length === 0) {
73
- pushIssue(issues, path4, emptyMessage);
73
+ pushIssue(issues, path5, emptyMessage);
74
74
  return void 0;
75
75
  }
76
76
  return normalized;
77
77
  }
78
- function parseOptionalBoolean(value, path4, issues, message = "Expected a boolean.") {
78
+ function parseOptionalBoolean(value, path5, issues, message = "Expected a boolean.") {
79
79
  if (value === void 0) {
80
80
  return void 0;
81
81
  }
82
82
  if (typeof value !== "boolean") {
83
- pushIssue(issues, path4, message);
83
+ pushIssue(issues, path5, message);
84
84
  return void 0;
85
85
  }
86
86
  return value;
87
87
  }
88
- function parseOptionalIntegerInRange(value, path4, issues, bounds) {
88
+ function parseOptionalIntegerInRange(value, path5, issues, bounds) {
89
89
  if (value === void 0) {
90
90
  return void 0;
91
91
  }
92
92
  if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
93
- pushIssue(issues, path4, integerRangeMessage(bounds));
93
+ pushIssue(issues, path5, integerRangeMessage(bounds));
94
94
  return void 0;
95
95
  }
96
96
  if (bounds.min !== void 0 && value < bounds.min) {
97
- pushIssue(issues, path4, integerRangeMessage(bounds));
97
+ pushIssue(issues, path5, integerRangeMessage(bounds));
98
98
  return void 0;
99
99
  }
100
100
  if (bounds.max !== void 0 && value > bounds.max) {
101
- pushIssue(issues, path4, integerRangeMessage(bounds));
101
+ pushIssue(issues, path5, integerRangeMessage(bounds));
102
102
  return void 0;
103
103
  }
104
104
  return value;
105
105
  }
106
- function parseOptionalTimestampString(value, path4, issues, message = "Expected a valid timestamp string.") {
107
- const timestamp = parseOptionalTrimmedString(value, path4, issues);
106
+ function parseOptionalTimestampString(value, path5, issues, message = "Expected a valid timestamp string.") {
107
+ const timestamp = parseOptionalTrimmedString(value, path5, issues);
108
108
  if (timestamp === void 0) {
109
109
  return void 0;
110
110
  }
111
111
  if (Number.isNaN(Date.parse(timestamp))) {
112
- pushIssue(issues, path4, message);
112
+ pushIssue(issues, path5, message);
113
113
  return void 0;
114
114
  }
115
115
  return timestamp;
@@ -142,8 +142,7 @@ function integerRangeMessage(bounds) {
142
142
  // src/config.ts
143
143
  import fs from "fs";
144
144
  import os from "os";
145
- import path from "path";
146
- import { fileURLToPath } from "url";
145
+ import path2 from "path";
147
146
 
148
147
  // src/app/features/types.ts
149
148
  var AGENR_FEATURE_FLAG_KEYS = ["workingMemory", "sessionTreeLineage", "sessionTreeCompaction", "goalContinuation"];
@@ -153,9 +152,12 @@ var DEFAULT_AGENR_FEATURE_FLAGS = {
153
152
  sessionTreeCompaction: false,
154
153
  goalContinuation: false
155
154
  };
155
+ function createAllEnabledFeatureFlagConfig() {
156
+ return Object.fromEntries(AGENR_FEATURE_FLAG_KEYS.map((key) => [key, true]));
157
+ }
156
158
 
157
159
  // src/adapters/config/parse-feature-flags.ts
158
- function parseFeatureFlags(value, path4, issues) {
160
+ function parseFeatureFlags(value, path5, issues) {
159
161
  const defaults = DEFAULT_AGENR_FEATURE_FLAGS;
160
162
  if (value === void 0) {
161
163
  return {
@@ -163,17 +165,17 @@ function parseFeatureFlags(value, path4, issues) {
163
165
  };
164
166
  }
165
167
  if (!isRecord(value)) {
166
- pushIssue(issues, path4, "Expected an object.");
168
+ pushIssue(issues, path5, "Expected an object.");
167
169
  return {
168
170
  resolved: { ...defaults }
169
171
  };
170
172
  }
171
173
  const startIndex = issues.length;
172
- pushUnexpectedFields(value, new Set(AGENR_FEATURE_FLAG_KEYS), path4, issues);
173
- const workingMemory = parseOptionalBoolean(value.workingMemory, `${path4}.workingMemory`, issues);
174
- const sessionTreeLineage = parseOptionalBoolean(value.sessionTreeLineage, `${path4}.sessionTreeLineage`, issues);
175
- const sessionTreeCompaction = parseOptionalBoolean(value.sessionTreeCompaction, `${path4}.sessionTreeCompaction`, issues);
176
- const goalContinuation = parseOptionalBoolean(value.goalContinuation, `${path4}.goalContinuation`, issues);
174
+ pushUnexpectedFields(value, new Set(AGENR_FEATURE_FLAG_KEYS), path5, issues);
175
+ const workingMemory = parseOptionalBoolean(value.workingMemory, `${path5}.workingMemory`, issues);
176
+ const sessionTreeLineage = parseOptionalBoolean(value.sessionTreeLineage, `${path5}.sessionTreeLineage`, issues);
177
+ const sessionTreeCompaction = parseOptionalBoolean(value.sessionTreeCompaction, `${path5}.sessionTreeCompaction`, issues);
178
+ const goalContinuation = parseOptionalBoolean(value.goalContinuation, `${path5}.goalContinuation`, issues);
177
179
  if (issues.length > startIndex) {
178
180
  return {
179
181
  resolved: { ...defaults }
@@ -464,41 +466,41 @@ function pushTopLevelIssues(value, issues) {
464
466
  pushIssue(issues, "embeddingApiKey", "Removed field. Move this value to credentials.openaiApiKey, then delete embeddingApiKey.");
465
467
  }
466
468
  }
467
- function parseAuth(value, path4, issues) {
468
- const normalized = parseOptionalTrimmedString(value, path4, issues);
469
+ function parseAuth(value, path5, issues) {
470
+ const normalized = parseOptionalTrimmedString(value, path5, issues);
469
471
  if (!normalized) {
470
472
  return void 0;
471
473
  }
472
474
  if (!isAgenrAuthMethod(normalized)) {
473
- pushIssue(issues, path4, "Expected a supported auth method.");
475
+ pushIssue(issues, path5, "Expected a supported auth method.");
474
476
  return void 0;
475
477
  }
476
478
  return normalized;
477
479
  }
478
- function parseProvider(value, path4, issues) {
479
- const normalized = parseOptionalTrimmedString(value, path4, issues);
480
+ function parseProvider(value, path5, issues) {
481
+ const normalized = parseOptionalTrimmedString(value, path5, issues);
480
482
  if (!normalized) {
481
483
  return void 0;
482
484
  }
483
485
  if (!isAgenrProvider(normalized)) {
484
- pushIssue(issues, path4, "Expected a supported provider.");
486
+ pushIssue(issues, path5, "Expected a supported provider.");
485
487
  return void 0;
486
488
  }
487
489
  return normalized;
488
490
  }
489
- function parseCredentials(value, path4, issues) {
491
+ function parseCredentials(value, path5, issues) {
490
492
  if (value === void 0) {
491
493
  return void 0;
492
494
  }
493
495
  if (!isRecord(value)) {
494
- pushIssue(issues, path4, "Expected an object.");
496
+ pushIssue(issues, path5, "Expected an object.");
495
497
  return void 0;
496
498
  }
497
499
  const startIndex = issues.length;
498
- pushUnexpectedFields(value, /* @__PURE__ */ new Set(["openaiApiKey", "anthropicApiKey", "anthropicOauthToken"]), path4, issues);
499
- const openaiApiKey = parseOptionalTrimmedString(value.openaiApiKey, `${path4}.openaiApiKey`, issues);
500
- const anthropicApiKey = parseOptionalTrimmedString(value.anthropicApiKey, `${path4}.anthropicApiKey`, issues);
501
- const anthropicOauthToken = parseOptionalTrimmedString(value.anthropicOauthToken, `${path4}.anthropicOauthToken`, issues);
500
+ pushUnexpectedFields(value, /* @__PURE__ */ new Set(["openaiApiKey", "anthropicApiKey", "anthropicOauthToken"]), path5, issues);
501
+ const openaiApiKey = parseOptionalTrimmedString(value.openaiApiKey, `${path5}.openaiApiKey`, issues);
502
+ const anthropicApiKey = parseOptionalTrimmedString(value.anthropicApiKey, `${path5}.anthropicApiKey`, issues);
503
+ const anthropicOauthToken = parseOptionalTrimmedString(value.anthropicOauthToken, `${path5}.anthropicOauthToken`, issues);
502
504
  if (issues.length > startIndex) {
503
505
  return void 0;
504
506
  }
@@ -509,20 +511,20 @@ function parseCredentials(value, path4, issues) {
509
511
  };
510
512
  return hasStoredCredentials(credentials) ? credentials : void 0;
511
513
  }
512
- function parseModelConfig(value, path4, issues) {
514
+ function parseModelConfig(value, path5, issues) {
513
515
  if (value === void 0) {
514
516
  return void 0;
515
517
  }
516
518
  if (!isRecord(value)) {
517
- pushIssue(issues, path4, "Expected an object.");
519
+ pushIssue(issues, path5, "Expected an object.");
518
520
  return void 0;
519
521
  }
520
522
  const startIndex = issues.length;
521
- pushUnexpectedFields(value, /* @__PURE__ */ new Set(["provider", "model"]), path4, issues);
522
- const provider = parseProvider(value.provider, `${path4}.provider`, issues);
523
- const model = parseOptionalTrimmedString(value.model, `${path4}.model`, issues);
523
+ pushUnexpectedFields(value, /* @__PURE__ */ new Set(["provider", "model"]), path5, issues);
524
+ const provider = parseProvider(value.provider, `${path5}.provider`, issues);
525
+ const model = parseOptionalTrimmedString(value.model, `${path5}.model`, issues);
524
526
  if (!provider && !model) {
525
- pushIssue(issues, path4, "Expected at least one of provider or model.");
527
+ pushIssue(issues, path5, "Expected at least one of provider or model.");
526
528
  }
527
529
  if (issues.length > startIndex) {
528
530
  return void 0;
@@ -532,7 +534,7 @@ function parseModelConfig(value, path4, issues) {
532
534
  ...model ? { model } : {}
533
535
  };
534
536
  }
535
- function parseClaimExtractionConfig(value, path4, issues) {
537
+ function parseClaimExtractionConfig(value, path5, issues) {
536
538
  const defaults = createDefaultClaimExtractionConfig();
537
539
  if (value === void 0) {
538
540
  return {
@@ -540,20 +542,20 @@ function parseClaimExtractionConfig(value, path4, issues) {
540
542
  };
541
543
  }
542
544
  if (!isRecord(value)) {
543
- pushIssue(issues, path4, "Expected an object.");
545
+ pushIssue(issues, path5, "Expected an object.");
544
546
  return {
545
547
  resolved: defaults
546
548
  };
547
549
  }
548
550
  const startIndex = issues.length;
549
- pushUnexpectedFields(value, /* @__PURE__ */ new Set(["enabled", "confidenceThreshold", "eligibleTypes", "concurrency", "model"]), path4, issues);
550
- const enabled = parseOptionalBoolean(value.enabled, `${path4}.enabled`, issues);
551
- const confidenceThreshold = parseOptionalUnitInterval(value.confidenceThreshold, `${path4}.confidenceThreshold`, issues);
552
- const eligibleTypes = parseEligibleTypes(value.eligibleTypes, `${path4}.eligibleTypes`, issues);
553
- const concurrency = parseOptionalIntegerInRange(value.concurrency, `${path4}.concurrency`, issues, {
551
+ pushUnexpectedFields(value, /* @__PURE__ */ new Set(["enabled", "confidenceThreshold", "eligibleTypes", "concurrency", "model"]), path5, issues);
552
+ const enabled = parseOptionalBoolean(value.enabled, `${path5}.enabled`, issues);
553
+ const confidenceThreshold = parseOptionalUnitInterval(value.confidenceThreshold, `${path5}.confidenceThreshold`, issues);
554
+ const eligibleTypes = parseEligibleTypes(value.eligibleTypes, `${path5}.eligibleTypes`, issues);
555
+ const concurrency = parseOptionalIntegerInRange(value.concurrency, `${path5}.concurrency`, issues, {
554
556
  min: 1
555
557
  });
556
- const model = parseModelConfig(value.model, `${path4}.model`, issues);
558
+ const model = parseModelConfig(value.model, `${path5}.model`, issues);
557
559
  if (issues.length > startIndex) {
558
560
  return {
559
561
  resolved: defaults
@@ -577,7 +579,7 @@ function parseClaimExtractionConfig(value, path4, issues) {
577
579
  }
578
580
  };
579
581
  }
580
- function parseSurgeonConfig(value, path4, issues) {
582
+ function parseSurgeonConfig(value, path5, issues) {
581
583
  const defaults = createDefaultSurgeonConfig();
582
584
  if (value === void 0) {
583
585
  return {
@@ -585,19 +587,19 @@ function parseSurgeonConfig(value, path4, issues) {
585
587
  };
586
588
  }
587
589
  if (!isRecord(value)) {
588
- pushIssue(issues, path4, "Expected an object.");
590
+ pushIssue(issues, path5, "Expected an object.");
589
591
  return {
590
592
  resolved: defaults
591
593
  };
592
594
  }
593
595
  const startIndex = issues.length;
594
- pushUnexpectedFields(value, /* @__PURE__ */ new Set(["model", "costCap", "dailyCostCap", "contextLimit", "customInstructions", "passes"]), path4, issues);
595
- const model = parseModelConfig(value.model, `${path4}.model`, issues);
596
- const costCap = parseOptionalPositiveNumber(value.costCap, `${path4}.costCap`, issues);
597
- const dailyCostCap = parseOptionalNonNegativeNumber(value.dailyCostCap, `${path4}.dailyCostCap`, issues);
598
- const contextLimit = parseOptionalIntegerInRange(value.contextLimit, `${path4}.contextLimit`, issues, { min: 0 });
599
- const customInstructions = parseOptionalTrimmedString(value.customInstructions, `${path4}.customInstructions`, issues);
600
- const retirement = parseRetirementPassConfig(value.passes, `${path4}.passes`, issues);
596
+ pushUnexpectedFields(value, /* @__PURE__ */ new Set(["model", "costCap", "dailyCostCap", "contextLimit", "customInstructions", "passes"]), path5, issues);
597
+ const model = parseModelConfig(value.model, `${path5}.model`, issues);
598
+ const costCap = parseOptionalPositiveNumber(value.costCap, `${path5}.costCap`, issues);
599
+ const dailyCostCap = parseOptionalNonNegativeNumber(value.dailyCostCap, `${path5}.dailyCostCap`, issues);
600
+ const contextLimit = parseOptionalIntegerInRange(value.contextLimit, `${path5}.contextLimit`, issues, { min: 0 });
601
+ const customInstructions = parseOptionalTrimmedString(value.customInstructions, `${path5}.customInstructions`, issues);
602
+ const retirement = parseRetirementPassConfig(value.passes, `${path5}.passes`, issues);
601
603
  if (issues.length > startIndex) {
602
604
  return {
603
605
  resolved: defaults
@@ -629,7 +631,7 @@ function parseSurgeonConfig(value, path4, issues) {
629
631
  }
630
632
  };
631
633
  }
632
- function parseRetirementPassConfig(value, path4, issues) {
634
+ function parseRetirementPassConfig(value, path5, issues) {
633
635
  const defaults = createDefaultRetirementPassConfig();
634
636
  if (value === void 0) {
635
637
  return {
@@ -637,36 +639,36 @@ function parseRetirementPassConfig(value, path4, issues) {
637
639
  };
638
640
  }
639
641
  if (!isRecord(value)) {
640
- pushIssue(issues, path4, "Expected an object.");
642
+ pushIssue(issues, path5, "Expected an object.");
641
643
  return {
642
644
  resolved: defaults
643
645
  };
644
646
  }
645
647
  const startIndex = issues.length;
646
- pushUnexpectedFields(value, /* @__PURE__ */ new Set(["retirement"]), path4, issues);
648
+ pushUnexpectedFields(value, /* @__PURE__ */ new Set(["retirement"]), path5, issues);
647
649
  const retirement = value.retirement;
648
650
  if (retirement === void 0) {
649
651
  if (issues.length === startIndex) {
650
- pushIssue(issues, path4, "Expected a retirement config when passes is provided.");
652
+ pushIssue(issues, path5, "Expected a retirement config when passes is provided.");
651
653
  }
652
654
  return {
653
655
  resolved: defaults
654
656
  };
655
657
  }
656
658
  if (!isRecord(retirement)) {
657
- pushIssue(issues, `${path4}.retirement`, "Expected an object.");
659
+ pushIssue(issues, `${path5}.retirement`, "Expected an object.");
658
660
  return {
659
661
  resolved: defaults
660
662
  };
661
663
  }
662
- pushUnexpectedFields(retirement, /* @__PURE__ */ new Set(["protectRecalledDays", "protectMinImportance", "skipRecentlyEvaluatedDays"]), `${path4}.retirement`, issues);
663
- const protectRecalledDays = parseOptionalIntegerInRange(retirement.protectRecalledDays, `${path4}.retirement.protectRecalledDays`, issues, {
664
+ pushUnexpectedFields(retirement, /* @__PURE__ */ new Set(["protectRecalledDays", "protectMinImportance", "skipRecentlyEvaluatedDays"]), `${path5}.retirement`, issues);
665
+ const protectRecalledDays = parseOptionalIntegerInRange(retirement.protectRecalledDays, `${path5}.retirement.protectRecalledDays`, issues, {
664
666
  min: 0
665
667
  });
666
- const protectMinImportance = parseOptionalIntegerInRange(retirement.protectMinImportance, `${path4}.retirement.protectMinImportance`, issues, {
668
+ const protectMinImportance = parseOptionalIntegerInRange(retirement.protectMinImportance, `${path5}.retirement.protectMinImportance`, issues, {
667
669
  min: 0
668
670
  });
669
- const skipRecentlyEvaluatedDays = parseOptionalIntegerInRange(retirement.skipRecentlyEvaluatedDays, `${path4}.retirement.skipRecentlyEvaluatedDays`, issues, {
671
+ const skipRecentlyEvaluatedDays = parseOptionalIntegerInRange(retirement.skipRecentlyEvaluatedDays, `${path5}.retirement.skipRecentlyEvaluatedDays`, issues, {
670
672
  min: 0
671
673
  });
672
674
  if (issues.length > startIndex) {
@@ -688,54 +690,54 @@ function parseRetirementPassConfig(value, path4, issues) {
688
690
  }
689
691
  };
690
692
  }
691
- function parseOptionalUnitInterval(value, path4, issues) {
693
+ function parseOptionalUnitInterval(value, path5, issues) {
692
694
  if (value === void 0) {
693
695
  return void 0;
694
696
  }
695
697
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
696
- pushIssue(issues, path4, "Expected a number from 0 to 1.");
698
+ pushIssue(issues, path5, "Expected a number from 0 to 1.");
697
699
  return void 0;
698
700
  }
699
701
  return value;
700
702
  }
701
- function parseOptionalPositiveNumber(value, path4, issues) {
703
+ function parseOptionalPositiveNumber(value, path5, issues) {
702
704
  if (value === void 0) {
703
705
  return void 0;
704
706
  }
705
707
  if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
706
- pushIssue(issues, path4, "Expected a positive number.");
708
+ pushIssue(issues, path5, "Expected a positive number.");
707
709
  return void 0;
708
710
  }
709
711
  return value;
710
712
  }
711
- function parseOptionalNonNegativeNumber(value, path4, issues) {
713
+ function parseOptionalNonNegativeNumber(value, path5, issues) {
712
714
  if (value === void 0) {
713
715
  return void 0;
714
716
  }
715
717
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
716
- pushIssue(issues, path4, "Expected a non-negative number.");
718
+ pushIssue(issues, path5, "Expected a non-negative number.");
717
719
  return void 0;
718
720
  }
719
721
  return value;
720
722
  }
721
- function parseEligibleTypes(value, path4, issues) {
723
+ function parseEligibleTypes(value, path5, issues) {
722
724
  if (value === void 0) {
723
725
  return void 0;
724
726
  }
725
727
  if (!Array.isArray(value)) {
726
- pushIssue(issues, path4, "Expected an array of entry types.");
728
+ pushIssue(issues, path5, "Expected an array of entry types.");
727
729
  return void 0;
728
730
  }
729
731
  const normalized = [];
730
732
  const seen = /* @__PURE__ */ new Set();
731
733
  for (const [index, item] of value.entries()) {
732
734
  if (typeof item !== "string") {
733
- pushIssue(issues, `${path4}.${index}`, "Expected a supported entry type.");
735
+ pushIssue(issues, `${path5}.${index}`, "Expected a supported entry type.");
734
736
  continue;
735
737
  }
736
738
  const trimmed = item.trim();
737
739
  if (!isEntryType(trimmed)) {
738
- pushIssue(issues, `${path4}.${index}`, "Expected a supported entry type.");
740
+ pushIssue(issues, `${path5}.${index}`, "Expected a supported entry type.");
739
741
  continue;
740
742
  }
741
743
  if (!seen.has(trimmed)) {
@@ -744,7 +746,7 @@ function parseEligibleTypes(value, path4, issues) {
744
746
  }
745
747
  }
746
748
  if (normalized.length === 0) {
747
- pushIssue(issues, path4, "Expected at least one supported entry type.");
749
+ pushIssue(issues, path5, "Expected at least one supported entry type.");
748
750
  return void 0;
749
751
  }
750
752
  return normalized;
@@ -818,8 +820,53 @@ function toSurgeonInput(value) {
818
820
  return hasSurgeonInput(input) ? input : void 0;
819
821
  }
820
822
 
823
+ // src/filesystem-path.ts
824
+ import path from "path";
825
+ import { fileURLToPath, pathToFileURL } from "url";
826
+ function toAbsoluteFileUrl(filePath) {
827
+ return pathToFileURL(path.resolve(filePath)).href;
828
+ }
829
+ function resolveLocalFilesystemPath(targetPath) {
830
+ const trimmedPath = targetPath.trim();
831
+ if (trimmedPath.length === 0 || trimmedPath === ":memory:" || isInMemoryFileUrl(trimmedPath)) {
832
+ return null;
833
+ }
834
+ if (trimmedPath.startsWith("file:")) {
835
+ if (isAbsoluteFileUrl(trimmedPath)) {
836
+ try {
837
+ return fileURLToPath(trimmedPath);
838
+ } catch {
839
+ return null;
840
+ }
841
+ }
842
+ const relativePath = decodeRelativeFileUrlPath(trimmedPath);
843
+ return relativePath ? path.resolve(relativePath) : null;
844
+ }
845
+ return path.resolve(trimmedPath);
846
+ }
847
+ function resolveConfigFilesystemPath(targetPath) {
848
+ return resolveLocalFilesystemPath(targetPath) ?? targetPath;
849
+ }
850
+ function isAbsoluteFileUrl(targetPath) {
851
+ return /^file:(?:\/|[A-Za-z]:[\\/])/u.test(targetPath);
852
+ }
853
+ function isInMemoryFileUrl(targetPath) {
854
+ return targetPath === "file::memory:" || targetPath.startsWith("file::memory:?");
855
+ }
856
+ function decodeRelativeFileUrlPath(targetPath) {
857
+ const rawPath = targetPath.slice("file:".length).split(/[?#]/u, 1)[0]?.trim();
858
+ if (!rawPath) {
859
+ return null;
860
+ }
861
+ try {
862
+ return decodeURIComponent(rawPath);
863
+ } catch {
864
+ return rawPath;
865
+ }
866
+ }
867
+
821
868
  // src/config.ts
822
- var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".agenr");
869
+ var DEFAULT_CONFIG_DIR = path2.join(os.homedir(), ".agenr");
823
870
  var DEFAULT_DB_NAME = "knowledge.db";
824
871
  var CONFIG_DIR_MODE = 448;
825
872
  var CONFIG_FILE_MODE = 384;
@@ -839,7 +886,7 @@ function resolveConfigPath(options = {}) {
839
886
  if (adjacentConfigPath) {
840
887
  return adjacentConfigPath;
841
888
  }
842
- return path.join(resolveConfigDir(), "config.json");
889
+ return path2.join(resolveConfigDir(), "config.json");
843
890
  }
844
891
  function resolveDbPath(config) {
845
892
  return normalizeOptionalString(process.env.AGENR_DB_PATH) ?? normalizeOptionalString(config?.dbPath) ?? resolvePersistedDefaultDbPath();
@@ -880,7 +927,7 @@ function resolveClaimExtractionConfig(config) {
880
927
  };
881
928
  }
882
929
  function readConfig(options = {}) {
883
- const configPath = resolveFilesystemPath(resolveConfigPath(options));
930
+ const configPath = resolveConfigFilesystemPath(resolveConfigPath(options));
884
931
  const defaultDbPath = resolveReadDefaultDbPath(options);
885
932
  if (!fs.existsSync(configPath)) {
886
933
  const parsed2 = parseAgenrConfig(void 0, { defaultDbPath });
@@ -906,11 +953,11 @@ function readConfig(options = {}) {
906
953
  return parsed.value;
907
954
  }
908
955
  function configFileExists(options = {}) {
909
- return fs.existsSync(resolveFilesystemPath(resolveConfigPath(options)));
956
+ return fs.existsSync(resolveConfigFilesystemPath(resolveConfigPath(options)));
910
957
  }
911
958
  function writeConfig(config, options = {}) {
912
- const configPath = resolveFilesystemPath(resolveConfigPath(options));
913
- const configDir = path.dirname(configPath);
959
+ const configPath = resolveConfigFilesystemPath(resolveConfigPath(options));
960
+ const configDir = path2.dirname(configPath);
914
961
  const canonical = canonicalizeAgenrConfigInput(config, {
915
962
  defaultDbPath: resolvePersistedDefaultDbPath()
916
963
  });
@@ -938,30 +985,17 @@ function resolveAdjacentConfigPath(dbPath) {
938
985
  return void 0;
939
986
  }
940
987
  if (normalizedDbPath.startsWith("file:")) {
941
- try {
942
- return path.join(path.dirname(fileURLToPath(normalizedDbPath)), "config.json");
943
- } catch {
944
- return void 0;
945
- }
988
+ const filePath = resolveLocalFilesystemPath(normalizedDbPath);
989
+ return filePath ? path2.join(path2.dirname(filePath), "config.json") : void 0;
946
990
  }
947
- return path.join(path.dirname(normalizedDbPath), "config.json");
991
+ return path2.join(path2.dirname(normalizedDbPath), "config.json");
948
992
  }
949
993
  function normalizeOptionalString(value) {
950
994
  const normalized = value?.trim();
951
995
  return normalized && normalized.length > 0 ? normalized : void 0;
952
996
  }
953
- function resolveFilesystemPath(targetPath) {
954
- if (!targetPath.startsWith("file:")) {
955
- return targetPath;
956
- }
957
- try {
958
- return fileURLToPath(targetPath);
959
- } catch {
960
- return targetPath;
961
- }
962
- }
963
997
  function resolvePersistedDefaultDbPath() {
964
- return path.join(resolveConfigDir(), DEFAULT_DB_NAME);
998
+ return path2.join(resolveConfigDir(), DEFAULT_DB_NAME);
965
999
  }
966
1000
  function resolveReadDefaultDbPath(options) {
967
1001
  return normalizeOptionalString(process.env.AGENR_DB_PATH) ?? normalizeOptionalString(options.dbPath) ?? resolvePersistedDefaultDbPath();
@@ -1151,7 +1185,7 @@ async function sleep(durationMs) {
1151
1185
  import { createHash } from "crypto";
1152
1186
  import fs2 from "fs";
1153
1187
  import os2 from "os";
1154
- import path2 from "path";
1188
+ import path3 from "path";
1155
1189
  import { createRequire } from "module";
1156
1190
  import { completeSimple, getEnvApiKey, getModel } from "@earendil-works/pi-ai";
1157
1191
  var DEFAULT_REASONING = "medium";
@@ -1330,33 +1364,38 @@ function safeReadJson(filePath) {
1330
1364
  }
1331
1365
  }
1332
1366
  function resolveHomeDir(env) {
1333
- const home = normalizeOptionalString2(env.HOME);
1367
+ const home = normalizeOptionalString2(env.HOME) ?? normalizeOptionalString2(env.USERPROFILE) ?? resolveWindowsHomeFromParts(env);
1334
1368
  return home ? resolveUserPath(home) : os2.homedir();
1335
1369
  }
1336
1370
  function resolveCodexHome(env) {
1337
1371
  const configured = normalizeOptionalString2(env.CODEX_HOME) ?? "~/.codex";
1338
- const resolved = resolveUserPath(configured);
1372
+ const resolved = resolveUserPath(configured, resolveHomeDir(env));
1339
1373
  try {
1340
1374
  return fs2.realpathSync.native(resolved);
1341
1375
  } catch {
1342
1376
  return resolved;
1343
1377
  }
1344
1378
  }
1345
- function resolveUserPath(value) {
1379
+ function resolveUserPath(value, homeDir = os2.homedir()) {
1346
1380
  const trimmed = value.trim();
1347
1381
  if (trimmed === "~") {
1348
- return os2.homedir();
1382
+ return homeDir;
1349
1383
  }
1350
1384
  if (trimmed.startsWith("~/")) {
1351
- return path2.join(os2.homedir(), trimmed.slice(2));
1385
+ return path3.join(homeDir, trimmed.slice(2));
1352
1386
  }
1353
1387
  if (trimmed.startsWith("~\\")) {
1354
- return path2.join(os2.homedir(), trimmed.slice(2));
1388
+ return path3.join(homeDir, trimmed.slice(2));
1355
1389
  }
1356
- return path2.resolve(trimmed);
1390
+ return path3.resolve(trimmed);
1391
+ }
1392
+ function resolveWindowsHomeFromParts(env) {
1393
+ const drive = normalizeOptionalString2(env.HOMEDRIVE);
1394
+ const homePath = normalizeOptionalString2(env.HOMEPATH);
1395
+ return drive && homePath ? `${drive}${homePath}` : void 0;
1357
1396
  }
1358
1397
  function parseCodexFromFile(env) {
1359
- const authPath = path2.join(resolveCodexHome(env), "auth.json");
1398
+ const authPath = path3.join(resolveCodexHome(env), "auth.json");
1360
1399
  const parsed = safeReadJson(authPath);
1361
1400
  if (!parsed || typeof parsed !== "object") {
1362
1401
  return null;
@@ -1419,7 +1458,7 @@ function parseClaudeCredentialRecord(parsed, source) {
1419
1458
  }
1420
1459
  function parseClaudeFromFiles(env) {
1421
1460
  const homeDir = resolveHomeDir(env);
1422
- const candidates = [path2.join(homeDir, ".claude", ".credentials.json"), path2.join(homeDir, ".claude", "credentials.json")];
1461
+ const candidates = [path3.join(homeDir, ".claude", ".credentials.json"), path3.join(homeDir, ".claude", "credentials.json")];
1423
1462
  for (const candidate of candidates) {
1424
1463
  const parsed = safeReadJson(candidate);
1425
1464
  const resolved = parseClaudeCredentialRecord(parsed, `file:${candidate}`);
@@ -1747,7 +1786,7 @@ async function sleep2(durationMs) {
1747
1786
 
1748
1787
  // src/adapters/db/client.ts
1749
1788
  import fs3 from "fs/promises";
1750
- import path3 from "path";
1789
+ import path4 from "path";
1751
1790
  import { createClient } from "@libsql/client";
1752
1791
 
1753
1792
  // src/adapters/db/episode-queries.ts
@@ -3192,14 +3231,14 @@ function normalizeProcedureSources(value, label, filePath, options = {}) {
3192
3231
  function normalizeProcedureSource(record, label, filePath) {
3193
3232
  rejectUnexpectedProcedureFields(record, SOURCE_KEYS, label, filePath);
3194
3233
  const kind = readProcedureSourceKind(record.kind, `${label}.kind`, filePath, PROCEDURE_SOURCE_KINDS);
3195
- const path4 = readOptionalProcedureString(record.path, `${label}.path`, filePath);
3234
+ const path5 = readOptionalProcedureString(record.path, `${label}.path`, filePath);
3196
3235
  const locator = readOptionalProcedureString(record.locator, `${label}.locator`, filePath);
3197
3236
  const sourceLabel = readOptionalProcedureString(record.label, `${label}.label`, filePath);
3198
3237
  switch (kind) {
3199
3238
  case "skill":
3200
3239
  case "doc":
3201
3240
  case "repo_file":
3202
- if (!path4) {
3241
+ if (!path5) {
3203
3242
  throw new Error(`Invalid procedure ${filePath}: ${label}.${kind} sources require a path.`);
3204
3243
  }
3205
3244
  break;
@@ -3217,7 +3256,7 @@ function normalizeProcedureSource(record, label, filePath) {
3217
3256
  }
3218
3257
  return {
3219
3258
  kind,
3220
- ...path4 ? { path: path4 } : {},
3259
+ ...path5 ? { path: path5 } : {},
3221
3260
  ...locator ? { locator } : {},
3222
3261
  ...sourceLabel ? { label: sourceLabel } : {}
3223
3262
  };
@@ -5371,9 +5410,9 @@ async function openClient(dbPath) {
5371
5410
  if (trimmedPath.length === 0) {
5372
5411
  throw new Error("Database path must not be empty.");
5373
5412
  }
5374
- if (trimmedPath !== ":memory:" && !trimmedPath.startsWith("file:")) {
5375
- const resolvedPath = path3.resolve(trimmedPath);
5376
- await fs3.mkdir(path3.dirname(resolvedPath), { recursive: true });
5413
+ const localDbPath = resolveLocalFilesystemPath(trimmedPath);
5414
+ if (localDbPath) {
5415
+ await fs3.mkdir(path4.dirname(localDbPath), { recursive: true });
5377
5416
  }
5378
5417
  const client = createClient({ url: resolveClientUrl(trimmedPath) });
5379
5418
  await client.execute("PRAGMA foreign_keys = ON");
@@ -5390,7 +5429,7 @@ function resolveClientUrl(dbPath) {
5390
5429
  if (dbPath.startsWith("file:")) {
5391
5430
  return dbPath;
5392
5431
  }
5393
- return `file:${path3.resolve(dbPath)}`;
5432
+ return toAbsoluteFileUrl(dbPath);
5394
5433
  }
5395
5434
  async function rollbackTransaction(transaction) {
5396
5435
  if (transaction.closed) {
@@ -5400,8 +5439,6 @@ async function rollbackTransaction(transaction) {
5400
5439
  }
5401
5440
 
5402
5441
  // src/adapters/shared/memory-tool-format.ts
5403
- var DEFAULT_RECALL_LIMIT = 10;
5404
- var RESULT_SUBJECT_LOG_LIMIT = 5;
5405
5442
  var ENTRY_PREVIEW_MAX_CHARS = 220;
5406
5443
  var ENTRY_FETCH_MAX_CONTENT_CHARS = 32768;
5407
5444
  function buildEntryRecallPreview(content) {
@@ -5433,68 +5470,6 @@ function truncate(value, maxChars) {
5433
5470
  }
5434
5471
  return `${value.slice(0, maxChars - 3).trimEnd()}...`;
5435
5472
  }
5436
- function sanitizeStoreToolParams(params) {
5437
- return {
5438
- type: params.type,
5439
- subject: params.subject,
5440
- ...params.importance !== void 0 ? { importance: params.importance } : {},
5441
- ...params.expiry !== void 0 ? { expiry: params.expiry } : {},
5442
- ...params.tags.length > 0 ? { tags: params.tags } : {},
5443
- contentLength: params.content.length,
5444
- ...params.sourceContext !== void 0 ? { sourceContextLength: params.sourceContext.length } : {},
5445
- ...params.supersedes !== void 0 ? { hasSupersedes: true } : {},
5446
- ...params.claimKey !== void 0 ? { hasClaimKey: true } : {},
5447
- ...params.validFrom !== void 0 ? { hasValidFrom: true } : {},
5448
- ...params.validTo !== void 0 ? { hasValidTo: true } : {}
5449
- };
5450
- }
5451
- function formatRecallToolSummary(params) {
5452
- const parts = [`query=${JSON.stringify(truncate(params.query, 80))}`];
5453
- if (params.mode) {
5454
- parts.push(`mode=${params.mode}`);
5455
- }
5456
- if (params.limit !== void 0 && params.limit !== DEFAULT_RECALL_LIMIT) {
5457
- parts.push(`limit=${params.limit}`);
5458
- }
5459
- if (params.types.length > 0) {
5460
- parts.push(`types=${JSON.stringify(params.types)}`);
5461
- }
5462
- if (params.tags.length > 0) {
5463
- parts.push(`tags=${JSON.stringify(params.tags)}`);
5464
- }
5465
- if (params.asOf) {
5466
- parts.push(`as_of=${JSON.stringify(params.asOf)}`);
5467
- }
5468
- if (params.budget !== void 0) {
5469
- parts.push(`budget=${params.budget}`);
5470
- }
5471
- return parts.join(" ");
5472
- }
5473
- function sanitizeRecallToolParams(params) {
5474
- return {
5475
- query: params.query,
5476
- ...params.mode ? { mode: params.mode } : {},
5477
- ...params.limit !== void 0 ? { limit: params.limit } : {},
5478
- ...params.threshold !== void 0 ? { threshold: params.threshold } : {},
5479
- ...params.types.length > 0 ? { types: params.types } : {},
5480
- ...params.tags.length > 0 ? { tags: params.tags } : {},
5481
- ...params.asOf ? { asOf: params.asOf } : {},
5482
- ...params.budget !== void 0 ? { budget: params.budget } : {}
5483
- };
5484
- }
5485
- function formatUnifiedRecallLogSummary(result) {
5486
- const procedureCount = result.procedureCandidates.length;
5487
- const procedureSummary = result.procedure ? ` [procedure: ${JSON.stringify(truncate(result.procedure.title, 80))}]` : "";
5488
- const entrySubjects = result.entries.map((entry) => entry.entry.subject.trim()).filter((subject) => subject.length > 0);
5489
- const displayed = entrySubjects.slice(0, RESULT_SUBJECT_LOG_LIMIT).map((subject) => JSON.stringify(truncate(subject, 80)));
5490
- const remaining = entrySubjects.length - RESULT_SUBJECT_LOG_LIMIT;
5491
- const suffix = displayed.length === 0 ? "" : ` [entry subjects: ${displayed.join(", ")}${remaining > 0 ? `, ... and ${remaining} more` : ""}]`;
5492
- const entryEpisodeSummary = `${result.episodes.length} episode${result.episodes.length === 1 ? "" : "s"}, ${result.entries.length} entr${result.entries.length === 1 ? "y" : "ies"}`;
5493
- if (procedureCount === 0 && !result.procedure) {
5494
- return `${entryEpisodeSummary}${suffix}`;
5495
- }
5496
- return `${procedureCount} procedure candidate${procedureCount === 1 ? "" : "s"}, ${entryEpisodeSummary}${procedureSummary}${suffix}`;
5497
- }
5498
5473
  function buildRecallToolDetails(result, extraDetails = {}) {
5499
5474
  return {
5500
5475
  status: "ok",
@@ -7909,6 +7884,7 @@ function dedupePreservingOrder2(values) {
7909
7884
  }
7910
7885
 
7911
7886
  export {
7887
+ resolveLocalFilesystemPath,
7912
7888
  ENTRY_TYPES,
7913
7889
  EXPIRY_LEVELS,
7914
7890
  CLAIM_KEY_STATUSES,
@@ -7968,6 +7944,7 @@ export {
7968
7944
  parseOptionalTimestampString,
7969
7945
  AGENR_FEATURE_FLAG_KEYS,
7970
7946
  DEFAULT_AGENR_FEATURE_FLAGS,
7947
+ createAllEnabledFeatureFlagConfig,
7971
7948
  DEFAULT_SURGEON_COST_CAP,
7972
7949
  DEFAULT_SURGEON_DAILY_COST_CAP,
7973
7950
  DEFAULT_SURGEON_CONTEXT_LIMIT,
@@ -8000,10 +7977,6 @@ export {
8000
7977
  recallResultHasTruncatedEntryPreviews,
8001
7978
  assertEntryFetchableContentLength,
8002
7979
  truncate,
8003
- sanitizeStoreToolParams,
8004
- formatRecallToolSummary,
8005
- sanitizeRecallToolParams,
8006
- formatUnifiedRecallLogSummary,
8007
7980
  buildRecallToolDetails,
8008
7981
  formatFetchedEntryText,
8009
7982
  buildFetchToolDetails,