sigma-agents 0.1.9 → 0.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.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { ModelProfiler } from "./profiles.js";
2
1
  export { SmartRouter } from "./router.js";
3
- export { SubAgentManager } from "./sub-agent.js";
4
2
  export * from "./types.js";
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -14,12 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SubAgentManager = exports.SmartRouter = exports.ModelProfiler = void 0;
18
- var profiles_js_1 = require("./profiles.js");
19
- Object.defineProperty(exports, "ModelProfiler", { enumerable: true, get: function () { return profiles_js_1.ModelProfiler; } });
17
+ exports.SmartRouter = void 0;
20
18
  var router_js_1 = require("./router.js");
21
19
  Object.defineProperty(exports, "SmartRouter", { enumerable: true, get: function () { return router_js_1.SmartRouter; } });
22
- var sub_agent_js_1 = require("./sub-agent.js");
23
- Object.defineProperty(exports, "SubAgentManager", { enumerable: true, get: function () { return sub_agent_js_1.SubAgentManager; } });
24
20
  __exportStar(require("./types.js"), exports);
25
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA8C;AAArC,4GAAA,aAAa,OAAA;AACtB,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,+CAAiD;AAAxC,+GAAA,eAAe,OAAA;AACxB,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AACpB,6CAA2B"}
package/dist/router.d.ts CHANGED
@@ -3,8 +3,17 @@ export declare class SmartRouter {
3
3
  private config;
4
4
  constructor(config: RoutingConfig);
5
5
  /**
6
- * Analyse le prompt et retourne la catégorie de tâche
7
- * Priorité : debug > code > plan > review > test > explore > general
6
+ * Analyse le prompt et retourne la catégorie de tâche.
7
+ *
8
+ * Scoring: whole-word keyword matches per category (naive plural folding,
9
+ * multi-word keywords match as substrings). Best score wins. Ties break by
10
+ * intent priority — categories whose keywords are strong action verbs
11
+ * (debug, test, explore, review) beat categories that also match on generic
12
+ * nouns like "code" or "structure" (code, plan):
13
+ * debug > test > explore > review > code > plan > general.
14
+ *
15
+ * Whole-word matching matters: the previous substring match classified
16
+ * "functionality" as code (contains "function") and "codebase" as code.
8
17
  */
9
18
  classifyTask(prompt: string): TaskCategory;
10
19
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,qBAAa,WAAW;IACvB,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAIjC;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAkC1C;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE;IAmBlG;;OAEG;WACU,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBnE;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa;IA2CtE;;;;OAIG;IACH,MAAM,CAAC,aAAa,IAAI,aAAa;CAoIrC"}
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,qBAAa,WAAW;IACvB,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAIjC;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAoD1C;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE;IAmBlG;;OAEG;WACU,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBnE;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,aAAa;IA2CtE;;;;OAIG;IACH,MAAM,CAAC,aAAa,IAAI,aAAa;CAkIrC"}
package/dist/router.js CHANGED
@@ -8,35 +8,63 @@ class SmartRouter {
8
8
  this.config = config;
9
9
  }
10
10
  /**
11
- * Analyse le prompt et retourne la catégorie de tâche
12
- * Priorité : debug > code > plan > review > test > explore > general
11
+ * Analyse le prompt et retourne la catégorie de tâche.
12
+ *
13
+ * Scoring: whole-word keyword matches per category (naive plural folding,
14
+ * multi-word keywords match as substrings). Best score wins. Ties break by
15
+ * intent priority — categories whose keywords are strong action verbs
16
+ * (debug, test, explore, review) beat categories that also match on generic
17
+ * nouns like "code" or "structure" (code, plan):
18
+ * debug > test > explore > review > code > plan > general.
19
+ *
20
+ * Whole-word matching matters: the previous substring match classified
21
+ * "functionality" as code (contains "function") and "codebase" as code.
13
22
  */
14
23
  classifyTask(prompt) {
15
24
  const lowerPrompt = prompt.toLowerCase();
16
- const categories = [];
17
25
  if (!this.config?.routes) {
18
26
  return "general";
19
27
  }
20
- // Check each category
28
+ // Tokenize into whole words, folding naive plurals ("tests" -> "test").
29
+ const words = new Set();
30
+ for (const word of lowerPrompt.match(/[\p{L}\p{N}]+/gu) ?? []) {
31
+ words.add(word);
32
+ if (word.length > 3 && word.endsWith("s")) {
33
+ words.add(word.slice(0, -1));
34
+ }
35
+ }
36
+ const scores = new Map();
21
37
  for (const [category, route] of Object.entries(this.config.routes)) {
22
38
  if (!Array.isArray(route?.keywords))
23
39
  continue;
24
- const hasKeyword = route.keywords.some((keyword) => lowerPrompt.includes(keyword.toLowerCase()));
25
- if (hasKeyword) {
26
- categories.push(category);
40
+ let score = 0;
41
+ // Dedupe so a keyword listed twice in a config cannot double-count.
42
+ for (const needle of new Set(route.keywords.map((k) => k.toLowerCase()))) {
43
+ const matched = needle.includes(" ") ? lowerPrompt.includes(needle) : words.has(needle);
44
+ if (matched)
45
+ score++;
46
+ }
47
+ if (score > 0) {
48
+ scores.set(category, score);
27
49
  }
28
50
  }
29
- if (categories.length === 0) {
51
+ if (scores.size === 0) {
30
52
  return "general";
31
53
  }
32
- // Apply priorities
33
- const priorityOrder = ["debug", "code", "plan", "review", "test", "explore", "general"];
34
- for (const priority of priorityOrder) {
35
- if (categories.includes(priority)) {
36
- return priority;
54
+ const priorityOrder = ["debug", "test", "explore", "review", "code", "plan", "general"];
55
+ let best;
56
+ let bestScore = 0;
57
+ for (const [category, score] of scores) {
58
+ if (score > bestScore ||
59
+ (score === bestScore &&
60
+ best !== undefined &&
61
+ priorityOrder.indexOf(category) !== -1 &&
62
+ priorityOrder.indexOf(category) < priorityOrder.indexOf(best))) {
63
+ best = category;
64
+ bestScore = score;
37
65
  }
38
66
  }
39
- return categories[0];
67
+ return best ?? "general";
40
68
  }
41
69
  /**
42
70
  * Retourne le modèle et l'agent recommandés pour un prompt
@@ -172,7 +200,6 @@ class SmartRouter {
172
200
  "examine",
173
201
  "investigate",
174
202
  "study",
175
- "review",
176
203
  "explorer",
177
204
  "analyser",
178
205
  "comprendre",
@@ -192,7 +219,6 @@ class SmartRouter {
192
219
  "organize",
193
220
  "concevoir",
194
221
  "planifier",
195
- "architecture",
196
222
  ],
197
223
  },
198
224
  test: {
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAG5C,MAAa,WAAW;IACf,MAAM,CAAgB;IAE9B,YAAY,MAAqB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,MAAc;QAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,UAAU,GAAmB,EAAE,CAAC;QAEtC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,sBAAsB;QACtB,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAAE,SAAS;YAC9C,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,C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;iBACD;gBACD,IAAI,EAAE;oBACL,cAAc,EAAE,SAAS;oBACzB,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE;wBACT,MAAM;wBACN,QAAQ;wBACR,cAAc;wBACd,UAAU;wBACV,UAAU;wBACV,WAAW;wBACX,UAAU;wBACV,WAAW;wBACX,WAAW;qBACX;iBACD;gBACD,IAAI,EAAE;oBACL,cAAc,EAAE,SAAS;oBACzB,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE;wBACT,MAAM;wBACN,SAAS;wBACT,MAAM;wBACN,aAAa;wBACb,QAAQ;wBACR,UAAU;wBACV,OAAO;wBACP,QAAQ;wBACR,UAAU;wBACV,SAAS;qBACT;iBACD;gBACD,MAAM,EAAE;oBACP,cAAc,EAAE,SAAS;oBACzB,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE;wBACT,QAAQ;wBACR,OAAO;wBACP,OAAO;wBACP,UAAU;wBACV,SAAS;wBACT,SAAS;wBACT,UAAU;wBACV,SAAS;wBACT,WAAW;wBACX,WAAW;qBACX;iBACD;gBACD,OAAO,EAAE;oBACR,cAAc,EAAE,SAAS;oBACzB,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,IAAI;oBACX,QAAQ,EAAE;wBACT,MAAM;wBACN,SAAS;wBACT,MAAM;wBACN,KAAK;wBACL,KAAK;wBACL,UAAU;wBACV,MAAM;wBACN,WAAW;wBACX,SAAS;wBACT,UAAU;qBACV;iBACD;aACD;YACD,OAAO,EAAE;gBACR,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,IAAI;aACX;SACD,CAAC;IACH,CAAC;CACD;AA1SD,kCA0SC"}
package/dist/types.d.ts CHANGED
@@ -1,13 +1,4 @@
1
1
  export type TaskCategory = "code" | "debug" | "explore" | "plan" | "test" | "review" | "general";
2
- export interface ModelProfile {
3
- id: string;
4
- provider: string;
5
- speed: "fast" | "medium" | "slow";
6
- quality: "high" | "medium" | "low";
7
- strengths: TaskCategory[];
8
- maxTokens: number;
9
- supportsTools: boolean;
10
- }
11
2
  export interface RoutingConfig {
12
3
  routes: Record<TaskCategory, {
13
4
  preferredModel: string;
@@ -20,21 +11,4 @@ export interface RoutingConfig {
20
11
  agent: string | null;
21
12
  };
22
13
  }
23
- export interface SubAgentConfig {
24
- name: string;
25
- description: string;
26
- model: string;
27
- tools: string[];
28
- systemPrompt: string;
29
- maxTokens?: number;
30
- }
31
- export interface SubAgentResult {
32
- agentName: string;
33
- model: string;
34
- output: string;
35
- tokensUsed: number;
36
- durationMs: number;
37
- success: boolean;
38
- error?: string;
39
- }
40
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACnC,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CACb,YAAY,EACZ;QACC,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACnB,CACD,CAAC;IACF,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CACb,YAAY,EACZ;QACC,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACnB,CACD,CAAC;IACF,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigma-agents",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Intelligent sub-agent system with model routing for Phi Code",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "build": "tsc",
9
9
  "clean": "shx rm -rf dist",
10
10
  "prepublishOnly": "npm run clean && npm run build",
11
- "test": "node --test dist/test/*.test.js"
11
+ "test": "tsx --test test/*.test.ts"
12
12
  },
13
13
  "dependencies": {},
14
14
  "devDependencies": {
package/src/index.ts CHANGED
@@ -1,4 +1,2 @@
1
- export { ModelProfiler } from "./profiles.js";
2
1
  export { SmartRouter } from "./router.js";
3
- export { SubAgentManager } from "./sub-agent.js";
4
2
  export * from "./types.js";
package/src/router.ts CHANGED
@@ -9,41 +9,68 @@ export class SmartRouter {
9
9
  }
10
10
 
11
11
  /**
12
- * Analyse le prompt et retourne la catégorie de tâche
13
- * Priorité : debug > code > plan > review > test > explore > general
12
+ * Analyse le prompt et retourne la catégorie de tâche.
13
+ *
14
+ * Scoring: whole-word keyword matches per category (naive plural folding,
15
+ * multi-word keywords match as substrings). Best score wins. Ties break by
16
+ * intent priority — categories whose keywords are strong action verbs
17
+ * (debug, test, explore, review) beat categories that also match on generic
18
+ * nouns like "code" or "structure" (code, plan):
19
+ * debug > test > explore > review > code > plan > general.
20
+ *
21
+ * Whole-word matching matters: the previous substring match classified
22
+ * "functionality" as code (contains "function") and "codebase" as code.
14
23
  */
15
24
  classifyTask(prompt: string): TaskCategory {
16
25
  const lowerPrompt = prompt.toLowerCase();
17
- const categories: TaskCategory[] = [];
18
-
19
26
  if (!this.config?.routes) {
20
27
  return "general";
21
28
  }
22
29
 
23
- // Check each category
30
+ // Tokenize into whole words, folding naive plurals ("tests" -> "test").
31
+ const words = new Set<string>();
32
+ for (const word of lowerPrompt.match(/[\p{L}\p{N}]+/gu) ?? []) {
33
+ words.add(word);
34
+ if (word.length > 3 && word.endsWith("s")) {
35
+ words.add(word.slice(0, -1));
36
+ }
37
+ }
38
+
39
+ const scores = new Map<TaskCategory, number>();
24
40
  for (const [category, route] of Object.entries(this.config.routes)) {
25
41
  if (!Array.isArray(route?.keywords)) continue;
26
- const hasKeyword = route.keywords.some((keyword) => lowerPrompt.includes(keyword.toLowerCase()));
27
-
28
- if (hasKeyword) {
29
- categories.push(category as TaskCategory);
42
+ let score = 0;
43
+ // Dedupe so a keyword listed twice in a config cannot double-count.
44
+ for (const needle of new Set(route.keywords.map((k) => k.toLowerCase()))) {
45
+ const matched = needle.includes(" ") ? lowerPrompt.includes(needle) : words.has(needle);
46
+ if (matched) score++;
47
+ }
48
+ if (score > 0) {
49
+ scores.set(category as TaskCategory, score);
30
50
  }
31
51
  }
32
52
 
33
- if (categories.length === 0) {
53
+ if (scores.size === 0) {
34
54
  return "general";
35
55
  }
36
56
 
37
- // Apply priorities
38
- const priorityOrder: TaskCategory[] = ["debug", "code", "plan", "review", "test", "explore", "general"];
39
-
40
- for (const priority of priorityOrder) {
41
- if (categories.includes(priority)) {
42
- return priority;
57
+ const priorityOrder: TaskCategory[] = ["debug", "test", "explore", "review", "code", "plan", "general"];
58
+ let best: TaskCategory | undefined;
59
+ let bestScore = 0;
60
+ for (const [category, score] of scores) {
61
+ if (
62
+ score > bestScore ||
63
+ (score === bestScore &&
64
+ best !== undefined &&
65
+ priorityOrder.indexOf(category) !== -1 &&
66
+ priorityOrder.indexOf(category) < priorityOrder.indexOf(best))
67
+ ) {
68
+ best = category;
69
+ bestScore = score;
43
70
  }
44
71
  }
45
72
 
46
- return categories[0];
73
+ return best ?? "general";
47
74
  }
48
75
 
49
76
  /**
@@ -193,7 +220,6 @@ export class SmartRouter {
193
220
  "examine",
194
221
  "investigate",
195
222
  "study",
196
- "review",
197
223
  "explorer",
198
224
  "analyser",
199
225
  "comprendre",
@@ -213,7 +239,6 @@ export class SmartRouter {
213
239
  "organize",
214
240
  "concevoir",
215
241
  "planifier",
216
- "architecture",
217
242
  ],
218
243
  },
219
244
  test: {
package/src/types.ts CHANGED
@@ -1,15 +1,5 @@
1
1
  export type TaskCategory = "code" | "debug" | "explore" | "plan" | "test" | "review" | "general";
2
2
 
3
- export interface ModelProfile {
4
- id: string;
5
- provider: string;
6
- speed: "fast" | "medium" | "slow";
7
- quality: "high" | "medium" | "low";
8
- strengths: TaskCategory[];
9
- maxTokens: number;
10
- supportsTools: boolean;
11
- }
12
-
13
3
  export interface RoutingConfig {
14
4
  routes: Record<
15
5
  TaskCategory,
@@ -23,21 +13,3 @@ export interface RoutingConfig {
23
13
  default: { model: string; agent: string | null };
24
14
  }
25
15
 
26
- export interface SubAgentConfig {
27
- name: string;
28
- description: string;
29
- model: string;
30
- tools: string[];
31
- systemPrompt: string;
32
- maxTokens?: number;
33
- }
34
-
35
- export interface SubAgentResult {
36
- agentName: string;
37
- model: string;
38
- output: string;
39
- tokensUsed: number;
40
- durationMs: number;
41
- success: boolean;
42
- error?: string;
43
- }
@@ -1,37 +0,0 @@
1
- import type { ModelProfile, TaskCategory } from "./types.js";
2
- export declare class ModelProfiler {
3
- profiles: Map<string, ModelProfile>;
4
- /**
5
- * Charge les profiles depuis un fichier JSON
6
- */
7
- loadFromFile(path: string): Promise<void>;
8
- /**
9
- * Sauvegarde les profiles vers un fichier JSON
10
- */
11
- saveToFile(path: string): Promise<void>;
12
- /**
13
- * Ajoute un profile
14
- */
15
- addProfile(profile: ModelProfile): void;
16
- /**
17
- * Retourne le meilleur modèle pour une tâche donnée
18
- */
19
- getBestForTask(category: TaskCategory): ModelProfile | null;
20
- /**
21
- * Charge les profiles par défaut des modèles Alibaba
22
- */
23
- private loadDefaultProfiles;
24
- /**
25
- * Valide la forme d'un profile chargé depuis un JSON non fiable.
26
- * Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
27
- * et les champs malformés qui feraient planter getBestForTask.
28
- */
29
- static isValidProfile(profile: unknown): profile is ModelProfile;
30
- /**
31
- * Returns empty default profiles.
32
- * Actual profiles should be populated from /phi-init or user configuration.
33
- * sigma-agents is provider-agnostic — no hardcoded model names.
34
- */
35
- getDefaultProfiles(): ModelProfile[];
36
- }
37
- //# sourceMappingURL=profiles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7D,qBAAa,aAAa;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAa;IAEvD;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB/C;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI;IAqB3D;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,YAAY;IA6BhE;;;;OAIG;IACH,kBAAkB,IAAI,YAAY,EAAE;CAGpC"}
package/dist/profiles.js DELETED
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelProfiler = void 0;
4
- const promises_1 = require("node:fs/promises");
5
- class ModelProfiler {
6
- profiles = new Map();
7
- /**
8
- * Charge les profiles depuis un fichier JSON
9
- */
10
- async loadFromFile(path) {
11
- try {
12
- const content = await (0, promises_1.readFile)(path, "utf8");
13
- const data = JSON.parse(content);
14
- if (Array.isArray(data.profiles)) {
15
- this.profiles.clear();
16
- for (const profile of data.profiles) {
17
- if (!ModelProfiler.isValidProfile(profile)) {
18
- console.warn("Skipping invalid profile entry");
19
- continue;
20
- }
21
- this.profiles.set(profile.id, profile);
22
- }
23
- }
24
- }
25
- catch (error) {
26
- // Missing file is nominal: fall back to defaults silently.
27
- // Only warn on real read/parse errors.
28
- if (error.code !== "ENOENT") {
29
- console.warn(`Could not load profiles from ${path}:`, error);
30
- }
31
- this.loadDefaultProfiles();
32
- }
33
- }
34
- /**
35
- * Sauvegarde les profiles vers un fichier JSON
36
- */
37
- async saveToFile(path) {
38
- const data = {
39
- profiles: Array.from(this.profiles.values()),
40
- };
41
- await (0, promises_1.writeFile)(path, JSON.stringify(data, null, 2), "utf8");
42
- }
43
- /**
44
- * Ajoute un profile
45
- */
46
- addProfile(profile) {
47
- this.profiles.set(profile.id, profile);
48
- }
49
- /**
50
- * Retourne le meilleur modèle pour une tâche donnée
51
- */
52
- getBestForTask(category) {
53
- const candidates = Array.from(this.profiles.values())
54
- .filter((profile) => profile.strengths.includes(category))
55
- .sort((a, b) => {
56
- // Priority: quality > speed
57
- if (a.quality !== b.quality) {
58
- const qualityOrder = { high: 3, medium: 2, low: 1 };
59
- return qualityOrder[b.quality] - qualityOrder[a.quality];
60
- }
61
- if (a.speed !== b.speed) {
62
- const speedOrder = { fast: 3, medium: 2, slow: 1 };
63
- return speedOrder[b.speed] - speedOrder[a.speed];
64
- }
65
- return 0; // Equal priority
66
- });
67
- return candidates[0] || null;
68
- }
69
- /**
70
- * Charge les profiles par défaut des modèles Alibaba
71
- */
72
- loadDefaultProfiles() {
73
- const defaultProfiles = this.getDefaultProfiles();
74
- this.profiles.clear();
75
- for (const profile of defaultProfiles) {
76
- this.profiles.set(profile.id, profile);
77
- }
78
- }
79
- /**
80
- * Valide la forme d'un profile chargé depuis un JSON non fiable.
81
- * Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
82
- * et les champs malformés qui feraient planter getBestForTask.
83
- */
84
- static isValidProfile(profile) {
85
- if (typeof profile !== "object" || profile === null) {
86
- return false;
87
- }
88
- const p = profile;
89
- if (typeof p.id !== "string" || p.id.length === 0) {
90
- return false;
91
- }
92
- if (typeof p.provider !== "string") {
93
- return false;
94
- }
95
- if (p.speed !== "fast" && p.speed !== "medium" && p.speed !== "slow") {
96
- return false;
97
- }
98
- if (p.quality !== "high" && p.quality !== "medium" && p.quality !== "low") {
99
- return false;
100
- }
101
- if (!Array.isArray(p.strengths) || !p.strengths.every((s) => typeof s === "string")) {
102
- return false;
103
- }
104
- if (typeof p.maxTokens !== "number" || typeof p.supportsTools !== "boolean") {
105
- return false;
106
- }
107
- return true;
108
- }
109
- /**
110
- * Returns empty default profiles.
111
- * Actual profiles should be populated from /phi-init or user configuration.
112
- * sigma-agents is provider-agnostic — no hardcoded model names.
113
- */
114
- getDefaultProfiles() {
115
- return [];
116
- }
117
- }
118
- exports.ModelProfiler = ModelProfiler;
119
- //# sourceMappingURL=profiles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,aAAa;IAClB,QAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEvD;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,IAAY;QAC9B,IAAI,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAEjC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACrC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;wBAC5C,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;wBAC/C,SAAS;oBACV,CAAC;oBACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;gBACxC,CAAC;YACF,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,2DAA2D;YAC3D,uCAA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,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC3E,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;YACrF,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YAC7E,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,kBAAkB;QACjB,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AA/HD,sCA+HC"}
@@ -1,42 +0,0 @@
1
- import type { SubAgentConfig } from "./types.js";
2
- export declare class SubAgentManager {
3
- private agents;
4
- /**
5
- * Charge les définitions d'agents depuis un répertoire
6
- * Les fichiers .md doivent avoir un frontmatter YAML
7
- */
8
- loadAgentDefinitions(agentsDir: string): Promise<void>;
9
- /**
10
- * Retourne la liste des agents disponibles
11
- */
12
- getAvailableAgents(): SubAgentConfig[];
13
- /**
14
- * Construit la commande CLI pour spawner un sous-agent phi
15
- */
16
- createCommand(agent: SubAgentConfig, task: string): string[];
17
- /**
18
- * Parse un fichier markdown avec frontmatter YAML
19
- * Format attendu :
20
- * ---
21
- * name: agent-name
22
- * description: Agent description
23
- * model: model-name
24
- * tools: [tool1, tool2]
25
- * maxTokens: 4096
26
- * ---
27
- *
28
- * # System Prompt
29
- *
30
- * Le contenu après le frontmatter devient le system prompt...
31
- */
32
- parseAgentMarkdown(content: string): SubAgentConfig | null;
33
- /**
34
- * Récupère un agent par son nom
35
- */
36
- getAgent(name: string): SubAgentConfig | null;
37
- /**
38
- * Vérifie si un agent existe
39
- */
40
- hasAgent(name: string): boolean;
41
- }
42
- //# sourceMappingURL=sub-agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sub-agent.d.ts","sourceRoot":"","sources":["../src/sub-agent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,eAAe;IAC3B,OAAO,CAAC,MAAM,CAA0C;IAExD;;;OAGG;IACG,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB5D;;OAEG;IACH,kBAAkB,IAAI,cAAc,EAAE;IAItC;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAI5D;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IA4E1D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAI7C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG/B"}
package/dist/sub-agent.js DELETED
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SubAgentManager = void 0;
4
- const promises_1 = require("node:fs/promises");
5
- const node_path_1 = require("node:path");
6
- class SubAgentManager {
7
- agents = new Map();
8
- /**
9
- * Charge les définitions d'agents depuis un répertoire
10
- * Les fichiers .md doivent avoir un frontmatter YAML
11
- */
12
- async loadAgentDefinitions(agentsDir) {
13
- try {
14
- const files = await (0, promises_1.readdir)(agentsDir);
15
- const mdFiles = files.filter((file) => file.endsWith(".md"));
16
- this.agents.clear();
17
- for (const file of mdFiles) {
18
- try {
19
- const filePath = (0, node_path_1.join)(agentsDir, file);
20
- const content = await (0, promises_1.readFile)(filePath, "utf8");
21
- const agent = this.parseAgentMarkdown(content);
22
- if (agent) {
23
- this.agents.set(agent.name, agent);
24
- }
25
- }
26
- catch (error) {
27
- console.warn(`Could not parse agent file ${file}:`, error);
28
- }
29
- }
30
- }
31
- catch (error) {
32
- console.warn(`Could not load agent definitions from ${agentsDir}:`, error);
33
- }
34
- }
35
- /**
36
- * Retourne la liste des agents disponibles
37
- */
38
- getAvailableAgents() {
39
- return Array.from(this.agents.values());
40
- }
41
- /**
42
- * Construit la commande CLI pour spawner un sous-agent phi
43
- */
44
- createCommand(agent, task) {
45
- return ["phi", "--print", "--model", agent.model, "--no-session", "--system-prompt", agent.systemPrompt, task];
46
- }
47
- /**
48
- * Parse un fichier markdown avec frontmatter YAML
49
- * Format attendu :
50
- * ---
51
- * name: agent-name
52
- * description: Agent description
53
- * model: model-name
54
- * tools: [tool1, tool2]
55
- * maxTokens: 4096
56
- * ---
57
- *
58
- * # System Prompt
59
- *
60
- * Le contenu après le frontmatter devient le system prompt...
61
- */
62
- parseAgentMarkdown(content) {
63
- const lines = content.split(/\r?\n/);
64
- if (!lines[0]?.startsWith("---")) {
65
- return null;
66
- }
67
- // Trouver la fin du frontmatter
68
- let frontmatterEnd = -1;
69
- for (let i = 1; i < lines.length; i++) {
70
- if (lines[i] === "---") {
71
- frontmatterEnd = i;
72
- break;
73
- }
74
- }
75
- if (frontmatterEnd === -1) {
76
- return null;
77
- }
78
- // Extraire et parser le frontmatter YAML
79
- const frontmatterLines = lines.slice(1, frontmatterEnd);
80
- const frontmatter = {};
81
- for (const line of frontmatterLines) {
82
- const trimmed = line.trim();
83
- if (!trimmed || trimmed.startsWith("#"))
84
- continue;
85
- const colonIndex = trimmed.indexOf(":");
86
- if (colonIndex === -1)
87
- continue;
88
- const key = trimmed.substring(0, colonIndex).trim();
89
- const valueStr = trimmed.substring(colonIndex + 1).trim();
90
- // Parser la valeur
91
- let value = valueStr;
92
- // Arrays (format: [item1, item2])
93
- if (valueStr.startsWith("[") && valueStr.endsWith("]")) {
94
- const arrayContent = valueStr.slice(1, -1);
95
- value = arrayContent.split(",").map((item) => item.trim().replace(/['"]/g, ""));
96
- }
97
- // Numbers
98
- else if (/^\d+$/.test(valueStr)) {
99
- value = parseInt(valueStr, 10);
100
- }
101
- // Remove quotes from strings
102
- else if ((valueStr.startsWith('"') && valueStr.endsWith('"')) ||
103
- (valueStr.startsWith("'") && valueStr.endsWith("'"))) {
104
- value = valueStr.slice(1, -1);
105
- }
106
- frontmatter[key] = value;
107
- }
108
- // Extract system prompt (content after frontmatter)
109
- const systemPromptLines = lines.slice(frontmatterEnd + 1);
110
- const systemPrompt = systemPromptLines.join("\n").trim();
111
- // Valider les champs requis
112
- if (!frontmatter.name || !frontmatter.model || !systemPrompt) {
113
- return null;
114
- }
115
- return {
116
- name: frontmatter.name,
117
- description: frontmatter.description || "",
118
- model: frontmatter.model,
119
- tools: Array.isArray(frontmatter.tools) ? frontmatter.tools : [],
120
- systemPrompt,
121
- maxTokens: frontmatter.maxTokens || undefined,
122
- };
123
- }
124
- /**
125
- * Récupère un agent par son nom
126
- */
127
- getAgent(name) {
128
- return this.agents.get(name) || null;
129
- }
130
- /**
131
- * Vérifie si un agent existe
132
- */
133
- hasAgent(name) {
134
- return this.agents.has(name);
135
- }
136
- }
137
- exports.SubAgentManager = SubAgentManager;
138
- //# sourceMappingURL=sub-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sub-agent.js","sourceRoot":"","sources":["../src/sub-agent.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AACrD,yCAAiC;AAGjC,MAAa,eAAe;IACnB,MAAM,GAAgC,IAAI,GAAG,EAAE,CAAC;IAExD;;;OAGG;IACH,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAC3C,IAAI,CAAC;YACJ,MAAM,KAAK,GAAG,M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AC,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO;YACN,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,WAAW,EAAE,WAAW,CAAC,WAAW,IAAI,EAAE;YAC1C,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YAChE,YAAY;YACZ,SAAS,EAAE,WAAW,CAAC,SAAS,IAAI,SAAS;SAC7C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACD;AAtJD,0CAsJC"}
package/src/profiles.ts DELETED
@@ -1,131 +0,0 @@
1
- import { readFile, writeFile } from "node:fs/promises";
2
- import type { ModelProfile, TaskCategory } from "./types.js";
3
-
4
- export class ModelProfiler {
5
- public profiles: Map<string, ModelProfile> = new Map();
6
-
7
- /**
8
- * Charge les profiles depuis un fichier JSON
9
- */
10
- async loadFromFile(path: string): Promise<void> {
11
- try {
12
- const content = await readFile(path, "utf8");
13
- const data = JSON.parse(content);
14
-
15
- if (Array.isArray(data.profiles)) {
16
- this.profiles.clear();
17
- for (const profile of data.profiles) {
18
- if (!ModelProfiler.isValidProfile(profile)) {
19
- console.warn("Skipping invalid profile entry");
20
- continue;
21
- }
22
- this.profiles.set(profile.id, profile);
23
- }
24
- }
25
- } catch (error) {
26
- // Missing file is nominal: fall back to defaults silently.
27
- // Only warn on real read/parse errors.
28
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
29
- console.warn(`Could not load profiles from ${path}:`, error);
30
- }
31
- this.loadDefaultProfiles();
32
- }
33
- }
34
-
35
- /**
36
- * Sauvegarde les profiles vers un fichier JSON
37
- */
38
- async saveToFile(path: string): Promise<void> {
39
- const data = {
40
- profiles: Array.from(this.profiles.values()),
41
- };
42
-
43
- await writeFile(path, JSON.stringify(data, null, 2), "utf8");
44
- }
45
-
46
- /**
47
- * Ajoute un profile
48
- */
49
- addProfile(profile: ModelProfile): void {
50
- this.profiles.set(profile.id, profile);
51
- }
52
-
53
- /**
54
- * Retourne le meilleur modèle pour une tâche donnée
55
- */
56
- getBestForTask(category: TaskCategory): ModelProfile | null {
57
- const candidates = Array.from(this.profiles.values())
58
- .filter((profile) => profile.strengths.includes(category))
59
- .sort((a, b) => {
60
- // Priority: quality > speed
61
- if (a.quality !== b.quality) {
62
- const qualityOrder = { high: 3, medium: 2, low: 1 };
63
- return qualityOrder[b.quality] - qualityOrder[a.quality];
64
- }
65
-
66
- if (a.speed !== b.speed) {
67
- const speedOrder = { fast: 3, medium: 2, slow: 1 };
68
- return speedOrder[b.speed] - speedOrder[a.speed];
69
- }
70
-
71
- return 0; // Equal priority
72
- });
73
-
74
- return candidates[0] || null;
75
- }
76
-
77
- /**
78
- * Charge les profiles par défaut des modèles Alibaba
79
- */
80
- private loadDefaultProfiles(): void {
81
- const defaultProfiles = this.getDefaultProfiles();
82
- this.profiles.clear();
83
-
84
- for (const profile of defaultProfiles) {
85
- this.profiles.set(profile.id, profile);
86
- }
87
- }
88
-
89
- /**
90
- * Valide la forme d'un profile chargé depuis un JSON non fiable.
91
- * Empêche les entrées sans id (qui s'écraseraient sous la clé undefined)
92
- * et les champs malformés qui feraient planter getBestForTask.
93
- */
94
- static isValidProfile(profile: unknown): profile is ModelProfile {
95
- if (typeof profile !== "object" || profile === null) {
96
- return false;
97
- }
98
-
99
- const p = profile as Record<string, unknown>;
100
-
101
- if (typeof p.id !== "string" || p.id.length === 0) {
102
- return false;
103
- }
104
- if (typeof p.provider !== "string") {
105
- return false;
106
- }
107
- if (p.speed !== "fast" && p.speed !== "medium" && p.speed !== "slow") {
108
- return false;
109
- }
110
- if (p.quality !== "high" && p.quality !== "medium" && p.quality !== "low") {
111
- return false;
112
- }
113
- if (!Array.isArray(p.strengths) || !p.strengths.every((s) => typeof s === "string")) {
114
- return false;
115
- }
116
- if (typeof p.maxTokens !== "number" || typeof p.supportsTools !== "boolean") {
117
- return false;
118
- }
119
-
120
- return true;
121
- }
122
-
123
- /**
124
- * Returns empty default profiles.
125
- * Actual profiles should be populated from /phi-init or user configuration.
126
- * sigma-agents is provider-agnostic — no hardcoded model names.
127
- */
128
- getDefaultProfiles(): ModelProfile[] {
129
- return [];
130
- }
131
- }
package/src/sub-agent.ts DELETED
@@ -1,155 +0,0 @@
1
- import { readdir, readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import type { SubAgentConfig } from "./types.js";
4
-
5
- export class SubAgentManager {
6
- private agents: Map<string, SubAgentConfig> = new Map();
7
-
8
- /**
9
- * Charge les définitions d'agents depuis un répertoire
10
- * Les fichiers .md doivent avoir un frontmatter YAML
11
- */
12
- async loadAgentDefinitions(agentsDir: string): Promise<void> {
13
- try {
14
- const files = await readdir(agentsDir);
15
- const mdFiles = files.filter((file) => file.endsWith(".md"));
16
-
17
- this.agents.clear();
18
-
19
- for (const file of mdFiles) {
20
- try {
21
- const filePath = join(agentsDir, file);
22
- const content = await readFile(filePath, "utf8");
23
- const agent = this.parseAgentMarkdown(content);
24
-
25
- if (agent) {
26
- this.agents.set(agent.name, agent);
27
- }
28
- } catch (error) {
29
- console.warn(`Could not parse agent file ${file}:`, error);
30
- }
31
- }
32
- } catch (error) {
33
- console.warn(`Could not load agent definitions from ${agentsDir}:`, error);
34
- }
35
- }
36
-
37
- /**
38
- * Retourne la liste des agents disponibles
39
- */
40
- getAvailableAgents(): SubAgentConfig[] {
41
- return Array.from(this.agents.values());
42
- }
43
-
44
- /**
45
- * Construit la commande CLI pour spawner un sous-agent phi
46
- */
47
- createCommand(agent: SubAgentConfig, task: string): string[] {
48
- return ["phi", "--print", "--model", agent.model, "--no-session", "--system-prompt", agent.systemPrompt, task];
49
- }
50
-
51
- /**
52
- * Parse un fichier markdown avec frontmatter YAML
53
- * Format attendu :
54
- * ---
55
- * name: agent-name
56
- * description: Agent description
57
- * model: model-name
58
- * tools: [tool1, tool2]
59
- * maxTokens: 4096
60
- * ---
61
- *
62
- * # System Prompt
63
- *
64
- * Le contenu après le frontmatter devient le system prompt...
65
- */
66
- parseAgentMarkdown(content: string): SubAgentConfig | null {
67
- const lines = content.split(/\r?\n/);
68
-
69
- if (!lines[0]?.startsWith("---")) {
70
- return null;
71
- }
72
-
73
- // Trouver la fin du frontmatter
74
- let frontmatterEnd = -1;
75
- for (let i = 1; i < lines.length; i++) {
76
- if (lines[i] === "---") {
77
- frontmatterEnd = i;
78
- break;
79
- }
80
- }
81
-
82
- if (frontmatterEnd === -1) {
83
- return null;
84
- }
85
-
86
- // Extraire et parser le frontmatter YAML
87
- const frontmatterLines = lines.slice(1, frontmatterEnd);
88
- const frontmatter: any = {};
89
-
90
- for (const line of frontmatterLines) {
91
- const trimmed = line.trim();
92
- if (!trimmed || trimmed.startsWith("#")) continue;
93
-
94
- const colonIndex = trimmed.indexOf(":");
95
- if (colonIndex === -1) continue;
96
-
97
- const key = trimmed.substring(0, colonIndex).trim();
98
- const valueStr = trimmed.substring(colonIndex + 1).trim();
99
-
100
- // Parser la valeur
101
- let value: any = valueStr;
102
-
103
- // Arrays (format: [item1, item2])
104
- if (valueStr.startsWith("[") && valueStr.endsWith("]")) {
105
- const arrayContent = valueStr.slice(1, -1);
106
- value = arrayContent.split(",").map((item) => item.trim().replace(/['"]/g, ""));
107
- }
108
- // Numbers
109
- else if (/^\d+$/.test(valueStr)) {
110
- value = parseInt(valueStr, 10);
111
- }
112
- // Remove quotes from strings
113
- else if (
114
- (valueStr.startsWith('"') && valueStr.endsWith('"')) ||
115
- (valueStr.startsWith("'") && valueStr.endsWith("'"))
116
- ) {
117
- value = valueStr.slice(1, -1);
118
- }
119
-
120
- frontmatter[key] = value;
121
- }
122
-
123
- // Extract system prompt (content after frontmatter)
124
- const systemPromptLines = lines.slice(frontmatterEnd + 1);
125
- const systemPrompt = systemPromptLines.join("\n").trim();
126
-
127
- // Valider les champs requis
128
- if (!frontmatter.name || !frontmatter.model || !systemPrompt) {
129
- return null;
130
- }
131
-
132
- return {
133
- name: frontmatter.name,
134
- description: frontmatter.description || "",
135
- model: frontmatter.model,
136
- tools: Array.isArray(frontmatter.tools) ? frontmatter.tools : [],
137
- systemPrompt,
138
- maxTokens: frontmatter.maxTokens || undefined,
139
- };
140
- }
141
-
142
- /**
143
- * Récupère un agent par son nom
144
- */
145
- getAgent(name: string): SubAgentConfig | null {
146
- return this.agents.get(name) || null;
147
- }
148
-
149
- /**
150
- * Vérifie si un agent existe
151
- */
152
- hasAgent(name: string): boolean {
153
- return this.agents.has(name);
154
- }
155
- }