capman 0.5.4 → 0.5.5
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/CHANGELOG.md +46 -0
- package/CODEBASE.md +111 -66
- package/README.md +45 -4
- package/bin/lib/cmd-generate.js +44 -28
- package/dist/cjs/cache.d.ts.map +1 -1
- package/dist/cjs/cache.js +22 -5
- package/dist/cjs/cache.js.map +1 -1
- package/dist/cjs/engine.d.ts.map +1 -1
- package/dist/cjs/engine.js +39 -14
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/generator.d.ts.map +1 -1
- package/dist/cjs/generator.js +7 -1
- package/dist/cjs/generator.js.map +1 -1
- package/dist/cjs/learning.d.ts.map +1 -1
- package/dist/cjs/learning.js +39 -12
- package/dist/cjs/learning.js.map +1 -1
- package/dist/cjs/matcher.d.ts +14 -9
- package/dist/cjs/matcher.d.ts.map +1 -1
- package/dist/cjs/matcher.js +71 -22
- package/dist/cjs/matcher.js.map +1 -1
- package/dist/cjs/parser.d.ts.map +1 -1
- package/dist/cjs/parser.js +15 -8
- package/dist/cjs/parser.js.map +1 -1
- package/dist/cjs/resolver.d.ts +1 -0
- package/dist/cjs/resolver.d.ts.map +1 -1
- package/dist/cjs/resolver.js +16 -5
- package/dist/cjs/resolver.js.map +1 -1
- package/dist/cjs/schema.d.ts +18 -18
- package/dist/cjs/schema.js +1 -1
- package/dist/cjs/schema.js.map +1 -1
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/cache.js +22 -5
- package/dist/esm/engine.js +41 -16
- package/dist/esm/generator.js +7 -1
- package/dist/esm/learning.js +39 -12
- package/dist/esm/matcher.d.ts +14 -9
- package/dist/esm/matcher.js +71 -22
- package/dist/esm/parser.js +15 -8
- package/dist/esm/resolver.d.ts +1 -0
- package/dist/esm/resolver.js +16 -6
- package/dist/esm/schema.d.ts +18 -18
- package/dist/esm/schema.js +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/dist/cjs/schema.d.ts
CHANGED
|
@@ -11,19 +11,19 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
11
11
|
name: z.ZodString;
|
|
12
12
|
description: z.ZodString;
|
|
13
13
|
required: z.ZodBoolean;
|
|
14
|
-
source: z.ZodEnum<["user_query", "session"
|
|
14
|
+
source: z.ZodEnum<["user_query", "session"]>;
|
|
15
15
|
default: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
17
|
name: string;
|
|
18
18
|
required: boolean;
|
|
19
19
|
description: string;
|
|
20
|
-
source: "user_query" | "session"
|
|
20
|
+
source: "user_query" | "session";
|
|
21
21
|
default?: string | number | boolean | undefined;
|
|
22
22
|
}, {
|
|
23
23
|
name: string;
|
|
24
24
|
required: boolean;
|
|
25
25
|
description: string;
|
|
26
|
-
source: "user_query" | "session"
|
|
26
|
+
source: "user_query" | "session";
|
|
27
27
|
default?: string | number | boolean | undefined;
|
|
28
28
|
}>, "many">;
|
|
29
29
|
returns: z.ZodArray<z.ZodString, "many">;
|
|
@@ -151,7 +151,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
151
151
|
name: string;
|
|
152
152
|
required: boolean;
|
|
153
153
|
description: string;
|
|
154
|
-
source: "user_query" | "session"
|
|
154
|
+
source: "user_query" | "session";
|
|
155
155
|
default?: string | number | boolean | undefined;
|
|
156
156
|
}[];
|
|
157
157
|
description: string;
|
|
@@ -193,7 +193,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
193
193
|
name: string;
|
|
194
194
|
required: boolean;
|
|
195
195
|
description: string;
|
|
196
|
-
source: "user_query" | "session"
|
|
196
|
+
source: "user_query" | "session";
|
|
197
197
|
default?: string | number | boolean | undefined;
|
|
198
198
|
}[];
|
|
199
199
|
description: string;
|
|
@@ -235,7 +235,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
235
235
|
name: string;
|
|
236
236
|
required: boolean;
|
|
237
237
|
description: string;
|
|
238
|
-
source: "user_query" | "session"
|
|
238
|
+
source: "user_query" | "session";
|
|
239
239
|
default?: string | number | boolean | undefined;
|
|
240
240
|
}[];
|
|
241
241
|
description: string;
|
|
@@ -277,7 +277,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
277
277
|
name: string;
|
|
278
278
|
required: boolean;
|
|
279
279
|
description: string;
|
|
280
|
-
source: "user_query" | "session"
|
|
280
|
+
source: "user_query" | "session";
|
|
281
281
|
default?: string | number | boolean | undefined;
|
|
282
282
|
}[];
|
|
283
283
|
description: string;
|
|
@@ -322,7 +322,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
322
322
|
name: string;
|
|
323
323
|
required: boolean;
|
|
324
324
|
description: string;
|
|
325
|
-
source: "user_query" | "session"
|
|
325
|
+
source: "user_query" | "session";
|
|
326
326
|
default?: string | number | boolean | undefined;
|
|
327
327
|
}[];
|
|
328
328
|
description: string;
|
|
@@ -368,7 +368,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
368
368
|
name: string;
|
|
369
369
|
required: boolean;
|
|
370
370
|
description: string;
|
|
371
|
-
source: "user_query" | "session"
|
|
371
|
+
source: "user_query" | "session";
|
|
372
372
|
default?: string | number | boolean | undefined;
|
|
373
373
|
}[];
|
|
374
374
|
description: string;
|
|
@@ -414,7 +414,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
414
414
|
name: string;
|
|
415
415
|
required: boolean;
|
|
416
416
|
description: string;
|
|
417
|
-
source: "user_query" | "session"
|
|
417
|
+
source: "user_query" | "session";
|
|
418
418
|
default?: string | number | boolean | undefined;
|
|
419
419
|
}[];
|
|
420
420
|
description: string;
|
|
@@ -460,7 +460,7 @@ export declare const CapmanConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
460
460
|
name: string;
|
|
461
461
|
required: boolean;
|
|
462
462
|
description: string;
|
|
463
|
-
source: "user_query" | "session"
|
|
463
|
+
source: "user_query" | "session";
|
|
464
464
|
default?: string | number | boolean | undefined;
|
|
465
465
|
}[];
|
|
466
466
|
description: string;
|
|
@@ -511,19 +511,19 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
511
511
|
name: z.ZodString;
|
|
512
512
|
description: z.ZodString;
|
|
513
513
|
required: z.ZodBoolean;
|
|
514
|
-
source: z.ZodEnum<["user_query", "session"
|
|
514
|
+
source: z.ZodEnum<["user_query", "session"]>;
|
|
515
515
|
default: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
516
516
|
}, "strip", z.ZodTypeAny, {
|
|
517
517
|
name: string;
|
|
518
518
|
required: boolean;
|
|
519
519
|
description: string;
|
|
520
|
-
source: "user_query" | "session"
|
|
520
|
+
source: "user_query" | "session";
|
|
521
521
|
default?: string | number | boolean | undefined;
|
|
522
522
|
}, {
|
|
523
523
|
name: string;
|
|
524
524
|
required: boolean;
|
|
525
525
|
description: string;
|
|
526
|
-
source: "user_query" | "session"
|
|
526
|
+
source: "user_query" | "session";
|
|
527
527
|
default?: string | number | boolean | undefined;
|
|
528
528
|
}>, "many">;
|
|
529
529
|
returns: z.ZodArray<z.ZodString, "many">;
|
|
@@ -651,7 +651,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
651
651
|
name: string;
|
|
652
652
|
required: boolean;
|
|
653
653
|
description: string;
|
|
654
|
-
source: "user_query" | "session"
|
|
654
|
+
source: "user_query" | "session";
|
|
655
655
|
default?: string | number | boolean | undefined;
|
|
656
656
|
}[];
|
|
657
657
|
description: string;
|
|
@@ -693,7 +693,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
693
693
|
name: string;
|
|
694
694
|
required: boolean;
|
|
695
695
|
description: string;
|
|
696
|
-
source: "user_query" | "session"
|
|
696
|
+
source: "user_query" | "session";
|
|
697
697
|
default?: string | number | boolean | undefined;
|
|
698
698
|
}[];
|
|
699
699
|
description: string;
|
|
@@ -739,7 +739,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
739
739
|
name: string;
|
|
740
740
|
required: boolean;
|
|
741
741
|
description: string;
|
|
742
|
-
source: "user_query" | "session"
|
|
742
|
+
source: "user_query" | "session";
|
|
743
743
|
default?: string | number | boolean | undefined;
|
|
744
744
|
}[];
|
|
745
745
|
description: string;
|
|
@@ -786,7 +786,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
786
786
|
name: string;
|
|
787
787
|
required: boolean;
|
|
788
788
|
description: string;
|
|
789
|
-
source: "user_query" | "session"
|
|
789
|
+
source: "user_query" | "session";
|
|
790
790
|
default?: string | number | boolean | undefined;
|
|
791
791
|
}[];
|
|
792
792
|
description: string;
|
package/dist/cjs/schema.js
CHANGED
|
@@ -9,7 +9,7 @@ const CapabilityParamSchema = zod_1.z.object({
|
|
|
9
9
|
name: zod_1.z.string().min(1, 'param name is required'),
|
|
10
10
|
description: zod_1.z.string().min(1, 'param description is required'),
|
|
11
11
|
required: zod_1.z.boolean(),
|
|
12
|
-
source: zod_1.z.enum(['user_query', 'session'
|
|
12
|
+
source: zod_1.z.enum(['user_query', 'session']),
|
|
13
13
|
default: zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]).optional(),
|
|
14
14
|
});
|
|
15
15
|
// ─── Resolver Schemas ─────────────────────────────────────────────────────────
|
package/dist/cjs/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":";;;AA8GA,wCAQC;AAED,4CAQC;AAhID,6BAAuB;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AK,EAAS,MAAM,CAAA;IACpB,OAAO,EAAO,OAAO,CAAA;IACrB,wEAAwE;IACxE,WAAW,EAAG,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAO,MAAM,CAAA;IAClB,OAAO,EAAE;QACP,UAAU,EAAE,UAAU,GAAG,IAAI,CAAA;QAC7B,UAAU,EAAE,MAAM,CAAA;QAClB,MAAM,EAAM,MAAM,CAAA;QAClB,SAAS,EAAG,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,UAAU,EAAI,gBAAgB,EAAE,CAAA;IAChC,YAAY,EAAE;QACZ,YAAY,EAAE,YAAY,GAAG,IAAI,CAAA;QACjC,8EAA8E;QAC9E,MAAM,EAAQ,MAAM,GAAG,IAAI,CAAA;QAC3B,OAAO,EAAO,MAAM,GAAG,IAAI,CAAA;QAC3B,uDAAuD;QACvD,OAAO,EAAO,MAAM,GAAG,IAAI,CAAA;KAC5B,CAAA;IACD,WAAW,EAAG,SAAS,GAAG,KAAK,CAAA;IAC/B,UAAU,EAAI,MAAM,CAAA;CACrB;AAID,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAA"}
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.5.
|
|
1
|
+
export declare const VERSION = "0.5.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/cache.js
CHANGED
|
@@ -3,7 +3,12 @@ import * as path from 'path';
|
|
|
3
3
|
import { logger } from './logger';
|
|
4
4
|
// ─── Normalize query for cache key ────────────────────────────────────────────
|
|
5
5
|
export function normalizeQuery(query) {
|
|
6
|
-
return query
|
|
6
|
+
return query
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.trim()
|
|
9
|
+
.replace(/[^\w\s]/g, '') // strip punctuation — "show orders!" and "show orders" same key
|
|
10
|
+
.replace(/\s+/g, ' ')
|
|
11
|
+
.trim();
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
14
|
* Build a smarter cache key based on matched capability + extracted params.
|
|
@@ -80,7 +85,10 @@ export class FileCache {
|
|
|
80
85
|
}
|
|
81
86
|
load() {
|
|
82
87
|
if (!this.loadPromise) {
|
|
83
|
-
this.loadPromise = this._doLoad()
|
|
88
|
+
this.loadPromise = this._doLoad().catch(err => {
|
|
89
|
+
this.loadPromise = null; // allow retry on next call
|
|
90
|
+
throw err;
|
|
91
|
+
});
|
|
84
92
|
}
|
|
85
93
|
return this.loadPromise;
|
|
86
94
|
}
|
|
@@ -94,7 +102,12 @@ export class FileCache {
|
|
|
94
102
|
// e.g. "Show me articles" and "show me articles" collapse to the same key.
|
|
95
103
|
const normalized = new Map();
|
|
96
104
|
for (const [k, v] of Object.entries(parsed)) {
|
|
97
|
-
|
|
105
|
+
// Structured keys (cap:/query: prefix from buildCacheKey) are already
|
|
106
|
+
// canonical — normalizeQuery strips their colons and equals signs.
|
|
107
|
+
const storeKey = (k.startsWith('cap:') || k.startsWith('query:'))
|
|
108
|
+
? k
|
|
109
|
+
: normalizeQuery(k);
|
|
110
|
+
normalized.set(storeKey, v);
|
|
98
111
|
}
|
|
99
112
|
this.store = normalized;
|
|
100
113
|
logger.debug(`File cache loaded: ${this.store.size} entries`);
|
|
@@ -103,8 +116,12 @@ export class FileCache {
|
|
|
103
116
|
logger.warn(`File cache at ${this.filePath} contained unexpected format — starting fresh`);
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
|
-
catch {
|
|
107
|
-
|
|
119
|
+
catch (err) {
|
|
120
|
+
const code = err.code;
|
|
121
|
+
if (code !== 'ENOENT') {
|
|
122
|
+
logger.warn(`Failed to load file cache from ${this.filePath} (${code ?? 'unknown error'}) — starting fresh`);
|
|
123
|
+
}
|
|
124
|
+
// ENOENT = file doesn't exist yet — expected on first run, no warning needed
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
127
|
save() {
|
package/dist/esm/engine.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { match as _match, matchWithLLM as _matchWithLLM, resolverToIntent, extractParams, STOPWORDS, LLMParseError } from './matcher';
|
|
2
|
-
import { resolve as _resolve } from './resolver';
|
|
2
|
+
import { resolve as _resolve, checkPrivacy } from './resolver';
|
|
3
3
|
import { MemoryLearningStore } from './learning';
|
|
4
4
|
import { logger } from './logger';
|
|
5
|
-
import { MemoryCache, normalizeQuery } from './cache';
|
|
5
|
+
import { MemoryCache, normalizeQuery, buildCacheKey } from './cache';
|
|
6
6
|
import { VERSION } from './version';
|
|
7
7
|
// ─── CapmanEngine ─────────────────────────────────────────────────────────────
|
|
8
8
|
export class CapmanEngine {
|
|
@@ -107,17 +107,20 @@ export class CapmanEngine {
|
|
|
107
107
|
}
|
|
108
108
|
// ── Step 2: Match ────────────────────────────────────────────────────────
|
|
109
109
|
let { matchResult, resolvedVia } = await this._runMatch(query, steps);
|
|
110
|
-
|
|
110
|
+
// Shallow copy with candidates slice — not a reference alias.
|
|
111
|
+
// applyBoostToMatchResult() returns a new object today, but an explicit
|
|
112
|
+
// copy makes the invariant clear and safe against future in-place mutation.
|
|
113
|
+
const preBoostMatchResult = { ...matchResult, candidates: matchResult.candidates.slice() };
|
|
111
114
|
// ── Step 2.5: Apply learning boost ───────────────────────────────────────
|
|
112
|
-
matchResult = await this.applyBoostToMatchResult(query, matchResult);
|
|
115
|
+
matchResult = await this.applyBoostToMatchResult(query, matchResult, resolvedVia);
|
|
113
116
|
// ── Step 3: Privacy check ────────────────────────────────────────────────
|
|
114
117
|
if (matchResult.capability) {
|
|
115
|
-
const
|
|
118
|
+
const privacyError = checkPrivacy(matchResult.capability, this.auth);
|
|
116
119
|
steps.push({
|
|
117
120
|
type: 'privacy_check',
|
|
118
|
-
status: 'pass',
|
|
121
|
+
status: privacyError ? 'fail' : 'pass',
|
|
119
122
|
durationMs: 0,
|
|
120
|
-
detail: `level: ${
|
|
123
|
+
detail: privacyError ?? `level: ${matchResult.capability.privacy.level}`,
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
// ── Step 4: Resolve ──────────────────────────────────────────────────────
|
|
@@ -130,14 +133,17 @@ export class CapmanEngine {
|
|
|
130
133
|
detail: resolution.error ?? `via ${resolution.resolverType}`,
|
|
131
134
|
});
|
|
132
135
|
// ── Step 5: Cache after successful resolution ────────────────────────────
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
136
|
+
// Write under two keys:
|
|
137
|
+
// 1. normalizeQuery — exact phrasing lookup for this query
|
|
138
|
+
// 2. buildCacheKey — semantic key (capability + params) so differently-phrased
|
|
139
|
+
// queries that resolve to the same capability share a cache entry
|
|
137
140
|
if (this.cache && resolution.success && matchResult.capability
|
|
138
141
|
&& matchResult.capability.privacy.level === 'public') {
|
|
139
142
|
const queryKey = normalizeQuery(query);
|
|
143
|
+
const capKey = buildCacheKey(query, matchResult.capability.id, matchResult.extractedParams);
|
|
140
144
|
await this.cache.set(queryKey, matchResult);
|
|
145
|
+
await this.cache.set(capKey, matchResult);
|
|
146
|
+
// capKey always starts with 'cap:' — structurally distinct from queryKey
|
|
141
147
|
}
|
|
142
148
|
// ── Step 6: Build reasoning array ────────────────────────────────────────
|
|
143
149
|
const reasoning = [];
|
|
@@ -243,6 +249,10 @@ export class CapmanEngine {
|
|
|
243
249
|
this.checkManifestVersion(manifest);
|
|
244
250
|
this.manifest = manifest;
|
|
245
251
|
await this.clearCache();
|
|
252
|
+
// Note: LLM rate limiter state (llmCallsThisMinute, llmConsecutiveFails,
|
|
253
|
+
// llmCircuitOpenAt) is intentionally preserved across manifest reloads.
|
|
254
|
+
// The LLM provider has not changed, so circuit breaker state remains valid.
|
|
255
|
+
// If you need a clean rate limiter state, create a new CapmanEngine instance.
|
|
246
256
|
}
|
|
247
257
|
/**
|
|
248
258
|
* Explain what would happen for a query — without executing it.
|
|
@@ -279,8 +289,9 @@ export class CapmanEngine {
|
|
|
279
289
|
}
|
|
280
290
|
let resolvedVia = _resolvedVia;
|
|
281
291
|
// ── Apply learning boost (same as ask()) ─────────────────────────────────
|
|
282
|
-
matchResult = await this.applyBoostToMatchResult(query, matchResult);
|
|
292
|
+
matchResult = await this.applyBoostToMatchResult(query, matchResult, resolvedVia);
|
|
283
293
|
// ── Build candidate explanations ─────────────────────────────────────────
|
|
294
|
+
const qWordSet = new Set(query.toLowerCase().split(/\W+/).filter(Boolean));
|
|
284
295
|
const candidates = matchResult.candidates
|
|
285
296
|
.sort((a, b) => b.score - a.score)
|
|
286
297
|
.map(c => {
|
|
@@ -293,10 +304,9 @@ export class CapmanEngine {
|
|
|
293
304
|
explanation = `Strong match (${c.score}%) — query closely matches examples`;
|
|
294
305
|
}
|
|
295
306
|
else if (c.score >= 50) {
|
|
296
|
-
const qWords = query.toLowerCase().split(/\W+/).filter(Boolean);
|
|
297
307
|
const matchedWords = (cap?.examples ?? [])
|
|
298
308
|
.flatMap(e => e.toLowerCase().split(/\s+/))
|
|
299
|
-
.filter(w =>
|
|
309
|
+
.filter(w => qWordSet.has(w) && w.length > 2);
|
|
300
310
|
const unique = [...new Set(matchedWords)].slice(0, 3);
|
|
301
311
|
explanation = unique.length
|
|
302
312
|
? `Matched keywords: ${unique.join(', ')} (${c.score}%)`
|
|
@@ -442,8 +452,10 @@ export class CapmanEngine {
|
|
|
442
452
|
this.llmCallsThisMinute = 0;
|
|
443
453
|
this.llmWindowStart = now;
|
|
444
454
|
}
|
|
455
|
+
if (this.maxLLMCallsPerMinute === 0) {
|
|
456
|
+
return 'LLM disabled — maxLLMCallsPerMinute is 0';
|
|
457
|
+
}
|
|
445
458
|
if (this.llmCallsThisMinute >= this.maxLLMCallsPerMinute) {
|
|
446
|
-
// Recalculate elapsed after possible window reset above
|
|
447
459
|
const resetIn = Math.ceil((60_000 - (now - this.llmWindowStart)) / 1000);
|
|
448
460
|
return `rate limit reached (${this.maxLLMCallsPerMinute}/min) — resets in ${Math.max(0, resetIn)}s`;
|
|
449
461
|
}
|
|
@@ -462,6 +474,10 @@ export class CapmanEngine {
|
|
|
462
474
|
* Records a failed LLM call — may open the circuit breaker.
|
|
463
475
|
*/
|
|
464
476
|
recordLLMFailure() {
|
|
477
|
+
// Refund the rate-limit slot — the call failed so it shouldn't count
|
|
478
|
+
// against the per-minute quota. Without this, sustained failures
|
|
479
|
+
// exhaust the limit prematurely and silently degrade to keyword-only.
|
|
480
|
+
this.llmCallsThisMinute = Math.max(0, this.llmCallsThisMinute - 1);
|
|
465
481
|
this.llmConsecutiveFails++;
|
|
466
482
|
if (this.llmConsecutiveFails >= this.llmCircuitBreakerThreshold) {
|
|
467
483
|
this.llmCircuitOpenAt = Date.now();
|
|
@@ -490,6 +506,8 @@ export class CapmanEngine {
|
|
|
490
506
|
}
|
|
491
507
|
case 'accurate': {
|
|
492
508
|
if (this.llm) {
|
|
509
|
+
// Rate limiter shared between ask() and explain() — explain() counts
|
|
510
|
+
// against the same quota since it makes real LLM calls.
|
|
493
511
|
const skipReason = this.checkLLMAllowed();
|
|
494
512
|
if (skipReason) {
|
|
495
513
|
logger.warn(`LLM skipped — ${skipReason} — falling back to keyword`);
|
|
@@ -545,6 +563,8 @@ export class CapmanEngine {
|
|
|
545
563
|
matchResult = keywordResult;
|
|
546
564
|
}
|
|
547
565
|
else {
|
|
566
|
+
// Rate limiter shared between ask() and explain() — explain() counts
|
|
567
|
+
// against the same quota since it makes real LLM calls.
|
|
548
568
|
const skipReason = this.checkLLMAllowed();
|
|
549
569
|
if (skipReason) {
|
|
550
570
|
logger.warn(`LLM skipped — ${skipReason}`);
|
|
@@ -590,7 +610,12 @@ export class CapmanEngine {
|
|
|
590
610
|
* Applies learning boost to a MatchResult and returns the updated result.
|
|
591
611
|
* Shared by ask() and explain() to avoid logic divergence.
|
|
592
612
|
*/
|
|
593
|
-
async applyBoostToMatchResult(query, matchResult) {
|
|
613
|
+
async applyBoostToMatchResult(query, matchResult, resolvedVia = 'keyword') {
|
|
614
|
+
// Skip boost when LLM matched with high confidence — learning signal is
|
|
615
|
+
// less reliable than a strong LLM result and could incorrectly override it.
|
|
616
|
+
// Threshold 80% leaves room for boost to help on borderline LLM matches.
|
|
617
|
+
if (resolvedVia === 'llm' && matchResult.confidence > 80)
|
|
618
|
+
return matchResult;
|
|
594
619
|
const hasKeywordSignal = matchResult.candidates.some(c => c.score > 0);
|
|
595
620
|
if (!hasKeywordSignal || matchResult.candidates.length === 0 || !this.learning || this.mode === 'cheap') {
|
|
596
621
|
return matchResult;
|
package/dist/esm/generator.js
CHANGED
|
@@ -73,7 +73,13 @@ export function loadConfig(configPath) {
|
|
|
73
73
|
`Run: node bin/capman.js init to create one.`);
|
|
74
74
|
}
|
|
75
75
|
export function writeManifest(manifest, outputPath = 'manifest.json') {
|
|
76
|
-
const
|
|
76
|
+
const cwd = process.cwd();
|
|
77
|
+
const resolved = path.resolve(cwd, outputPath);
|
|
78
|
+
const allowedPrefix = cwd === '/' ? '/' : cwd + path.sep;
|
|
79
|
+
if (!resolved.startsWith(allowedPrefix)) {
|
|
80
|
+
throw new Error(`writeManifest: output path "${outputPath}" resolves outside the working directory.\n` +
|
|
81
|
+
`Resolved: ${resolved}\nAllowed: ${cwd}`);
|
|
82
|
+
}
|
|
77
83
|
fs.writeFileSync(resolved, JSON.stringify(manifest, null, 2));
|
|
78
84
|
return resolved;
|
|
79
85
|
}
|
package/dist/esm/learning.js
CHANGED
|
@@ -6,12 +6,38 @@ import { STOPWORDS } from './matcher';
|
|
|
6
6
|
// Module-level registry — tracks all active FileLearningStore instances
|
|
7
7
|
// for process exit flushing. Handlers registered once to avoid accumulation.
|
|
8
8
|
const activeStores = new Set();
|
|
9
|
-
|
|
9
|
+
// Module-level handler references — stored so they can be removed
|
|
10
|
+
// when all stores are destroyed. Never call process.exit() in a library.
|
|
11
|
+
let exitHandler = null;
|
|
12
|
+
let sigTermHandler = null;
|
|
13
|
+
let sigIntHandler = null;
|
|
10
14
|
function flushAllStores() {
|
|
11
15
|
for (const store of activeStores) {
|
|
12
16
|
store.flushSync();
|
|
13
17
|
}
|
|
14
18
|
}
|
|
19
|
+
function registerExitHandlers() {
|
|
20
|
+
if (exitHandler)
|
|
21
|
+
return; // already registered
|
|
22
|
+
exitHandler = flushAllStores;
|
|
23
|
+
sigTermHandler = flushAllStores;
|
|
24
|
+
sigIntHandler = flushAllStores;
|
|
25
|
+
process.on('exit', exitHandler);
|
|
26
|
+
process.on('SIGTERM', sigTermHandler);
|
|
27
|
+
process.on('SIGINT', sigIntHandler);
|
|
28
|
+
}
|
|
29
|
+
function unregisterExitHandlers() {
|
|
30
|
+
if (!exitHandler)
|
|
31
|
+
return; // nothing registered
|
|
32
|
+
if (activeStores.size > 0)
|
|
33
|
+
return; // other stores still active
|
|
34
|
+
process.off('exit', exitHandler);
|
|
35
|
+
process.off('SIGTERM', sigTermHandler);
|
|
36
|
+
process.off('SIGINT', sigIntHandler);
|
|
37
|
+
exitHandler = null;
|
|
38
|
+
sigTermHandler = null;
|
|
39
|
+
sigIntHandler = null;
|
|
40
|
+
}
|
|
15
41
|
// ─── Shared computation helpers ───────────────────────────────────────────────
|
|
16
42
|
function computeTopCapabilities(entries, limit) {
|
|
17
43
|
const counts = {};
|
|
@@ -120,12 +146,7 @@ export class FileLearningStore {
|
|
|
120
146
|
this.filePath = resolved;
|
|
121
147
|
logger.info(`FileLearningStore initialized — writing to: ${this.filePath}`);
|
|
122
148
|
activeStores.add(this);
|
|
123
|
-
|
|
124
|
-
exitHandlersRegistered = true;
|
|
125
|
-
process.on('exit', flushAllStores);
|
|
126
|
-
process.on('SIGTERM', () => { flushAllStores(); process.exit(0); });
|
|
127
|
-
process.on('SIGINT', () => { flushAllStores(); process.exit(0); });
|
|
128
|
-
}
|
|
149
|
+
registerExitHandlers();
|
|
129
150
|
}
|
|
130
151
|
flushSync() {
|
|
131
152
|
// Cancel pending timer — prevents scheduleSave firing after sync write
|
|
@@ -160,15 +181,17 @@ export class FileLearningStore {
|
|
|
160
181
|
}
|
|
161
182
|
if (this.dirty) {
|
|
162
183
|
this.dirty = false;
|
|
163
|
-
// Await final flush before removing from registry —
|
|
164
|
-
// ensures data is written before the store becomes unreachable
|
|
165
184
|
await this.save();
|
|
166
185
|
}
|
|
167
186
|
activeStores.delete(this);
|
|
187
|
+
unregisterExitHandlers(); // remove handlers if no stores remain
|
|
168
188
|
}
|
|
169
189
|
load() {
|
|
170
190
|
if (!this.loadPromise) {
|
|
171
|
-
this.loadPromise = this._doLoad()
|
|
191
|
+
this.loadPromise = this._doLoad().catch(err => {
|
|
192
|
+
this.loadPromise = null; // allow retry on next call
|
|
193
|
+
throw err;
|
|
194
|
+
});
|
|
172
195
|
}
|
|
173
196
|
return this.loadPromise;
|
|
174
197
|
}
|
|
@@ -185,8 +208,12 @@ export class FileLearningStore {
|
|
|
185
208
|
logger.warn(`Learning store at ${this.filePath} contained unexpected format — starting fresh`);
|
|
186
209
|
}
|
|
187
210
|
}
|
|
188
|
-
catch {
|
|
189
|
-
|
|
211
|
+
catch (err) {
|
|
212
|
+
const code = err.code;
|
|
213
|
+
if (code !== 'ENOENT') {
|
|
214
|
+
logger.warn(`Failed to load learning store from ${this.filePath} (${code ?? 'unknown error'}) — starting fresh`);
|
|
215
|
+
}
|
|
216
|
+
// ENOENT = file doesn't exist yet — expected on first run, no warning needed
|
|
190
217
|
}
|
|
191
218
|
}
|
|
192
219
|
scheduleSave(urgencyMs = 5_000) {
|
package/dist/esm/matcher.d.ts
CHANGED
|
@@ -6,12 +6,17 @@ export declare const STOPWORDS: Set<string>;
|
|
|
6
6
|
export declare function resolverToIntent(cap: Capability): MatchResult['intent'];
|
|
7
7
|
/**
|
|
8
8
|
* Extracts parameter values from a user query using keyword heuristics.
|
|
9
|
+
*
|
|
9
10
|
* Known limits:
|
|
10
11
|
* - Extracts single tokens only — "jane smith" would extract "jane"
|
|
11
12
|
* - Keyword matching is positional — "articles from authors I follow"
|
|
12
13
|
* may extract "authors" instead of nothing, since "from" is a keyword
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
14
|
+
* - Required param fallback grabs the last meaningful word — "list all
|
|
15
|
+
* recent orders" may extract "orders" even with the denylist extended.
|
|
16
|
+
* For precise extraction of complex queries, use matchWithLLM() which
|
|
17
|
+
* handles param extraction via structured LLM prompt.
|
|
18
|
+
* - To support richer extraction patterns, add a `pattern` field to
|
|
19
|
+
* CapabilityParam in a future version.
|
|
15
20
|
*/
|
|
16
21
|
export declare function extractParams(query: string, cap: Capability): Record<string, string | null>;
|
|
17
22
|
export interface MatchOptions {
|
|
@@ -25,12 +30,12 @@ export interface LLMMatcherOptions {
|
|
|
25
30
|
/**
|
|
26
31
|
* Matches a query to a capability using an LLM.
|
|
27
32
|
*
|
|
28
|
-
* ⚠️ SECURITY NOTE: Capability
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* ⚠️ SECURITY NOTE: Capability fields are sanitized before injection into
|
|
34
|
+
* the LLM prompt (newlines stripped, delimiters neutralized, length capped).
|
|
35
|
+
* However, the current interface passes a single prompt string — it cannot
|
|
36
|
+
* provide true system/user message separation that some LLM APIs support.
|
|
37
|
+
* For maximum injection resistance in high-security deployments, use an LLM
|
|
38
|
+
* wrapper that maps the prompt to a proper system message, keeping user query
|
|
39
|
+
* data in the user turn only.
|
|
35
40
|
*/
|
|
36
41
|
export declare function matchWithLLM(query: string, manifest: Manifest, options: LLMMatcherOptions): Promise<MatchResult>;
|