nexus-agents 2.29.0 → 2.29.2
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/adaptive-memory-5VP5WWTE.js +15 -0
- package/dist/chunk-5COIDGQJ.js +1585 -0
- package/dist/chunk-5COIDGQJ.js.map +1 -0
- package/dist/{chunk-HWDBNDUX.js → chunk-63AJLNKU.js} +2 -2
- package/dist/chunk-66NNHMVB.js +195 -0
- package/dist/chunk-66NNHMVB.js.map +1 -0
- package/dist/chunk-AP2FD37C.js +127 -0
- package/dist/chunk-AP2FD37C.js.map +1 -0
- package/dist/chunk-BC3M4VLP.js +359 -0
- package/dist/chunk-BC3M4VLP.js.map +1 -0
- package/dist/chunk-BQ4YXGGQ.js +127 -0
- package/dist/chunk-BQ4YXGGQ.js.map +1 -0
- package/dist/{chunk-ZBZJHXRT.js → chunk-CW2Z773T.js} +19 -347
- package/dist/chunk-CW2Z773T.js.map +1 -0
- package/dist/chunk-DDQGAVQA.js +944 -0
- package/dist/chunk-DDQGAVQA.js.map +1 -0
- package/dist/chunk-ED6VQWNG.js +63 -0
- package/dist/chunk-ED6VQWNG.js.map +1 -0
- package/dist/{chunk-7F6HYUIY.js → chunk-EPMBGZQX.js} +16 -97
- package/dist/chunk-EPMBGZQX.js.map +1 -0
- package/dist/chunk-GX436VRU.js +931 -0
- package/dist/chunk-GX436VRU.js.map +1 -0
- package/dist/{chunk-IMWYKX4H.js → chunk-HSOPD265.js} +444 -399
- package/dist/chunk-HSOPD265.js.map +1 -0
- package/dist/{chunk-S3BKWNST.js → chunk-J245RJGW.js} +680 -1436
- package/dist/chunk-J245RJGW.js.map +1 -0
- package/dist/{chunk-I6YDS23R.js → chunk-KQIDTE52.js} +2 -2
- package/dist/{chunk-POBO4G2P.js → chunk-LDIN2PLV.js} +250 -110
- package/dist/chunk-LDIN2PLV.js.map +1 -0
- package/dist/{chunk-KGDG6PWZ.js → chunk-LKDHAJJB.js} +2 -2
- package/dist/{chunk-T7PU3NPQ.js → chunk-NKGTEJYU.js} +7 -5
- package/dist/{chunk-T7PU3NPQ.js.map → chunk-NKGTEJYU.js.map} +1 -1
- package/dist/chunk-QGODFK36.js +122 -0
- package/dist/chunk-QGODFK36.js.map +1 -0
- package/dist/{chunk-DAMRMAM2.js → chunk-QSNAFOE6.js} +12369 -14499
- package/dist/chunk-QSNAFOE6.js.map +1 -0
- package/dist/chunk-TL2GJMJ5.js +700 -0
- package/dist/chunk-TL2GJMJ5.js.map +1 -0
- package/dist/{chunk-WSK4VSXP.js → chunk-V6MSPUQF.js} +2 -2
- package/dist/chunk-VZ2YOQWU.js +90 -0
- package/dist/chunk-VZ2YOQWU.js.map +1 -0
- package/dist/{chunk-5VZLXMO7.js → chunk-WSYJN7BI.js} +7 -6
- package/dist/chunk-WSYJN7BI.js.map +1 -0
- package/dist/chunk-Y477EGI4.js +356 -0
- package/dist/chunk-Y477EGI4.js.map +1 -0
- package/dist/{chunk-HH5LVGEE.js → chunk-Z4OZ25VS.js} +4 -4
- package/dist/cli-circuit-breaker-6EJO3PPU.js +13 -0
- package/dist/cli.js +123 -68
- package/dist/cli.js.map +1 -1
- package/dist/codebase-search-CZUA37RU.js +9 -0
- package/dist/{composite-router-YPRWVTRB.js → composite-router-JD7URTC2.js} +2 -2
- package/dist/{consensus-vote-DBE6RNZG.js → consensus-vote-COW34Q2Y.js} +7 -5
- package/dist/{dist-7PQR2BQB.js → dist-CV74KUT7.js} +1302 -805
- package/dist/dist-CV74KUT7.js.map +1 -0
- package/dist/{doctor-deep-AWE7SRU6.js → doctor-deep-4A4X5X6U.js} +3 -3
- package/dist/expert-bridge-J36C7VES.js +10 -0
- package/dist/{expert-config-FHNBQRX2.js → expert-config-MQ5OJE3U.js} +2 -2
- package/dist/{factory-O5C7ZBZO.js → factory-4Z4RSUYE.js} +5 -4
- package/dist/{factory-PCHGQ3ZG.js → factory-NHORX63J.js} +4 -3
- package/dist/index.d.ts +507 -42
- package/dist/index.js +331 -78
- package/dist/index.js.map +1 -1
- package/dist/issue-triage-TIG3RKXF.js +15 -0
- package/dist/{mcp-config-AUZQPUBY.js → mcp-config-ETY7GFGW.js} +3 -3
- package/dist/mobimem-5PAAMVFR.js +13 -0
- package/dist/mobimem-5PAAMVFR.js.map +1 -0
- package/dist/repo-analyze-HWMXSK5C.js +24 -0
- package/dist/repo-analyze-HWMXSK5C.js.map +1 -0
- package/dist/repo-security-plan-KQB3ZJTE.js +17 -0
- package/dist/repo-security-plan-KQB3ZJTE.js.map +1 -0
- package/dist/research-helpers-synthesize-ZMERZZ5B.js +10 -0
- package/dist/research-helpers-synthesize-ZMERZZ5B.js.map +1 -0
- package/dist/{routing-memory-QY3XMU2R.js → routing-memory-3ES3OHLM.js} +2 -2
- package/dist/routing-memory-3ES3OHLM.js.map +1 -0
- package/dist/{session-memory-3MBCE5KS.js → session-memory-E2OE2CYR.js} +3 -3
- package/dist/session-memory-E2OE2CYR.js.map +1 -0
- package/dist/{setup-command-IQ4MD3FT.js → setup-command-CMCQRBJF.js} +7 -6
- package/dist/setup-command-CMCQRBJF.js.map +1 -0
- package/dist/{setup-config-5YUPLDXF.js → setup-config-KITOPV7V.js} +3 -3
- package/dist/setup-config-KITOPV7V.js.map +1 -0
- package/dist/shared-memory-AEO2HJLC.js +8 -0
- package/dist/shared-memory-AEO2HJLC.js.map +1 -0
- package/dist/symbol-extractor-UEBANFSN.js +10 -0
- package/dist/symbol-extractor-UEBANFSN.js.map +1 -0
- package/dist/{weather-report-CC2C4KAX.js → weather-report-KUSVNXDZ.js} +2 -2
- package/dist/weather-report-KUSVNXDZ.js.map +1 -0
- package/package.json +14 -13
- package/dist/chunk-5VZLXMO7.js.map +0 -1
- package/dist/chunk-7F6HYUIY.js.map +0 -1
- package/dist/chunk-DAMRMAM2.js.map +0 -1
- package/dist/chunk-IMWYKX4H.js.map +0 -1
- package/dist/chunk-POBO4G2P.js.map +0 -1
- package/dist/chunk-S3BKWNST.js.map +0 -1
- package/dist/chunk-ZBZJHXRT.js.map +0 -1
- package/dist/dist-7PQR2BQB.js.map +0 -1
- /package/dist/{composite-router-YPRWVTRB.js.map → adaptive-memory-5VP5WWTE.js.map} +0 -0
- /package/dist/{chunk-HWDBNDUX.js.map → chunk-63AJLNKU.js.map} +0 -0
- /package/dist/{chunk-I6YDS23R.js.map → chunk-KQIDTE52.js.map} +0 -0
- /package/dist/{chunk-KGDG6PWZ.js.map → chunk-LKDHAJJB.js.map} +0 -0
- /package/dist/{chunk-WSK4VSXP.js.map → chunk-V6MSPUQF.js.map} +0 -0
- /package/dist/{chunk-HH5LVGEE.js.map → chunk-Z4OZ25VS.js.map} +0 -0
- /package/dist/{consensus-vote-DBE6RNZG.js.map → cli-circuit-breaker-6EJO3PPU.js.map} +0 -0
- /package/dist/{doctor-deep-AWE7SRU6.js.map → codebase-search-CZUA37RU.js.map} +0 -0
- /package/dist/{expert-config-FHNBQRX2.js.map → composite-router-JD7URTC2.js.map} +0 -0
- /package/dist/{factory-O5C7ZBZO.js.map → consensus-vote-COW34Q2Y.js.map} +0 -0
- /package/dist/{factory-PCHGQ3ZG.js.map → doctor-deep-4A4X5X6U.js.map} +0 -0
- /package/dist/{mcp-config-AUZQPUBY.js.map → expert-bridge-J36C7VES.js.map} +0 -0
- /package/dist/{routing-memory-QY3XMU2R.js.map → expert-config-MQ5OJE3U.js.map} +0 -0
- /package/dist/{session-memory-3MBCE5KS.js.map → factory-4Z4RSUYE.js.map} +0 -0
- /package/dist/{setup-command-IQ4MD3FT.js.map → factory-NHORX63J.js.map} +0 -0
- /package/dist/{setup-config-5YUPLDXF.js.map → issue-triage-TIG3RKXF.js.map} +0 -0
- /package/dist/{weather-report-CC2C4KAX.js.map → mcp-config-ETY7GFGW.js.map} +0 -0
|
@@ -210,7 +210,7 @@ ${COLORS.dim}${entry.error.stack}${COLORS.reset}` : "";
|
|
|
210
210
|
`;
|
|
211
211
|
}
|
|
212
212
|
var globalFormat = "json";
|
|
213
|
-
var globalDestination = "
|
|
213
|
+
var globalDestination = "stderr";
|
|
214
214
|
var globalFilePath;
|
|
215
215
|
var fileStream;
|
|
216
216
|
function getOutputStream() {
|
|
@@ -270,6 +270,33 @@ function createLogger(baseContext) {
|
|
|
270
270
|
}
|
|
271
271
|
var logger = createLogger();
|
|
272
272
|
|
|
273
|
+
// src/context/mobimem-types.ts
|
|
274
|
+
import { z } from "zod";
|
|
275
|
+
var DEFAULT_MOBIMEM_CONFIG = {
|
|
276
|
+
dbPath: ":memory:",
|
|
277
|
+
maxProfileEntries: 100,
|
|
278
|
+
maxExperiencePatterns: 500,
|
|
279
|
+
maxActionCacheEntries: 1e3,
|
|
280
|
+
actionCacheTtlMs: 36e5,
|
|
281
|
+
// 1 hour
|
|
282
|
+
minProfileConfidence: 0.6,
|
|
283
|
+
minExperienceSuccessRate: 0.7,
|
|
284
|
+
autoEviction: true
|
|
285
|
+
};
|
|
286
|
+
var MobiMemConfigSchema = z.object({
|
|
287
|
+
dbPath: z.string(),
|
|
288
|
+
maxProfileEntries: z.number().int().positive().default(100),
|
|
289
|
+
maxExperiencePatterns: z.number().int().positive().default(500),
|
|
290
|
+
maxActionCacheEntries: z.number().int().positive().default(1e3),
|
|
291
|
+
actionCacheTtlMs: z.number().int().positive().default(36e5),
|
|
292
|
+
minProfileConfidence: z.number().min(0).max(1).default(0.6),
|
|
293
|
+
minExperienceSuccessRate: z.number().min(0).max(1).default(0.7),
|
|
294
|
+
autoEviction: z.boolean().default(true)
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// src/context/mobimem-impl.ts
|
|
298
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
299
|
+
|
|
273
300
|
// src/core/result.ts
|
|
274
301
|
function ok(value) {
|
|
275
302
|
return { ok: true, value };
|
|
@@ -471,7 +498,7 @@ function extractObjectMessage(error, fallback) {
|
|
|
471
498
|
}
|
|
472
499
|
|
|
473
500
|
// src/config/model-capabilities-types.ts
|
|
474
|
-
import { z } from "zod";
|
|
501
|
+
import { z as z2 } from "zod";
|
|
475
502
|
var OUTPUT_MODALITIES = [
|
|
476
503
|
"text",
|
|
477
504
|
"image_png",
|
|
@@ -508,7 +535,7 @@ var SPECIAL_FEATURES = [
|
|
|
508
535
|
];
|
|
509
536
|
var PROVIDERS = ["anthropic", "google", "openai", "custom-openai", "openrouter"];
|
|
510
537
|
var CLI_NAMES = ["claude", "gemini", "codex", "opencode"];
|
|
511
|
-
var CliNameSchema =
|
|
538
|
+
var CliNameSchema = z2.enum(CLI_NAMES);
|
|
512
539
|
var DEFAULT_CLI = "claude";
|
|
513
540
|
var MODEL_IDS = [
|
|
514
541
|
"claude-opus",
|
|
@@ -527,63 +554,63 @@ var MODEL_IDS = [
|
|
|
527
554
|
"openrouter-nemotron-super",
|
|
528
555
|
"openrouter-qwen-coder"
|
|
529
556
|
];
|
|
530
|
-
var QualityScoresSchema =
|
|
531
|
-
reasoning:
|
|
532
|
-
codeGeneration:
|
|
533
|
-
speed:
|
|
534
|
-
cost:
|
|
557
|
+
var QualityScoresSchema = z2.object({
|
|
558
|
+
reasoning: z2.number().min(0).max(10),
|
|
559
|
+
codeGeneration: z2.number().min(0).max(10),
|
|
560
|
+
speed: z2.number().min(0).max(10),
|
|
561
|
+
cost: z2.number().min(0).max(10)
|
|
535
562
|
});
|
|
536
|
-
var PricingSchema =
|
|
537
|
-
inputPer1M:
|
|
538
|
-
outputPer1M:
|
|
563
|
+
var PricingSchema = z2.object({
|
|
564
|
+
inputPer1M: z2.number().nonnegative(),
|
|
565
|
+
outputPer1M: z2.number().nonnegative()
|
|
539
566
|
});
|
|
540
|
-
var ModelCapabilitySchema =
|
|
567
|
+
var ModelCapabilitySchema = z2.object({
|
|
541
568
|
/** Unique model identifier matching delegate_to_model model IDs */
|
|
542
|
-
id:
|
|
569
|
+
id: z2.enum(MODEL_IDS),
|
|
543
570
|
/** Human-readable display name */
|
|
544
|
-
displayName:
|
|
571
|
+
displayName: z2.string().min(1),
|
|
545
572
|
/** Provider/vendor */
|
|
546
|
-
provider:
|
|
573
|
+
provider: z2.enum(PROVIDERS),
|
|
547
574
|
/** Maximum context window in tokens */
|
|
548
|
-
contextWindow:
|
|
575
|
+
contextWindow: z2.number().int().positive(),
|
|
549
576
|
/** Output modalities this model can produce */
|
|
550
|
-
outputModalities:
|
|
577
|
+
outputModalities: z2.array(z2.enum(OUTPUT_MODALITIES)).min(1),
|
|
551
578
|
/** Input modalities this model can accept */
|
|
552
|
-
inputModalities:
|
|
579
|
+
inputModalities: z2.array(z2.enum(INPUT_MODALITIES)).min(1),
|
|
553
580
|
/** Tool/integration capabilities */
|
|
554
|
-
toolCapabilities:
|
|
581
|
+
toolCapabilities: z2.array(z2.enum(TOOL_CAPABILITIES)),
|
|
555
582
|
/** Special features beyond standard generation */
|
|
556
|
-
specialFeatures:
|
|
583
|
+
specialFeatures: z2.array(z2.enum(SPECIAL_FEATURES)),
|
|
557
584
|
/** Known constraints or limitations */
|
|
558
|
-
constraints:
|
|
585
|
+
constraints: z2.array(z2.string()).optional(),
|
|
559
586
|
/** Notes about the model (e.g., beta features, pricing tier) */
|
|
560
|
-
notes:
|
|
587
|
+
notes: z2.string().optional(),
|
|
561
588
|
/** Pricing per 1M tokens (USD) */
|
|
562
589
|
pricing: PricingSchema.optional(),
|
|
563
590
|
/** Quality scores for routing (0-10 scale) */
|
|
564
591
|
qualityScores: QualityScoresSchema.optional(),
|
|
565
592
|
/** Maximum output tokens */
|
|
566
|
-
maxOutputTokens:
|
|
593
|
+
maxOutputTokens: z2.number().int().positive().optional(),
|
|
567
594
|
/** Which CLI tool this model belongs to */
|
|
568
|
-
cliName:
|
|
595
|
+
cliName: z2.enum(CLI_NAMES).optional(),
|
|
569
596
|
/** Short alias used by the CLI (e.g., 'opus' for Claude CLI) */
|
|
570
|
-
cliAlias:
|
|
597
|
+
cliAlias: z2.string().optional(),
|
|
571
598
|
/** Model name the CLI binary expects (e.g., 'gemini-2.5-pro') */
|
|
572
|
-
cliModelName:
|
|
599
|
+
cliModelName: z2.string().optional(),
|
|
573
600
|
/** Whether this model is deprecated and should receive a scoring penalty */
|
|
574
|
-
deprecated:
|
|
601
|
+
deprecated: z2.boolean().optional(),
|
|
575
602
|
/** ISO date when the model was deprecated (informational) */
|
|
576
|
-
deprecatedAt:
|
|
603
|
+
deprecatedAt: z2.string().optional(),
|
|
577
604
|
/** Model ID to migrate to (informational guidance) */
|
|
578
|
-
replacedBy:
|
|
605
|
+
replacedBy: z2.enum(MODEL_IDS).optional()
|
|
579
606
|
});
|
|
580
|
-
var ModelCapabilitiesMatrixSchema =
|
|
607
|
+
var ModelCapabilitiesMatrixSchema = z2.object({
|
|
581
608
|
/** Schema version for forward compatibility */
|
|
582
|
-
version:
|
|
609
|
+
version: z2.number().int().positive(),
|
|
583
610
|
/** Last updated date (ISO 8601) */
|
|
584
|
-
updatedAt:
|
|
611
|
+
updatedAt: z2.string(),
|
|
585
612
|
/** Model capability definitions */
|
|
586
|
-
models:
|
|
613
|
+
models: z2.array(ModelCapabilitySchema).min(1)
|
|
587
614
|
});
|
|
588
615
|
|
|
589
616
|
// src/config/model-capabilities.ts
|
|
@@ -1437,7 +1464,7 @@ function formatPercentage(value, decimals = 0) {
|
|
|
1437
1464
|
|
|
1438
1465
|
// src/core/artifact.ts
|
|
1439
1466
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1440
|
-
import { z as
|
|
1467
|
+
import { z as z3 } from "zod";
|
|
1441
1468
|
var ArtifactType = {
|
|
1442
1469
|
/** Planning documents and task breakdowns */
|
|
1443
1470
|
PLAN: "plan",
|
|
@@ -1450,30 +1477,30 @@ var ArtifactType = {
|
|
|
1450
1477
|
/** Intent declarations for policy authorization */
|
|
1451
1478
|
INTENT: "intent"
|
|
1452
1479
|
};
|
|
1453
|
-
var ArtifactTypeSchema =
|
|
1480
|
+
var ArtifactTypeSchema = z3.enum([
|
|
1454
1481
|
ArtifactType.PLAN,
|
|
1455
1482
|
ArtifactType.ANALYSIS,
|
|
1456
1483
|
ArtifactType.DECISION,
|
|
1457
1484
|
ArtifactType.RESULT,
|
|
1458
1485
|
ArtifactType.INTENT
|
|
1459
1486
|
]);
|
|
1460
|
-
var ArtifactMetadataSchema =
|
|
1461
|
-
createdAt:
|
|
1462
|
-
createdBy:
|
|
1463
|
-
parentId:
|
|
1464
|
-
taskId:
|
|
1465
|
-
traceId:
|
|
1487
|
+
var ArtifactMetadataSchema = z3.object({
|
|
1488
|
+
createdAt: z3.iso.datetime({ message: "createdAt must be ISO 8601 format" }),
|
|
1489
|
+
createdBy: z3.string().min(1, "createdBy is required"),
|
|
1490
|
+
parentId: z3.uuid().optional(),
|
|
1491
|
+
taskId: z3.string().min(1, "taskId is required"),
|
|
1492
|
+
traceId: z3.string().optional()
|
|
1466
1493
|
});
|
|
1467
1494
|
function createArtifactSchema(dataSchema) {
|
|
1468
|
-
return
|
|
1469
|
-
id:
|
|
1495
|
+
return z3.object({
|
|
1496
|
+
id: z3.uuid(),
|
|
1470
1497
|
type: ArtifactTypeSchema,
|
|
1471
|
-
schemaVersion:
|
|
1498
|
+
schemaVersion: z3.string().regex(/^\d+\.\d+\.\d+$/, "schemaVersion must be semver"),
|
|
1472
1499
|
data: dataSchema,
|
|
1473
1500
|
metadata: ArtifactMetadataSchema
|
|
1474
1501
|
});
|
|
1475
1502
|
}
|
|
1476
|
-
var BaseArtifactSchema = createArtifactSchema(
|
|
1503
|
+
var BaseArtifactSchema = createArtifactSchema(z3.unknown());
|
|
1477
1504
|
|
|
1478
1505
|
// src/core/metrics.ts
|
|
1479
1506
|
var MAX_RECENT_ERRORS = 1e3;
|
|
@@ -3513,19 +3540,19 @@ var TopsisRouter = class {
|
|
|
3513
3540
|
};
|
|
3514
3541
|
|
|
3515
3542
|
// src/cli-adapters/budget-router-types.ts
|
|
3516
|
-
import { z as
|
|
3517
|
-
var BudgetConstraintSchema =
|
|
3518
|
-
maxTokens:
|
|
3519
|
-
maxCostUSD:
|
|
3520
|
-
maxLatencyMs:
|
|
3543
|
+
import { z as z4 } from "zod";
|
|
3544
|
+
var BudgetConstraintSchema = z4.object({
|
|
3545
|
+
maxTokens: z4.number().int().positive().optional(),
|
|
3546
|
+
maxCostUSD: z4.number().positive().optional(),
|
|
3547
|
+
maxLatencyMs: z4.number().positive().optional()
|
|
3521
3548
|
});
|
|
3522
|
-
var SessionBudgetSchema =
|
|
3523
|
-
totalTokens:
|
|
3524
|
-
totalCostUSD:
|
|
3525
|
-
usedTokens:
|
|
3526
|
-
usedCostUSD:
|
|
3527
|
-
startTime:
|
|
3528
|
-
sessionId:
|
|
3549
|
+
var SessionBudgetSchema = z4.object({
|
|
3550
|
+
totalTokens: z4.number().int().positive(),
|
|
3551
|
+
totalCostUSD: z4.number().positive(),
|
|
3552
|
+
usedTokens: z4.number().int().min(0).default(0),
|
|
3553
|
+
usedCostUSD: z4.number().min(0).default(0),
|
|
3554
|
+
startTime: z4.number().int().positive(),
|
|
3555
|
+
sessionId: z4.string().min(1)
|
|
3529
3556
|
});
|
|
3530
3557
|
var DEFAULT_LINUCB_CONFIG = {
|
|
3531
3558
|
numArms: 4,
|
|
@@ -3533,11 +3560,11 @@ var DEFAULT_LINUCB_CONFIG = {
|
|
|
3533
3560
|
alpha: 1,
|
|
3534
3561
|
lambda: 1
|
|
3535
3562
|
};
|
|
3536
|
-
var LinUCBConfigSchema =
|
|
3537
|
-
numArms:
|
|
3538
|
-
featureDim:
|
|
3539
|
-
alpha:
|
|
3540
|
-
lambda:
|
|
3563
|
+
var LinUCBConfigSchema = z4.object({
|
|
3564
|
+
numArms: z4.number().int().positive().default(4),
|
|
3565
|
+
featureDim: z4.number().int().positive().default(6),
|
|
3566
|
+
alpha: z4.number().positive().default(1),
|
|
3567
|
+
lambda: z4.number().positive().default(1)
|
|
3541
3568
|
});
|
|
3542
3569
|
|
|
3543
3570
|
// src/cli-adapters/linucb-math.ts
|
|
@@ -3892,7 +3919,7 @@ var LinUCBBandit = class {
|
|
|
3892
3919
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3893
3920
|
|
|
3894
3921
|
// src/cli-adapters/preference-router-types.ts
|
|
3895
|
-
import { z as
|
|
3922
|
+
import { z as z5 } from "zod";
|
|
3896
3923
|
var DEFAULT_PREFERENCE_ROUTER_CONFIG = {
|
|
3897
3924
|
strongModel: {
|
|
3898
3925
|
tier: "strong",
|
|
@@ -3913,24 +3940,24 @@ var DEFAULT_PREFERENCE_ROUTER_CONFIG = {
|
|
|
3913
3940
|
maxDataPoints: 1e4,
|
|
3914
3941
|
enableOnlineLearning: true
|
|
3915
3942
|
};
|
|
3916
|
-
var PreferenceRouterConfigSchema =
|
|
3917
|
-
strongModel:
|
|
3918
|
-
tier:
|
|
3919
|
-
cli:
|
|
3920
|
-
costPerMillionTokens:
|
|
3921
|
-
qualityBaseline:
|
|
3943
|
+
var PreferenceRouterConfigSchema = z5.object({
|
|
3944
|
+
strongModel: z5.object({
|
|
3945
|
+
tier: z5.literal("strong"),
|
|
3946
|
+
cli: z5.enum(["claude", "gemini", "codex", "opencode"]),
|
|
3947
|
+
costPerMillionTokens: z5.number().positive(),
|
|
3948
|
+
qualityBaseline: z5.number().min(0).max(1)
|
|
3922
3949
|
}),
|
|
3923
|
-
weakModel:
|
|
3924
|
-
tier:
|
|
3925
|
-
cli:
|
|
3926
|
-
costPerMillionTokens:
|
|
3927
|
-
qualityBaseline:
|
|
3950
|
+
weakModel: z5.object({
|
|
3951
|
+
tier: z5.literal("weak"),
|
|
3952
|
+
cli: z5.enum(["claude", "gemini", "codex", "opencode"]),
|
|
3953
|
+
costPerMillionTokens: z5.number().positive(),
|
|
3954
|
+
qualityBaseline: z5.number().min(0).max(1)
|
|
3928
3955
|
}),
|
|
3929
|
-
routingThreshold:
|
|
3930
|
-
minDataPoints:
|
|
3931
|
-
maxDataPoints:
|
|
3932
|
-
enableOnlineLearning:
|
|
3933
|
-
domainThresholds:
|
|
3956
|
+
routingThreshold: z5.number().min(0).max(1).default(0.5),
|
|
3957
|
+
minDataPoints: z5.number().int().positive().default(10),
|
|
3958
|
+
maxDataPoints: z5.number().int().positive().default(1e4),
|
|
3959
|
+
enableOnlineLearning: z5.boolean().default(true),
|
|
3960
|
+
domainThresholds: z5.record(z5.string(), z5.number().min(0).max(1)).optional()
|
|
3934
3961
|
});
|
|
3935
3962
|
|
|
3936
3963
|
// src/cli-adapters/preference-router-store.ts
|
|
@@ -4272,8 +4299,8 @@ function createPreferenceRouter(config, dataStore) {
|
|
|
4272
4299
|
}
|
|
4273
4300
|
|
|
4274
4301
|
// src/cli-adapters/zero-router-types.ts
|
|
4275
|
-
import { z as
|
|
4276
|
-
var DifficultyDimensionSchema =
|
|
4302
|
+
import { z as z6 } from "zod";
|
|
4303
|
+
var DifficultyDimensionSchema = z6.enum([
|
|
4277
4304
|
"reasoning",
|
|
4278
4305
|
"knowledge",
|
|
4279
4306
|
"creativity",
|
|
@@ -4287,17 +4314,17 @@ var DIFFICULTY_DIMENSIONS = [
|
|
|
4287
4314
|
"precision",
|
|
4288
4315
|
"context_length"
|
|
4289
4316
|
];
|
|
4290
|
-
var DifficultySpaceSchema =
|
|
4317
|
+
var DifficultySpaceSchema = z6.object({
|
|
4291
4318
|
/** Reasoning difficulty: logical complexity, multi-step inference (0-1) */
|
|
4292
|
-
reasoning:
|
|
4319
|
+
reasoning: z6.number().min(0).max(1),
|
|
4293
4320
|
/** Knowledge difficulty: domain expertise required (0-1) */
|
|
4294
|
-
knowledge:
|
|
4321
|
+
knowledge: z6.number().min(0).max(1),
|
|
4295
4322
|
/** Creativity difficulty: novel generation, open-endedness (0-1) */
|
|
4296
|
-
creativity:
|
|
4323
|
+
creativity: z6.number().min(0).max(1),
|
|
4297
4324
|
/** Precision difficulty: accuracy requirements, error tolerance (0-1) */
|
|
4298
|
-
precision:
|
|
4325
|
+
precision: z6.number().min(0).max(1),
|
|
4299
4326
|
/** Context length difficulty: amount of context to process (0-1) */
|
|
4300
|
-
context_length:
|
|
4327
|
+
context_length: z6.number().min(0).max(1)
|
|
4301
4328
|
});
|
|
4302
4329
|
var DEFAULT_DIFFICULTY_THRESHOLDS = {
|
|
4303
4330
|
easyUpperBound: 0.3,
|
|
@@ -4313,12 +4340,12 @@ var DEFAULT_TIER_TO_CLIS = {
|
|
|
4313
4340
|
balanced: ["codex", "opencode", "gemini", "claude"],
|
|
4314
4341
|
powerful: ["claude", "codex", "opencode", "gemini"]
|
|
4315
4342
|
};
|
|
4316
|
-
var DifficultyWeightsSchema =
|
|
4317
|
-
reasoning:
|
|
4318
|
-
knowledge:
|
|
4319
|
-
creativity:
|
|
4320
|
-
precision:
|
|
4321
|
-
context_length:
|
|
4343
|
+
var DifficultyWeightsSchema = z6.object({
|
|
4344
|
+
reasoning: z6.number().min(0).max(1),
|
|
4345
|
+
knowledge: z6.number().min(0).max(1),
|
|
4346
|
+
creativity: z6.number().min(0).max(1),
|
|
4347
|
+
precision: z6.number().min(0).max(1),
|
|
4348
|
+
context_length: z6.number().min(0).max(1)
|
|
4322
4349
|
});
|
|
4323
4350
|
var DEFAULT_DIFFICULTY_WEIGHTS = {
|
|
4324
4351
|
reasoning: 0.3,
|
|
@@ -4327,29 +4354,29 @@ var DEFAULT_DIFFICULTY_WEIGHTS = {
|
|
|
4327
4354
|
precision: 0.25,
|
|
4328
4355
|
context_length: 0.15
|
|
4329
4356
|
};
|
|
4330
|
-
var ZeroRouterConfigSchema =
|
|
4357
|
+
var ZeroRouterConfigSchema = z6.object({
|
|
4331
4358
|
/** Difficulty thresholds for level classification */
|
|
4332
|
-
thresholds:
|
|
4333
|
-
easyUpperBound:
|
|
4334
|
-
hardLowerBound:
|
|
4359
|
+
thresholds: z6.object({
|
|
4360
|
+
easyUpperBound: z6.number().min(0).max(1),
|
|
4361
|
+
hardLowerBound: z6.number().min(0).max(1)
|
|
4335
4362
|
}).default(DEFAULT_DIFFICULTY_THRESHOLDS),
|
|
4336
4363
|
/** Weights for difficulty aggregation */
|
|
4337
4364
|
weights: DifficultyWeightsSchema.default(DEFAULT_DIFFICULTY_WEIGHTS),
|
|
4338
4365
|
/** Mapping from difficulty level to model tier */
|
|
4339
|
-
difficultyToTier:
|
|
4366
|
+
difficultyToTier: z6.record(z6.enum(["easy", "medium", "hard"]), z6.enum(["fast", "balanced", "powerful"])).default(DEFAULT_DIFFICULTY_TO_TIER),
|
|
4340
4367
|
/** Mapping from model tier to CLI preference order */
|
|
4341
|
-
tierToClis:
|
|
4342
|
-
|
|
4343
|
-
|
|
4368
|
+
tierToClis: z6.record(
|
|
4369
|
+
z6.enum(["fast", "balanced", "powerful"]),
|
|
4370
|
+
z6.array(z6.enum(["claude", "gemini", "codex", "opencode"]))
|
|
4344
4371
|
).default(DEFAULT_TIER_TO_CLIS),
|
|
4345
4372
|
/** Enable adaptive calibration from outcomes */
|
|
4346
|
-
enableCalibration:
|
|
4373
|
+
enableCalibration: z6.boolean().default(true),
|
|
4347
4374
|
/** Maximum outcomes to store for calibration */
|
|
4348
|
-
maxCalibrationOutcomes:
|
|
4375
|
+
maxCalibrationOutcomes: z6.number().int().positive().default(1e3),
|
|
4349
4376
|
/** Minimum outcomes before applying calibration adjustments */
|
|
4350
|
-
minCalibrationOutcomes:
|
|
4377
|
+
minCalibrationOutcomes: z6.number().int().positive().default(50),
|
|
4351
4378
|
/** Verbose logging */
|
|
4352
|
-
verbose:
|
|
4379
|
+
verbose: z6.boolean().default(false)
|
|
4353
4380
|
});
|
|
4354
4381
|
var DEFAULT_ZERO_ROUTER_CONFIG = {
|
|
4355
4382
|
thresholds: DEFAULT_DIFFICULTY_THRESHOLDS,
|
|
@@ -4873,16 +4900,16 @@ var ZeroRouter = class {
|
|
|
4873
4900
|
};
|
|
4874
4901
|
|
|
4875
4902
|
// src/cli-adapters/latency-tracker-types.ts
|
|
4876
|
-
import { z as
|
|
4877
|
-
var LatencyTrackerConfigSchema =
|
|
4903
|
+
import { z as z7 } from "zod";
|
|
4904
|
+
var LatencyTrackerConfigSchema = z7.object({
|
|
4878
4905
|
/** Maximum number of samples to keep per CLI (default: 100) */
|
|
4879
|
-
windowSize:
|
|
4906
|
+
windowSize: z7.number().int().positive().default(100),
|
|
4880
4907
|
/** Time-weighted decay factor (0-1, higher = more weight to recent) (default: 0.95) */
|
|
4881
|
-
decayFactor:
|
|
4908
|
+
decayFactor: z7.number().min(0).max(1).default(0.95),
|
|
4882
4909
|
/** Maximum age of samples in milliseconds before forced eviction (default: 3600000 = 1 hour) */
|
|
4883
|
-
maxSampleAgeMs:
|
|
4910
|
+
maxSampleAgeMs: z7.number().int().positive().default(36e5),
|
|
4884
4911
|
/** Percentiles to calculate (default: [50, 95, 99]) */
|
|
4885
|
-
percentiles:
|
|
4912
|
+
percentiles: z7.array(z7.number().min(0).max(100)).default([50, 95, 99])
|
|
4886
4913
|
});
|
|
4887
4914
|
var EMPTY_LATENCY_STATS = {
|
|
4888
4915
|
count: 0,
|
|
@@ -5116,20 +5143,192 @@ var LatencyTracker = class {
|
|
|
5116
5143
|
}
|
|
5117
5144
|
};
|
|
5118
5145
|
|
|
5146
|
+
// src/context/routing-memory.ts
|
|
5147
|
+
var DEFAULT_ROUTING_MEMORY_CONFIG = {
|
|
5148
|
+
minObservations: 5,
|
|
5149
|
+
confidenceThreshold: 0.6,
|
|
5150
|
+
successRateThreshold: 0.7,
|
|
5151
|
+
actionCacheMaxAgeMs: 36e5
|
|
5152
|
+
// 1 hour
|
|
5153
|
+
};
|
|
5154
|
+
var RoutingMemory = class {
|
|
5155
|
+
mobimem;
|
|
5156
|
+
config;
|
|
5157
|
+
logger;
|
|
5158
|
+
// Statistics
|
|
5159
|
+
cacheHits = 0;
|
|
5160
|
+
cacheMisses = 0;
|
|
5161
|
+
recommendationsMade = 0;
|
|
5162
|
+
constructor(config, mobimem) {
|
|
5163
|
+
this.config = { ...DEFAULT_ROUTING_MEMORY_CONFIG, ...config };
|
|
5164
|
+
this.logger = this.config.logger ?? createLogger({ component: "RoutingMemory" });
|
|
5165
|
+
this.mobimem = mobimem ?? new MobiMem();
|
|
5166
|
+
this.logger.info("RoutingMemory initialized", {
|
|
5167
|
+
minObservations: this.config.minObservations,
|
|
5168
|
+
confidenceThreshold: this.config.confidenceThreshold
|
|
5169
|
+
});
|
|
5170
|
+
}
|
|
5171
|
+
storePreference(model, taskType, performance2) {
|
|
5172
|
+
const preferenceKey = `model_preference:${taskType}`;
|
|
5173
|
+
const entityId = `routing:${model}`;
|
|
5174
|
+
const entry = this.mobimem.profile.observe(entityId, "agent", preferenceKey, {
|
|
5175
|
+
model,
|
|
5176
|
+
performance: performance2,
|
|
5177
|
+
updatedAt: getTimeProvider().nowIso()
|
|
5178
|
+
});
|
|
5179
|
+
this.logger.debug("Stored model preference", {
|
|
5180
|
+
model,
|
|
5181
|
+
taskType,
|
|
5182
|
+
confidence: entry.confidence,
|
|
5183
|
+
observations: entry.observationCount
|
|
5184
|
+
});
|
|
5185
|
+
}
|
|
5186
|
+
getPreferences(taskType) {
|
|
5187
|
+
const preferenceKey = `model_preference:${taskType}`;
|
|
5188
|
+
const preferences = [];
|
|
5189
|
+
for (const model of CLI_NAMES) {
|
|
5190
|
+
const entityId = `routing:${model}`;
|
|
5191
|
+
const entry = this.mobimem.profile.getPreference(entityId, preferenceKey);
|
|
5192
|
+
if (entry !== null && entry.observationCount >= this.config.minObservations) {
|
|
5193
|
+
const value = entry.preferenceValue;
|
|
5194
|
+
preferences.push({
|
|
5195
|
+
model: value.model,
|
|
5196
|
+
strength: this.calculateStrength(value.performance),
|
|
5197
|
+
performance: value.performance,
|
|
5198
|
+
confidence: entry.confidence
|
|
5199
|
+
});
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5202
|
+
return preferences.sort((a, b) => b.strength - a.strength);
|
|
5203
|
+
}
|
|
5204
|
+
recordExperience(workflow, models, success, metrics2) {
|
|
5205
|
+
const contextSignature = models.join("->");
|
|
5206
|
+
const actionSequence = models.map((model, index) => ({
|
|
5207
|
+
index,
|
|
5208
|
+
actionType: "model_route",
|
|
5209
|
+
parameters: { model },
|
|
5210
|
+
durationMs: Math.floor(metrics2.durationMs / models.length),
|
|
5211
|
+
success
|
|
5212
|
+
}));
|
|
5213
|
+
const outcome = metrics2.qualityScore !== void 0 ? {
|
|
5214
|
+
success,
|
|
5215
|
+
qualityScore: metrics2.qualityScore,
|
|
5216
|
+
totalDurationMs: metrics2.durationMs,
|
|
5217
|
+
tokensUsed: metrics2.tokensUsed
|
|
5218
|
+
} : {
|
|
5219
|
+
success,
|
|
5220
|
+
totalDurationMs: metrics2.durationMs,
|
|
5221
|
+
tokensUsed: metrics2.tokensUsed
|
|
5222
|
+
};
|
|
5223
|
+
this.mobimem.experience.recordExecution(workflow, actionSequence, outcome, contextSignature);
|
|
5224
|
+
this.logger.debug("Recorded routing experience", {
|
|
5225
|
+
workflow,
|
|
5226
|
+
models: models.join("->"),
|
|
5227
|
+
success,
|
|
5228
|
+
durationMs: metrics2.durationMs
|
|
5229
|
+
});
|
|
5230
|
+
}
|
|
5231
|
+
getExperiencePatterns(workflow) {
|
|
5232
|
+
const experiences = this.mobimem.experience.findPatterns(workflow);
|
|
5233
|
+
return experiences.filter((exp) => exp.successRate >= this.config.successRateThreshold).map((exp) => this.mapExperienceToPattern(exp));
|
|
5234
|
+
}
|
|
5235
|
+
cacheAction(action, model, result, durationMs2) {
|
|
5236
|
+
const input = { actionSignature: action, model };
|
|
5237
|
+
this.mobimem.action.cache(input, result, durationMs2);
|
|
5238
|
+
this.logger.debug("Cached action result", { action: action.slice(0, 50), model, durationMs: durationMs2 });
|
|
5239
|
+
}
|
|
5240
|
+
getCachedAction(action) {
|
|
5241
|
+
for (const model of CLI_NAMES) {
|
|
5242
|
+
const input = { actionSignature: action, model };
|
|
5243
|
+
const entry = this.mobimem.action.get(input);
|
|
5244
|
+
if (entry !== null) {
|
|
5245
|
+
this.cacheHits++;
|
|
5246
|
+
const inputData = entry.input;
|
|
5247
|
+
return {
|
|
5248
|
+
action,
|
|
5249
|
+
result: entry.result,
|
|
5250
|
+
model: inputData.model,
|
|
5251
|
+
cachedAt: entry.cachedAt,
|
|
5252
|
+
timeSavedMs: entry.timeSavedMs
|
|
5253
|
+
};
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
this.cacheMisses++;
|
|
5257
|
+
return void 0;
|
|
5258
|
+
}
|
|
5259
|
+
getRecommendation(taskType) {
|
|
5260
|
+
const preferences = this.getPreferences(taskType);
|
|
5261
|
+
const top = preferences[0];
|
|
5262
|
+
if (top !== void 0 && top.confidence >= this.config.confidenceThreshold) {
|
|
5263
|
+
this.recommendationsMade++;
|
|
5264
|
+
this.logger.debug("Generated routing recommendation", {
|
|
5265
|
+
taskType,
|
|
5266
|
+
recommended: top.model,
|
|
5267
|
+
confidence: top.confidence,
|
|
5268
|
+
strength: top.strength
|
|
5269
|
+
});
|
|
5270
|
+
return top.model;
|
|
5271
|
+
}
|
|
5272
|
+
return void 0;
|
|
5273
|
+
}
|
|
5274
|
+
getStats() {
|
|
5275
|
+
const mobiStats = this.mobimem.getStats();
|
|
5276
|
+
return {
|
|
5277
|
+
totalPreferences: mobiStats.profile.totalEntries,
|
|
5278
|
+
totalExperiences: mobiStats.experience.totalPatterns,
|
|
5279
|
+
cacheHits: this.cacheHits,
|
|
5280
|
+
cacheMisses: this.cacheMisses,
|
|
5281
|
+
recommendationsMade: this.recommendationsMade
|
|
5282
|
+
};
|
|
5283
|
+
}
|
|
5284
|
+
// ========================================================================
|
|
5285
|
+
// Private Helpers
|
|
5286
|
+
// ========================================================================
|
|
5287
|
+
/**
|
|
5288
|
+
* Calculate preference strength from performance metrics.
|
|
5289
|
+
*/
|
|
5290
|
+
calculateStrength(performance2) {
|
|
5291
|
+
const qualityWeight = 0.4;
|
|
5292
|
+
const successWeight = 0.3;
|
|
5293
|
+
const speedWeight = 0.2;
|
|
5294
|
+
const efficiencyWeight = 0.1;
|
|
5295
|
+
const normalizedLatency = 1 - Math.min(performance2.avgLatencyMs / 1e4, 1);
|
|
5296
|
+
const normalizedTokens = 1 - Math.min(performance2.avgTokens / 1e5, 1);
|
|
5297
|
+
return performance2.avgQuality * qualityWeight + performance2.successRate * successWeight + normalizedLatency * speedWeight + normalizedTokens * efficiencyWeight;
|
|
5298
|
+
}
|
|
5299
|
+
/**
|
|
5300
|
+
* Map MobiMem experience entry to routing pattern.
|
|
5301
|
+
*/
|
|
5302
|
+
mapExperienceToPattern(exp) {
|
|
5303
|
+
const models = exp.actionSequence.filter((step) => step.actionType === "model_route").map((step) => step.parameters.model);
|
|
5304
|
+
const avgDuration = exp.outcome.totalDurationMs;
|
|
5305
|
+
return {
|
|
5306
|
+
workflow: exp.taskType,
|
|
5307
|
+
modelSequence: models,
|
|
5308
|
+
successRate: exp.successRate,
|
|
5309
|
+
avgDurationMs: avgDuration,
|
|
5310
|
+
usageCount: exp.attemptCount
|
|
5311
|
+
};
|
|
5312
|
+
}
|
|
5313
|
+
};
|
|
5314
|
+
function createRoutingMemory(config, mobimem) {
|
|
5315
|
+
return new RoutingMemory(config, mobimem);
|
|
5316
|
+
}
|
|
5317
|
+
|
|
5119
5318
|
// src/cli-adapters/routing/router-stage.ts
|
|
5120
|
-
import { z as
|
|
5121
|
-
var StageConfigSchema =
|
|
5122
|
-
enabled:
|
|
5123
|
-
priority:
|
|
5124
|
-
options:
|
|
5319
|
+
import { z as z8 } from "zod";
|
|
5320
|
+
var StageConfigSchema = z8.object({
|
|
5321
|
+
enabled: z8.boolean().default(true),
|
|
5322
|
+
priority: z8.number().int().min(0).max(100).default(50),
|
|
5323
|
+
options: z8.record(z8.string(), z8.unknown()).optional()
|
|
5125
5324
|
});
|
|
5126
|
-
var RoutingOutcomeSchema =
|
|
5325
|
+
var RoutingOutcomeSchema = z8.object({
|
|
5127
5326
|
selectedCli: CliNameSchema,
|
|
5128
|
-
task:
|
|
5129
|
-
success:
|
|
5130
|
-
qualityScore:
|
|
5131
|
-
latencyMs:
|
|
5132
|
-
tokensUsed:
|
|
5327
|
+
task: z8.string(),
|
|
5328
|
+
success: z8.boolean(),
|
|
5329
|
+
qualityScore: z8.number().min(0).max(1).optional(),
|
|
5330
|
+
latencyMs: z8.number().int().positive().optional(),
|
|
5331
|
+
tokensUsed: z8.number().int().positive().optional()
|
|
5133
5332
|
});
|
|
5134
5333
|
function createRoutingContext(task, availableClis = ["claude", "gemini", "codex", "opencode"], metadata) {
|
|
5135
5334
|
return {
|
|
@@ -5326,7 +5525,7 @@ var ConfidenceCascadeStage = class {
|
|
|
5326
5525
|
};
|
|
5327
5526
|
|
|
5328
5527
|
// src/config/task-specialization-types.ts
|
|
5329
|
-
import { z as
|
|
5528
|
+
import { z as z9 } from "zod";
|
|
5330
5529
|
var TASK_CATEGORIES = [
|
|
5331
5530
|
"architecture",
|
|
5332
5531
|
"code_generation",
|
|
@@ -5339,8 +5538,8 @@ var TASK_CATEGORIES = [
|
|
|
5339
5538
|
"devops",
|
|
5340
5539
|
"exploration"
|
|
5341
5540
|
];
|
|
5342
|
-
var TaskCategorySchema =
|
|
5343
|
-
var TaskSpecializationSchema =
|
|
5541
|
+
var TaskCategorySchema = z9.enum(TASK_CATEGORIES);
|
|
5542
|
+
var TaskSpecializationSchema = z9.object({
|
|
5344
5543
|
/** Task category identifier */
|
|
5345
5544
|
category: TaskCategorySchema,
|
|
5346
5545
|
/** Primary CLI recommendation */
|
|
@@ -5348,11 +5547,11 @@ var TaskSpecializationSchema = z8.object({
|
|
|
5348
5547
|
/** Secondary CLI fallback */
|
|
5349
5548
|
secondaryCli: CliNameSchema,
|
|
5350
5549
|
/** Why this CLI is preferred for this task type */
|
|
5351
|
-
reasoning:
|
|
5550
|
+
reasoning: z9.string(),
|
|
5352
5551
|
/** Keywords that trigger this category detection */
|
|
5353
|
-
keywords:
|
|
5552
|
+
keywords: z9.array(z9.string()).min(1),
|
|
5354
5553
|
/** Bonus score applied when this category matches (0-20) */
|
|
5355
|
-
bonus:
|
|
5554
|
+
bonus: z9.number().min(0).max(20)
|
|
5356
5555
|
});
|
|
5357
5556
|
|
|
5358
5557
|
// src/config/task-specialization.ts
|
|
@@ -5465,7 +5664,7 @@ var TASK_SPECIALIZATION_MATRIX = [
|
|
|
5465
5664
|
"dast",
|
|
5466
5665
|
"zap",
|
|
5467
5666
|
"semgrep",
|
|
5468
|
-
"
|
|
5667
|
+
"grype",
|
|
5469
5668
|
"fork",
|
|
5470
5669
|
"kind",
|
|
5471
5670
|
"cluster",
|
|
@@ -6575,10 +6774,10 @@ function createPersistentDistillerOrFallback(outcomeStore, logger9) {
|
|
|
6575
6774
|
}
|
|
6576
6775
|
|
|
6577
6776
|
// src/orchestration/outcomes/outcome-types.ts
|
|
6578
|
-
import { z as
|
|
6777
|
+
import { z as z10 } from "zod";
|
|
6579
6778
|
var logger5 = createLogger({ component: "outcome-error-taxonomy" });
|
|
6580
|
-
var OutcomeSourceSchema =
|
|
6581
|
-
var OutcomeFailureCategorySchema =
|
|
6779
|
+
var OutcomeSourceSchema = z10.enum(["delegate", "consensus", "manual"]);
|
|
6780
|
+
var OutcomeFailureCategorySchema = z10.enum([
|
|
6582
6781
|
"timeout",
|
|
6583
6782
|
"authentication",
|
|
6584
6783
|
"rate_limit",
|
|
@@ -6591,33 +6790,37 @@ var OutcomeFailureCategorySchema = z9.enum([
|
|
|
6591
6790
|
"generic",
|
|
6592
6791
|
"unknown"
|
|
6593
6792
|
]);
|
|
6594
|
-
var TaskOutcomeSchema =
|
|
6595
|
-
id:
|
|
6793
|
+
var TaskOutcomeSchema = z10.object({
|
|
6794
|
+
id: z10.string().min(1),
|
|
6596
6795
|
cli: CliNameSchema,
|
|
6597
6796
|
category: TaskCategorySchema,
|
|
6598
|
-
model:
|
|
6599
|
-
success:
|
|
6600
|
-
durationMs:
|
|
6601
|
-
timestamp:
|
|
6602
|
-
qualitySignals:
|
|
6797
|
+
model: z10.string().min(1),
|
|
6798
|
+
success: z10.boolean(),
|
|
6799
|
+
durationMs: z10.number().nonnegative(),
|
|
6800
|
+
timestamp: z10.string().min(1),
|
|
6801
|
+
qualitySignals: z10.array(z10.string()).optional(),
|
|
6603
6802
|
failureCategory: OutcomeFailureCategorySchema.optional(),
|
|
6604
|
-
errorMessage:
|
|
6803
|
+
errorMessage: z10.string().max(500).optional(),
|
|
6605
6804
|
source: OutcomeSourceSchema,
|
|
6606
6805
|
/** Whether this outcome came from a triage-initiated retry (#1506). */
|
|
6607
|
-
wasRetried:
|
|
6806
|
+
wasRetried: z10.boolean().optional(),
|
|
6608
6807
|
/** Triage action taken on the failure (#1506). */
|
|
6609
|
-
triageAction:
|
|
6808
|
+
triageAction: z10.string().max(30).optional(),
|
|
6809
|
+
/** Routing stage that selected this CLI (#1785). */
|
|
6810
|
+
routingStage: z10.string().max(50).optional(),
|
|
6811
|
+
/** Number of retry attempts before this outcome (#1785). */
|
|
6812
|
+
retryCount: z10.number().int().nonnegative().optional()
|
|
6610
6813
|
});
|
|
6611
|
-
var OutcomeQuerySchema =
|
|
6814
|
+
var OutcomeQuerySchema = z10.object({
|
|
6612
6815
|
cli: CliNameSchema.optional(),
|
|
6613
6816
|
category: TaskCategorySchema.optional(),
|
|
6614
6817
|
source: OutcomeSourceSchema.optional(),
|
|
6615
|
-
success:
|
|
6818
|
+
success: z10.boolean().optional(),
|
|
6616
6819
|
failureCategory: OutcomeFailureCategorySchema.optional(),
|
|
6617
|
-
since:
|
|
6618
|
-
limit:
|
|
6820
|
+
since: z10.string().optional(),
|
|
6821
|
+
limit: z10.number().int().positive().optional(),
|
|
6619
6822
|
/** Exclude outcomes with any of these quality signals (#1680). */
|
|
6620
|
-
excludeQualitySignals:
|
|
6823
|
+
excludeQualitySignals: z10.array(z10.string()).optional()
|
|
6621
6824
|
});
|
|
6622
6825
|
var TIMEOUT_PATTERNS = ["timeout", "timed out", "deadline exceeded", "socket hang up", "aborted"];
|
|
6623
6826
|
var AUTH_PATTERNS = [
|
|
@@ -7182,52 +7385,52 @@ function runWarmUp(logger9) {
|
|
|
7182
7385
|
}
|
|
7183
7386
|
|
|
7184
7387
|
// src/cli-adapters/composite-router-types.ts
|
|
7185
|
-
import { z as
|
|
7186
|
-
var CompositeRouterConfigSchema =
|
|
7388
|
+
import { z as z11 } from "zod";
|
|
7389
|
+
var CompositeRouterConfigSchema = z11.object({
|
|
7187
7390
|
/** Enable confidence cascade stage (default: false) (Issue #755, ADR-0005) */
|
|
7188
|
-
enableConfidenceCascade:
|
|
7391
|
+
enableConfidenceCascade: z11.boolean().default(false),
|
|
7189
7392
|
/** Enable budget filtering stage (default: true) */
|
|
7190
|
-
enableBudgetFilter:
|
|
7393
|
+
enableBudgetFilter: z11.boolean().default(true),
|
|
7191
7394
|
/** Enable capability match stage (default: false) (Issue #755, ADR-0005) */
|
|
7192
|
-
enableCapabilityMatch:
|
|
7395
|
+
enableCapabilityMatch: z11.boolean().default(false),
|
|
7193
7396
|
/** Enable ZeroRouter difficulty-based routing stage (default: true) (Issue #473) */
|
|
7194
|
-
enableZeroRouter:
|
|
7397
|
+
enableZeroRouter: z11.boolean().default(true),
|
|
7195
7398
|
/** Enable preference-trained routing stage (default: false) */
|
|
7196
|
-
enablePreferenceRouting:
|
|
7399
|
+
enablePreferenceRouting: z11.boolean().default(false),
|
|
7197
7400
|
/** Enable TOPSIS ranking stage (default: true) */
|
|
7198
|
-
enableTopsisRanking:
|
|
7401
|
+
enableTopsisRanking: z11.boolean().default(true),
|
|
7199
7402
|
/** Enable LinUCB selection stage (default: true) */
|
|
7200
|
-
enableLinUCBSelection:
|
|
7403
|
+
enableLinUCBSelection: z11.boolean().default(true),
|
|
7201
7404
|
/** Enable quality constraint stage (default: false) (Issue #755, ADR-0005) */
|
|
7202
|
-
enableQualityConstraint:
|
|
7405
|
+
enableQualityConstraint: z11.boolean().default(false),
|
|
7203
7406
|
/** Enable resource strategy stage for budget-aware oscillation (default: true) (Issue #998) */
|
|
7204
|
-
enableResourceStrategy:
|
|
7407
|
+
enableResourceStrategy: z11.boolean().default(true),
|
|
7205
7408
|
/** Enable strategy distillation for learned routing rules (default: false) (Issue #999) */
|
|
7206
|
-
enableStrategyDistillation:
|
|
7409
|
+
enableStrategyDistillation: z11.boolean().default(false),
|
|
7207
7410
|
/** Enable latency tracking for routing decisions (default: true) (Issue #361) */
|
|
7208
|
-
enableLatencyTracking:
|
|
7411
|
+
enableLatencyTracking: z11.boolean().default(true),
|
|
7209
7412
|
/** Enable routing memory for learned routing (default: false) (Issue #463, #461) */
|
|
7210
|
-
enableRoutingMemory:
|
|
7413
|
+
enableRoutingMemory: z11.boolean().default(false),
|
|
7211
7414
|
/** Enable KNN experience-based routing (default: false) (arXiv:2507.05370) */
|
|
7212
|
-
enableKnnRouting:
|
|
7415
|
+
enableKnnRouting: z11.boolean().default(false),
|
|
7213
7416
|
/** Weight for latency score in final routing (0-1, default: 0.2) */
|
|
7214
|
-
latencyScoreWeight:
|
|
7417
|
+
latencyScoreWeight: z11.number().min(0).max(1).default(0.2),
|
|
7215
7418
|
/** Budget constraints (optional) */
|
|
7216
|
-
budgetConstraints:
|
|
7217
|
-
maxTokens:
|
|
7218
|
-
maxCostUsd:
|
|
7219
|
-
maxLatencyMs:
|
|
7419
|
+
budgetConstraints: z11.object({
|
|
7420
|
+
maxTokens: z11.number().positive(),
|
|
7421
|
+
maxCostUsd: z11.number().positive(),
|
|
7422
|
+
maxLatencyMs: z11.number().positive()
|
|
7220
7423
|
}).partial().optional(),
|
|
7221
7424
|
/** LinUCB exploration parameter (default: 1.0) */
|
|
7222
|
-
linucbAlpha:
|
|
7425
|
+
linucbAlpha: z11.number().positive().default(1),
|
|
7223
7426
|
/** Billing mode: 'plan' zeroes cost weight, 'api' preserves current behavior (default: 'plan') */
|
|
7224
|
-
billingMode:
|
|
7427
|
+
billingMode: z11.enum(["plan", "api"]).default("plan"),
|
|
7225
7428
|
/** Enable capacity-aware load balancing (deprioritize exhausted CLIs) (default: true) (Issue #807) */
|
|
7226
|
-
enableCapacityBalancing:
|
|
7429
|
+
enableCapacityBalancing: z11.boolean().default(true),
|
|
7227
7430
|
/** Maximum routing decision time in ms (default: 50) */
|
|
7228
|
-
maxDecisionTimeMs:
|
|
7431
|
+
maxDecisionTimeMs: z11.number().positive().default(50),
|
|
7229
7432
|
/** Minimum preference data points before using learned routing (default: 10) */
|
|
7230
|
-
preferenceMinDataPoints:
|
|
7433
|
+
preferenceMinDataPoints: z11.number().int().positive().default(10)
|
|
7231
7434
|
});
|
|
7232
7435
|
var DEFAULT_COMPOSITE_CONFIG = {
|
|
7233
7436
|
enableConfidenceCascade: false,
|
|
@@ -7511,12 +7714,12 @@ async function fetchCapacityData(adapters) {
|
|
|
7511
7714
|
}
|
|
7512
7715
|
|
|
7513
7716
|
// src/mcp/tools/weather-report-types.ts
|
|
7514
|
-
import { z as
|
|
7515
|
-
var WeatherReportInputSchema =
|
|
7717
|
+
import { z as z12 } from "zod";
|
|
7718
|
+
var WeatherReportInputSchema = z12.object({
|
|
7516
7719
|
/** Filter by CLI name. */
|
|
7517
|
-
cli:
|
|
7720
|
+
cli: z12.enum(CLI_NAMES).optional().describe("Filter by CLI"),
|
|
7518
7721
|
/** Filter by task category. */
|
|
7519
|
-
category:
|
|
7722
|
+
category: z12.enum([
|
|
7520
7723
|
"architecture",
|
|
7521
7724
|
"code_generation",
|
|
7522
7725
|
"code_review",
|
|
@@ -7529,22 +7732,22 @@ var WeatherReportInputSchema = z11.object({
|
|
|
7529
7732
|
"exploration"
|
|
7530
7733
|
]).optional().describe("Filter by task category"),
|
|
7531
7734
|
/** Include adaptive routing bonus data. */
|
|
7532
|
-
includeAdaptive:
|
|
7735
|
+
includeAdaptive: z12.boolean().optional().default(true).describe("Include adaptive routing bonuses (default: true)")
|
|
7533
7736
|
});
|
|
7534
7737
|
var DEFAULT_OUTCOME_LOOKBACK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
7535
|
-
var WeatherReportConfigSchema =
|
|
7738
|
+
var WeatherReportConfigSchema = z12.object({
|
|
7536
7739
|
/** Minimum observations before adjusting bonuses (lowered for faster activation). */
|
|
7537
|
-
coldStartThreshold:
|
|
7740
|
+
coldStartThreshold: z12.number().int().min(1).max(1e3).default(3),
|
|
7538
7741
|
/** Exploration rate: fraction of random routing (0.0-1.0). */
|
|
7539
|
-
explorationRate:
|
|
7742
|
+
explorationRate: z12.number().min(0).max(1).default(0.1),
|
|
7540
7743
|
/** Max adaptive bonus adjustment (+/-). */
|
|
7541
|
-
maxBonusAdjustment:
|
|
7744
|
+
maxBonusAdjustment: z12.number().min(0).max(20).default(10),
|
|
7542
7745
|
/**
|
|
7543
7746
|
* Lookback window for outcome queries (ms). Only outcomes within this
|
|
7544
7747
|
* window are used for adaptive bonuses. Falls back to all history if
|
|
7545
7748
|
* the window has fewer samples than coldStartThreshold. Default: 7 days.
|
|
7546
7749
|
*/
|
|
7547
|
-
outcomeLookbackMs:
|
|
7750
|
+
outcomeLookbackMs: z12.number().int().min(0).default(DEFAULT_OUTCOME_LOOKBACK_MS)
|
|
7548
7751
|
});
|
|
7549
7752
|
function createDefaultWeatherConfig() {
|
|
7550
7753
|
return WeatherReportConfigSchema.parse({});
|
|
@@ -7929,47 +8132,47 @@ function createMetricsMiddleware() {
|
|
|
7929
8132
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
7930
8133
|
|
|
7931
8134
|
// src/config/defaults-types.ts
|
|
7932
|
-
import { z as
|
|
8135
|
+
import { z as z13 } from "zod";
|
|
7933
8136
|
function isKnownCliName(cli) {
|
|
7934
8137
|
return cli === "claude" || cli === "gemini" || cli === "codex" || cli === "opencode" || cli === "default";
|
|
7935
8138
|
}
|
|
7936
|
-
var positiveInt =
|
|
7937
|
-
var nonNegativeInt =
|
|
7938
|
-
var durationMs =
|
|
7939
|
-
var TimeoutProfileSchema =
|
|
8139
|
+
var positiveInt = z13.number().int().positive();
|
|
8140
|
+
var nonNegativeInt = z13.number().int().nonnegative();
|
|
8141
|
+
var durationMs = z13.number().int().positive().describe("Duration in milliseconds");
|
|
8142
|
+
var TimeoutProfileSchema = z13.object({
|
|
7940
8143
|
simple: durationMs.describe("Timeout for simple tasks"),
|
|
7941
8144
|
standard: durationMs.describe("Timeout for standard tasks"),
|
|
7942
8145
|
complex: durationMs.describe("Timeout for complex tasks")
|
|
7943
8146
|
});
|
|
7944
|
-
var RetryDefaultsSchema =
|
|
8147
|
+
var RetryDefaultsSchema = z13.object({
|
|
7945
8148
|
maxRetries: nonNegativeInt.max(10).describe("Maximum retry attempts"),
|
|
7946
8149
|
baseDelayMs: durationMs.describe("Base delay between retries"),
|
|
7947
8150
|
maxDelayMs: durationMs.describe("Maximum delay between retries"),
|
|
7948
|
-
jitterFactor:
|
|
8151
|
+
jitterFactor: z13.number().min(0).max(1).describe("Jitter factor (0-1)")
|
|
7949
8152
|
});
|
|
7950
|
-
var RateLimitDefaultsSchema =
|
|
8153
|
+
var RateLimitDefaultsSchema = z13.object({
|
|
7951
8154
|
requestsPerMinute: positiveInt.max(1e3).describe("Max requests per minute"),
|
|
7952
|
-
enabled:
|
|
8155
|
+
enabled: z13.boolean().describe("Whether rate limiting is enabled"),
|
|
7953
8156
|
maxConcurrent: positiveInt.max(100).describe("Max concurrent requests"),
|
|
7954
8157
|
capacity: positiveInt.describe("Token bucket capacity"),
|
|
7955
8158
|
refillRate: positiveInt.describe("Token refill rate"),
|
|
7956
8159
|
refillIntervalMs: durationMs.describe("Token refill interval")
|
|
7957
8160
|
});
|
|
7958
|
-
var CircuitBreakerDefaultsSchema =
|
|
7959
|
-
failureThreshold:
|
|
8161
|
+
var CircuitBreakerDefaultsSchema = z13.object({
|
|
8162
|
+
failureThreshold: z13.number().int().min(1).max(100).describe("Failures before opening"),
|
|
7960
8163
|
resetTimeoutMs: durationMs.describe("Time before attempting reset"),
|
|
7961
|
-
halfOpenSuccessThreshold:
|
|
7962
|
-
countTimeoutsAsFailures:
|
|
7963
|
-
countAuthFailuresAsFailures:
|
|
7964
|
-
countRateLimitsAsFailures:
|
|
8164
|
+
halfOpenSuccessThreshold: z13.number().int().min(1).max(10).describe("Successes to close"),
|
|
8165
|
+
countTimeoutsAsFailures: z13.boolean().describe("Count timeouts as failures"),
|
|
8166
|
+
countAuthFailuresAsFailures: z13.boolean().describe("Count auth failures as failures"),
|
|
8167
|
+
countRateLimitsAsFailures: z13.boolean().describe("Count rate limit errors as failures"),
|
|
7965
8168
|
halfOpenMaxRequests: positiveInt.describe("Max requests in half-open state")
|
|
7966
8169
|
});
|
|
7967
|
-
var ToolRateLimitConfigSchema =
|
|
8170
|
+
var ToolRateLimitConfigSchema = z13.object({
|
|
7968
8171
|
capacity: positiveInt.describe("Token bucket capacity"),
|
|
7969
8172
|
refillRate: positiveInt.describe("Token refill rate"),
|
|
7970
8173
|
refillIntervalMs: durationMs.describe("Token refill interval")
|
|
7971
8174
|
});
|
|
7972
|
-
var WorkerDefaultsSchema =
|
|
8175
|
+
var WorkerDefaultsSchema = z13.object({
|
|
7973
8176
|
maxWorkers: positiveInt.max(32).describe("Maximum worker threads"),
|
|
7974
8177
|
poolSize: positiveInt.max(32).describe("Worker pool size"),
|
|
7975
8178
|
idleTimeoutMs: durationMs.describe("Worker idle timeout"),
|
|
@@ -7979,7 +8182,7 @@ var WorkerDefaultsSchema = z12.object({
|
|
|
7979
8182
|
eventBusMaxHistory: nonNegativeInt.max(1e4).describe("Event bus history limit"),
|
|
7980
8183
|
swarmObserverMaxEvents: nonNegativeInt.max(1e4).describe("Swarm observer event limit")
|
|
7981
8184
|
});
|
|
7982
|
-
var TimeoutDefaultsSchema =
|
|
8185
|
+
var TimeoutDefaultsSchema = z13.object({
|
|
7983
8186
|
cliMs: durationMs.describe("Default CLI timeout"),
|
|
7984
8187
|
cliSimpleMs: durationMs.describe("Simple CLI task timeout"),
|
|
7985
8188
|
cliComplexMs: durationMs.describe("Complex CLI task timeout"),
|
|
@@ -9224,6 +9427,17 @@ async function applyQualityConstraints(candidates, stagesExecuted, deps) {
|
|
|
9224
9427
|
}
|
|
9225
9428
|
return ok({ candidates: qualityResult.eligible, qualityResult });
|
|
9226
9429
|
}
|
|
9430
|
+
function applyLinUCBFloorOverride(linucbCli, topsisRanking, opts) {
|
|
9431
|
+
if (opts.perfData === void 0) return linucbCli;
|
|
9432
|
+
const cliPerf = opts.perfData.get(linucbCli);
|
|
9433
|
+
if (cliPerf === void 0 || cliPerf.sampleCount < 20 || cliPerf.successRate >= 0.5) {
|
|
9434
|
+
return linucbCli;
|
|
9435
|
+
}
|
|
9436
|
+
const topsisTop = topsisRanking[0];
|
|
9437
|
+
if (topsisTop === void 0 || topsisTop === linucbCli) return linucbCli;
|
|
9438
|
+
opts.stagesExecuted.push("perf-floor-override");
|
|
9439
|
+
return topsisTop;
|
|
9440
|
+
}
|
|
9227
9441
|
async function runPipeline(task, taskProfile, stagesExecuted, cliNames, deps) {
|
|
9228
9442
|
let candidates = [...cliNames];
|
|
9229
9443
|
if (candidates.length === 0) {
|
|
@@ -9248,12 +9462,17 @@ async function runPipeline(task, taskProfile, stagesExecuted, cliNames, deps) {
|
|
|
9248
9462
|
if (linucbResult.selectedCli === void 0) {
|
|
9249
9463
|
return err(new CompositeRoutingError("No candidates available", "selection"));
|
|
9250
9464
|
}
|
|
9251
|
-
const
|
|
9252
|
-
const selectedCli = selectWithMemoryInfluence(
|
|
9465
|
+
const effectiveSelection = applyLinUCBFloorOverride(
|
|
9253
9466
|
linucbResult.selectedCli,
|
|
9254
|
-
|
|
9255
|
-
|
|
9467
|
+
topsisResult.ranking,
|
|
9468
|
+
{
|
|
9469
|
+
perfData: topsisOpts.performanceData,
|
|
9470
|
+
taskType: taskProfile.taskType,
|
|
9471
|
+
stagesExecuted
|
|
9472
|
+
}
|
|
9256
9473
|
);
|
|
9474
|
+
const latencyResult = runLatencyStage(candidates, stagesExecuted, deps);
|
|
9475
|
+
const selectedCli = selectWithMemoryInfluence(effectiveSelection, scoring.memoryResult, deps);
|
|
9257
9476
|
return ok(
|
|
9258
9477
|
buildPipelineResult({
|
|
9259
9478
|
...scoring,
|
|
@@ -9985,33 +10204,6 @@ var OrchestratorError = class extends Error {
|
|
|
9985
10204
|
}
|
|
9986
10205
|
};
|
|
9987
10206
|
|
|
9988
|
-
// src/context/mobimem-types.ts
|
|
9989
|
-
import { z as z13 } from "zod";
|
|
9990
|
-
var DEFAULT_MOBIMEM_CONFIG = {
|
|
9991
|
-
dbPath: ":memory:",
|
|
9992
|
-
maxProfileEntries: 100,
|
|
9993
|
-
maxExperiencePatterns: 500,
|
|
9994
|
-
maxActionCacheEntries: 1e3,
|
|
9995
|
-
actionCacheTtlMs: 36e5,
|
|
9996
|
-
// 1 hour
|
|
9997
|
-
minProfileConfidence: 0.6,
|
|
9998
|
-
minExperienceSuccessRate: 0.7,
|
|
9999
|
-
autoEviction: true
|
|
10000
|
-
};
|
|
10001
|
-
var MobiMemConfigSchema = z13.object({
|
|
10002
|
-
dbPath: z13.string(),
|
|
10003
|
-
maxProfileEntries: z13.number().int().positive().default(100),
|
|
10004
|
-
maxExperiencePatterns: z13.number().int().positive().default(500),
|
|
10005
|
-
maxActionCacheEntries: z13.number().int().positive().default(1e3),
|
|
10006
|
-
actionCacheTtlMs: z13.number().int().positive().default(36e5),
|
|
10007
|
-
minProfileConfidence: z13.number().min(0).max(1).default(0.6),
|
|
10008
|
-
minExperienceSuccessRate: z13.number().min(0).max(1).default(0.7),
|
|
10009
|
-
autoEviction: z13.boolean().default(true)
|
|
10010
|
-
});
|
|
10011
|
-
|
|
10012
|
-
// src/context/mobimem-impl.ts
|
|
10013
|
-
import { randomUUID as randomUUID4 } from "crypto";
|
|
10014
|
-
|
|
10015
10207
|
// src/context/mobimem-impl-helpers.ts
|
|
10016
10208
|
import { createHash as createHash2 } from "crypto";
|
|
10017
10209
|
function calculateConfidence2(observationCount) {
|
|
@@ -10401,178 +10593,29 @@ var MobiMem = class {
|
|
|
10401
10593
|
close() {
|
|
10402
10594
|
logger8.info("MobiMem closed");
|
|
10403
10595
|
}
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
// src/context/routing-memory.ts
|
|
10407
|
-
var DEFAULT_ROUTING_MEMORY_CONFIG = {
|
|
10408
|
-
minObservations: 5,
|
|
10409
|
-
confidenceThreshold: 0.6,
|
|
10410
|
-
successRateThreshold: 0.7,
|
|
10411
|
-
actionCacheMaxAgeMs: 36e5
|
|
10412
|
-
// 1 hour
|
|
10413
|
-
};
|
|
10414
|
-
var RoutingMemory = class {
|
|
10415
|
-
mobimem;
|
|
10416
|
-
config;
|
|
10417
|
-
logger;
|
|
10418
|
-
// Statistics
|
|
10419
|
-
cacheHits = 0;
|
|
10420
|
-
cacheMisses = 0;
|
|
10421
|
-
recommendationsMade = 0;
|
|
10422
|
-
constructor(config, mobimem) {
|
|
10423
|
-
this.config = { ...DEFAULT_ROUTING_MEMORY_CONFIG, ...config };
|
|
10424
|
-
this.logger = this.config.logger ?? createLogger({ component: "RoutingMemory" });
|
|
10425
|
-
this.mobimem = mobimem ?? new MobiMem();
|
|
10426
|
-
this.logger.info("RoutingMemory initialized", {
|
|
10427
|
-
minObservations: this.config.minObservations,
|
|
10428
|
-
confidenceThreshold: this.config.confidenceThreshold
|
|
10429
|
-
});
|
|
10430
|
-
}
|
|
10431
|
-
storePreference(model, taskType, performance2) {
|
|
10432
|
-
const preferenceKey = `model_preference:${taskType}`;
|
|
10433
|
-
const entityId = `routing:${model}`;
|
|
10434
|
-
const entry = this.mobimem.profile.observe(entityId, "agent", preferenceKey, {
|
|
10435
|
-
model,
|
|
10436
|
-
performance: performance2,
|
|
10437
|
-
updatedAt: getTimeProvider().nowIso()
|
|
10438
|
-
});
|
|
10439
|
-
this.logger.debug("Stored model preference", {
|
|
10440
|
-
model,
|
|
10441
|
-
taskType,
|
|
10442
|
-
confidence: entry.confidence,
|
|
10443
|
-
observations: entry.observationCount
|
|
10444
|
-
});
|
|
10445
|
-
}
|
|
10446
|
-
getPreferences(taskType) {
|
|
10447
|
-
const preferenceKey = `model_preference:${taskType}`;
|
|
10448
|
-
const preferences = [];
|
|
10449
|
-
for (const model of CLI_NAMES) {
|
|
10450
|
-
const entityId = `routing:${model}`;
|
|
10451
|
-
const entry = this.mobimem.profile.getPreference(entityId, preferenceKey);
|
|
10452
|
-
if (entry !== null && entry.observationCount >= this.config.minObservations) {
|
|
10453
|
-
const value = entry.preferenceValue;
|
|
10454
|
-
preferences.push({
|
|
10455
|
-
model: value.model,
|
|
10456
|
-
strength: this.calculateStrength(value.performance),
|
|
10457
|
-
performance: value.performance,
|
|
10458
|
-
confidence: entry.confidence
|
|
10459
|
-
});
|
|
10460
|
-
}
|
|
10461
|
-
}
|
|
10462
|
-
return preferences.sort((a, b) => b.strength - a.strength);
|
|
10463
|
-
}
|
|
10464
|
-
recordExperience(workflow, models, success, metrics2) {
|
|
10465
|
-
const contextSignature = models.join("->");
|
|
10466
|
-
const actionSequence = models.map((model, index) => ({
|
|
10467
|
-
index,
|
|
10468
|
-
actionType: "model_route",
|
|
10469
|
-
parameters: { model },
|
|
10470
|
-
durationMs: Math.floor(metrics2.durationMs / models.length),
|
|
10471
|
-
success
|
|
10472
|
-
}));
|
|
10473
|
-
const outcome = metrics2.qualityScore !== void 0 ? {
|
|
10474
|
-
success,
|
|
10475
|
-
qualityScore: metrics2.qualityScore,
|
|
10476
|
-
totalDurationMs: metrics2.durationMs,
|
|
10477
|
-
tokensUsed: metrics2.tokensUsed
|
|
10478
|
-
} : {
|
|
10479
|
-
success,
|
|
10480
|
-
totalDurationMs: metrics2.durationMs,
|
|
10481
|
-
tokensUsed: metrics2.tokensUsed
|
|
10482
|
-
};
|
|
10483
|
-
this.mobimem.experience.recordExecution(workflow, actionSequence, outcome, contextSignature);
|
|
10484
|
-
this.logger.debug("Recorded routing experience", {
|
|
10485
|
-
workflow,
|
|
10486
|
-
models: models.join("->"),
|
|
10487
|
-
success,
|
|
10488
|
-
durationMs: metrics2.durationMs
|
|
10489
|
-
});
|
|
10490
|
-
}
|
|
10491
|
-
getExperiencePatterns(workflow) {
|
|
10492
|
-
const experiences = this.mobimem.experience.findPatterns(workflow);
|
|
10493
|
-
return experiences.filter((exp) => exp.successRate >= this.config.successRateThreshold).map((exp) => this.mapExperienceToPattern(exp));
|
|
10494
|
-
}
|
|
10495
|
-
cacheAction(action, model, result, durationMs2) {
|
|
10496
|
-
const input = { actionSignature: action, model };
|
|
10497
|
-
this.mobimem.action.cache(input, result, durationMs2);
|
|
10498
|
-
this.logger.debug("Cached action result", { action: action.slice(0, 50), model, durationMs: durationMs2 });
|
|
10499
|
-
}
|
|
10500
|
-
getCachedAction(action) {
|
|
10501
|
-
for (const model of CLI_NAMES) {
|
|
10502
|
-
const input = { actionSignature: action, model };
|
|
10503
|
-
const entry = this.mobimem.action.get(input);
|
|
10504
|
-
if (entry !== null) {
|
|
10505
|
-
this.cacheHits++;
|
|
10506
|
-
const inputData = entry.input;
|
|
10507
|
-
return {
|
|
10508
|
-
action,
|
|
10509
|
-
result: entry.result,
|
|
10510
|
-
model: inputData.model,
|
|
10511
|
-
cachedAt: entry.cachedAt,
|
|
10512
|
-
timeSavedMs: entry.timeSavedMs
|
|
10513
|
-
};
|
|
10514
|
-
}
|
|
10515
|
-
}
|
|
10516
|
-
this.cacheMisses++;
|
|
10517
|
-
return void 0;
|
|
10518
|
-
}
|
|
10519
|
-
getRecommendation(taskType) {
|
|
10520
|
-
const preferences = this.getPreferences(taskType);
|
|
10521
|
-
const top = preferences[0];
|
|
10522
|
-
if (top !== void 0 && top.confidence >= this.config.confidenceThreshold) {
|
|
10523
|
-
this.recommendationsMade++;
|
|
10524
|
-
this.logger.debug("Generated routing recommendation", {
|
|
10525
|
-
taskType,
|
|
10526
|
-
recommended: top.model,
|
|
10527
|
-
confidence: top.confidence,
|
|
10528
|
-
strength: top.strength
|
|
10529
|
-
});
|
|
10530
|
-
return top.model;
|
|
10531
|
-
}
|
|
10532
|
-
return void 0;
|
|
10533
|
-
}
|
|
10534
|
-
getStats() {
|
|
10535
|
-
const mobiStats = this.mobimem.getStats();
|
|
10596
|
+
/** Export MobiMem state for disk persistence (#1782). */
|
|
10597
|
+
exportData() {
|
|
10536
10598
|
return {
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
cacheHits: this.cacheHits,
|
|
10540
|
-
cacheMisses: this.cacheMisses,
|
|
10541
|
-
recommendationsMade: this.recommendationsMade
|
|
10599
|
+
stats: this.getStats(),
|
|
10600
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10542
10601
|
};
|
|
10543
10602
|
}
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
const normalizedTokens = 1 - Math.min(performance2.avgTokens / 1e5, 1);
|
|
10557
|
-
return performance2.avgQuality * qualityWeight + performance2.successRate * successWeight + normalizedLatency * speedWeight + normalizedTokens * efficiencyWeight;
|
|
10558
|
-
}
|
|
10559
|
-
/**
|
|
10560
|
-
* Map MobiMem experience entry to routing pattern.
|
|
10561
|
-
*/
|
|
10562
|
-
mapExperienceToPattern(exp) {
|
|
10563
|
-
const models = exp.actionSequence.filter((step) => step.actionType === "model_route").map((step) => step.parameters.model);
|
|
10564
|
-
const avgDuration = exp.outcome.totalDurationMs;
|
|
10565
|
-
return {
|
|
10566
|
-
workflow: exp.taskType,
|
|
10567
|
-
modelSequence: models,
|
|
10568
|
-
successRate: exp.successRate,
|
|
10569
|
-
avgDurationMs: avgDuration,
|
|
10570
|
-
usageCount: exp.attemptCount
|
|
10571
|
-
};
|
|
10603
|
+
/** Save MobiMem state to disk (#1782). */
|
|
10604
|
+
async save(filePath) {
|
|
10605
|
+
try {
|
|
10606
|
+
const fs2 = await import("fs/promises");
|
|
10607
|
+
const path2 = await import("path");
|
|
10608
|
+
await fs2.mkdir(path2.dirname(filePath), { recursive: true });
|
|
10609
|
+
const data = JSON.stringify(this.exportData(), null, 2);
|
|
10610
|
+
await fs2.writeFile(filePath, data, "utf-8");
|
|
10611
|
+
logger8.debug("MobiMem state saved", { path: filePath });
|
|
10612
|
+
} catch (error) {
|
|
10613
|
+
logger8.warn("Failed to save MobiMem state", { error: String(error) });
|
|
10614
|
+
}
|
|
10572
10615
|
}
|
|
10573
10616
|
};
|
|
10574
|
-
function
|
|
10575
|
-
return new
|
|
10617
|
+
function createMobiMem(config) {
|
|
10618
|
+
return new MobiMem(config);
|
|
10576
10619
|
}
|
|
10577
10620
|
|
|
10578
10621
|
export {
|
|
@@ -10659,7 +10702,9 @@ export {
|
|
|
10659
10702
|
PreferenceRouter,
|
|
10660
10703
|
createPreferenceRouter,
|
|
10661
10704
|
DEFAULT_ZERO_ROUTER_CONFIG,
|
|
10705
|
+
DEFAULT_MOBIMEM_CONFIG,
|
|
10662
10706
|
MobiMem,
|
|
10707
|
+
createMobiMem,
|
|
10663
10708
|
DEFAULT_ROUTING_MEMORY_CONFIG,
|
|
10664
10709
|
RoutingMemory,
|
|
10665
10710
|
createRoutingMemory,
|
|
@@ -10738,4 +10783,4 @@ export {
|
|
|
10738
10783
|
ParseError,
|
|
10739
10784
|
OrchestratorError
|
|
10740
10785
|
};
|
|
10741
|
-
//# sourceMappingURL=chunk-
|
|
10786
|
+
//# sourceMappingURL=chunk-HSOPD265.js.map
|