@yugenlab/vaayu 0.1.1 → 0.1.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/chunks/{chunk-L7JICQBW.js → chunk-2ARPXEDC.js} +5 -3
- package/chunks/{chunk-IIET2K6D.js → chunk-5Z2BKSFF.js} +81 -603
- package/chunks/{chunk-URGEODS5.js → chunk-DQMAQ2VL.js} +4 -4
- package/chunks/{chunk-JZU37VQ5.js → chunk-F35MWELH.js} +6 -4
- package/chunks/chunk-F4T7POKM.js +545 -0
- package/chunks/{chunk-H76V36OF.js → chunk-FPNQLJLD.js} +4 -4
- package/chunks/{chunk-KDRROLVN.js → chunk-NBXCXQ3H.js} +2 -2
- package/chunks/{chunk-YSU3BWV6.js → chunk-OWBBY5XP.js} +2 -2
- package/chunks/{chunk-S4TBVCL2.js → chunk-SLA2OIMG.js} +5 -3
- package/chunks/chunk-UQLPHNGH.js +123 -0
- package/chunks/{chunk-ITIVYGUG.js → chunk-UW6E7IC4.js} +6 -4
- package/chunks/{chunk-HAPVUJ6A.js → chunk-XRHUKKBC.js} +9 -7
- package/chunks/{chunk-U6OLJ36B.js → chunk-YJRXLRTE.js} +21 -122
- package/chunks/{consolidation-indexer-TOTTDZXW.js → consolidation-indexer-A46RJU4R.js} +6 -5
- package/chunks/{day-consolidation-NKO63HZQ.js → day-consolidation-GQ2FDCR2.js} +2 -2
- package/chunks/{graphrag-ZI2FSU7S.js → graphrag-6YZ5YPLK.js} +4 -3
- package/chunks/{hierarchical-temporal-search-ZD46UMKR.js → hierarchical-temporal-search-VA4D3SON.js} +2 -2
- package/chunks/{hybrid-search-ZVLZVGFS.js → hybrid-search-6XMUT66S.js} +6 -5
- package/chunks/periodic-consolidation-N5MR77ZN.js +11 -0
- package/chunks/{recall-GMVHWQWW.js → recall-THTI6ZO2.js} +5 -4
- package/chunks/{search-7HZETVMZ.js → search-V7DJ3VNL.js} +5 -4
- package/chunks/{session-store-XKPGKXUS.js → session-store-GRKGTMHI.js} +4 -3
- package/chunks/{src-QAXOD5SB.js → src-54LTTDTH.js} +18 -14
- package/chunks/vasana-engine-Z4RXW2SB.js +10 -0
- package/gateway.js +18 -16
- package/package.json +1 -1
- package/chunks/periodic-consolidation-BPKOZDGB.js +0 -10
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
RecallEngine,
|
|
4
4
|
STREAM_ORDER,
|
|
5
5
|
StreamManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-F35MWELH.js";
|
|
7
7
|
import {
|
|
8
8
|
cosineSimilarity,
|
|
9
9
|
estimateTokens
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
listSessions,
|
|
14
14
|
loadSession,
|
|
15
15
|
saveSession
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-2ARPXEDC.js";
|
|
17
17
|
import {
|
|
18
18
|
DatabaseManager
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-UQLPHNGH.js";
|
|
20
20
|
import {
|
|
21
21
|
SessionError,
|
|
22
22
|
getChitraguptaHome
|
|
@@ -3743,7 +3743,7 @@ function stripFrontmatter(content) {
|
|
|
3743
3743
|
return fmMatch ? content.slice(fmMatch[0].length) : content;
|
|
3744
3744
|
}
|
|
3745
3745
|
|
|
3746
|
-
// ../chitragupta/packages/smriti/src/
|
|
3746
|
+
// ../chitragupta/packages/smriti/src/svapna-consolidation.ts
|
|
3747
3747
|
var FNV_OFFSET2 = 2166136261;
|
|
3748
3748
|
var FNV_PRIME2 = 16777619;
|
|
3749
3749
|
function fnv1a3(input) {
|
|
@@ -3755,543 +3755,6 @@ function fnv1a3(input) {
|
|
|
3755
3755
|
return hash.toString(16).padStart(8, "0");
|
|
3756
3756
|
}
|
|
3757
3757
|
var DEFAULT_CONFIG4 = {
|
|
3758
|
-
lambda: 50,
|
|
3759
|
-
changePointThreshold: 0.3,
|
|
3760
|
-
stabilityWindow: 5,
|
|
3761
|
-
windowSize: 20,
|
|
3762
|
-
holdoutTrainRatio: 0.7,
|
|
3763
|
-
accuracyThreshold: 0.6,
|
|
3764
|
-
decayHalfLifeMs: 30 * 864e5,
|
|
3765
|
-
promotionMinProjects: 3,
|
|
3766
|
-
maxRunLength: 200,
|
|
3767
|
-
priorMu: 0,
|
|
3768
|
-
priorKappa: 1,
|
|
3769
|
-
priorAlpha: 1,
|
|
3770
|
-
anomalyRevertWindow: 3,
|
|
3771
|
-
anomalyConfirmRatio: 0.5
|
|
3772
|
-
};
|
|
3773
|
-
var HARD_CEILINGS = {
|
|
3774
|
-
windowSize: 500,
|
|
3775
|
-
maxRunLength: 2e3,
|
|
3776
|
-
stabilityWindow: 100
|
|
3777
|
-
};
|
|
3778
|
-
function logsumexp2(xs) {
|
|
3779
|
-
if (xs.length === 0) return -Infinity;
|
|
3780
|
-
const m = Math.max(...xs);
|
|
3781
|
-
if (m === -Infinity) return -Infinity;
|
|
3782
|
-
let s = 0;
|
|
3783
|
-
for (let i = 0; i < xs.length; i++) s += Math.exp(xs[i] - m);
|
|
3784
|
-
return m + Math.log(s);
|
|
3785
|
-
}
|
|
3786
|
-
function lgamma(z) {
|
|
3787
|
-
const c = [
|
|
3788
|
-
0.9999999999998099,
|
|
3789
|
-
676.5203681218851,
|
|
3790
|
-
-1259.1392167224028,
|
|
3791
|
-
771.3234287776531,
|
|
3792
|
-
-176.6150291621406,
|
|
3793
|
-
12.507343278686905,
|
|
3794
|
-
-0.13857109526572012,
|
|
3795
|
-
9984369578019572e-21,
|
|
3796
|
-
15056327351493116e-23
|
|
3797
|
-
];
|
|
3798
|
-
if (z < 0.5) return Math.log(Math.PI / Math.sin(Math.PI * z)) - lgamma(1 - z);
|
|
3799
|
-
z -= 1;
|
|
3800
|
-
let x = c[0];
|
|
3801
|
-
for (let i = 1; i < 9; i++) x += c[i] / (z + i);
|
|
3802
|
-
const t = z + 7.5;
|
|
3803
|
-
return 0.5 * Math.log(2 * Math.PI) + (z + 0.5) * Math.log(t) - t + Math.log(x);
|
|
3804
|
-
}
|
|
3805
|
-
function logStudentT(x, nu, mu, sigma) {
|
|
3806
|
-
const safeSigma = sigma > 1e-15 ? sigma : 1e-15;
|
|
3807
|
-
const z = (x - mu) / safeSigma;
|
|
3808
|
-
return lgamma((nu + 1) / 2) - lgamma(nu / 2) - 0.5 * Math.log(nu * Math.PI * safeSigma * safeSigma) - (nu + 1) / 2 * Math.log(1 + z * z / nu);
|
|
3809
|
-
}
|
|
3810
|
-
var VasanaEngine = class {
|
|
3811
|
-
cfg;
|
|
3812
|
-
states = /* @__PURE__ */ new Map();
|
|
3813
|
-
obs = /* @__PURE__ */ new Map();
|
|
3814
|
-
cache = /* @__PURE__ */ new Map();
|
|
3815
|
-
constructor(config) {
|
|
3816
|
-
const merged = { ...DEFAULT_CONFIG4, ...config };
|
|
3817
|
-
for (const [k, ceil] of Object.entries(HARD_CEILINGS)) {
|
|
3818
|
-
const key = k;
|
|
3819
|
-
if (typeof merged[key] === "number" && typeof ceil === "number")
|
|
3820
|
-
merged[key] = Math.min(merged[key], ceil);
|
|
3821
|
-
}
|
|
3822
|
-
this.cfg = merged;
|
|
3823
|
-
}
|
|
3824
|
-
// ── Core API ─────────────────────────────────────────────────────────
|
|
3825
|
-
/** Observe a samskara: extract features and update BOCPD state per dimension. */
|
|
3826
|
-
observe(samskara) {
|
|
3827
|
-
for (const [feat, val] of this.extractFeatures(samskara)) {
|
|
3828
|
-
if (!this.states.has(feat)) this.states.set(feat, this.initState());
|
|
3829
|
-
const buf = this.obs.get(feat) ?? [];
|
|
3830
|
-
buf.push(val);
|
|
3831
|
-
if (buf.length > this.cfg.windowSize) buf.splice(0, buf.length - this.cfg.windowSize);
|
|
3832
|
-
this.obs.set(feat, buf);
|
|
3833
|
-
this.updateBOCPD(feat, val);
|
|
3834
|
-
}
|
|
3835
|
-
}
|
|
3836
|
-
/** Run crystallization: stability check, holdout validation, vasana upsert. */
|
|
3837
|
-
crystallize(project) {
|
|
3838
|
-
const now = Date.now();
|
|
3839
|
-
const res = { created: [], reinforced: [], pending: [], changePoints: [], anomalies: [], timestamp: now };
|
|
3840
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3841
|
-
const rows = db.prepare(
|
|
3842
|
-
`SELECT id, session_id, pattern_type, pattern_content, observation_count,
|
|
3843
|
-
confidence, pramana_type, project, created_at, updated_at
|
|
3844
|
-
FROM samskaras WHERE project = ? OR project IS NULL
|
|
3845
|
-
ORDER BY updated_at DESC LIMIT ?`
|
|
3846
|
-
).all(project, this.cfg.windowSize * 10);
|
|
3847
|
-
for (const [key, ids] of this.clusterSamskaras(rows)) {
|
|
3848
|
-
const feat = `cluster:${key}`;
|
|
3849
|
-
const st = this.states.get(feat);
|
|
3850
|
-
if (!st) {
|
|
3851
|
-
res.pending.push(key);
|
|
3852
|
-
continue;
|
|
3853
|
-
}
|
|
3854
|
-
const deviation = this.classifyDeviation(st);
|
|
3855
|
-
if (deviation === "change-point") {
|
|
3856
|
-
st.stableCount = 0;
|
|
3857
|
-
res.changePoints.push(key);
|
|
3858
|
-
continue;
|
|
3859
|
-
}
|
|
3860
|
-
if (deviation === "anomaly") {
|
|
3861
|
-
res.anomalies.push(key);
|
|
3862
|
-
continue;
|
|
3863
|
-
}
|
|
3864
|
-
st.stableCount++;
|
|
3865
|
-
if (st.stableCount < this.cfg.stabilityWindow) {
|
|
3866
|
-
res.pending.push(key);
|
|
3867
|
-
continue;
|
|
3868
|
-
}
|
|
3869
|
-
const o = this.obs.get(feat) ?? [];
|
|
3870
|
-
if (o.length < 4) {
|
|
3871
|
-
res.pending.push(key);
|
|
3872
|
-
continue;
|
|
3873
|
-
}
|
|
3874
|
-
const acc = this.holdoutValidation(o);
|
|
3875
|
-
if (acc < this.cfg.accuracyThreshold) {
|
|
3876
|
-
res.pending.push(key);
|
|
3877
|
-
continue;
|
|
3878
|
-
}
|
|
3879
|
-
const stability = this.stabilityScore(st);
|
|
3880
|
-
const valence = this.assignValence(rows.filter((r) => ids.has(r.id)));
|
|
3881
|
-
const vid = fnv1a3(key + ":" + project);
|
|
3882
|
-
const existing = this.loadVasana(vid);
|
|
3883
|
-
if (existing) {
|
|
3884
|
-
existing.strength = Math.min(1, existing.strength + 0.1);
|
|
3885
|
-
existing.stability = stability;
|
|
3886
|
-
existing.reinforcementCount++;
|
|
3887
|
-
existing.lastActivated = now;
|
|
3888
|
-
existing.predictiveAccuracy = acc;
|
|
3889
|
-
existing.updatedAt = now;
|
|
3890
|
-
this.saveVasana(existing);
|
|
3891
|
-
res.reinforced.push(existing);
|
|
3892
|
-
} else {
|
|
3893
|
-
const rep = rows.find((r) => ids.has(r.id));
|
|
3894
|
-
const v = {
|
|
3895
|
-
id: vid,
|
|
3896
|
-
tendency: key.replace(/:/g, "-"),
|
|
3897
|
-
description: rep?.pattern_content ?? key,
|
|
3898
|
-
strength: 0.5 + acc * 0.3,
|
|
3899
|
-
stability,
|
|
3900
|
-
valence,
|
|
3901
|
-
sourceSamskaras: [...ids],
|
|
3902
|
-
reinforcementCount: 1,
|
|
3903
|
-
lastActivated: now,
|
|
3904
|
-
predictiveAccuracy: acc,
|
|
3905
|
-
project,
|
|
3906
|
-
createdAt: now,
|
|
3907
|
-
updatedAt: now
|
|
3908
|
-
};
|
|
3909
|
-
this.saveVasana(v);
|
|
3910
|
-
res.created.push(v);
|
|
3911
|
-
}
|
|
3912
|
-
}
|
|
3913
|
-
return res;
|
|
3914
|
-
}
|
|
3915
|
-
/** Reinforce with diminishing returns: delta = 0.1 / (1 + ln(1 + count)). */
|
|
3916
|
-
reinforce(vasanaId) {
|
|
3917
|
-
const v = this.loadVasana(vasanaId);
|
|
3918
|
-
if (!v) return;
|
|
3919
|
-
v.strength = Math.min(1, v.strength + 0.1 / (1 + Math.log(1 + v.reinforcementCount)));
|
|
3920
|
-
v.reinforcementCount++;
|
|
3921
|
-
v.lastActivated = v.updatedAt = Date.now();
|
|
3922
|
-
this.saveVasana(v);
|
|
3923
|
-
}
|
|
3924
|
-
/** Weaken by fixed decrement. */
|
|
3925
|
-
weaken(vasanaId) {
|
|
3926
|
-
const v = this.loadVasana(vasanaId);
|
|
3927
|
-
if (!v) return;
|
|
3928
|
-
v.strength = Math.max(0, v.strength - 0.15);
|
|
3929
|
-
v.updatedAt = Date.now();
|
|
3930
|
-
this.saveVasana(v);
|
|
3931
|
-
}
|
|
3932
|
-
/** Get vasanas for a project (includes global), sorted by strength desc. */
|
|
3933
|
-
getVasanas(project, topK = 20) {
|
|
3934
|
-
const rows = DatabaseManager.instance().get("agent").prepare(
|
|
3935
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
3936
|
-
project,created_at,updated_at,last_activated,activation_count
|
|
3937
|
-
FROM vasanas WHERE project=? OR project IS NULL OR project='__global__'
|
|
3938
|
-
ORDER BY strength DESC LIMIT ?`
|
|
3939
|
-
).all(project, topK);
|
|
3940
|
-
return rows.map((r) => this.toVasana(r));
|
|
3941
|
-
}
|
|
3942
|
-
/** Promote project vasanas to global when found in >= promotionMinProjects. */
|
|
3943
|
-
promoteToGlobal() {
|
|
3944
|
-
const now = Date.now();
|
|
3945
|
-
const res = { promoted: [], projectSources: {}, timestamp: now };
|
|
3946
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3947
|
-
const rows = db.prepare(
|
|
3948
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
3949
|
-
project,created_at,updated_at,last_activated,activation_count
|
|
3950
|
-
FROM vasanas WHERE project IS NOT NULL AND project!='__global__' AND strength>=0.4
|
|
3951
|
-
ORDER BY name`
|
|
3952
|
-
).all();
|
|
3953
|
-
const byName = /* @__PURE__ */ new Map();
|
|
3954
|
-
for (const r of rows) {
|
|
3955
|
-
const k = r.name.toLowerCase();
|
|
3956
|
-
byName.set(k, [...byName.get(k) ?? [], r]);
|
|
3957
|
-
}
|
|
3958
|
-
for (const [tendency, group] of byName) {
|
|
3959
|
-
const projects = new Set(group.map((r) => r.project));
|
|
3960
|
-
if (projects.size < this.cfg.promotionMinProjects) continue;
|
|
3961
|
-
if (db.prepare(`SELECT 1 FROM vasanas WHERE name=? AND (project IS NULL OR project='__global__')`).get(tendency)) continue;
|
|
3962
|
-
const allSrc = [];
|
|
3963
|
-
for (const r of group) allSrc.push(...jsonArr(r.source_samskaras));
|
|
3964
|
-
const votes = { positive: 0, negative: 0, neutral: 0 };
|
|
3965
|
-
for (const r of group) votes[r.valence]++;
|
|
3966
|
-
const valence = ["positive", "negative", "neutral"].reduce((a, b) => votes[a] >= votes[b] ? a : b);
|
|
3967
|
-
const gv = {
|
|
3968
|
-
id: fnv1a3(tendency + ":__global__"),
|
|
3969
|
-
tendency,
|
|
3970
|
-
description: group[0].description,
|
|
3971
|
-
strength: group.reduce((s, r) => s + r.strength, 0) / group.length,
|
|
3972
|
-
stability: Math.max(...group.map((r) => r.stability)),
|
|
3973
|
-
valence,
|
|
3974
|
-
sourceSamskaras: [...new Set(allSrc)],
|
|
3975
|
-
reinforcementCount: group.reduce((s, r) => s + r.activation_count, 0),
|
|
3976
|
-
lastActivated: now,
|
|
3977
|
-
predictiveAccuracy: Math.max(...group.map((r) => r.stability)),
|
|
3978
|
-
project: "__global__",
|
|
3979
|
-
createdAt: now,
|
|
3980
|
-
updatedAt: now
|
|
3981
|
-
};
|
|
3982
|
-
this.saveVasana(gv);
|
|
3983
|
-
res.promoted.push(gv);
|
|
3984
|
-
res.projectSources[tendency] = [...projects];
|
|
3985
|
-
}
|
|
3986
|
-
return res;
|
|
3987
|
-
}
|
|
3988
|
-
/** Exponential decay: strength *= exp(-ln2 * elapsed / halfLife). Deletes below 0.01. */
|
|
3989
|
-
decay(halfLifeMs) {
|
|
3990
|
-
const hl = halfLifeMs ?? this.cfg.decayHalfLifeMs;
|
|
3991
|
-
const now = Date.now();
|
|
3992
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3993
|
-
const rows = db.prepare(`SELECT id, strength, last_activated FROM vasanas`).all();
|
|
3994
|
-
let deleted = 0;
|
|
3995
|
-
for (const r of rows) {
|
|
3996
|
-
const elapsed = now - (r.last_activated ?? now);
|
|
3997
|
-
if (elapsed <= 0) continue;
|
|
3998
|
-
const s = r.strength * Math.exp(-Math.LN2 * elapsed / hl);
|
|
3999
|
-
if (s < 0.01) {
|
|
4000
|
-
db.prepare(`DELETE FROM vasanas WHERE id=?`).run(r.id);
|
|
4001
|
-
deleted++;
|
|
4002
|
-
} else db.prepare(`UPDATE vasanas SET strength=?,updated_at=? WHERE id=?`).run(s, now, r.id);
|
|
4003
|
-
}
|
|
4004
|
-
return deleted;
|
|
4005
|
-
}
|
|
4006
|
-
/** Persist BOCPD state (run-length distributions + observations) to SQLite. */
|
|
4007
|
-
persist() {
|
|
4008
|
-
const json = JSON.stringify({
|
|
4009
|
-
features: Object.fromEntries(this.states),
|
|
4010
|
-
observations: Object.fromEntries(this.obs)
|
|
4011
|
-
});
|
|
4012
|
-
DatabaseManager.instance().get("agent").prepare(
|
|
4013
|
-
`INSERT OR REPLACE INTO consolidation_rules
|
|
4014
|
-
(id, category, rule_text, confidence, source_sessions, created_at, updated_at, hit_count, project)
|
|
4015
|
-
VALUES ((SELECT id FROM consolidation_rules WHERE category='bocpd_state' AND project='__vasana_engine__'),
|
|
4016
|
-
'bocpd_state',?,1.0,NULL,?,?,1,'__vasana_engine__')`
|
|
4017
|
-
).run(json, Date.now(), Date.now());
|
|
4018
|
-
}
|
|
4019
|
-
/** Restore BOCPD state from SQLite. No-op if nothing persisted. */
|
|
4020
|
-
restore() {
|
|
4021
|
-
const row = DatabaseManager.instance().get("agent").prepare(
|
|
4022
|
-
`SELECT rule_text FROM consolidation_rules
|
|
4023
|
-
WHERE category='bocpd_state' AND project='__vasana_engine__' LIMIT 1`
|
|
4024
|
-
).get();
|
|
4025
|
-
if (!row) return;
|
|
4026
|
-
try {
|
|
4027
|
-
const s = JSON.parse(row.rule_text);
|
|
4028
|
-
this.states = new Map(Object.entries(s.features));
|
|
4029
|
-
this.obs = new Map(Object.entries(s.observations).map(([k, v]) => [k, Array.isArray(v) ? v : []]));
|
|
4030
|
-
} catch (err) {
|
|
4031
|
-
process.stderr.write(`[vasana-engine] restore() failed to parse BOCPD state: ${err instanceof Error ? err.message : err}
|
|
4032
|
-
`);
|
|
4033
|
-
this.states.clear();
|
|
4034
|
-
this.obs.clear();
|
|
4035
|
-
}
|
|
4036
|
-
}
|
|
4037
|
-
// ── BOCPD Core (Adams & MacKay 2007) ─────────────────────────────────
|
|
4038
|
-
initState() {
|
|
4039
|
-
return {
|
|
4040
|
-
logR: [0],
|
|
4041
|
-
// P(r=0) = 1
|
|
4042
|
-
stats: [{
|
|
4043
|
-
mu: this.cfg.priorMu,
|
|
4044
|
-
kappa: this.cfg.priorKappa,
|
|
4045
|
-
alpha: this.cfg.priorAlpha,
|
|
4046
|
-
beta: this.cfg.priorAlpha
|
|
4047
|
-
}],
|
|
4048
|
-
stableCount: 0,
|
|
4049
|
-
totalObs: 0,
|
|
4050
|
-
recentCpProbs: []
|
|
4051
|
-
};
|
|
4052
|
-
}
|
|
4053
|
-
/**
|
|
4054
|
-
* Online BOCPD update for one observation on one feature dimension.
|
|
4055
|
-
*
|
|
4056
|
-
* 1. Predictive P(x_t | r) via Student-t with Normal-Gamma sufficient stats
|
|
4057
|
-
* 2. Growth: P(r_t=r+1) = P(x|r) * P(r) * (1-H)
|
|
4058
|
-
* 3. Change-point: P(r_t=0) = sum_r P(x|r) * P(r) * H
|
|
4059
|
-
* 4. Normalize, update sufficient stats, prune low-probability tails
|
|
4060
|
-
*/
|
|
4061
|
-
updateBOCPD(feat, x) {
|
|
4062
|
-
const st = this.states.get(feat);
|
|
4063
|
-
const logH = -Math.log(this.cfg.lambda);
|
|
4064
|
-
const log1H = Math.log(1 - 1 / this.cfg.lambda);
|
|
4065
|
-
const n = st.logR.length;
|
|
4066
|
-
const lpp = new Array(n);
|
|
4067
|
-
for (let r = 0; r < n; r++) {
|
|
4068
|
-
const s = st.stats[r];
|
|
4069
|
-
lpp[r] = logStudentT(x, 2 * s.alpha, s.mu, Math.sqrt(s.beta * (s.kappa + 1) / (s.alpha * s.kappa)));
|
|
4070
|
-
}
|
|
4071
|
-
const cpTerms = new Array(n);
|
|
4072
|
-
const newLR = new Array(n + 1);
|
|
4073
|
-
for (let r = 0; r < n; r++) {
|
|
4074
|
-
newLR[r + 1] = lpp[r] + st.logR[r] + log1H;
|
|
4075
|
-
cpTerms[r] = lpp[r] + st.logR[r] + logH;
|
|
4076
|
-
}
|
|
4077
|
-
newLR[0] = logsumexp2(cpTerms);
|
|
4078
|
-
const logZ = logsumexp2(newLR);
|
|
4079
|
-
for (let i = 0; i <= n; i++) newLR[i] -= logZ;
|
|
4080
|
-
const newS = new Array(n + 1);
|
|
4081
|
-
newS[0] = {
|
|
4082
|
-
mu: this.cfg.priorMu,
|
|
4083
|
-
kappa: this.cfg.priorKappa,
|
|
4084
|
-
alpha: this.cfg.priorAlpha,
|
|
4085
|
-
beta: this.cfg.priorAlpha
|
|
4086
|
-
};
|
|
4087
|
-
for (let r = 0; r < n; r++) {
|
|
4088
|
-
const p = st.stats[r];
|
|
4089
|
-
const k = p.kappa + 1;
|
|
4090
|
-
const dx = x - p.mu;
|
|
4091
|
-
newS[r + 1] = {
|
|
4092
|
-
mu: (p.kappa * p.mu + x) / k,
|
|
4093
|
-
kappa: k,
|
|
4094
|
-
alpha: p.alpha + 0.5,
|
|
4095
|
-
beta: p.beta + 0.5 * p.kappa * dx * dx / k
|
|
4096
|
-
};
|
|
4097
|
-
}
|
|
4098
|
-
if (newLR.length > this.cfg.maxRunLength) {
|
|
4099
|
-
const idx = newLR.map((lp, i) => ({ lp, i })).sort((a, b) => b.lp - a.lp);
|
|
4100
|
-
const keep = new Set(idx.slice(0, this.cfg.maxRunLength).map((e) => e.i));
|
|
4101
|
-
const pR = [], pS = [];
|
|
4102
|
-
for (let i = 0; i <= n; i++) if (keep.has(i)) {
|
|
4103
|
-
pR.push(newLR[i]);
|
|
4104
|
-
pS.push(newS[i]);
|
|
4105
|
-
}
|
|
4106
|
-
const norm = logsumexp2(pR);
|
|
4107
|
-
for (let i = 0; i < pR.length; i++) pR[i] -= norm;
|
|
4108
|
-
st.logR = pR;
|
|
4109
|
-
st.stats = pS;
|
|
4110
|
-
} else {
|
|
4111
|
-
st.logR = newLR;
|
|
4112
|
-
st.stats = newS;
|
|
4113
|
-
}
|
|
4114
|
-
st.totalObs++;
|
|
4115
|
-
const cpProb = st.logR.length > 0 ? Math.exp(st.logR[0]) : 0;
|
|
4116
|
-
if (!st.recentCpProbs) st.recentCpProbs = [];
|
|
4117
|
-
st.recentCpProbs.push(cpProb);
|
|
4118
|
-
if (st.recentCpProbs.length > this.cfg.anomalyRevertWindow) {
|
|
4119
|
-
st.recentCpProbs.shift();
|
|
4120
|
-
}
|
|
4121
|
-
}
|
|
4122
|
-
/**
|
|
4123
|
-
* Classify a deviation as change-point, anomaly, or stable.
|
|
4124
|
-
*
|
|
4125
|
-
* Joint anomaly/change-point discrimination (arxiv 2508.06385):
|
|
4126
|
-
* - If P(r=0) > threshold and persists across the revert window → change-point
|
|
4127
|
-
* - If P(r=0) > threshold but reverts within the window → anomaly (one-off)
|
|
4128
|
-
* - Otherwise → stable
|
|
4129
|
-
*/
|
|
4130
|
-
classifyDeviation(st) {
|
|
4131
|
-
if (st.logR.length === 0) return "stable";
|
|
4132
|
-
const cpProb = Math.exp(st.logR[0]);
|
|
4133
|
-
if (cpProb <= this.cfg.changePointThreshold) return "stable";
|
|
4134
|
-
const recent = st.recentCpProbs ?? [cpProb];
|
|
4135
|
-
const exceedCount = recent.filter((p) => p > this.cfg.changePointThreshold).length;
|
|
4136
|
-
const ratio = exceedCount / Math.max(1, recent.length);
|
|
4137
|
-
if (recent.length >= this.cfg.anomalyRevertWindow && ratio >= this.cfg.anomalyConfirmRatio) {
|
|
4138
|
-
return "change-point";
|
|
4139
|
-
}
|
|
4140
|
-
return "anomaly";
|
|
4141
|
-
}
|
|
4142
|
-
isChangePoint(st) {
|
|
4143
|
-
return this.classifyDeviation(st) === "change-point";
|
|
4144
|
-
}
|
|
4145
|
-
stabilityScore(st) {
|
|
4146
|
-
if (st.logR.length === 0) return 0;
|
|
4147
|
-
return Math.max(0, Math.min(1, 1 - Math.exp(st.logR[0])));
|
|
4148
|
-
}
|
|
4149
|
-
// ── Feature Extraction & Validation ──────────────────────────────────
|
|
4150
|
-
extractFeatures(s) {
|
|
4151
|
-
const f = /* @__PURE__ */ new Map();
|
|
4152
|
-
const tMap = {
|
|
4153
|
-
"tool-sequence": 0.2,
|
|
4154
|
-
preference: 0.4,
|
|
4155
|
-
decision: 0.6,
|
|
4156
|
-
correction: 0.8,
|
|
4157
|
-
convention: 1
|
|
4158
|
-
};
|
|
4159
|
-
f.set(`type:${s.patternType}`, tMap[s.patternType] ?? 0.5);
|
|
4160
|
-
f.set("confidence", s.confidence);
|
|
4161
|
-
f.set("log_obs", Math.min(1, Math.log(1 + s.observationCount) / Math.log(101)));
|
|
4162
|
-
const ch = parseInt(fnv1a3(s.patternContent), 16);
|
|
4163
|
-
f.set(`cluster:${s.patternType}:${fnv1a3(s.patternContent)}`, ch / 4294967295);
|
|
4164
|
-
return f;
|
|
4165
|
-
}
|
|
4166
|
-
/** 70/30 holdout: fraction of test points within 1.5 sigma of train mean. */
|
|
4167
|
-
holdoutValidation(obs) {
|
|
4168
|
-
if (obs.length < 4) return 0;
|
|
4169
|
-
const si = Math.floor(obs.length * this.cfg.holdoutTrainRatio);
|
|
4170
|
-
const train = obs.slice(0, si), test = obs.slice(si);
|
|
4171
|
-
if (!train.length || !test.length) return 0;
|
|
4172
|
-
const mu = train.reduce((a, b) => a + b, 0) / train.length;
|
|
4173
|
-
const std = Math.sqrt(train.reduce((a, v) => a + (v - mu) ** 2, 0) / train.length + 1e-10);
|
|
4174
|
-
let ok = 0;
|
|
4175
|
-
for (const v of test) if (Math.abs(v - mu) <= 1.5 * std) ok++;
|
|
4176
|
-
return ok / test.length;
|
|
4177
|
-
}
|
|
4178
|
-
assignValence(rows) {
|
|
4179
|
-
let pos = 0, neg = 0;
|
|
4180
|
-
for (const r of rows) {
|
|
4181
|
-
if (r.pattern_type === "correction") neg += r.confidence;
|
|
4182
|
-
else if (r.pattern_type !== "tool-sequence" || r.confidence > 0.6)
|
|
4183
|
-
pos += r.confidence * (r.pattern_type === "tool-sequence" ? 0.5 : 1);
|
|
4184
|
-
}
|
|
4185
|
-
const tot = pos + neg;
|
|
4186
|
-
if (tot < 0.1) return "neutral";
|
|
4187
|
-
return pos / tot > 0.6 ? "positive" : neg / tot > 0.6 ? "negative" : "neutral";
|
|
4188
|
-
}
|
|
4189
|
-
clusterSamskaras(rows) {
|
|
4190
|
-
const m = /* @__PURE__ */ new Map();
|
|
4191
|
-
for (const r of rows) {
|
|
4192
|
-
const k = `${r.pattern_type}:${fnv1a3(r.pattern_content.toLowerCase().trim().replace(/\s+/g, " "))}`;
|
|
4193
|
-
const s = m.get(k) ?? /* @__PURE__ */ new Set();
|
|
4194
|
-
s.add(r.id);
|
|
4195
|
-
m.set(k, s);
|
|
4196
|
-
}
|
|
4197
|
-
return m;
|
|
4198
|
-
}
|
|
4199
|
-
// ── SQLite Helpers ───────────────────────────────────────────────────
|
|
4200
|
-
// Schema mapping: Vasana.tendency→name, sourceSamskaras→source_samskaras(JSON),
|
|
4201
|
-
// reinforcementCount→activation_count, lastActivated→last_activated
|
|
4202
|
-
saveVasana(v) {
|
|
4203
|
-
const db = DatabaseManager.instance().get("agent");
|
|
4204
|
-
const existing = db.prepare(
|
|
4205
|
-
`SELECT id FROM vasanas WHERE name=? AND (project=? OR (project IS NULL AND ?='__global__'))`
|
|
4206
|
-
).get(v.tendency, v.project, v.project);
|
|
4207
|
-
if (existing) {
|
|
4208
|
-
db.prepare(
|
|
4209
|
-
`UPDATE vasanas SET description=?,valence=?,strength=?,stability=?,
|
|
4210
|
-
source_samskaras=?,updated_at=?,last_activated=?,activation_count=? WHERE id=?`
|
|
4211
|
-
).run(
|
|
4212
|
-
v.description,
|
|
4213
|
-
v.valence,
|
|
4214
|
-
v.strength,
|
|
4215
|
-
v.stability,
|
|
4216
|
-
JSON.stringify(v.sourceSamskaras),
|
|
4217
|
-
v.updatedAt,
|
|
4218
|
-
v.lastActivated,
|
|
4219
|
-
v.reinforcementCount,
|
|
4220
|
-
existing.id
|
|
4221
|
-
);
|
|
4222
|
-
} else {
|
|
4223
|
-
db.prepare(
|
|
4224
|
-
`INSERT INTO vasanas (name,description,valence,strength,stability,source_samskaras,
|
|
4225
|
-
project,created_at,updated_at,last_activated,activation_count) VALUES (?,?,?,?,?,?,?,?,?,?,?)`
|
|
4226
|
-
).run(
|
|
4227
|
-
v.tendency,
|
|
4228
|
-
v.description,
|
|
4229
|
-
v.valence,
|
|
4230
|
-
v.strength,
|
|
4231
|
-
v.stability,
|
|
4232
|
-
JSON.stringify(v.sourceSamskaras),
|
|
4233
|
-
v.project === "__global__" ? null : v.project,
|
|
4234
|
-
v.createdAt,
|
|
4235
|
-
v.updatedAt,
|
|
4236
|
-
v.lastActivated,
|
|
4237
|
-
v.reinforcementCount
|
|
4238
|
-
);
|
|
4239
|
-
}
|
|
4240
|
-
this.cache.set(v.id, v);
|
|
4241
|
-
}
|
|
4242
|
-
loadVasana(vid) {
|
|
4243
|
-
if (this.cache.has(vid)) return this.cache.get(vid);
|
|
4244
|
-
const rows = DatabaseManager.instance().get("agent").prepare(
|
|
4245
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
4246
|
-
project,created_at,updated_at,last_activated,activation_count FROM vasanas`
|
|
4247
|
-
).all();
|
|
4248
|
-
for (const r of rows) {
|
|
4249
|
-
const v = this.toVasana(r);
|
|
4250
|
-
this.cache.set(v.id, v);
|
|
4251
|
-
}
|
|
4252
|
-
return this.cache.get(vid) ?? null;
|
|
4253
|
-
}
|
|
4254
|
-
toVasana(r) {
|
|
4255
|
-
const proj = r.project ?? "__global__";
|
|
4256
|
-
return {
|
|
4257
|
-
id: fnv1a3(r.name + ":" + proj),
|
|
4258
|
-
tendency: r.name,
|
|
4259
|
-
description: r.description,
|
|
4260
|
-
strength: r.strength,
|
|
4261
|
-
stability: r.stability,
|
|
4262
|
-
valence: r.valence,
|
|
4263
|
-
sourceSamskaras: jsonArr(r.source_samskaras),
|
|
4264
|
-
reinforcementCount: r.activation_count,
|
|
4265
|
-
lastActivated: r.last_activated ?? r.updated_at,
|
|
4266
|
-
predictiveAccuracy: r.stability,
|
|
4267
|
-
project: proj,
|
|
4268
|
-
createdAt: r.created_at,
|
|
4269
|
-
updatedAt: r.updated_at
|
|
4270
|
-
};
|
|
4271
|
-
}
|
|
4272
|
-
};
|
|
4273
|
-
function jsonArr(s) {
|
|
4274
|
-
if (!s) return [];
|
|
4275
|
-
try {
|
|
4276
|
-
const p = JSON.parse(s);
|
|
4277
|
-
return Array.isArray(p) ? p : [];
|
|
4278
|
-
} catch {
|
|
4279
|
-
return [];
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4282
|
-
|
|
4283
|
-
// ../chitragupta/packages/smriti/src/svapna-consolidation.ts
|
|
4284
|
-
var FNV_OFFSET3 = 2166136261;
|
|
4285
|
-
var FNV_PRIME3 = 16777619;
|
|
4286
|
-
function fnv1a4(input) {
|
|
4287
|
-
let hash = FNV_OFFSET3;
|
|
4288
|
-
for (let i = 0; i < input.length; i++) {
|
|
4289
|
-
hash ^= input.charCodeAt(i);
|
|
4290
|
-
hash = Math.imul(hash, FNV_PRIME3) >>> 0;
|
|
4291
|
-
}
|
|
4292
|
-
return hash.toString(16).padStart(8, "0");
|
|
4293
|
-
}
|
|
4294
|
-
var DEFAULT_CONFIG5 = {
|
|
4295
3758
|
maxSessionsPerCycle: 50,
|
|
4296
3759
|
surpriseThreshold: 0.7,
|
|
4297
3760
|
minPatternFrequency: 3,
|
|
@@ -4317,10 +3780,10 @@ function buildToolFingerprint(toolNames2) {
|
|
|
4317
3780
|
const fingerprint = /* @__PURE__ */ new Set();
|
|
4318
3781
|
if (toolNames2.length === 0) return fingerprint;
|
|
4319
3782
|
for (const name of toolNames2) {
|
|
4320
|
-
fingerprint.add(
|
|
3783
|
+
fingerprint.add(fnv1a3(`u:${name}`));
|
|
4321
3784
|
}
|
|
4322
3785
|
for (let i = 0; i < toolNames2.length - 1; i++) {
|
|
4323
|
-
fingerprint.add(
|
|
3786
|
+
fingerprint.add(fnv1a3(`b:${toolNames2[i]}:${toolNames2[i + 1]}`));
|
|
4324
3787
|
}
|
|
4325
3788
|
return fingerprint;
|
|
4326
3789
|
}
|
|
@@ -4412,7 +3875,7 @@ var SvapnaConsolidation = class {
|
|
|
4412
3875
|
* @param db - Optional DatabaseManager instance (uses singleton if omitted).
|
|
4413
3876
|
*/
|
|
4414
3877
|
constructor(config, db) {
|
|
4415
|
-
this.config = { ...
|
|
3878
|
+
this.config = { ...DEFAULT_CONFIG4, ...config };
|
|
4416
3879
|
this.db = db ?? DatabaseManager.instance();
|
|
4417
3880
|
this.cycleId = `svapna-${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
4418
3881
|
}
|
|
@@ -4737,7 +4200,7 @@ var SvapnaConsolidation = class {
|
|
|
4737
4200
|
for (const cluster of clusters) {
|
|
4738
4201
|
if (cluster.sessionIds.size < 2) continue;
|
|
4739
4202
|
const tendency = this.slugify(cluster.representative);
|
|
4740
|
-
const vasanaId =
|
|
4203
|
+
const vasanaId = fnv1a3(`${tendency}:${this.config.project}`);
|
|
4741
4204
|
const existing = agentDb.prepare("SELECT id, strength, activation_count FROM vasanas WHERE name = ? AND (project = ? OR project IS NULL)").get(tendency, this.config.project);
|
|
4742
4205
|
if (existing) {
|
|
4743
4206
|
const newStrength = Math.min(1, existing.strength + 0.1);
|
|
@@ -4916,7 +4379,7 @@ var SvapnaConsolidation = class {
|
|
|
4916
4379
|
});
|
|
4917
4380
|
}
|
|
4918
4381
|
const vidhiName = this.slugify(ngramKey.replace(/ -> /g, "-then-"));
|
|
4919
|
-
const vidhiId =
|
|
4382
|
+
const vidhiId = fnv1a3(`${vidhiName}:${this.config.project}`);
|
|
4920
4383
|
const existing = agentDb.prepare("SELECT id FROM vidhis WHERE id = ?").get(vidhiId);
|
|
4921
4384
|
if (existing) continue;
|
|
4922
4385
|
const vidhi = {
|
|
@@ -5221,8 +4684,8 @@ var SvapnaConsolidation = class {
|
|
|
5221
4684
|
};
|
|
5222
4685
|
|
|
5223
4686
|
// ../chitragupta/packages/smriti/src/vidhi-engine.ts
|
|
5224
|
-
var
|
|
5225
|
-
var
|
|
4687
|
+
var FNV_OFFSET3 = 2166136261;
|
|
4688
|
+
var FNV_PRIME3 = 16777619;
|
|
5226
4689
|
var ACTION_VERBS = /* @__PURE__ */ new Set([
|
|
5227
4690
|
"add",
|
|
5228
4691
|
"create",
|
|
@@ -5288,24 +4751,24 @@ var ACTION_VERBS = /* @__PURE__ */ new Set([
|
|
|
5288
4751
|
"scaffold",
|
|
5289
4752
|
"bootstrap"
|
|
5290
4753
|
]);
|
|
5291
|
-
var
|
|
4754
|
+
var DEFAULT_CONFIG5 = {
|
|
5292
4755
|
minSessions: 3,
|
|
5293
4756
|
minSuccessRate: 0.8,
|
|
5294
4757
|
minSequenceLength: 2,
|
|
5295
4758
|
maxSequenceLength: 5
|
|
5296
4759
|
};
|
|
5297
|
-
function
|
|
5298
|
-
let hash =
|
|
4760
|
+
function fnv1a4(str) {
|
|
4761
|
+
let hash = FNV_OFFSET3;
|
|
5299
4762
|
for (let i = 0; i < str.length; i++) {
|
|
5300
4763
|
hash ^= str.charCodeAt(i);
|
|
5301
|
-
hash = hash *
|
|
4764
|
+
hash = hash * FNV_PRIME3 >>> 0;
|
|
5302
4765
|
}
|
|
5303
4766
|
return hash.toString(16).padStart(8, "0");
|
|
5304
4767
|
}
|
|
5305
4768
|
var VidhiEngine = class {
|
|
5306
4769
|
_config;
|
|
5307
4770
|
constructor(config) {
|
|
5308
|
-
this._config = { ...
|
|
4771
|
+
this._config = { ...DEFAULT_CONFIG5, ...config };
|
|
5309
4772
|
}
|
|
5310
4773
|
// ─── Public API ───────────────────────────────────────────────────
|
|
5311
4774
|
/**
|
|
@@ -5598,7 +5061,7 @@ var VidhiEngine = class {
|
|
|
5598
5061
|
_buildVidhi(agg) {
|
|
5599
5062
|
const now = Date.now();
|
|
5600
5063
|
const name = this._generateName(agg.toolNames);
|
|
5601
|
-
const id =
|
|
5064
|
+
const id = fnv1a4(name + "|" + this._config.project);
|
|
5602
5065
|
const parameterSchema = {};
|
|
5603
5066
|
const steps = [];
|
|
5604
5067
|
for (let stepIdx = 0; stepIdx < agg.toolNames.length; stepIdx++) {
|
|
@@ -6056,13 +5519,13 @@ var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
|
6056
5519
|
"over",
|
|
6057
5520
|
"after"
|
|
6058
5521
|
]);
|
|
6059
|
-
var
|
|
6060
|
-
var
|
|
6061
|
-
function
|
|
6062
|
-
let hash =
|
|
5522
|
+
var FNV_OFFSET4 = 2166136261;
|
|
5523
|
+
var FNV_PRIME4 = 16777619;
|
|
5524
|
+
function fnv1a5(input) {
|
|
5525
|
+
let hash = FNV_OFFSET4;
|
|
6063
5526
|
for (let i = 0; i < input.length; i++) {
|
|
6064
5527
|
hash ^= input.charCodeAt(i);
|
|
6065
|
-
hash = Math.imul(hash,
|
|
5528
|
+
hash = Math.imul(hash, FNV_PRIME4) >>> 0;
|
|
6066
5529
|
}
|
|
6067
5530
|
return hash.toString(16).padStart(8, "0");
|
|
6068
5531
|
}
|
|
@@ -6079,7 +5542,7 @@ function jaccardSimilarity2(a, b) {
|
|
|
6079
5542
|
return union === 0 ? 0 : intersection / union;
|
|
6080
5543
|
}
|
|
6081
5544
|
var DAY_MS = 864e5;
|
|
6082
|
-
var
|
|
5545
|
+
var DEFAULT_CONFIG6 = {
|
|
6083
5546
|
decayHalfLife: 7 * DAY_MS,
|
|
6084
5547
|
// 7 days
|
|
6085
5548
|
minStrength: 0.01,
|
|
@@ -6091,7 +5554,7 @@ var DEFAULT_CONFIG7 = {
|
|
|
6091
5554
|
diminishingAlpha: 0.3,
|
|
6092
5555
|
frequencyDecayBeta: 0.5
|
|
6093
5556
|
};
|
|
6094
|
-
var
|
|
5557
|
+
var HARD_CEILINGS = {
|
|
6095
5558
|
maxTraces: 5e4,
|
|
6096
5559
|
minDecayHalfLife: 36e5,
|
|
6097
5560
|
// 1 hour minimum
|
|
@@ -6105,16 +5568,16 @@ var AkashaField = class {
|
|
|
6105
5568
|
reinforcedBy = /* @__PURE__ */ new Map();
|
|
6106
5569
|
constructor(config) {
|
|
6107
5570
|
this.config = {
|
|
6108
|
-
...
|
|
5571
|
+
...DEFAULT_CONFIG6,
|
|
6109
5572
|
...config,
|
|
6110
5573
|
// Clamp to hard ceilings
|
|
6111
5574
|
maxTraces: Math.min(
|
|
6112
|
-
config?.maxTraces ??
|
|
6113
|
-
|
|
5575
|
+
config?.maxTraces ?? DEFAULT_CONFIG6.maxTraces,
|
|
5576
|
+
HARD_CEILINGS.maxTraces
|
|
6114
5577
|
),
|
|
6115
5578
|
decayHalfLife: Math.max(
|
|
6116
|
-
config?.decayHalfLife ??
|
|
6117
|
-
|
|
5579
|
+
config?.decayHalfLife ?? DEFAULT_CONFIG6.decayHalfLife,
|
|
5580
|
+
HARD_CEILINGS.minDecayHalfLife
|
|
6118
5581
|
)
|
|
6119
5582
|
};
|
|
6120
5583
|
}
|
|
@@ -6134,8 +5597,8 @@ var AkashaField = class {
|
|
|
6134
5597
|
* @returns The created StigmergicTrace.
|
|
6135
5598
|
*/
|
|
6136
5599
|
leave(agentId, type, topic, content, metadata) {
|
|
6137
|
-
const truncatedContent = content.length >
|
|
6138
|
-
const id = `aks-${
|
|
5600
|
+
const truncatedContent = content.length > HARD_CEILINGS.maxContentSize ? content.slice(0, HARD_CEILINGS.maxContentSize) : content;
|
|
5601
|
+
const id = `aks-${fnv1a5(agentId + ":" + type + ":" + topic + ":" + truncatedContent)}`;
|
|
6139
5602
|
const now = Date.now();
|
|
6140
5603
|
const trace = {
|
|
6141
5604
|
id,
|
|
@@ -6589,7 +6052,7 @@ var DEFAULT_SCALE_WEIGHTS = {
|
|
|
6589
6052
|
quarter: 0.08,
|
|
6590
6053
|
year: 0.07
|
|
6591
6054
|
};
|
|
6592
|
-
var
|
|
6055
|
+
var HARD_CEILINGS2 = {
|
|
6593
6056
|
/** Minimum half-life: 1 second. Anything faster is meaningless. */
|
|
6594
6057
|
minDecayRate: 1e3,
|
|
6595
6058
|
/** Maximum half-life: 10 years. Beyond this, nothing decays. */
|
|
@@ -6636,8 +6099,8 @@ var KalaChakra = class {
|
|
|
6636
6099
|
if (config.decayRates[scale] !== void 0) {
|
|
6637
6100
|
this._decayRates[scale] = clamp(
|
|
6638
6101
|
config.decayRates[scale],
|
|
6639
|
-
|
|
6640
|
-
|
|
6102
|
+
HARD_CEILINGS2.minDecayRate,
|
|
6103
|
+
HARD_CEILINGS2.maxDecayRate
|
|
6641
6104
|
);
|
|
6642
6105
|
}
|
|
6643
6106
|
}
|
|
@@ -6647,8 +6110,8 @@ var KalaChakra = class {
|
|
|
6647
6110
|
if (config.scaleWeights[scale] !== void 0) {
|
|
6648
6111
|
this._scaleWeights[scale] = clamp(
|
|
6649
6112
|
config.scaleWeights[scale],
|
|
6650
|
-
|
|
6651
|
-
|
|
6113
|
+
HARD_CEILINGS2.minWeight,
|
|
6114
|
+
HARD_CEILINGS2.maxWeight
|
|
6652
6115
|
);
|
|
6653
6116
|
}
|
|
6654
6117
|
}
|
|
@@ -6890,8 +6353,8 @@ var KalaChakra = class {
|
|
|
6890
6353
|
if (typeof data.decayRates[scale] === "number") {
|
|
6891
6354
|
this._decayRates[scale] = clamp(
|
|
6892
6355
|
data.decayRates[scale],
|
|
6893
|
-
|
|
6894
|
-
|
|
6356
|
+
HARD_CEILINGS2.minDecayRate,
|
|
6357
|
+
HARD_CEILINGS2.maxDecayRate
|
|
6895
6358
|
);
|
|
6896
6359
|
}
|
|
6897
6360
|
}
|
|
@@ -6901,8 +6364,8 @@ var KalaChakra = class {
|
|
|
6901
6364
|
if (typeof data.scaleWeights[scale] === "number") {
|
|
6902
6365
|
this._scaleWeights[scale] = clamp(
|
|
6903
6366
|
data.scaleWeights[scale],
|
|
6904
|
-
|
|
6905
|
-
|
|
6367
|
+
HARD_CEILINGS2.minWeight,
|
|
6368
|
+
HARD_CEILINGS2.maxWeight
|
|
6906
6369
|
);
|
|
6907
6370
|
}
|
|
6908
6371
|
}
|
|
@@ -6943,13 +6406,13 @@ function mondayOfISOWeek(isoYear, isoWeekNum) {
|
|
|
6943
6406
|
}
|
|
6944
6407
|
|
|
6945
6408
|
// ../chitragupta/packages/smriti/src/pancha-vritti.ts
|
|
6946
|
-
var
|
|
6947
|
-
var
|
|
6948
|
-
function
|
|
6949
|
-
let hash =
|
|
6409
|
+
var FNV_OFFSET5 = 2166136261;
|
|
6410
|
+
var FNV_PRIME5 = 16777619;
|
|
6411
|
+
function fnv1a6(input) {
|
|
6412
|
+
let hash = FNV_OFFSET5;
|
|
6950
6413
|
for (let i = 0; i < input.length; i++) {
|
|
6951
6414
|
hash ^= input.charCodeAt(i);
|
|
6952
|
-
hash = Math.imul(hash,
|
|
6415
|
+
hash = Math.imul(hash, FNV_PRIME5);
|
|
6953
6416
|
}
|
|
6954
6417
|
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
6955
6418
|
}
|
|
@@ -6967,13 +6430,13 @@ var VRITTI_CONFIDENCE_WEIGHTS = {
|
|
|
6967
6430
|
vikalpa: 0.5,
|
|
6968
6431
|
viparyaya: 0.3
|
|
6969
6432
|
};
|
|
6970
|
-
var
|
|
6433
|
+
var DEFAULT_CONFIG7 = {
|
|
6971
6434
|
maxClassifications: 5e3,
|
|
6972
6435
|
minConfidence: 0.4,
|
|
6973
6436
|
snippetMaxLength: 200,
|
|
6974
6437
|
confidenceWeights: { ...VRITTI_CONFIDENCE_WEIGHTS }
|
|
6975
6438
|
};
|
|
6976
|
-
var
|
|
6439
|
+
var HARD_CEILINGS3 = {
|
|
6977
6440
|
maxClassifications: 5e4,
|
|
6978
6441
|
snippetMaxLength: 1e3
|
|
6979
6442
|
};
|
|
@@ -7101,23 +6564,23 @@ var PanchaVritti = class {
|
|
|
7101
6564
|
totalReclassified = 0;
|
|
7102
6565
|
constructor(config) {
|
|
7103
6566
|
const merged = {
|
|
7104
|
-
...
|
|
6567
|
+
...DEFAULT_CONFIG7,
|
|
7105
6568
|
...config,
|
|
7106
6569
|
confidenceWeights: {
|
|
7107
|
-
...
|
|
6570
|
+
...DEFAULT_CONFIG7.confidenceWeights,
|
|
7108
6571
|
...config?.confidenceWeights
|
|
7109
6572
|
}
|
|
7110
6573
|
};
|
|
7111
|
-
if (typeof
|
|
6574
|
+
if (typeof HARD_CEILINGS3.maxClassifications === "number") {
|
|
7112
6575
|
merged.maxClassifications = Math.min(
|
|
7113
6576
|
merged.maxClassifications,
|
|
7114
|
-
|
|
6577
|
+
HARD_CEILINGS3.maxClassifications
|
|
7115
6578
|
);
|
|
7116
6579
|
}
|
|
7117
|
-
if (typeof
|
|
6580
|
+
if (typeof HARD_CEILINGS3.snippetMaxLength === "number") {
|
|
7118
6581
|
merged.snippetMaxLength = Math.min(
|
|
7119
6582
|
merged.snippetMaxLength,
|
|
7120
|
-
|
|
6583
|
+
HARD_CEILINGS3.snippetMaxLength
|
|
7121
6584
|
);
|
|
7122
6585
|
}
|
|
7123
6586
|
this.cfg = merged;
|
|
@@ -7151,7 +6614,7 @@ var PanchaVritti = class {
|
|
|
7151
6614
|
prePatterns.push("context:error-flag");
|
|
7152
6615
|
}
|
|
7153
6616
|
if (content.trim().length === 0) {
|
|
7154
|
-
const id2 =
|
|
6617
|
+
const id2 = fnv1a6("nidra:" + now.toString());
|
|
7155
6618
|
const classification2 = {
|
|
7156
6619
|
id: id2,
|
|
7157
6620
|
type: "nidra",
|
|
@@ -7227,7 +6690,7 @@ var PanchaVritti = class {
|
|
|
7227
6690
|
if (winnerConfidence < this.cfg.minConfidence) {
|
|
7228
6691
|
winnerPatterns.push("low-confidence");
|
|
7229
6692
|
}
|
|
7230
|
-
const id =
|
|
6693
|
+
const id = fnv1a6(winnerType + ":" + content.slice(0, 100) + ":" + now.toString());
|
|
7231
6694
|
const classification = {
|
|
7232
6695
|
id,
|
|
7233
6696
|
type: winnerType,
|
|
@@ -7469,16 +6932,16 @@ async function recall(query, options) {
|
|
|
7469
6932
|
}
|
|
7470
6933
|
async function searchHybrid(query, project, limit) {
|
|
7471
6934
|
try {
|
|
7472
|
-
const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-
|
|
6935
|
+
const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-6XMUT66S.js");
|
|
7473
6936
|
let recallEngine = null;
|
|
7474
6937
|
let graphEngine = null;
|
|
7475
6938
|
try {
|
|
7476
|
-
const { RecallEngine: RecallEngine2 } = await import("./recall-
|
|
6939
|
+
const { RecallEngine: RecallEngine2 } = await import("./recall-THTI6ZO2.js");
|
|
7477
6940
|
recallEngine = new RecallEngine2();
|
|
7478
6941
|
} catch {
|
|
7479
6942
|
}
|
|
7480
6943
|
try {
|
|
7481
|
-
const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-
|
|
6944
|
+
const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-6YZ5YPLK.js");
|
|
7482
6945
|
graphEngine = new GraphRAGEngine2();
|
|
7483
6946
|
} catch {
|
|
7484
6947
|
}
|
|
@@ -7516,8 +6979,8 @@ async function searchHybrid(query, project, limit) {
|
|
|
7516
6979
|
}
|
|
7517
6980
|
async function searchTurns(query, project) {
|
|
7518
6981
|
try {
|
|
7519
|
-
const { searchSessions: searchSessions2 } = await import("./search-
|
|
7520
|
-
const { loadSession: loadSession2 } = await import("./session-store-
|
|
6982
|
+
const { searchSessions: searchSessions2 } = await import("./search-V7DJ3VNL.js");
|
|
6983
|
+
const { loadSession: loadSession2 } = await import("./session-store-GRKGTMHI.js");
|
|
7521
6984
|
const metas = searchSessions2(query, project);
|
|
7522
6985
|
const results = [];
|
|
7523
6986
|
for (const meta of metas.slice(0, 10)) {
|
|
@@ -7563,7 +7026,7 @@ async function searchTurns(query, project) {
|
|
|
7563
7026
|
}
|
|
7564
7027
|
async function searchMemoryLayer(query) {
|
|
7565
7028
|
try {
|
|
7566
|
-
const { searchMemory: searchMemory2 } = await import("./search-
|
|
7029
|
+
const { searchMemory: searchMemory2 } = await import("./search-V7DJ3VNL.js");
|
|
7567
7030
|
const results = searchMemory2(query);
|
|
7568
7031
|
return results.slice(0, 5).map((r) => ({
|
|
7569
7032
|
score: Math.min((r.relevance ?? 0.5) + 0.1, 1),
|
|
@@ -7577,7 +7040,7 @@ async function searchMemoryLayer(query) {
|
|
|
7577
7040
|
}
|
|
7578
7041
|
async function searchDayFileLayer(query, limit) {
|
|
7579
7042
|
try {
|
|
7580
|
-
const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-
|
|
7043
|
+
const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-VA4D3SON.js");
|
|
7581
7044
|
const results = await hierarchicalTemporalSearch2(query, { limit });
|
|
7582
7045
|
if (results.length > 0) {
|
|
7583
7046
|
return results.map((r) => ({
|
|
@@ -7592,7 +7055,7 @@ async function searchDayFileLayer(query, limit) {
|
|
|
7592
7055
|
} catch {
|
|
7593
7056
|
}
|
|
7594
7057
|
try {
|
|
7595
|
-
const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-
|
|
7058
|
+
const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-GQ2FDCR2.js");
|
|
7596
7059
|
const results = searchDayFiles2(query, { limit });
|
|
7597
7060
|
return results.map((r) => ({
|
|
7598
7061
|
score: 0.5,
|
|
@@ -7640,8 +7103,20 @@ async function loadProviderContext(project, options) {
|
|
|
7640
7103
|
} catch {
|
|
7641
7104
|
}
|
|
7642
7105
|
}
|
|
7106
|
+
let vasanaContext = "";
|
|
7643
7107
|
try {
|
|
7644
|
-
const {
|
|
7108
|
+
const { VasanaEngine: VasanaEngine2 } = await import("./vasana-engine-Z4RXW2SB.js");
|
|
7109
|
+
const engine = new VasanaEngine2();
|
|
7110
|
+
const vasanas = engine.getVasanas(project ?? "__global__", 5);
|
|
7111
|
+
if (vasanas.length > 0) {
|
|
7112
|
+
vasanaContext = vasanas.map(
|
|
7113
|
+
(v) => `- ${v.tendency} (strength: ${(v.strength * 100).toFixed(0)}%): ${v.description}`
|
|
7114
|
+
).join("\n");
|
|
7115
|
+
}
|
|
7116
|
+
} catch {
|
|
7117
|
+
}
|
|
7118
|
+
try {
|
|
7119
|
+
const { listSessions: listSessions2, loadSession: loadSession2 } = await import("./session-store-GRKGTMHI.js");
|
|
7645
7120
|
const sessions = project ? listSessions2(project).slice(0, recentLimit) : listSessions2().slice(0, recentLimit);
|
|
7646
7121
|
const summaries = [];
|
|
7647
7122
|
for (const meta of sessions) {
|
|
@@ -7675,6 +7150,10 @@ async function loadProviderContext(project, options) {
|
|
|
7675
7150
|
parts.push("## Recent Sessions\n" + recentContext.trim());
|
|
7676
7151
|
itemCount += recentContext.split("\n").filter((l) => l.trim()).length;
|
|
7677
7152
|
}
|
|
7153
|
+
if (vasanaContext.trim()) {
|
|
7154
|
+
parts.push("## Behavioral Patterns\n" + vasanaContext.trim());
|
|
7155
|
+
itemCount += vasanaContext.split("\n").filter((l) => l.trim()).length;
|
|
7156
|
+
}
|
|
7678
7157
|
const assembled = parts.join("\n\n");
|
|
7679
7158
|
return {
|
|
7680
7159
|
globalFacts: globalFacts.trim(),
|
|
@@ -7713,7 +7192,6 @@ export {
|
|
|
7713
7192
|
detectMemoryIntent,
|
|
7714
7193
|
detectCategory,
|
|
7715
7194
|
IdentityContext,
|
|
7716
|
-
VasanaEngine,
|
|
7717
7195
|
SvapnaConsolidation,
|
|
7718
7196
|
VidhiEngine,
|
|
7719
7197
|
AkashaField,
|
|
@@ -7725,4 +7203,4 @@ export {
|
|
|
7725
7203
|
recall,
|
|
7726
7204
|
loadProviderContext
|
|
7727
7205
|
};
|
|
7728
|
-
//# sourceMappingURL=chunk-
|
|
7206
|
+
//# sourceMappingURL=chunk-5Z2BKSFF.js.map
|