holomime 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4794,6 +4794,40 @@ var memorySchema = z4.object({
4794
4794
  interaction_count: z4.number().int().default(0)
4795
4795
  })).default([])
4796
4796
  });
4797
+ var MemoryLevel = /* @__PURE__ */ ((MemoryLevel2) => {
4798
+ MemoryLevel2[MemoryLevel2["ABSTRACT"] = 0] = "ABSTRACT";
4799
+ MemoryLevel2[MemoryLevel2["OVERVIEW"] = 1] = "OVERVIEW";
4800
+ MemoryLevel2[MemoryLevel2["DETAIL"] = 2] = "DETAIL";
4801
+ return MemoryLevel2;
4802
+ })(MemoryLevel || {});
4803
+ var memoryNodeSchema = z4.object({
4804
+ id: z4.string(),
4805
+ category: z4.enum(["triggers", "corrections", "patterns", "trajectories"]),
4806
+ level: z4.nativeEnum(MemoryLevel).default(2 /* DETAIL */),
4807
+ abstract: z4.string(),
4808
+ // L0 text (always present)
4809
+ overview: z4.string().optional(),
4810
+ // L1 text
4811
+ fullData: z4.record(z4.unknown()).optional(),
4812
+ // L2 data
4813
+ confidence: z4.number().min(0).max(1).default(0.5),
4814
+ createdAt: z4.string().optional(),
4815
+ updatedAt: z4.string().optional()
4816
+ });
4817
+ var memoryOperationSchema = z4.object({
4818
+ type: z4.enum(["write", "edit", "delete"]),
4819
+ memoryId: z4.string().optional(),
4820
+ memoryType: z4.string(),
4821
+ data: z4.record(z4.unknown()).optional(),
4822
+ reason: z4.string()
4823
+ });
4824
+ var retrievalStepSchema = z4.object({
4825
+ step: z4.number(),
4826
+ action: z4.enum(["search", "rerank", "drill_down"]),
4827
+ candidateCount: z4.number(),
4828
+ selectedCount: z4.number(),
4829
+ elapsedMs: z4.number()
4830
+ });
4797
4831
  var STACK_FILES = {
4798
4832
  soul: "soul.md",
4799
4833
  mind: "mind.sys",
@@ -8306,6 +8340,34 @@ function startWatch(spec, options) {
8306
8340
  // src/analysis/fleet-core.ts
8307
8341
  import { readFileSync as readFileSync15, existsSync as existsSync14, readdirSync as readdirSync5 } from "fs";
8308
8342
  import { join as join15, resolve as resolve12 } from "path";
8343
+ function evaluateConscienceGate(taskDescription, rules) {
8344
+ const sortedRules = [...rules].sort((a, b) => a.priority - b.priority);
8345
+ for (const rule of sortedRules) {
8346
+ const lowerContent = rule.content.toLowerCase();
8347
+ if (lowerContent.includes("deny") || lowerContent.includes("never")) {
8348
+ const denyPatterns = extractDenyPatterns(rule.content);
8349
+ for (const pattern of denyPatterns) {
8350
+ if (taskDescription.toLowerCase().includes(pattern.toLowerCase())) {
8351
+ return {
8352
+ passed: false,
8353
+ reason: `Blocked by conscience rule "${rule.name}": ${pattern}`,
8354
+ ruleTriggered: rule.name
8355
+ };
8356
+ }
8357
+ }
8358
+ }
8359
+ }
8360
+ return { passed: true };
8361
+ }
8362
+ function extractDenyPatterns(ruleContent) {
8363
+ const patterns = [];
8364
+ const lines = ruleContent.split("\n");
8365
+ for (const line of lines) {
8366
+ const match = line.match(/[-*]\s*(?:deny|never|block|refuse):\s*(.+)/i);
8367
+ if (match) patterns.push(match[1].trim());
8368
+ }
8369
+ return patterns;
8370
+ }
8309
8371
  function loadFleetConfig(configPath) {
8310
8372
  const raw = JSON.parse(readFileSync15(configPath, "utf-8"));
8311
8373
  if (!raw.agents || !Array.isArray(raw.agents)) {
@@ -8494,9 +8556,122 @@ function startSingleAgent(agent, options, statusMap, allEvents, handles) {
8494
8556
  handles.push({ name: agent.name, handle });
8495
8557
  }
8496
8558
 
8559
+ // src/analysis/conscience-loader.ts
8560
+ import { readFileSync as readFileSync16, existsSync as existsSync15, readdirSync as readdirSync6 } from "fs";
8561
+ import { join as join16, basename } from "path";
8562
+ import { parse as parseYaml3 } from "yaml";
8563
+ function parseConscienceRule(filePath) {
8564
+ const content = readFileSync16(filePath, "utf-8");
8565
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
8566
+ if (!frontmatterMatch) {
8567
+ return {
8568
+ name: basename(filePath, ".md"),
8569
+ enabled: true,
8570
+ priority: 5,
8571
+ scope: "agent",
8572
+ content: content.trim()
8573
+ };
8574
+ }
8575
+ const meta = parseYaml3(frontmatterMatch[1]) || {};
8576
+ const body = frontmatterMatch[2].trim();
8577
+ return {
8578
+ name: meta.name || basename(filePath, ".md"),
8579
+ enabled: meta.enabled !== false,
8580
+ priority: meta.priority || 5,
8581
+ scope: meta.scope || "agent",
8582
+ content: body
8583
+ };
8584
+ }
8585
+ function loadConscienceRules(rulesDir) {
8586
+ if (!existsSync15(rulesDir)) return [];
8587
+ const files = readdirSync6(rulesDir).filter((f) => f.endsWith(".md"));
8588
+ return files.map((f) => parseConscienceRule(join16(rulesDir, f)));
8589
+ }
8590
+ function filterByConfig(rules, config) {
8591
+ return rules.map((rule) => {
8592
+ const cfg = config.rules[rule.name];
8593
+ if (cfg) {
8594
+ return {
8595
+ ...rule,
8596
+ enabled: cfg.enabled,
8597
+ priority: cfg.priority ?? rule.priority
8598
+ };
8599
+ }
8600
+ return rule;
8601
+ }).filter((rule) => rule.enabled).sort((a, b) => a.priority - b.priority);
8602
+ }
8603
+ function injectConscienceRules(basePrompt, rules) {
8604
+ if (rules.length === 0) return basePrompt;
8605
+ const rulesSection = [
8606
+ "\n\n## Conscience Rules (Enforcement Layer)",
8607
+ "",
8608
+ ...rules.map(
8609
+ (r) => `### ${r.name} (priority: ${r.priority}, scope: ${r.scope})
8610
+ ${r.content}`
8611
+ )
8612
+ ].join("\n");
8613
+ return basePrompt + rulesSection;
8614
+ }
8615
+
8616
+ // src/core/model-router.ts
8617
+ var DEFAULT_MODEL_CONFIG = {
8618
+ default: "claude-3-5-sonnet",
8619
+ tasks: {
8620
+ "therapy-analysis": { model: "claude-3-5-sonnet", temperature: 0.3 },
8621
+ "therapy-session": { model: "claude-3-5-sonnet", temperature: 0.7 },
8622
+ "summarization": { model: "gpt-4o-mini", temperature: 0.2, maxTokens: 500 },
8623
+ "memory-extraction": { model: "gpt-4o-mini", temperature: 0.1 },
8624
+ "conscience-enforcement": { model: "claude-3-5-haiku", temperature: 0 },
8625
+ "drift-detection": { model: "claude-3-5-haiku", temperature: 0.1 },
8626
+ "fleet-orchestration": { model: "claude-3-5-sonnet", temperature: 0.3 }
8627
+ }
8628
+ };
8629
+ var ModelRouter = class {
8630
+ config;
8631
+ constructor(config) {
8632
+ this.config = {
8633
+ ...DEFAULT_MODEL_CONFIG,
8634
+ ...config,
8635
+ tasks: { ...DEFAULT_MODEL_CONFIG.tasks, ...config?.tasks }
8636
+ };
8637
+ }
8638
+ /**
8639
+ * Get model config for a specific task.
8640
+ */
8641
+ getModelForTask(taskName) {
8642
+ const taskConfig = this.config.tasks[taskName];
8643
+ if (taskConfig) {
8644
+ return {
8645
+ model: taskConfig.model,
8646
+ temperature: taskConfig.temperature ?? 0.3,
8647
+ maxTokens: taskConfig.maxTokens
8648
+ };
8649
+ }
8650
+ return { model: this.config.default, temperature: 0.3 };
8651
+ }
8652
+ /**
8653
+ * List all configured task assignments.
8654
+ */
8655
+ listAssignments() {
8656
+ return Object.entries(this.config.tasks).map(([task, cfg]) => ({
8657
+ task,
8658
+ model: cfg.model
8659
+ }));
8660
+ }
8661
+ /**
8662
+ * Override model for a specific task at runtime.
8663
+ */
8664
+ override(taskName, model, temperature) {
8665
+ this.config.tasks[taskName] = {
8666
+ model,
8667
+ temperature: temperature ?? this.config.tasks[taskName]?.temperature ?? 0.3
8668
+ };
8669
+ }
8670
+ };
8671
+
8497
8672
  // src/analysis/certify-core.ts
8498
- import { writeFileSync as writeFileSync13, mkdirSync as mkdirSync11, existsSync as existsSync15 } from "fs";
8499
- import { join as join16, resolve as resolve13 } from "path";
8673
+ import { writeFileSync as writeFileSync13, mkdirSync as mkdirSync11, existsSync as existsSync16 } from "fs";
8674
+ import { join as join17, resolve as resolve13 } from "path";
8500
8675
  function djb2Hash(str) {
8501
8676
  let hash = 0;
8502
8677
  for (let i = 0; i < str.length; i++) {
@@ -8610,12 +8785,12 @@ function verifyCredential(credential, spec) {
8610
8785
  }
8611
8786
  function saveCredential(credential, outputDir) {
8612
8787
  const dir = outputDir ?? resolve13(process.cwd(), ".holomime", "credentials");
8613
- if (!existsSync15(dir)) {
8788
+ if (!existsSync16(dir)) {
8614
8789
  mkdirSync11(dir, { recursive: true });
8615
8790
  }
8616
8791
  const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
8617
8792
  const filename = `${credential.agent.handle}-${date}.json`;
8618
- const filepath = join16(dir, filename);
8793
+ const filepath = join17(dir, filename);
8619
8794
  writeFileSync13(filepath, JSON.stringify(credential, null, 2) + "\n");
8620
8795
  return filepath;
8621
8796
  }
@@ -8888,7 +9063,7 @@ async function* ollamaChatStream(model, messages) {
8888
9063
  }
8889
9064
 
8890
9065
  // src/marketplace/registry.ts
8891
- import { readFileSync as readFileSync17 } from "fs";
9066
+ import { readFileSync as readFileSync18 } from "fs";
8892
9067
  import { resolve as resolve14, dirname as dirname3 } from "path";
8893
9068
  import { fileURLToPath } from "url";
8894
9069
  var REGISTRY_URL = "https://raw.githubusercontent.com/productstein/holomime/main/registry/index.json";
@@ -8902,7 +9077,7 @@ function loadLocalRegistry() {
8902
9077
  ];
8903
9078
  for (const p of candidates) {
8904
9079
  try {
8905
- const raw = readFileSync17(p, "utf-8");
9080
+ const raw = readFileSync18(p, "utf-8");
8906
9081
  return JSON.parse(raw);
8907
9082
  } catch {
8908
9083
  continue;
@@ -8944,7 +9119,7 @@ async function fetchPersonality(url) {
8944
9119
  ];
8945
9120
  for (const p of candidates) {
8946
9121
  try {
8947
- const raw = readFileSync17(p, "utf-8");
9122
+ const raw = readFileSync18(p, "utf-8");
8948
9123
  return JSON.parse(raw);
8949
9124
  } catch {
8950
9125
  continue;
@@ -8983,52 +9158,52 @@ async function createGist(spec, handle, token) {
8983
9158
  }
8984
9159
 
8985
9160
  // src/marketplace/api.ts
8986
- import { existsSync as existsSync17, readFileSync as readFileSync19 } from "fs";
8987
- import { join as join18 } from "path";
9161
+ import { existsSync as existsSync18, readFileSync as readFileSync20 } from "fs";
9162
+ import { join as join19 } from "path";
8988
9163
  import { homedir as homedir3 } from "os";
8989
9164
 
8990
9165
  // src/marketplace/local-backend.ts
8991
- import { existsSync as existsSync16, mkdirSync as mkdirSync12, readFileSync as readFileSync18, writeFileSync as writeFileSync14 } from "fs";
8992
- import { join as join17 } from "path";
9166
+ import { existsSync as existsSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync19, writeFileSync as writeFileSync14 } from "fs";
9167
+ import { join as join18 } from "path";
8993
9168
  import { homedir as homedir2 } from "os";
8994
9169
  function marketplaceDir() {
8995
- const dir = join17(homedir2(), ".holomime", "marketplace");
8996
- if (!existsSync16(dir)) {
9170
+ const dir = join18(homedir2(), ".holomime", "marketplace");
9171
+ if (!existsSync17(dir)) {
8997
9172
  mkdirSync12(dir, { recursive: true });
8998
9173
  }
8999
9174
  return dir;
9000
9175
  }
9001
9176
  function assetsDir() {
9002
- const dir = join17(marketplaceDir(), "assets");
9003
- if (!existsSync16(dir)) {
9177
+ const dir = join18(marketplaceDir(), "assets");
9178
+ if (!existsSync17(dir)) {
9004
9179
  mkdirSync12(dir, { recursive: true });
9005
9180
  }
9006
9181
  return dir;
9007
9182
  }
9008
9183
  function reviewsDir() {
9009
- const dir = join17(marketplaceDir(), "reviews");
9010
- if (!existsSync16(dir)) {
9184
+ const dir = join18(marketplaceDir(), "reviews");
9185
+ if (!existsSync17(dir)) {
9011
9186
  mkdirSync12(dir, { recursive: true });
9012
9187
  }
9013
9188
  return dir;
9014
9189
  }
9015
9190
  function reportsDir() {
9016
- const dir = join17(marketplaceDir(), "reports");
9017
- if (!existsSync16(dir)) {
9191
+ const dir = join18(marketplaceDir(), "reports");
9192
+ if (!existsSync17(dir)) {
9018
9193
  mkdirSync12(dir, { recursive: true });
9019
9194
  }
9020
9195
  return dir;
9021
9196
  }
9022
9197
  function indexPath() {
9023
- return join17(marketplaceDir(), "index.json");
9198
+ return join18(marketplaceDir(), "index.json");
9024
9199
  }
9025
9200
  function loadIndex() {
9026
9201
  const path = indexPath();
9027
- if (!existsSync16(path)) {
9202
+ if (!existsSync17(path)) {
9028
9203
  return [];
9029
9204
  }
9030
9205
  try {
9031
- return JSON.parse(readFileSync18(path, "utf-8"));
9206
+ return JSON.parse(readFileSync19(path, "utf-8"));
9032
9207
  } catch {
9033
9208
  return [];
9034
9209
  }
@@ -9037,18 +9212,18 @@ function saveIndex(assets) {
9037
9212
  writeFileSync14(indexPath(), JSON.stringify(assets, null, 2) + "\n");
9038
9213
  }
9039
9214
  function loadStoredAsset(id) {
9040
- const path = join17(assetsDir(), `${id}.json`);
9041
- if (!existsSync16(path)) {
9215
+ const path = join18(assetsDir(), `${id}.json`);
9216
+ if (!existsSync17(path)) {
9042
9217
  return null;
9043
9218
  }
9044
9219
  try {
9045
- return JSON.parse(readFileSync18(path, "utf-8"));
9220
+ return JSON.parse(readFileSync19(path, "utf-8"));
9046
9221
  } catch {
9047
9222
  return null;
9048
9223
  }
9049
9224
  }
9050
9225
  function saveStoredAsset(stored) {
9051
- const path = join17(assetsDir(), `${stored.meta.id}.json`);
9226
+ const path = join18(assetsDir(), `${stored.meta.id}.json`);
9052
9227
  writeFileSync14(path, JSON.stringify(stored, null, 2) + "\n");
9053
9228
  }
9054
9229
  function generateId(type, handle) {
@@ -9213,11 +9388,11 @@ var LocalMarketplaceBackend = class {
9213
9388
  }
9214
9389
  async rate(id, review) {
9215
9390
  this.seed();
9216
- const reviewFile = join17(reviewsDir(), `${id}.json`);
9391
+ const reviewFile = join18(reviewsDir(), `${id}.json`);
9217
9392
  let reviews = [];
9218
- if (existsSync16(reviewFile)) {
9393
+ if (existsSync17(reviewFile)) {
9219
9394
  try {
9220
- reviews = JSON.parse(readFileSync18(reviewFile, "utf-8"));
9395
+ reviews = JSON.parse(readFileSync19(reviewFile, "utf-8"));
9221
9396
  } catch {
9222
9397
  reviews = [];
9223
9398
  }
@@ -9234,7 +9409,7 @@ var LocalMarketplaceBackend = class {
9234
9409
  }
9235
9410
  }
9236
9411
  async report(id, reason) {
9237
- const reportFile = join17(reportsDir(), `${id}--${Date.now()}.json`);
9412
+ const reportFile = join18(reportsDir(), `${id}--${Date.now()}.json`);
9238
9413
  writeFileSync14(
9239
9414
  reportFile,
9240
9415
  JSON.stringify({ id, reason, reported_at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2) + "\n"
@@ -9244,12 +9419,12 @@ var LocalMarketplaceBackend = class {
9244
9419
 
9245
9420
  // src/marketplace/api.ts
9246
9421
  function loadConfig() {
9247
- const configPath = join18(homedir3(), ".holomime", "config.json");
9248
- if (!existsSync17(configPath)) {
9422
+ const configPath = join19(homedir3(), ".holomime", "config.json");
9423
+ if (!existsSync18(configPath)) {
9249
9424
  return {};
9250
9425
  }
9251
9426
  try {
9252
- return JSON.parse(readFileSync19(configPath, "utf-8"));
9427
+ return JSON.parse(readFileSync20(configPath, "utf-8"));
9253
9428
  } catch {
9254
9429
  return {};
9255
9430
  }
@@ -10526,8 +10701,8 @@ function checkIterationBudget(currentIteration, policy) {
10526
10701
  }
10527
10702
 
10528
10703
  // src/analysis/cross-agent-sharing.ts
10529
- import { readdirSync as readdirSync7, existsSync as existsSync18 } from "fs";
10530
- import { join as join19 } from "path";
10704
+ import { readdirSync as readdirSync8, existsSync as existsSync19 } from "fs";
10705
+ import { join as join20 } from "path";
10531
10706
  function buildSharedKnowledge(graphs, repertoires) {
10532
10707
  const interventionMap = /* @__PURE__ */ new Map();
10533
10708
  const patternAgentMap = /* @__PURE__ */ new Map();
@@ -10624,15 +10799,15 @@ function discoverAgentData(baseDir) {
10624
10799
  if (mainRepertoire.interventions.some((i) => i.timesUsed > 0)) {
10625
10800
  repertoires.push(mainRepertoire);
10626
10801
  }
10627
- if (baseDir && existsSync18(baseDir)) {
10802
+ if (baseDir && existsSync19(baseDir)) {
10628
10803
  try {
10629
- const entries = readdirSync7(baseDir, { withFileTypes: true });
10804
+ const entries = readdirSync8(baseDir, { withFileTypes: true });
10630
10805
  for (const entry of entries) {
10631
10806
  if (!entry.isDirectory()) continue;
10632
- const agentDir = join19(baseDir, entry.name);
10633
- const agentGraphPath = join19(agentDir, ".holomime", "graph", "knowledge-graph.json");
10634
- const agentRepertoirePath = join19(agentDir, ".holomime", "interventions", "repertoire.json");
10635
- if (existsSync18(agentGraphPath)) {
10807
+ const agentDir = join20(baseDir, entry.name);
10808
+ const agentGraphPath = join20(agentDir, ".holomime", "graph", "knowledge-graph.json");
10809
+ const agentRepertoirePath = join20(agentDir, ".holomime", "interventions", "repertoire.json");
10810
+ if (existsSync19(agentGraphPath)) {
10636
10811
  try {
10637
10812
  const graph = JSON.parse(
10638
10813
  __require("fs").readFileSync(agentGraphPath, "utf-8")
@@ -10641,7 +10816,7 @@ function discoverAgentData(baseDir) {
10641
10816
  } catch {
10642
10817
  }
10643
10818
  }
10644
- if (existsSync18(agentRepertoirePath)) {
10819
+ if (existsSync19(agentRepertoirePath)) {
10645
10820
  try {
10646
10821
  const repertoire = JSON.parse(
10647
10822
  __require("fs").readFileSync(agentRepertoirePath, "utf-8")
@@ -10657,9 +10832,153 @@ function discoverAgentData(baseDir) {
10657
10832
  return { graphs, repertoires };
10658
10833
  }
10659
10834
 
10835
+ // src/analysis/memory-extractor.ts
10836
+ function extractMemoryFromSession(sessionLog, existingNodes) {
10837
+ const writeOps = [];
10838
+ const editOps = [];
10839
+ const deleteOps = [];
10840
+ if (sessionLog.patternsDetected) {
10841
+ for (const pattern of sessionLog.patternsDetected) {
10842
+ const existing = existingNodes.find(
10843
+ (n) => n.category === "patterns" && n.abstract.includes(pattern)
10844
+ );
10845
+ if (existing) {
10846
+ editOps.push({
10847
+ type: "edit",
10848
+ memoryId: existing.id,
10849
+ memoryType: "patterns",
10850
+ data: { confidence: Math.min(1, existing.confidence + 0.1) },
10851
+ reason: `Pattern "${pattern}" observed again in session ${sessionLog.sessionId}`
10852
+ });
10853
+ } else {
10854
+ writeOps.push({
10855
+ type: "write",
10856
+ memoryType: "patterns",
10857
+ data: {
10858
+ id: `pattern_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
10859
+ category: "patterns",
10860
+ level: 2 /* DETAIL */,
10861
+ abstract: `Detected pattern: ${pattern}`,
10862
+ confidence: 0.5,
10863
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
10864
+ },
10865
+ reason: `New pattern detected in session ${sessionLog.sessionId}`
10866
+ });
10867
+ }
10868
+ }
10869
+ }
10870
+ if (sessionLog.correctionsApplied) {
10871
+ for (const correction of sessionLog.correctionsApplied) {
10872
+ writeOps.push({
10873
+ type: "write",
10874
+ memoryType: "corrections",
10875
+ data: {
10876
+ id: `correction_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
10877
+ category: "corrections",
10878
+ level: 2 /* DETAIL */,
10879
+ abstract: `Correction applied: ${correction}`,
10880
+ confidence: 0.7,
10881
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
10882
+ },
10883
+ reason: `Correction from session ${sessionLog.sessionId}`
10884
+ });
10885
+ }
10886
+ }
10887
+ const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString();
10888
+ for (const node of existingNodes) {
10889
+ if (node.confidence < 0.3 && node.updatedAt && node.updatedAt < thirtyDaysAgo) {
10890
+ deleteOps.push(node.id);
10891
+ }
10892
+ }
10893
+ return {
10894
+ reasoning: `Session ${sessionLog.sessionId}: ${writeOps.length} new, ${editOps.length} updated, ${deleteOps.length} decayed`,
10895
+ writeOps,
10896
+ editOps,
10897
+ deleteOps
10898
+ };
10899
+ }
10900
+ function applyMemoryOperations(nodes, ops) {
10901
+ let written = 0;
10902
+ let edited = 0;
10903
+ let deleted = 0;
10904
+ const updatedNodes = [...nodes];
10905
+ for (const op of ops.writeOps) {
10906
+ if (op.data) {
10907
+ updatedNodes.push(op.data);
10908
+ written++;
10909
+ }
10910
+ }
10911
+ for (const op of ops.editOps) {
10912
+ const idx = updatedNodes.findIndex((n) => n.id === op.memoryId);
10913
+ if (idx >= 0 && op.data) {
10914
+ updatedNodes[idx] = {
10915
+ ...updatedNodes[idx],
10916
+ ...op.data,
10917
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
10918
+ };
10919
+ edited++;
10920
+ }
10921
+ }
10922
+ const deleteSet = new Set(ops.deleteOps);
10923
+ const finalNodes = updatedNodes.filter((n) => !deleteSet.has(n.id));
10924
+ deleted = updatedNodes.length - finalNodes.length;
10925
+ return {
10926
+ nodes: finalNodes,
10927
+ result: { written, edited, deleted, operations: ops }
10928
+ };
10929
+ }
10930
+
10931
+ // src/analysis/memory-retriever.ts
10932
+ function recommendTier2(context) {
10933
+ if (context.isTherapySession) return 2 /* DETAIL */;
10934
+ if (context.driftDetected) return 1 /* OVERVIEW */;
10935
+ if (context.highThroughput) return 0 /* ABSTRACT */;
10936
+ return 1 /* OVERVIEW */;
10937
+ }
10938
+ function retrieveMemory(query, nodes, options) {
10939
+ const tier = options?.tier ?? query.suggestedTier ?? 1 /* OVERVIEW */;
10940
+ const maxResults = options?.maxResults ?? 5;
10941
+ const minConfidence = options?.minConfidence ?? 0.2;
10942
+ let candidates = query.category ? nodes.filter((n) => n.category === query.category) : nodes;
10943
+ candidates = candidates.filter((n) => n.confidence >= minConfidence);
10944
+ const queryWords = query.text.toLowerCase().split(/\s+/);
10945
+ const scored = candidates.map((node) => {
10946
+ const text = `${node.abstract} ${node.overview || ""}`.toLowerCase();
10947
+ const matchCount = queryWords.filter((w) => text.includes(w)).length;
10948
+ const score = matchCount / queryWords.length;
10949
+ return { node, score };
10950
+ });
10951
+ scored.sort((a, b) => b.score - a.score);
10952
+ const topResults = scored.slice(0, maxResults);
10953
+ const tokensPerItem = tier === 0 /* ABSTRACT */ ? 25 : tier === 1 /* OVERVIEW */ ? 200 : 500;
10954
+ return {
10955
+ items: topResults.map((r) => r.node),
10956
+ tierUsed: tier,
10957
+ estimatedTokens: topResults.length * tokensPerItem,
10958
+ matchScores: topResults.map((r) => r.score)
10959
+ };
10960
+ }
10961
+ function compileMemoryForPrompt(nodes, tier) {
10962
+ if (nodes.length === 0) return "";
10963
+ const lines = ["## Behavioral Memory"];
10964
+ for (const node of nodes) {
10965
+ if (tier === 0 /* ABSTRACT */) {
10966
+ lines.push(`- ${node.abstract}`);
10967
+ } else if (tier === 1 /* OVERVIEW */) {
10968
+ lines.push(`### ${node.abstract}`);
10969
+ if (node.overview) lines.push(node.overview);
10970
+ } else {
10971
+ lines.push(`### ${node.abstract}`);
10972
+ if (node.overview) lines.push(node.overview);
10973
+ if (node.fullData) lines.push("```json", JSON.stringify(node.fullData, null, 2), "```");
10974
+ }
10975
+ }
10976
+ return lines.join("\n");
10977
+ }
10978
+
10660
10979
  // src/analysis/network-core.ts
10661
- import { existsSync as existsSync19, readdirSync as readdirSync8, readFileSync as readFileSync20 } from "fs";
10662
- import { join as join20, resolve as resolve16 } from "path";
10980
+ import { existsSync as existsSync20, readdirSync as readdirSync9, readFileSync as readFileSync21 } from "fs";
10981
+ import { join as join21, resolve as resolve16 } from "path";
10663
10982
 
10664
10983
  // src/psychology/therapist-meta.ts
10665
10984
  var THERAPIST_META_SPEC = {
@@ -10795,21 +11114,21 @@ Your patient is another AI agent with its own personality spec:
10795
11114
  // src/analysis/network-core.ts
10796
11115
  function discoverNetworkAgents(dir) {
10797
11116
  const absDir = resolve16(dir);
10798
- if (!existsSync19(absDir)) {
11117
+ if (!existsSync20(absDir)) {
10799
11118
  throw new Error(`Directory not found: ${absDir}`);
10800
11119
  }
10801
11120
  const agents = [];
10802
- const entries = readdirSync8(absDir, { withFileTypes: true });
11121
+ const entries = readdirSync9(absDir, { withFileTypes: true });
10803
11122
  for (const entry of entries) {
10804
11123
  if (!entry.isDirectory()) continue;
10805
- const agentDir = join20(absDir, entry.name);
10806
- const specPath = join20(agentDir, ".personality.json");
10807
- const logDir = join20(agentDir, "logs");
10808
- if (existsSync19(specPath)) {
11124
+ const agentDir = join21(absDir, entry.name);
11125
+ const specPath = join21(agentDir, ".personality.json");
11126
+ const logDir = join21(agentDir, "logs");
11127
+ if (existsSync20(specPath)) {
10809
11128
  agents.push({
10810
11129
  name: entry.name,
10811
11130
  specPath,
10812
- logDir: existsSync19(logDir) ? logDir : agentDir,
11131
+ logDir: existsSync20(logDir) ? logDir : agentDir,
10813
11132
  role: "both"
10814
11133
  });
10815
11134
  }
@@ -10817,7 +11136,7 @@ function discoverNetworkAgents(dir) {
10817
11136
  return agents;
10818
11137
  }
10819
11138
  function loadNetworkConfig(configPath) {
10820
- const raw = JSON.parse(readFileSync20(configPath, "utf-8"));
11139
+ const raw = JSON.parse(readFileSync21(configPath, "utf-8"));
10821
11140
  if (!raw.agents || !Array.isArray(raw.agents)) {
10822
11141
  throw new Error("network.json must contain an 'agents' array");
10823
11142
  }
@@ -11003,7 +11322,7 @@ async function runNetwork(config, provider, callbacks) {
11003
11322
  const spec = loadSpec(agent.specPath);
11004
11323
  agentSpecs.set(agent.name, spec);
11005
11324
  let messages = [];
11006
- if (agent.logDir && existsSync19(agent.logDir)) {
11325
+ if (agent.logDir && existsSync20(agent.logDir)) {
11007
11326
  messages = loadAgentMessages(agent.logDir);
11008
11327
  }
11009
11328
  agentMessages.set(agent.name, messages);
@@ -11120,15 +11439,15 @@ async function runNetwork(config, provider, callbacks) {
11120
11439
  };
11121
11440
  }
11122
11441
  function loadAgentMessages(logDir) {
11123
- if (!existsSync19(logDir)) return [];
11442
+ if (!existsSync20(logDir)) return [];
11124
11443
  const messages = [];
11125
11444
  try {
11126
- const files = readdirSync8(logDir).filter(
11445
+ const files = readdirSync9(logDir).filter(
11127
11446
  (f) => f.endsWith(".json") || f.endsWith(".jsonl")
11128
11447
  );
11129
11448
  for (const file of files.slice(0, 10)) {
11130
11449
  try {
11131
- const raw = readFileSync20(join20(logDir, file), "utf-8");
11450
+ const raw = readFileSync21(join21(logDir, file), "utf-8");
11132
11451
  const data = JSON.parse(raw);
11133
11452
  const conversations = parseConversationLog(data);
11134
11453
  for (const conv of conversations) {
@@ -11143,8 +11462,8 @@ function loadAgentMessages(logDir) {
11143
11462
  }
11144
11463
 
11145
11464
  // src/compliance/audit-trail.ts
11146
- import { readFileSync as readFileSync21, appendFileSync as appendFileSync2, existsSync as existsSync20, mkdirSync as mkdirSync13 } from "fs";
11147
- import { join as join21, resolve as resolve17 } from "path";
11465
+ import { readFileSync as readFileSync22, appendFileSync as appendFileSync2, existsSync as existsSync21, mkdirSync as mkdirSync13 } from "fs";
11466
+ import { join as join22, resolve as resolve17 } from "path";
11148
11467
  function djb2(str) {
11149
11468
  let hash = 5381;
11150
11469
  for (let i = 0; i < str.length; i++) {
@@ -11158,16 +11477,16 @@ function hashEntry(entry) {
11158
11477
  }
11159
11478
  function auditLogPath(agentHandle) {
11160
11479
  const dir = resolve17(process.cwd(), ".holomime", "audit");
11161
- if (!existsSync20(dir)) mkdirSync13(dir, { recursive: true });
11480
+ if (!existsSync21(dir)) mkdirSync13(dir, { recursive: true });
11162
11481
  const filename = agentHandle ? `${agentHandle}-audit.jsonl` : "audit.jsonl";
11163
- return join21(dir, filename);
11482
+ return join22(dir, filename);
11164
11483
  }
11165
11484
  function appendAuditEntry(event, agent, data, agentHandle) {
11166
11485
  const logPath = auditLogPath(agentHandle);
11167
11486
  let prevHash = "genesis";
11168
11487
  let seq = 1;
11169
- if (existsSync20(logPath)) {
11170
- const lines = readFileSync21(logPath, "utf-8").trim().split("\n").filter(Boolean);
11488
+ if (existsSync21(logPath)) {
11489
+ const lines = readFileSync22(logPath, "utf-8").trim().split("\n").filter(Boolean);
11171
11490
  if (lines.length > 0) {
11172
11491
  try {
11173
11492
  const lastEntry = JSON.parse(lines[lines.length - 1]);
@@ -11194,8 +11513,8 @@ function appendAuditEntry(event, agent, data, agentHandle) {
11194
11513
  }
11195
11514
  function loadAuditLog(agentHandle) {
11196
11515
  const logPath = auditLogPath(agentHandle);
11197
- if (!existsSync20(logPath)) return [];
11198
- return readFileSync21(logPath, "utf-8").trim().split("\n").filter(Boolean).map((line) => {
11516
+ if (!existsSync21(logPath)) return [];
11517
+ return readFileSync22(logPath, "utf-8").trim().split("\n").filter(Boolean).map((line) => {
11199
11518
  try {
11200
11519
  return JSON.parse(line);
11201
11520
  } catch {
@@ -11318,9 +11637,9 @@ function formatComplianceReportMarkdown(report) {
11318
11637
  }
11319
11638
 
11320
11639
  // src/compliance/iso-mappings.ts
11321
- import { readFileSync as readFileSync22, existsSync as existsSync21 } from "fs";
11322
- import { join as join22, resolve as resolve18, dirname as dirname4 } from "path";
11323
- import { parse as parseYaml3 } from "yaml";
11640
+ import { readFileSync as readFileSync23, existsSync as existsSync22 } from "fs";
11641
+ import { join as join23, resolve as resolve18, dirname as dirname4 } from "path";
11642
+ import { parse as parseYaml4 } from "yaml";
11324
11643
  import { fileURLToPath as fileURLToPath2 } from "url";
11325
11644
  var KNOWN_STANDARDS = {
11326
11645
  "iso-13482": "iso-13482.yaml",
@@ -11332,8 +11651,8 @@ function getRegistryDir() {
11332
11651
  const thisFile = typeof __filename !== "undefined" ? __filename : fileURLToPath2(import.meta.url);
11333
11652
  let dir = dirname4(thisFile);
11334
11653
  for (let i = 0; i < 6; i++) {
11335
- const candidate = join22(dir, "registry", "compliance");
11336
- if (existsSync21(candidate)) return candidate;
11654
+ const candidate = join23(dir, "registry", "compliance");
11655
+ if (existsSync22(candidate)) return candidate;
11337
11656
  dir = dirname4(dir);
11338
11657
  }
11339
11658
  return resolve18(process.cwd(), "registry", "compliance");
@@ -11341,15 +11660,15 @@ function getRegistryDir() {
11341
11660
  function loadStandard(name) {
11342
11661
  const registryDir = getRegistryDir();
11343
11662
  const filename = KNOWN_STANDARDS[name] ?? `${name}.yaml`;
11344
- const filepath = join22(registryDir, filename);
11345
- if (!existsSync21(filepath)) {
11663
+ const filepath = join23(registryDir, filename);
11664
+ if (!existsSync22(filepath)) {
11346
11665
  throw new Error(
11347
11666
  `ISO standard mapping not found: ${filepath}
11348
11667
  Available standards: ${Object.keys(KNOWN_STANDARDS).join(", ")}`
11349
11668
  );
11350
11669
  }
11351
- const content = readFileSync22(filepath, "utf-8");
11352
- const parsed = parseYaml3(content);
11670
+ const content = readFileSync23(filepath, "utf-8");
11671
+ const parsed = parseYaml4(content);
11353
11672
  if (!parsed.standard || !parsed.clauses || !Array.isArray(parsed.clauses)) {
11354
11673
  throw new Error(`Invalid ISO mapping file: ${filepath} \u2014 missing 'standard' or 'clauses'`);
11355
11674
  }
@@ -13303,13 +13622,13 @@ var HolomimeViolationError = class extends Error {
13303
13622
  };
13304
13623
 
13305
13624
  // src/integrations/openclaw.ts
13306
- import { readFileSync as readFileSync23, existsSync as existsSync22 } from "fs";
13625
+ import { readFileSync as readFileSync24, existsSync as existsSync23 } from "fs";
13307
13626
  import { resolve as resolve19 } from "path";
13308
13627
  function loadSpec2(specPath) {
13309
13628
  const resolved = resolve19(process.cwd(), specPath);
13310
- if (!existsSync22(resolved)) return null;
13629
+ if (!existsSync23(resolved)) return null;
13311
13630
  try {
13312
- return JSON.parse(readFileSync23(resolved, "utf-8"));
13631
+ return JSON.parse(readFileSync24(resolved, "utf-8"));
13313
13632
  } catch {
13314
13633
  return null;
13315
13634
  }
@@ -13465,12 +13784,85 @@ function loadSpecWithStack(specPath) {
13465
13784
  }
13466
13785
  return loadSpec(specPath);
13467
13786
  }
13787
+
13788
+ // src/integrations/kimodo-personality-mapper.ts
13789
+ function mapPersonalityToMotionStyle(bigFive) {
13790
+ const agreeFacets = bigFive.agreeableness.facets;
13791
+ const gentleness = (agreeFacets.cooperation + agreeFacets.warmth) / 2;
13792
+ const approachGentleness = Math.sqrt(gentleness);
13793
+ const consFacets = bigFive.conscientiousness.facets;
13794
+ const precisionDrive = (consFacets.attention_to_detail + consFacets.orderliness) / 2;
13795
+ const movementPrecision = 0.3 + precisionDrive * 0.7;
13796
+ const extraFacets = bigFive.extraversion.facets;
13797
+ const expressiveness = (extraFacets.enthusiasm + extraFacets.assertiveness) / 2;
13798
+ const gestureAmplitude = 0.2 + expressiveness * 0.8;
13799
+ const stabilityFacets = bigFive.emotional_stability.facets;
13800
+ const smoothnessDrive = (stabilityFacets.stress_tolerance + stabilityFacets.adaptability) / 2;
13801
+ const motionSmoothness = 0.4 + smoothnessDrive * 0.6;
13802
+ const openFacets = bigFive.openness.facets;
13803
+ const varietyDrive = (openFacets.willingness_to_experiment + openFacets.imagination) / 2;
13804
+ const movementVariety = 0.1 + varietyDrive * 0.6;
13805
+ const rawPace = 0.7 + extraFacets.initiative * 0.6;
13806
+ const paceMultiplier = rawPace * (1 - approachGentleness * 0.3);
13807
+ return {
13808
+ approachGentleness,
13809
+ movementPrecision,
13810
+ gestureAmplitude,
13811
+ motionSmoothness,
13812
+ movementVariety,
13813
+ paceMultiplier: Math.max(0.3, Math.min(1.5, paceMultiplier))
13814
+ };
13815
+ }
13816
+ function generateMotionConstraints(style, safetyEnvelope) {
13817
+ const constraints = [];
13818
+ const maxSpeed = safetyEnvelope?.max_linear_speed_m_s ?? 2;
13819
+ constraints.push({
13820
+ type: "root_waypoint_2d",
13821
+ description: "Personality-adjusted movement speed",
13822
+ parameters: {
13823
+ max_speed: maxSpeed * style.paceMultiplier,
13824
+ smoothing: style.motionSmoothness
13825
+ }
13826
+ });
13827
+ if (safetyEnvelope?.min_proximity_m) {
13828
+ constraints.push({
13829
+ type: "end_effector",
13830
+ description: "Personality-adjusted approach distance",
13831
+ parameters: {
13832
+ min_distance: safetyEnvelope.min_proximity_m * (1 + style.approachGentleness * 0.5),
13833
+ approach_speed_scale: 1 - style.approachGentleness * 0.6
13834
+ }
13835
+ });
13836
+ }
13837
+ constraints.push({
13838
+ type: "full_body_joint",
13839
+ description: "Personality-adjusted gesture range",
13840
+ parameters: {
13841
+ amplitude_scale: style.gestureAmplitude,
13842
+ precision_scale: style.movementPrecision,
13843
+ variety_scale: style.movementVariety
13844
+ }
13845
+ });
13846
+ return constraints;
13847
+ }
13848
+ function buildMotionRequest(prompt, bigFive, options) {
13849
+ const style = mapPersonalityToMotionStyle(bigFive);
13850
+ const constraints = generateMotionConstraints(style, options?.safetyEnvelope);
13851
+ return {
13852
+ prompt,
13853
+ model: options?.model ?? "G1",
13854
+ style,
13855
+ constraints,
13856
+ duration: options?.duration
13857
+ };
13858
+ }
13468
13859
  export {
13469
13860
  ARCHETYPES,
13470
13861
  ATTACHMENT_STYLES,
13471
13862
  AnthropicProvider,
13472
13863
  BUILT_IN_DETECTORS,
13473
13864
  CATEGORIES,
13865
+ DEFAULT_MODEL_CONFIG,
13474
13866
  DEFAULT_OVERSIGHT,
13475
13867
  DIMENSIONS,
13476
13868
  Guard,
@@ -13480,6 +13872,8 @@ export {
13480
13872
  LEARNING_ORIENTATIONS,
13481
13873
  LocalMarketplaceBackend,
13482
13874
  MarketplaceClient,
13875
+ MemoryLevel,
13876
+ ModelRouter,
13483
13877
  OllamaProvider,
13484
13878
  OpenAIProvider,
13485
13879
  PROVIDER_PARAMS,
@@ -13495,11 +13889,13 @@ export {
13495
13889
  agentHandleFromSpec,
13496
13890
  appendAuditEntry,
13497
13891
  appendEvolution,
13892
+ applyMemoryOperations,
13498
13893
  applyRecommendations,
13499
13894
  bigFiveSchema,
13500
13895
  bodySchema,
13501
13896
  buildAgentTherapistPrompt,
13502
13897
  buildAnonymizedReport,
13898
+ buildMotionRequest,
13503
13899
  buildPatientSystemPrompt,
13504
13900
  buildReACTContext,
13505
13901
  buildReACTFraming,
@@ -13520,6 +13916,7 @@ export {
13520
13916
  compileL0,
13521
13917
  compileL1,
13522
13918
  compileL2,
13919
+ compileMemoryForPrompt,
13523
13920
  compileStack,
13524
13921
  compileTiered,
13525
13922
  compiledConfigSchema,
@@ -13566,6 +13963,7 @@ export {
13566
13963
  emitBehavioralEvent,
13567
13964
  encodeSnapshot,
13568
13965
  estimateConfidence,
13966
+ evaluateConscienceGate,
13569
13967
  evaluateOutcome,
13570
13968
  expireOldEdges,
13571
13969
  exportTrainingData,
@@ -13573,11 +13971,13 @@ export {
13573
13971
  extractAlpacaExamples,
13574
13972
  extractDPOPairs,
13575
13973
  extractDPOPairsWithLLM,
13974
+ extractMemoryFromSession,
13576
13975
  extractRLHFExamples,
13577
13976
  extractRecommendations,
13578
13977
  fetchLeaderboard,
13579
13978
  fetchPersonality,
13580
13979
  fetchRegistry,
13980
+ filterByConfig,
13581
13981
  findCrossAgentCorrelations,
13582
13982
  findEdges,
13583
13983
  findNode,
@@ -13597,6 +13997,7 @@ export {
13597
13997
  generateGapRecommendation,
13598
13998
  generateIndexMarkdown,
13599
13999
  generateMonitoringCertificate,
14000
+ generateMotionConstraints,
13600
14001
  generateMutations,
13601
14002
  generatePrescriptions,
13602
14003
  generateProgressReport,
@@ -13633,6 +14034,7 @@ export {
13633
14034
  growthSchema,
13634
14035
  hapticPolicySchema,
13635
14036
  hashSpec2 as hashSpec,
14037
+ injectConscienceRules,
13636
14038
  isStackDirectory,
13637
14039
  learnIntervention,
13638
14040
  listArchetypeIds,
@@ -13644,6 +14046,7 @@ export {
13644
14046
  loadAuditLog,
13645
14047
  loadBehavioralMemory,
13646
14048
  loadBenchmarkResults,
14049
+ loadConscienceRules,
13647
14050
  loadCorpus,
13648
14051
  loadCustomDetectors,
13649
14052
  loadEvolution,
@@ -13658,6 +14061,9 @@ export {
13658
14061
  loadStandard,
13659
14062
  loadTranscripts,
13660
14063
  loadTreatmentPlan,
14064
+ mapPersonalityToMotionStyle,
14065
+ memoryNodeSchema,
14066
+ memoryOperationSchema,
13661
14067
  memorySchema,
13662
14068
  mergeStores,
13663
14069
  messageSchema,
@@ -13669,6 +14075,7 @@ export {
13669
14075
  parseAnthropicAPILog,
13670
14076
  parseChatGPTExport,
13671
14077
  parseClaudeExport,
14078
+ parseConscienceRule,
13672
14079
  parseConversationLog,
13673
14080
  parseConversationLogFromString,
13674
14081
  parseJSONLLog,
@@ -13691,6 +14098,7 @@ export {
13691
14098
  queryCorpus,
13692
14099
  queryInterventions,
13693
14100
  querySharedKnowledge,
14101
+ recommendTier2 as recommendMemoryTier,
13694
14102
  recommendTier,
13695
14103
  recordInterventionOutcome,
13696
14104
  recordObservation,
@@ -13702,6 +14110,8 @@ export {
13702
14110
  resetMarketplaceClient,
13703
14111
  resolveInheritance,
13704
14112
  resolveOversight,
14113
+ retrievalStepSchema,
14114
+ retrieveMemory,
13705
14115
  runAdversarialSuite,
13706
14116
  runAssessment,
13707
14117
  runAutopilot,