@cuylabs/agent-core 0.7.0 → 0.9.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.
Files changed (79) hide show
  1. package/dist/{builder-BRvqCcIk.d.ts → builder-BgZ_j4Vs.d.ts} +3 -2
  2. package/dist/chunk-4QFNWPIF.js +202 -0
  3. package/dist/chunk-5ARZJWD2.js +259 -0
  4. package/dist/chunk-DXFBQMXP.js +53 -0
  5. package/dist/chunk-EKR6PKXU.js +180 -0
  6. package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
  7. package/dist/{chunk-IEFIQENH.js → chunk-H3FUYU52.js} +15 -7
  8. package/dist/chunk-I6PKJ7XQ.js +292 -0
  9. package/dist/chunk-IYWQOJMQ.js +102 -0
  10. package/dist/{chunk-3HNO5SVI.js → chunk-J4QDGZIA.js} +20 -4
  11. package/dist/{chunk-7MUFEN4K.js → chunk-JLXG2SH7.js} +349 -3
  12. package/dist/{chunk-CDTV2UYU.js → chunk-MAZ5DY5B.js} +64 -276
  13. package/dist/{chunk-P6YF7USR.js → chunk-MHKK374K.js} +12 -11
  14. package/dist/{chunk-VBWWUHWI.js → chunk-OFDKHNCX.js} +4 -1
  15. package/dist/{chunk-YUUJK53A.js → chunk-RKEW5WXI.js} +1 -1
  16. package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
  17. package/dist/{chunk-QGOGIP7T.js → chunk-UDCZ673N.js} +385 -233
  18. package/dist/{chunk-BDBZ3SLK.js → chunk-UHCJEM2E.js} +39 -2
  19. package/dist/chunk-WGZAPU6N.js +929 -0
  20. package/dist/{chunk-5K7AQVOU.js → chunk-WKHDSSXG.js} +130 -209
  21. package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
  22. package/dist/context/index.js +1 -1
  23. package/dist/events-CE72w8W4.d.ts +149 -0
  24. package/dist/index-BCqEGzBj.d.ts +251 -0
  25. package/dist/{index-C33hlD6H.d.ts → index-DQuTZ8xL.d.ts} +319 -56
  26. package/dist/index.d.ts +42 -121
  27. package/dist/index.js +951 -848
  28. package/dist/inference/errors/index.d.ts +11 -0
  29. package/dist/inference/errors/index.js +16 -0
  30. package/dist/inference/index.d.ts +12 -8
  31. package/dist/inference/index.js +35 -7
  32. package/dist/llm-error-D93FNNLY.d.ts +32 -0
  33. package/dist/middleware/index.d.ts +246 -7
  34. package/dist/middleware/index.js +3 -1
  35. package/dist/models/index.d.ts +132 -9
  36. package/dist/models/index.js +48 -8
  37. package/dist/models/reasoning/index.d.ts +4 -0
  38. package/dist/{reasoning → models/reasoning}/index.js +2 -7
  39. package/dist/plugin/index.d.ts +414 -0
  40. package/dist/plugin/index.js +32 -0
  41. package/dist/presets/index.d.ts +53 -0
  42. package/dist/presets/index.js +30 -0
  43. package/dist/prompt/index.d.ts +11 -8
  44. package/dist/prompt/index.js +3 -2
  45. package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
  46. package/dist/runner-CI-XeR16.d.ts +91 -0
  47. package/dist/runtime/index.d.ts +12 -8
  48. package/dist/runtime/index.js +8 -7
  49. package/dist/safety/index.d.ts +38 -0
  50. package/dist/safety/index.js +12 -0
  51. package/dist/scope/index.d.ts +2 -2
  52. package/dist/{session-manager-B_CWGTsl.d.ts → session-manager-KbYt2WUh.d.ts} +8 -0
  53. package/dist/signal/index.d.ts +28 -0
  54. package/dist/signal/index.js +6 -0
  55. package/dist/skill/index.d.ts +7 -6
  56. package/dist/skill/index.js +3 -3
  57. package/dist/storage/index.d.ts +2 -2
  58. package/dist/storage/index.js +1 -1
  59. package/dist/sub-agent/index.d.ts +16 -10
  60. package/dist/sub-agent/index.js +21 -4
  61. package/dist/tool/index.d.ts +22 -6
  62. package/dist/tool/index.js +3 -3
  63. package/dist/tool-CZWN3KbO.d.ts +141 -0
  64. package/dist/{tool-HUtkiVBx.d.ts → tool-DkhSCV2Y.d.ts} +2 -2
  65. package/dist/tracking/index.d.ts +2 -2
  66. package/dist/tracking/index.js +1 -1
  67. package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
  68. package/dist/{types-FRpzzg_9.d.ts → types-BlOKk-Bb.d.ts} +10 -35
  69. package/dist/types-BlZwmnuW.d.ts +50 -0
  70. package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
  71. package/dist/types-CWm-7rvB.d.ts +55 -0
  72. package/dist/{runner-DSKaEz3z.d.ts → types-DTSkxakL.d.ts} +7 -235
  73. package/dist/{types-CqDZTh4d.d.ts → types-DmDwi2zI.d.ts} +8 -4
  74. package/dist/types-YuWV4ag7.d.ts +72 -0
  75. package/package.json +67 -6
  76. package/dist/capability-resolver-CgRGsWVX.d.ts +0 -254
  77. package/dist/chunk-ZPMACVZK.js +0 -305
  78. package/dist/index-CfBGYrpd.d.ts +0 -317
  79. package/dist/reasoning/index.d.ts +0 -117
@@ -1,6 +1,9 @@
1
+ import {
2
+ Presets
3
+ } from "./chunk-EKR6PKXU.js";
1
4
  import {
2
5
  Tool
3
- } from "./chunk-P6YF7USR.js";
6
+ } from "./chunk-MHKK374K.js";
4
7
 
5
8
  // src/sub-agent/types.ts
6
9
  var DEFAULT_MAX_CONCURRENT = 6;
@@ -169,7 +172,7 @@ var SubAgentTracker = class {
169
172
  }
170
173
  if (timeoutMs !== void 0 && timeoutMs > 0) {
171
174
  const timeout = new Promise(
172
- (resolve) => setTimeout(() => resolve({ timedOut: true }), timeoutMs)
175
+ (resolve2) => setTimeout(() => resolve2({ timedOut: true }), timeoutMs)
173
176
  );
174
177
  return Promise.race([...races, timeout]);
175
178
  }
@@ -550,10 +553,353 @@ function createSubAgentTools(parent, config) {
550
553
  return tools;
551
554
  }
552
555
 
556
+ // src/sub-agent/markdown-profile.ts
557
+ var FRONTMATTER_REGEX = /^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/;
558
+ var VALID_REASONING_LEVELS = /* @__PURE__ */ new Set([
559
+ "off",
560
+ "minimal",
561
+ "low",
562
+ "medium",
563
+ "high",
564
+ "xhigh"
565
+ ]);
566
+ function parseAgentFrontmatter(raw) {
567
+ const result = {};
568
+ const lines = raw.split("\n");
569
+ let i = 0;
570
+ while (i < lines.length) {
571
+ const line = lines[i];
572
+ if (line.trim() === "" || line.trim().startsWith("#")) {
573
+ i++;
574
+ continue;
575
+ }
576
+ const colonIndex = line.indexOf(":");
577
+ if (colonIndex === -1) {
578
+ i++;
579
+ continue;
580
+ }
581
+ const key = line.slice(0, colonIndex).trim();
582
+ let value = line.slice(colonIndex + 1).trim();
583
+ if (value === "|") {
584
+ const blockLines = [];
585
+ i++;
586
+ while (i < lines.length) {
587
+ const blockLine = lines[i];
588
+ if (blockLine.length > 0 && !blockLine.startsWith(" ") && !blockLine.startsWith(" ")) {
589
+ break;
590
+ }
591
+ blockLines.push(blockLine);
592
+ i++;
593
+ }
594
+ const minIndent = blockLines.filter((l) => l.trim().length > 0).reduce((min, l) => {
595
+ const indent = l.match(/^(\s*)/)?.[1].length ?? 0;
596
+ return Math.min(min, indent);
597
+ }, Infinity);
598
+ result[key] = blockLines.map((l) => l.trim().length === 0 ? "" : l.slice(minIndent)).join("\n").trim();
599
+ continue;
600
+ }
601
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
602
+ value = value.slice(1, -1);
603
+ }
604
+ if (key.length > 0) {
605
+ result[key] = value;
606
+ }
607
+ i++;
608
+ }
609
+ return result;
610
+ }
611
+ function parseMarkdownAgent(content, filePath) {
612
+ const match = content.match(FRONTMATTER_REGEX);
613
+ if (!match) {
614
+ return null;
615
+ }
616
+ const [, rawFrontmatter, body] = match;
617
+ const fields = parseAgentFrontmatter(rawFrontmatter);
618
+ if (!fields.name || !fields.description) {
619
+ return null;
620
+ }
621
+ const frontmatter = {
622
+ name: fields.name,
623
+ description: fields.description
624
+ };
625
+ if (fields.preset) frontmatter.preset = fields.preset;
626
+ if (fields.extends) frontmatter.extends = fields.extends;
627
+ if (fields.model) frontmatter.model = fields.model;
628
+ if (fields.maxSteps) frontmatter.maxSteps = fields.maxSteps;
629
+ if (fields.temperature) frontmatter.temperature = fields.temperature;
630
+ if (fields.reasoning) frontmatter.reasoning = fields.reasoning;
631
+ if (fields.tools) frontmatter.tools = fields.tools;
632
+ if (fields.skills) frontmatter.skills = fields.skills;
633
+ if (fields.canSpawn) frontmatter.canSpawn = fields.canSpawn;
634
+ return {
635
+ frontmatter,
636
+ body: body.trim(),
637
+ filePath
638
+ };
639
+ }
640
+ function parseToolSpec(raw) {
641
+ if (raw === void 0 || raw.trim() === "") {
642
+ return { mode: "inherit" };
643
+ }
644
+ const items = raw.split(",").map((s) => s.trim()).filter(Boolean);
645
+ if (items.length === 0) {
646
+ return { mode: "inherit" };
647
+ }
648
+ const hasModifiers = items.some((item) => item.startsWith("+") || item.startsWith("-"));
649
+ if (hasModifiers) {
650
+ const modifiers = items.map((item) => {
651
+ if (item.startsWith("+")) {
652
+ return { kind: "add", pattern: item.slice(1) };
653
+ }
654
+ if (item.startsWith("-")) {
655
+ return { kind: "remove", pattern: item.slice(1) };
656
+ }
657
+ return { kind: "add", pattern: item };
658
+ });
659
+ return { mode: "modifiers", modifiers };
660
+ }
661
+ return { mode: "explicit", patterns: items };
662
+ }
663
+ function toAgentProfile(parsed, resolvers = {}) {
664
+ const { frontmatter, body } = parsed;
665
+ const parent = frontmatter.extends ? resolvers.resolveParent?.(frontmatter.extends) : void 0;
666
+ const preset = frontmatter.preset ? resolvers.resolvePreset?.(frontmatter.preset) : parent?.preset;
667
+ let systemPrompt;
668
+ if (body.length > 0) {
669
+ const parentPrompt = parent?.systemPrompt ?? preset?.systemPrompt ?? "";
670
+ systemPrompt = body.includes("{basePrompt}") ? body.replace("{basePrompt}", parentPrompt) : body;
671
+ } else if (parent?.systemPrompt) {
672
+ systemPrompt = parent.systemPrompt;
673
+ }
674
+ const maxSteps = frontmatter.maxSteps ? parseInt(frontmatter.maxSteps, 10) : parent?.maxSteps;
675
+ let resolvedPreset = preset;
676
+ const temperature = frontmatter.temperature ? parseFloat(frontmatter.temperature) : void 0;
677
+ const reasoning = frontmatter.reasoning;
678
+ if (temperature !== void 0 || reasoning !== void 0) {
679
+ resolvedPreset = {
680
+ ...preset ?? { name: "custom", description: "Markdown-defined agent" },
681
+ ...temperature !== void 0 ? { temperature } : {},
682
+ ...reasoning !== void 0 && VALID_REASONING_LEVELS.has(reasoning) ? { reasoningLevel: reasoning } : {}
683
+ };
684
+ }
685
+ const toolSpec = parseToolSpec(frontmatter.tools);
686
+ if (toolSpec.mode === "explicit" || toolSpec.mode === "modifiers") {
687
+ resolvedPreset = {
688
+ ...resolvedPreset ?? { name: "custom", description: "Markdown-defined agent" }
689
+ };
690
+ if (toolSpec.mode === "explicit") {
691
+ resolvedPreset.allowTools = toolSpec.patterns;
692
+ resolvedPreset.denyTools = void 0;
693
+ } else {
694
+ const baseAllow = [...resolvedPreset.allowTools ?? []];
695
+ const baseDeny = [...resolvedPreset.denyTools ?? []];
696
+ for (const mod of toolSpec.modifiers) {
697
+ if (mod.kind === "add") {
698
+ baseAllow.push(mod.pattern);
699
+ const denyIdx = baseDeny.indexOf(mod.pattern);
700
+ if (denyIdx !== -1) baseDeny.splice(denyIdx, 1);
701
+ } else {
702
+ baseDeny.push(mod.pattern);
703
+ const allowIdx = baseAllow.indexOf(mod.pattern);
704
+ if (allowIdx !== -1) baseAllow.splice(allowIdx, 1);
705
+ }
706
+ }
707
+ if (baseAllow.length > 0) resolvedPreset.allowTools = baseAllow;
708
+ if (baseDeny.length > 0) resolvedPreset.denyTools = baseDeny;
709
+ }
710
+ }
711
+ const canSpawn = frontmatter.canSpawn ? frontmatter.canSpawn === "true" : parent?.canSpawn;
712
+ const profile = {
713
+ name: frontmatter.name,
714
+ description: frontmatter.description
715
+ };
716
+ if (resolvedPreset) profile.preset = resolvedPreset;
717
+ if (systemPrompt) profile.systemPrompt = systemPrompt;
718
+ if (maxSteps !== void 0 && !isNaN(maxSteps)) profile.maxSteps = maxSteps;
719
+ if (canSpawn !== void 0) profile.canSpawn = canSpawn;
720
+ if (frontmatter.model) {
721
+ profile._modelId = frontmatter.model;
722
+ }
723
+ if (frontmatter.skills) {
724
+ profile._skillNames = frontmatter.skills.split(",").map((s) => s.trim()).filter(Boolean);
725
+ }
726
+ profile._source = parsed.filePath;
727
+ return profile;
728
+ }
729
+ function isMarkdownProfile(profile) {
730
+ return "_source" in profile;
731
+ }
732
+
733
+ // src/sub-agent/discovery.ts
734
+ import { existsSync, readdirSync, readFileSync, statSync } from "fs";
735
+ import { homedir } from "os";
736
+ import { join, isAbsolute, resolve } from "path";
737
+ var DEFAULT_USER_DIR = join(homedir(), ".cuylabs", "agents");
738
+ var DEFAULT_PROJECT_DIR = ".cuylabs/agents";
739
+ var PRESET_MAP = {
740
+ explore: Presets.explore,
741
+ plan: Presets.plan,
742
+ review: Presets.review,
743
+ quick: Presets.quick,
744
+ careful: Presets.careful,
745
+ code: Presets.code,
746
+ watch: Presets.watch
747
+ };
748
+ function defaultResolvePreset(name) {
749
+ return PRESET_MAP[name.toLowerCase()];
750
+ }
751
+ function isLoadableMarkdown(filename) {
752
+ return filename.endsWith(".md") && !filename.startsWith("_") && !filename.startsWith(".");
753
+ }
754
+ function loadAgentDir(dir, source, resolvers, errors) {
755
+ if (!existsSync(dir)) return [];
756
+ let stat;
757
+ try {
758
+ stat = statSync(dir);
759
+ } catch {
760
+ return [];
761
+ }
762
+ if (!stat.isDirectory()) return [];
763
+ const results = [];
764
+ let entries;
765
+ try {
766
+ entries = readdirSync(dir, { withFileTypes: true });
767
+ } catch {
768
+ return [];
769
+ }
770
+ for (const entry of entries) {
771
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
772
+ if (!isLoadableMarkdown(entry.name)) continue;
773
+ const filePath = join(dir, entry.name);
774
+ try {
775
+ const content = readFileSync(filePath, "utf-8");
776
+ const parsed = parseMarkdownAgent(content, filePath);
777
+ if (!parsed) {
778
+ errors.push({ path: filePath, error: "Missing required frontmatter (name, description)" });
779
+ continue;
780
+ }
781
+ const profile = toAgentProfile(parsed, resolvers);
782
+ results.push({ profile, source, filePath });
783
+ } catch (err) {
784
+ errors.push({
785
+ path: filePath,
786
+ error: err instanceof Error ? err.message : String(err)
787
+ });
788
+ }
789
+ }
790
+ return results;
791
+ }
792
+ function loadAgentFile(filePath, source, resolvers, errors) {
793
+ if (!existsSync(filePath)) {
794
+ errors.push({ path: filePath, error: "File not found" });
795
+ return null;
796
+ }
797
+ try {
798
+ const content = readFileSync(filePath, "utf-8");
799
+ const parsed = parseMarkdownAgent(content, filePath);
800
+ if (!parsed) {
801
+ errors.push({ path: filePath, error: "Missing required frontmatter (name, description)" });
802
+ return null;
803
+ }
804
+ const profile = toAgentProfile(parsed, resolvers);
805
+ return { profile, source, filePath };
806
+ } catch (err) {
807
+ errors.push({
808
+ path: filePath,
809
+ error: err instanceof Error ? err.message : String(err)
810
+ });
811
+ return null;
812
+ }
813
+ }
814
+ function discoverAgentProfiles(options) {
815
+ const {
816
+ cwd,
817
+ userDir = DEFAULT_USER_DIR,
818
+ projectDir = DEFAULT_PROJECT_DIR,
819
+ configPaths = [],
820
+ builtInProfiles = [],
821
+ resolvePreset: customResolvePreset
822
+ } = options;
823
+ const errors = [];
824
+ const discovered = [];
825
+ const presetResolver = customResolvePreset ?? defaultResolvePreset;
826
+ const firstPassResolvers = {
827
+ resolvePreset: presetResolver
828
+ // resolveParent deferred to merge phase
829
+ };
830
+ for (const profile of builtInProfiles) {
831
+ discovered.push({ profile, source: "builtin" });
832
+ }
833
+ const userProfiles = loadAgentDir(userDir, "user", firstPassResolvers, errors);
834
+ discovered.push(...userProfiles);
835
+ const projectAgentsDir = resolve(cwd, projectDir);
836
+ const projectProfiles = loadAgentDir(projectAgentsDir, "project", firstPassResolvers, errors);
837
+ discovered.push(...projectProfiles);
838
+ for (const configPath of configPaths) {
839
+ const resolved = isAbsolute(configPath) ? configPath : resolve(cwd, configPath);
840
+ const entry = loadAgentFile(resolved, "config", firstPassResolvers, errors);
841
+ if (entry) discovered.push(entry);
842
+ }
843
+ const profileMap = /* @__PURE__ */ new Map();
844
+ for (const entry of discovered) {
845
+ profileMap.set(entry.profile.name, entry);
846
+ }
847
+ const merged = /* @__PURE__ */ new Map();
848
+ for (const [name, entry] of profileMap) {
849
+ const profile = entry.profile;
850
+ const md = profile;
851
+ if ("_source" in md) {
852
+ }
853
+ merged.set(name, profile);
854
+ }
855
+ const allProfiles = merged;
856
+ for (const [name, entry] of profileMap) {
857
+ const profile = entry.profile;
858
+ if (!("_source" in profile)) continue;
859
+ const md = profile;
860
+ if (!md._source) continue;
861
+ try {
862
+ const content = readFileSync(md._source, "utf-8");
863
+ const parsed = parseMarkdownAgent(content, md._source);
864
+ if (parsed?.frontmatter.extends) {
865
+ const parentName = parsed.frontmatter.extends;
866
+ const parent = allProfiles.get(parentName);
867
+ if (parent) {
868
+ const resolvedProfile = toAgentProfile(parsed, {
869
+ resolvePreset: presetResolver,
870
+ resolveParent: (n) => allProfiles.get(n)
871
+ });
872
+ merged.set(name, resolvedProfile);
873
+ }
874
+ }
875
+ } catch {
876
+ }
877
+ }
878
+ return {
879
+ profiles: Array.from(merged.values()),
880
+ discovered: Array.from(profileMap.values()),
881
+ errors
882
+ };
883
+ }
884
+ function getUserAgentsDir() {
885
+ return DEFAULT_USER_DIR;
886
+ }
887
+ function getProjectAgentsDir(cwd) {
888
+ return resolve(cwd, DEFAULT_PROJECT_DIR);
889
+ }
890
+
553
891
  export {
554
892
  DEFAULT_MAX_CONCURRENT,
555
893
  DEFAULT_MAX_SPAWN_DEPTH,
556
894
  DEFAULT_SESSION_TITLE_PREFIX,
557
895
  SubAgentTracker,
558
- createSubAgentTools
896
+ createSubAgentTools,
897
+ parseAgentFrontmatter,
898
+ parseMarkdownAgent,
899
+ parseToolSpec,
900
+ toAgentProfile,
901
+ isMarkdownProfile,
902
+ discoverAgentProfiles,
903
+ getUserAgentsDir,
904
+ getProjectAgentsDir
559
905
  };