hebbian 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/hebbian.js +171 -40
- package/dist/bin/hebbian.js.map +1 -1
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/digest.d.ts +5 -0
- package/dist/digest.d.ts.map +1 -1
- package/dist/evolve.d.ts +2 -1
- package/dist/evolve.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -24
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -23,4 +23,10 @@ export declare const SESSION_STATE_DIR = "hippocampus/session_state";
|
|
|
23
23
|
export declare const PROTECTED_REGIONS_CONTRA: string[];
|
|
24
24
|
/** Resolve brain root path from flag, env var, or defaults */
|
|
25
25
|
export declare function resolveBrainRoot(brainFlag?: string): string;
|
|
26
|
+
/** Resolve agent-specific brain path within a multi-brain setup */
|
|
27
|
+
export declare function resolveAgentBrain(brainRoot: string, agentName: string): string;
|
|
28
|
+
/** Resolve shared brain path within a multi-brain setup */
|
|
29
|
+
export declare function resolveSharedBrain(brainRoot: string): string;
|
|
30
|
+
export declare const AGENTS_DIR = "agents";
|
|
31
|
+
export declare const SHARED_DIR = "shared";
|
|
26
32
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,OAAO,2FAQV,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAQtD,CAAC;AAEF,e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;AAC3D,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
package/dist/digest.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export declare function digestTranscript(brainRoot: string, transcriptPath: stri
|
|
|
52
52
|
* Returns detected failures (exit code ≠ 0, is_error = true).
|
|
53
53
|
*/
|
|
54
54
|
export declare function parseToolResults(transcriptPath: string): ToolFailure[];
|
|
55
|
+
/**
|
|
56
|
+
* Detect retry patterns — same error appearing 3+ times in a session.
|
|
57
|
+
* Returns deduplicated failures with retry count.
|
|
58
|
+
*/
|
|
59
|
+
export declare function detectRetryPatterns(failures: ToolFailure[]): ToolFailure[];
|
|
55
60
|
/**
|
|
56
61
|
* Detect a tool failure from a tool_result block.
|
|
57
62
|
* Returns failure info if exit code ≠ 0, null otherwise.
|
package/dist/digest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,UAAU,cAAc;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,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AK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EACxF,aAAa,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,GAC7C,WAAW,GAAG,IAAI,CA8BpB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAiC5E"}
|
package/dist/evolve.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export interface EvolveResult {
|
|
|
12
12
|
skipped: number;
|
|
13
13
|
dryRun: boolean;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
15
|
+
export type EvolveMode = 'default' | 'prune';
|
|
16
|
+
export declare function runEvolve(brainRoot: string, dryRun: boolean, mode?: EvolveMode): Promise<EvolveResult>;
|
|
16
17
|
export declare function buildBrainSummary(brain: Brain): string;
|
|
17
18
|
export declare function buildPrompt(summary: string, episodes: Episode[], outcomeSummary?: string): string;
|
|
18
19
|
export declare function callGemini(prompt: string, apiKey: string): Promise<EvolveAction[]>;
|
package/dist/evolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evolve.d.ts","sourceRoot":"","sources":["../src/evolve.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAYrC,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,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,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CA8BzD;AAID,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,GAAG,YAAY,EAAE,CAwBtF;AAID,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CA8BjF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,13 +24,13 @@ export { processInbox, ensureInbox, appendCorrection } from './inbox';
|
|
|
24
24
|
export type { Correction, InboxResult } from './inbox';
|
|
25
25
|
export { installHooks, uninstallHooks, checkHooks } from './hooks';
|
|
26
26
|
export type { HookStatus } from './hooks';
|
|
27
|
-
export { digestTranscript, extractCorrections, readHookInput, parseToolResults, detectToolFailure } from './digest';
|
|
27
|
+
export { digestTranscript, extractCorrections, readHookInput, parseToolResults, detectToolFailure, detectRetryPatterns } from './digest';
|
|
28
28
|
export type { DigestResult, ExtractedCorrection, ToolFailure } from './digest';
|
|
29
|
-
export { resolveBrainRoot } from './constants';
|
|
29
|
+
export { resolveBrainRoot, resolveAgentBrain, resolveSharedBrain } from './constants';
|
|
30
30
|
export { growCandidate, promoteCandidates, listCandidates, toCandidatePath, fromCandidatePath } from './candidates';
|
|
31
31
|
export type { CandidateInfo, PromoteResult } from './candidates';
|
|
32
32
|
export { runEvolve } from './evolve';
|
|
33
|
-
export type { EvolveAction, EvolveResult } from './evolve';
|
|
33
|
+
export type { EvolveAction, EvolveResult, EvolveMode } from './evolve';
|
|
34
34
|
export { captureSessionStart, detectOutcome, buildOutcomeSummary, classifyOutcome } from './outcome';
|
|
35
35
|
export type { SessionState, OutcomeResult } from './outcome';
|
|
36
36
|
export { contraNeuron } from './fire';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,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,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,14 @@ function resolveBrainRoot(brainFlag) {
|
|
|
65
65
|
if (existsSync(resolve("./brain"))) return resolve("./brain");
|
|
66
66
|
return resolve(process.env.HOME || "~", "hebbian", "brain");
|
|
67
67
|
}
|
|
68
|
+
function resolveAgentBrain(brainRoot, agentName) {
|
|
69
|
+
return resolve(brainRoot, "agents", agentName);
|
|
70
|
+
}
|
|
71
|
+
function resolveSharedBrain(brainRoot) {
|
|
72
|
+
return resolve(brainRoot, "shared");
|
|
73
|
+
}
|
|
74
|
+
var AGENTS_DIR = "agents";
|
|
75
|
+
var SHARED_DIR = "shared";
|
|
68
76
|
|
|
69
77
|
// src/scanner.ts
|
|
70
78
|
import { readdirSync, statSync, readFileSync, existsSync as existsSync2 } from "fs";
|
|
@@ -882,8 +890,8 @@ function computeHash(result) {
|
|
|
882
890
|
}
|
|
883
891
|
|
|
884
892
|
// src/init.ts
|
|
885
|
-
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync7, existsSync as existsSync9, readdirSync as readdirSync6 } from "fs";
|
|
886
|
-
import { join as join10 } from "path";
|
|
893
|
+
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync7, readFileSync as readFileSync3, existsSync as existsSync9, readdirSync as readdirSync6, appendFileSync } from "fs";
|
|
894
|
+
import { join as join10, dirname as dirname2 } from "path";
|
|
887
895
|
var REGION_TEMPLATES = {
|
|
888
896
|
brainstem: {
|
|
889
897
|
description: "Absolute principles. Immutable. Read-only conscience.\nP0 \u2014 highest priority. bomb here halts EVERYTHING.",
|
|
@@ -944,6 +952,7 @@ ${template.description}
|
|
|
944
952
|
}
|
|
945
953
|
}
|
|
946
954
|
mkdirSync4(join10(brainPath, "_agents", "global_inbox"), { recursive: true });
|
|
955
|
+
autoGitignore(brainPath);
|
|
947
956
|
console.log(`\u{1F9E0} Brain initialized at ${brainPath}`);
|
|
948
957
|
console.log(` 7 regions created: ${REGIONS.join(", ")}`);
|
|
949
958
|
console.log("");
|
|
@@ -951,17 +960,41 @@ ${template.description}
|
|
|
951
960
|
console.log(` hebbian grow brainstem/NO_your_rule --brain ${brainPath}`);
|
|
952
961
|
console.log(` hebbian emit claude --brain ${brainPath}`);
|
|
953
962
|
}
|
|
963
|
+
function autoGitignore(brainPath) {
|
|
964
|
+
let dir = dirname2(brainPath);
|
|
965
|
+
for (let i = 0; i < 10; i++) {
|
|
966
|
+
if (existsSync9(join10(dir, ".git"))) {
|
|
967
|
+
const gitignorePath = join10(dir, ".gitignore");
|
|
968
|
+
const brainDirName = brainPath.replace(dir + "/", "") + "/";
|
|
969
|
+
if (existsSync9(gitignorePath)) {
|
|
970
|
+
const content = readFileSync3(gitignorePath, "utf8");
|
|
971
|
+
if (content.includes(brainDirName) || content.includes(brainDirName.replace(/\/$/, ""))) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
appendFileSync(gitignorePath, `
|
|
976
|
+
# hebbian brain (personal learning data)
|
|
977
|
+
${brainDirName}
|
|
978
|
+
`, "utf8");
|
|
979
|
+
console.log(` \u{1F4DD} Added ${brainDirName} to .gitignore`);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const parent = dirname2(dir);
|
|
983
|
+
if (parent === dir) break;
|
|
984
|
+
dir = parent;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
954
987
|
|
|
955
988
|
// src/api.ts
|
|
956
989
|
import { createServer } from "http";
|
|
957
990
|
|
|
958
991
|
// src/inbox.ts
|
|
959
|
-
import { readFileSync as
|
|
992
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync9, existsSync as existsSync12, mkdirSync as mkdirSync7 } from "fs";
|
|
960
993
|
import { join as join13 } from "path";
|
|
961
994
|
|
|
962
995
|
// src/candidates.ts
|
|
963
996
|
import { existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync7, renameSync as renameSync3, rmSync, statSync as statSync3 } from "fs";
|
|
964
|
-
import { join as join11, dirname as
|
|
997
|
+
import { join as join11, dirname as dirname3, relative as relative3 } from "path";
|
|
965
998
|
var CANDIDATE_THRESHOLD = 3;
|
|
966
999
|
var CANDIDATE_DECAY_DAYS = 14;
|
|
967
1000
|
var CANDIDATE_SEGMENT = "_candidates";
|
|
@@ -991,7 +1024,7 @@ function moveCandidate(brainRoot, candidatePath, targetPath) {
|
|
|
991
1024
|
fireNeuron(brainRoot, targetPath);
|
|
992
1025
|
rmSync(src, { recursive: true, force: true });
|
|
993
1026
|
} else {
|
|
994
|
-
mkdirSync5(
|
|
1027
|
+
mkdirSync5(dirname3(dst), { recursive: true });
|
|
995
1028
|
renameSync3(src, dst);
|
|
996
1029
|
}
|
|
997
1030
|
console.log(`\u{1F393} promoted: ${candidatePath} \u2192 ${targetPath}`);
|
|
@@ -1067,7 +1100,7 @@ function readCounter(dir) {
|
|
|
1067
1100
|
}
|
|
1068
1101
|
|
|
1069
1102
|
// src/episode.ts
|
|
1070
|
-
import { readdirSync as readdirSync8, readFileSync as
|
|
1103
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync4, writeFileSync as writeFileSync8, mkdirSync as mkdirSync6, existsSync as existsSync11 } from "fs";
|
|
1071
1104
|
import { join as join12 } from "path";
|
|
1072
1105
|
var MAX_EPISODES = 100;
|
|
1073
1106
|
var SESSION_LOG_DIR = "hippocampus/session_log";
|
|
@@ -1104,7 +1137,7 @@ function readEpisodes(brainRoot) {
|
|
|
1104
1137
|
for (const entry of entries) {
|
|
1105
1138
|
if (!entry.startsWith("memory") || !entry.endsWith(".neuron")) continue;
|
|
1106
1139
|
try {
|
|
1107
|
-
const content =
|
|
1140
|
+
const content = readFileSync4(join12(logDir, entry), "utf8");
|
|
1108
1141
|
if (content.trim()) {
|
|
1109
1142
|
episodes.push(JSON.parse(content));
|
|
1110
1143
|
}
|
|
@@ -1138,7 +1171,7 @@ function processInbox(brainRoot) {
|
|
|
1138
1171
|
if (!existsSync12(inboxPath)) {
|
|
1139
1172
|
return { processed: 0, skipped: 0, errors: [] };
|
|
1140
1173
|
}
|
|
1141
|
-
const content =
|
|
1174
|
+
const content = readFileSync5(inboxPath, "utf8").trim();
|
|
1142
1175
|
if (!content) {
|
|
1143
1176
|
return { processed: 0, skipped: 0, errors: [] };
|
|
1144
1177
|
}
|
|
@@ -1233,7 +1266,7 @@ function ensureInbox(brainRoot) {
|
|
|
1233
1266
|
function appendCorrection(brainRoot, correction) {
|
|
1234
1267
|
const filePath = ensureInbox(brainRoot);
|
|
1235
1268
|
const line = JSON.stringify(correction) + "\n";
|
|
1236
|
-
const existing =
|
|
1269
|
+
const existing = readFileSync5(filePath, "utf8");
|
|
1237
1270
|
writeFileSync9(filePath, existing + line, "utf8");
|
|
1238
1271
|
}
|
|
1239
1272
|
|
|
@@ -1503,7 +1536,7 @@ function clearReports() {
|
|
|
1503
1536
|
}
|
|
1504
1537
|
|
|
1505
1538
|
// src/hooks.ts
|
|
1506
|
-
import { readFileSync as
|
|
1539
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync10, existsSync as existsSync13, mkdirSync as mkdirSync8, readdirSync as readdirSync9 } from "fs";
|
|
1507
1540
|
import { execSync as execSync2 } from "child_process";
|
|
1508
1541
|
import { join as join14, resolve as resolve2 } from "path";
|
|
1509
1542
|
var SETTINGS_DIR = ".claude";
|
|
@@ -1534,7 +1567,7 @@ function installHooks(brainRoot, projectRoot, global) {
|
|
|
1534
1567
|
let settings = {};
|
|
1535
1568
|
if (existsSync13(settingsPath)) {
|
|
1536
1569
|
try {
|
|
1537
|
-
settings = JSON.parse(
|
|
1570
|
+
settings = JSON.parse(readFileSync6(settingsPath, "utf8"));
|
|
1538
1571
|
} catch {
|
|
1539
1572
|
console.log(`\u26A0\uFE0F settings.local.json was malformed, overwriting`);
|
|
1540
1573
|
}
|
|
@@ -1600,7 +1633,7 @@ function uninstallHooks(projectRoot, global) {
|
|
|
1600
1633
|
}
|
|
1601
1634
|
let settings;
|
|
1602
1635
|
try {
|
|
1603
|
-
settings = JSON.parse(
|
|
1636
|
+
settings = JSON.parse(readFileSync6(settingsPath, "utf8"));
|
|
1604
1637
|
} catch {
|
|
1605
1638
|
console.log("settings.local.json is malformed, nothing to uninstall");
|
|
1606
1639
|
return;
|
|
@@ -1643,7 +1676,7 @@ function checkHooks(projectRoot, global) {
|
|
|
1643
1676
|
}
|
|
1644
1677
|
let settings;
|
|
1645
1678
|
try {
|
|
1646
|
-
settings = JSON.parse(
|
|
1679
|
+
settings = JSON.parse(readFileSync6(settingsPath, "utf8"));
|
|
1647
1680
|
} catch {
|
|
1648
1681
|
console.log(`\u274C settings.local.json is malformed`);
|
|
1649
1682
|
return status;
|
|
@@ -1683,7 +1716,7 @@ function hasBrainRegions(dir) {
|
|
|
1683
1716
|
}
|
|
1684
1717
|
|
|
1685
1718
|
// src/digest.ts
|
|
1686
|
-
import { readFileSync as
|
|
1719
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync11, existsSync as existsSync14, mkdirSync as mkdirSync9 } from "fs";
|
|
1687
1720
|
import { join as join15, basename } from "path";
|
|
1688
1721
|
var NEGATION_PATTERNS = [
|
|
1689
1722
|
/\bdon[''\u2019]?t\b/i,
|
|
@@ -1753,8 +1786,13 @@ function digestTranscript(brainRoot, transcriptPath, sessionId) {
|
|
|
1753
1786
|
for (const failure of toolFailures) {
|
|
1754
1787
|
logEpisode(brainRoot, "tool-failure", failure.toolName, failure.errorText);
|
|
1755
1788
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1789
|
+
const retries = detectRetryPatterns(toolFailures);
|
|
1790
|
+
for (const retry of retries) {
|
|
1791
|
+
logEpisode(brainRoot, "retry-pattern", retry.toolName, retry.errorText);
|
|
1792
|
+
}
|
|
1793
|
+
const totalSignals = toolFailures.length + retries.length;
|
|
1794
|
+
if (totalSignals > 0) {
|
|
1795
|
+
console.log(`\u{1F527} digest: ${toolFailures.length} tool failure(s), ${retries.length} retry pattern(s) logged`);
|
|
1758
1796
|
}
|
|
1759
1797
|
const corrections = extractCorrections(messages);
|
|
1760
1798
|
if (corrections.length === 0 && toolFailures.length === 0) {
|
|
@@ -1790,7 +1828,7 @@ function digestTranscript(brainRoot, transcriptPath, sessionId) {
|
|
|
1790
1828
|
};
|
|
1791
1829
|
}
|
|
1792
1830
|
function parseTranscript(transcriptPath) {
|
|
1793
|
-
const content =
|
|
1831
|
+
const content = readFileSync7(transcriptPath, "utf8");
|
|
1794
1832
|
const lines = content.split("\n").filter(Boolean);
|
|
1795
1833
|
const messages = [];
|
|
1796
1834
|
for (const line of lines) {
|
|
@@ -1818,7 +1856,7 @@ function extractText(content) {
|
|
|
1818
1856
|
}
|
|
1819
1857
|
var MAX_FAILURES_PER_SESSION = 20;
|
|
1820
1858
|
function parseToolResults(transcriptPath) {
|
|
1821
|
-
const content =
|
|
1859
|
+
const content = readFileSync7(transcriptPath, "utf8");
|
|
1822
1860
|
const lines = content.split("\n").filter(Boolean);
|
|
1823
1861
|
const failures = [];
|
|
1824
1862
|
for (const line of lines) {
|
|
@@ -1840,6 +1878,22 @@ function parseToolResults(transcriptPath) {
|
|
|
1840
1878
|
}
|
|
1841
1879
|
return failures;
|
|
1842
1880
|
}
|
|
1881
|
+
function detectRetryPatterns(failures) {
|
|
1882
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1883
|
+
for (const f of failures) {
|
|
1884
|
+
const key = f.toolName.toLowerCase().trim();
|
|
1885
|
+
const existing = counts.get(key);
|
|
1886
|
+
if (existing) {
|
|
1887
|
+
existing.count++;
|
|
1888
|
+
} else {
|
|
1889
|
+
counts.set(key, { failure: f, count: 1 });
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
return [...counts.values()].filter((entry) => entry.count >= 3).map((entry) => ({
|
|
1893
|
+
...entry.failure,
|
|
1894
|
+
toolName: `[retry x${entry.count}] ${entry.failure.toolName}`
|
|
1895
|
+
}));
|
|
1896
|
+
}
|
|
1843
1897
|
function detectToolFailure(block, toolUseResult) {
|
|
1844
1898
|
if (!block.is_error) return null;
|
|
1845
1899
|
let errorText = "";
|
|
@@ -2052,12 +2106,12 @@ function writeAuditLog(brainRoot, sessionId, entries) {
|
|
|
2052
2106
|
}
|
|
2053
2107
|
|
|
2054
2108
|
// src/evolve.ts
|
|
2055
|
-
import { existsSync as existsSync16, readFileSync as
|
|
2109
|
+
import { existsSync as existsSync16, readFileSync as readFileSync9, writeFileSync as writeFileSync13 } from "fs";
|
|
2056
2110
|
import { join as join17 } from "path";
|
|
2057
2111
|
|
|
2058
2112
|
// src/outcome.ts
|
|
2059
2113
|
import { execSync as execSync3 } from "child_process";
|
|
2060
|
-
import { existsSync as existsSync15, mkdirSync as mkdirSync10, writeFileSync as writeFileSync12, readFileSync as
|
|
2114
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync10, writeFileSync as writeFileSync12, readFileSync as readFileSync8, readdirSync as readdirSync10, rmSync as rmSync2, statSync as statSync4 } from "fs";
|
|
2061
2115
|
import { join as join16 } from "path";
|
|
2062
2116
|
import { randomUUID } from "crypto";
|
|
2063
2117
|
function captureSessionStart(brainRoot) {
|
|
@@ -2256,7 +2310,7 @@ function readLatestSessionState(brainRoot) {
|
|
|
2256
2310
|
}
|
|
2257
2311
|
if (!latest) return null;
|
|
2258
2312
|
try {
|
|
2259
|
-
return JSON.parse(
|
|
2313
|
+
return JSON.parse(readFileSync8(latest.path, "utf8"));
|
|
2260
2314
|
} catch {
|
|
2261
2315
|
return null;
|
|
2262
2316
|
}
|
|
@@ -2283,7 +2337,7 @@ var DEFAULT_MODEL = "gemini-2.0-flash-lite";
|
|
|
2283
2337
|
var API_TIMEOUT = 3e4;
|
|
2284
2338
|
var RETRY_DELAY = 5e3;
|
|
2285
2339
|
var EVOLVE_COOLDOWN_FILE = "hippocampus/evolve_last_run";
|
|
2286
|
-
async function runEvolve(brainRoot, dryRun) {
|
|
2340
|
+
async function runEvolve(brainRoot, dryRun, mode = "default") {
|
|
2287
2341
|
const apiKey = process.env.GEMINI_API_KEY;
|
|
2288
2342
|
if (!apiKey) {
|
|
2289
2343
|
console.error("\u274C GEMINI_API_KEY not set. Get one at https://aistudio.google.com/apikey");
|
|
@@ -2293,7 +2347,7 @@ async function runEvolve(brainRoot, dryRun) {
|
|
|
2293
2347
|
const cooldownMs = (parseInt(process.env.EVOLVE_COOLDOWN_SECONDS ?? "60", 10) || 60) * 1e3;
|
|
2294
2348
|
const cooldownPath = join17(brainRoot, EVOLVE_COOLDOWN_FILE);
|
|
2295
2349
|
if (existsSync16(cooldownPath)) {
|
|
2296
|
-
const lastRun = parseInt(
|
|
2350
|
+
const lastRun = parseInt(readFileSync9(cooldownPath, "utf8").trim(), 10);
|
|
2297
2351
|
const elapsed = Date.now() - lastRun;
|
|
2298
2352
|
if (elapsed < cooldownMs) {
|
|
2299
2353
|
const remaining = Math.ceil((cooldownMs - elapsed) / 1e3);
|
|
@@ -2306,7 +2360,7 @@ async function runEvolve(brainRoot, dryRun) {
|
|
|
2306
2360
|
const brain = scanBrain(brainRoot);
|
|
2307
2361
|
const summary = buildBrainSummary(brain);
|
|
2308
2362
|
const outcomeSummary = buildOutcomeSummary(brainRoot);
|
|
2309
|
-
const prompt = buildPrompt(summary, episodes, outcomeSummary);
|
|
2363
|
+
const prompt = mode === "prune" ? buildPrunePrompt(summary, episodes) : buildPrompt(summary, episodes, outcomeSummary);
|
|
2310
2364
|
let rawActions;
|
|
2311
2365
|
try {
|
|
2312
2366
|
rawActions = await callGemini(prompt, apiKey);
|
|
@@ -2397,6 +2451,44 @@ Focus on: strengthening repeatedly-used rules, pruning ineffective ones, growing
|
|
|
2397
2451
|
Respond with a JSON array of actions:
|
|
2398
2452
|
[{"type":"fire","path":"cortex/NO_console_log","reason":"fired 3 times in recent sessions"}]`;
|
|
2399
2453
|
}
|
|
2454
|
+
function buildPrunePrompt(summary, episodes) {
|
|
2455
|
+
const episodeLines = episodes.length > 0 ? episodes.map((e) => `- [${e.ts}] ${e.type}: ${sanitizeForPrompt(e.detail)}`).join("\n") : "(no recent episodes)";
|
|
2456
|
+
return `You are the PRUNING engine for a hebbian brain \u2014 a filesystem-based memory system for AI agents.
|
|
2457
|
+
|
|
2458
|
+
Your job is CLEANUP. Remove what's stale, redundant, or harmful. Healthy forgetting.
|
|
2459
|
+
|
|
2460
|
+
## Axioms
|
|
2461
|
+
- Folder = Neuron, File = Firing Trace, Counter = Activation strength
|
|
2462
|
+
- 7 regions: brainstem(P0) > limbic(P1) > hippocampus(P2) > sensors(P3) > cortex(P4) > ego(P5) > prefrontal(P6)
|
|
2463
|
+
- PROTECTED regions (brainstem, limbic, sensors): NEVER touch these
|
|
2464
|
+
|
|
2465
|
+
## Current Brain
|
|
2466
|
+
${summary}
|
|
2467
|
+
|
|
2468
|
+
## Recent Episodes (last ${episodes.length})
|
|
2469
|
+
${episodeLines}
|
|
2470
|
+
|
|
2471
|
+
## Pruning Criteria
|
|
2472
|
+
1. **Stale neurons** \u2014 counter is low AND no recent episodes mention them. They occupy space but provide no value.
|
|
2473
|
+
2. **High contra ratio** \u2014 neurons present in many reverted sessions (contra_ratio > 0.7). They correlate with bad outcomes.
|
|
2474
|
+
3. **Redundant neurons** \u2014 two neurons in the same region with very similar names/meaning. Keep the stronger one, prune the weaker.
|
|
2475
|
+
4. **Contradicted neurons** \u2014 a newer neuron explicitly overrides an older one. Remove the older.
|
|
2476
|
+
|
|
2477
|
+
## Available Actions (pruning-focused)
|
|
2478
|
+
- prune: Decrement a neuron's counter. Use for rules that aren't working.
|
|
2479
|
+
- decay: Mark inactive neurons as dormant. Use for stale rules with no recent activity.
|
|
2480
|
+
- signal: Add bomb signal to block a problematic neuron. Use for neurons that actively cause harm.
|
|
2481
|
+
|
|
2482
|
+
Do NOT use grow or fire \u2014 this is a pruning pass, not a growth pass.
|
|
2483
|
+
|
|
2484
|
+
## Constraints
|
|
2485
|
+
- Max ${MAX_ACTIONS} actions per cycle
|
|
2486
|
+
- NEVER target brainstem, limbic, or sensors regions
|
|
2487
|
+
- Be conservative \u2014 only prune what you're confident about
|
|
2488
|
+
|
|
2489
|
+
Respond with a JSON array of actions:
|
|
2490
|
+
[{"type":"prune","path":"cortex/WARN_old_rule","reason":"not fired in 30+ days, no recent episodes"}]`;
|
|
2491
|
+
}
|
|
2400
2492
|
async function callGemini(prompt, apiKey) {
|
|
2401
2493
|
const model = process.env.EVOLVE_MODEL || DEFAULT_MODEL;
|
|
2402
2494
|
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
|
|
@@ -2535,6 +2627,7 @@ function actionIcon(type) {
|
|
|
2535
2627
|
}
|
|
2536
2628
|
}
|
|
2537
2629
|
export {
|
|
2630
|
+
AGENTS_DIR,
|
|
2538
2631
|
DECAY_DAYS,
|
|
2539
2632
|
DIGEST_LOG_DIR,
|
|
2540
2633
|
EMIT_TARGETS,
|
|
@@ -2553,6 +2646,7 @@ export {
|
|
|
2553
2646
|
REGION_KO,
|
|
2554
2647
|
REGION_PRIORITY,
|
|
2555
2648
|
SESSION_STATE_DIR,
|
|
2649
|
+
SHARED_DIR,
|
|
2556
2650
|
SIGNAL_TYPES,
|
|
2557
2651
|
SPOTLIGHT_DAYS,
|
|
2558
2652
|
appendCorrection,
|
|
@@ -2563,6 +2657,7 @@ export {
|
|
|
2563
2657
|
clearReports,
|
|
2564
2658
|
contraNeuron,
|
|
2565
2659
|
detectOutcome,
|
|
2660
|
+
detectRetryPatterns,
|
|
2566
2661
|
detectToolFailure,
|
|
2567
2662
|
digestTranscript,
|
|
2568
2663
|
emitBootstrap,
|
|
@@ -2590,7 +2685,9 @@ export {
|
|
|
2590
2685
|
promoteCandidates,
|
|
2591
2686
|
readEpisodes,
|
|
2592
2687
|
readHookInput,
|
|
2688
|
+
resolveAgentBrain,
|
|
2593
2689
|
resolveBrainRoot,
|
|
2690
|
+
resolveSharedBrain,
|
|
2594
2691
|
rollbackNeuron,
|
|
2595
2692
|
runDecay,
|
|
2596
2693
|
runDedup,
|