agenr 1.1.0 → 1.2.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.
Files changed (161) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/{chunk-B5C3FEPR.js → chunk-YU3EWRVT.js} +101 -2
  3. package/dist/cli.js +2589 -11
  4. package/dist/internal-recall-eval-server.js +1 -1
  5. package/package.json +29 -21
  6. package/.prettierrc +0 -5
  7. package/.vscode/launch.json +0 -77
  8. package/.vscode/tasks.json +0 -12
  9. package/AGENTS.md +0 -269
  10. package/docs/EVALS.md +0 -516
  11. package/docs/INGEST.md +0 -340
  12. package/docs/OPENCLAW-PLUGIN.md +0 -447
  13. package/docs/PLAN.md +0 -488
  14. package/docs/RECALL.md +0 -416
  15. package/docs/STORE.md +0 -246
  16. package/eslint.config.js +0 -172
  17. package/packages/openclaw-plugin/README.md +0 -12
  18. package/packages/openclaw-plugin/openclaw.plugin.json +0 -34
  19. package/packages/openclaw-plugin/package.json +0 -31
  20. package/packages/openclaw-plugin/src/index.ts +0 -1
  21. package/packages/openclaw-plugin/tsup.config.ts +0 -10
  22. package/pnpm-workspace.yaml +0 -2
  23. package/scripts/check-sim.ts +0 -89
  24. package/src/adapters/api/internal-recall-eval-server.ts +0 -204
  25. package/src/adapters/api/routes/internal-recall-eval.ts +0 -120
  26. package/src/adapters/api/validation/recall-eval-request.ts +0 -441
  27. package/src/adapters/db/client.ts +0 -206
  28. package/src/adapters/db/openclaw-plugin-queries.ts +0 -285
  29. package/src/adapters/db/queries.ts +0 -455
  30. package/src/adapters/db/recall-adapter.ts +0 -344
  31. package/src/adapters/db/row-mapping.ts +0 -216
  32. package/src/adapters/db/schema.ts +0 -399
  33. package/src/adapters/embeddings.ts +0 -286
  34. package/src/adapters/files/transcript-files.ts +0 -52
  35. package/src/adapters/llm.ts +0 -646
  36. package/src/adapters/openclaw/config.ts +0 -104
  37. package/src/adapters/openclaw/format/prompt-section.ts +0 -58
  38. package/src/adapters/openclaw/format/recall-format.ts +0 -86
  39. package/src/adapters/openclaw/hooks/before-prompt-build.ts +0 -338
  40. package/src/adapters/openclaw/hooks/before-reset.ts +0 -112
  41. package/src/adapters/openclaw/index.ts +0 -65
  42. package/src/adapters/openclaw/memory/flush-plan.ts +0 -21
  43. package/src/adapters/openclaw/memory/runtime.ts +0 -83
  44. package/src/adapters/openclaw/openclaw.plugin.json +0 -34
  45. package/src/adapters/openclaw/runtime.ts +0 -182
  46. package/src/adapters/openclaw/session/predecessor.ts +0 -319
  47. package/src/adapters/openclaw/session/sessions-store-reader.ts +0 -136
  48. package/src/adapters/openclaw/session/state.ts +0 -157
  49. package/src/adapters/openclaw/session/summary-reader.ts +0 -112
  50. package/src/adapters/openclaw/session/summary.ts +0 -373
  51. package/src/adapters/openclaw/session/tui-lane.ts +0 -59
  52. package/src/adapters/openclaw/tools.ts +0 -944
  53. package/src/adapters/openclaw/transcript/jsonl.ts +0 -53
  54. package/src/adapters/openclaw/transcript/message-content.ts +0 -300
  55. package/src/adapters/openclaw/transcript/parser.ts +0 -406
  56. package/src/adapters/openclaw/transcript/timestamps.ts +0 -99
  57. package/src/adapters/openclaw/transcript/tool-summarization.ts +0 -347
  58. package/src/adapters/openclaw/types.ts +0 -248
  59. package/src/app/evals/recall/collect-diagnostics.ts +0 -292
  60. package/src/app/evals/recall/contracts.ts +0 -345
  61. package/src/app/evals/recall/index.ts +0 -21
  62. package/src/app/evals/recall/instrumented-recall-ports.ts +0 -115
  63. package/src/app/evals/recall/normalize-response.ts +0 -78
  64. package/src/app/evals/recall/provision-fixtures.ts +0 -268
  65. package/src/app/evals/recall/run-recall-eval-case.ts +0 -134
  66. package/src/app/evals/recall/sandbox.ts +0 -92
  67. package/src/app/ingestion/index.ts +0 -9
  68. package/src/app/ingestion/ports.ts +0 -81
  69. package/src/app/ingestion/service.ts +0 -313
  70. package/src/cli/commands/db.ts +0 -117
  71. package/src/cli/commands/ingest.ts +0 -652
  72. package/src/cli/commands/init/cost-estimator.ts +0 -91
  73. package/src/cli/commands/init/external-commands.ts +0 -243
  74. package/src/cli/commands/init/index.ts +0 -17
  75. package/src/cli/commands/init/openclaw-detect.ts +0 -58
  76. package/src/cli/commands/init/session-scanner.ts +0 -83
  77. package/src/cli/commands/init/wizard.ts +0 -498
  78. package/src/cli/commands/recall.ts +0 -249
  79. package/src/cli/commands/setup.ts +0 -1411
  80. package/src/cli/main.ts +0 -41
  81. package/src/cli/ui.ts +0 -180
  82. package/src/cli.ts +0 -6
  83. package/src/config.ts +0 -357
  84. package/src/core/ingestion/dedup.ts +0 -561
  85. package/src/core/ingestion/extract.ts +0 -329
  86. package/src/core/ingestion/index.ts +0 -15
  87. package/src/core/ingestion/parser.ts +0 -271
  88. package/src/core/ingestion/pipeline.ts +0 -390
  89. package/src/core/ingestion/prompts.ts +0 -436
  90. package/src/core/ports.ts +0 -108
  91. package/src/core/recall/index.ts +0 -6
  92. package/src/core/recall/lexical.ts +0 -247
  93. package/src/core/recall/scoring.ts +0 -177
  94. package/src/core/recall/search.ts +0 -463
  95. package/src/core/recall/temporal.ts +0 -111
  96. package/src/core/recall/trace.ts +0 -124
  97. package/src/core/recall/types.ts +0 -67
  98. package/src/core/store/embedding-text.ts +0 -11
  99. package/src/core/store/hashing.ts +0 -28
  100. package/src/core/store/index.ts +0 -3
  101. package/src/core/store/pipeline.ts +0 -324
  102. package/src/core/store/validation.ts +0 -153
  103. package/src/core/types.ts +0 -112
  104. package/src/internal-recall-eval-server.ts +0 -95
  105. package/src/logger.ts +0 -83
  106. package/src/ui.ts +0 -74
  107. package/src/version.ts +0 -24
  108. package/tests/adapters/api/internal-recall-eval-server.test.ts +0 -88
  109. package/tests/adapters/api/routes/internal-recall-eval.test.ts +0 -461
  110. package/tests/adapters/api/validation/recall-eval-request.test.ts +0 -285
  111. package/tests/adapters/db/client.test.ts +0 -286
  112. package/tests/adapters/db/schema.test.ts +0 -275
  113. package/tests/adapters/embeddings.test.ts +0 -193
  114. package/tests/adapters/files/transcript-files.test.ts +0 -107
  115. package/tests/adapters/llm.test.ts +0 -453
  116. package/tests/adapters/openclaw/before-prompt-build.test.ts +0 -1160
  117. package/tests/adapters/openclaw/before-reset.test.ts +0 -287
  118. package/tests/adapters/openclaw/config.test.ts +0 -60
  119. package/tests/adapters/openclaw/flush-plan.test.ts +0 -18
  120. package/tests/adapters/openclaw/package-metadata.test.ts +0 -169
  121. package/tests/adapters/openclaw/prompt-section.test.ts +0 -25
  122. package/tests/adapters/openclaw/runtime.test.ts +0 -247
  123. package/tests/adapters/openclaw/session/predecessor.test.ts +0 -393
  124. package/tests/adapters/openclaw/session/summary.test.ts +0 -256
  125. package/tests/adapters/openclaw/session/tui-lane.test.ts +0 -32
  126. package/tests/adapters/openclaw/session-state.test.ts +0 -44
  127. package/tests/adapters/openclaw/tools.test.ts +0 -476
  128. package/tests/adapters/openclaw/transcript/parser.test.ts +0 -501
  129. package/tests/app/evals/recall/instrumented-recall-ports.test.ts +0 -120
  130. package/tests/app/evals/recall/run-recall-eval-case.test.ts +0 -508
  131. package/tests/app/ingestion/service.test.ts +0 -251
  132. package/tests/cli/commands/db.test.ts +0 -34
  133. package/tests/cli/commands/ingest.test.ts +0 -142
  134. package/tests/cli/commands/init/cost-estimator.test.ts +0 -50
  135. package/tests/cli/commands/init/external-commands.test.ts +0 -86
  136. package/tests/cli/commands/init/index.test.ts +0 -20
  137. package/tests/cli/commands/init/openclaw-detect.test.ts +0 -35
  138. package/tests/cli/commands/init/session-scanner.test.ts +0 -58
  139. package/tests/cli/commands/init/wizard.test.ts +0 -247
  140. package/tests/cli/commands/recall.test.ts +0 -82
  141. package/tests/cli/commands/setup.test.ts +0 -347
  142. package/tests/cli/fake-prompts.ts +0 -150
  143. package/tests/config.test.ts +0 -77
  144. package/tests/core/ingestion/dedup.test.ts +0 -351
  145. package/tests/core/ingestion/extract.test.ts +0 -294
  146. package/tests/core/ingestion/parser.test.ts +0 -251
  147. package/tests/core/ingestion/pipeline.test.ts +0 -592
  148. package/tests/core/ingestion/prompts.test.ts +0 -100
  149. package/tests/core/recall/lexical.test.ts +0 -91
  150. package/tests/core/recall/scoring.test.ts +0 -155
  151. package/tests/core/recall/search.integration.test.ts +0 -753
  152. package/tests/core/recall/search.test.ts +0 -262
  153. package/tests/core/recall/temporal.test.ts +0 -71
  154. package/tests/core/store/hashing.test.ts +0 -28
  155. package/tests/core/store/pipeline.test.ts +0 -295
  156. package/tests/core/store/validation.test.ts +0 -154
  157. package/tests/logger.test.ts +0 -77
  158. package/tests/ui.test.ts +0 -30
  159. package/tests/version.test.ts +0 -14
  160. package/tsconfig.json +0 -21
  161. package/tsup.config.ts +0 -12
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0] - 2026-03-29
4
+
5
+ The surgeon retirement pass — an autonomous agent that evaluates and retires stale knowledge entries.
6
+
7
+ ### Added
8
+
9
+ - **Surgeon retirement pass.** A standalone agent loop powered by `@mariozechner/pi-agent-core` that evaluates knowledge entries and retires semantically stale ones. Runs as `agenr surgeon run` with full dry-run and apply modes, budget governance, and completion guards.
10
+ - **7 surgeon tools.** `get_health_stats`, `query_candidates`, `inspect_entry`, `simulate_recall`, `retire_entry`, `update_entry`, and `complete_pass` — each adapted from the v0 surgeon for v1's simpler schema.
11
+ - **Recall simulation without telemetry.** The `simulate_recall` tool wraps the v1 recall pipeline with a no-op telemetry adapter and optional target-entry exclusion, so the surgeon can test retrieval impact without polluting recall metrics.
12
+ - **Surgeon CLI commands.** `agenr surgeon run`, `agenr surgeon status`, `agenr surgeon history`, and `agenr surgeon actions <run-id>` for running, inspecting, and auditing surgeon passes.
13
+ - **Surgeon status shows evaluation coverage.** `agenr surgeon status` now displays recently evaluated vs new candidates, so you can see how much work remains before running.
14
+ - **Surgeon model configuration in setup.** `agenr setup` and `agenr init` now include surgeon model overrides in the advanced task-specific model configuration flow.
15
+ - **Budget and completion governance.** Cost-based budget tracking, context-limit detection, completion guards that reject premature pass completion, and continuation prompts that keep the surgeon working when budget remains.
16
+ - **Run and action persistence.** Surgeon runs and individual actions (retirements, skips, updates) are logged to the database for auditability and recently-evaluated filtering on future runs.
17
+ - **Database backup before apply.** Surgeon creates a timestamped backup of the knowledge database (including WAL/SHM sidecars) before executing mutations in apply mode.
18
+ - **Surgeon configuration.** New `surgeon` section in `config.json` supporting model override, cost caps, daily cost limits, context limits, custom instructions, and per-pass protection thresholds.
19
+
20
+ ### Changed
21
+
22
+ - **Schema version bumped to 2.** The `surgeon_runs` table is expanded with pass type, status, token/cost tracking, model, dry-run flag, and structured summary fields. A new `surgeon_run_actions` table logs individual surgeon actions with indexed `entry_id` for efficient recently-evaluated queries. Existing databases are migrated automatically via `ALTER TABLE ADD COLUMN`.
23
+ - **Protection threshold raised to importance ≥ 9.** Entries with importance 8 are now eligible for surgeon evaluation since many entries default to importance 8 during ingestion.
24
+ - **Setup prompt updated.** The advanced model override prompt now reads "Customize task-specific models?" to reflect the addition of surgeon alongside extraction and dedup overrides.
25
+
26
+ ### Fixed
27
+
28
+ - **Tightened npm publish surface.** Root package now uses a strict `"files"` allowlist so only intended artifacts are published.
29
+
3
30
  ## [1.1.0] - 2026-03-28
4
31
 
5
32
  This release splits the OpenClaw plugin into its own publishable npm package and tightens session-start handoff reliability.
@@ -432,7 +432,7 @@ function normalizeInteger(value, fallback) {
432
432
  }
433
433
 
434
434
  // src/adapters/db/schema.ts
435
- var SCHEMA_VERSION = "1";
435
+ var SCHEMA_VERSION = "2";
436
436
  var VECTOR_INDEX_NAME = "idx_entries_embedding";
437
437
  var BULK_WRITE_STATE_META_KEY = "bulk_write_state";
438
438
  var CREATE_ENTRIES_TABLE_SQL = `
@@ -515,12 +515,49 @@ var CREATE_RECALL_EVENTS_TABLE_SQL = `
515
515
  var CREATE_SURGEON_RUNS_TABLE_SQL = `
516
516
  CREATE TABLE IF NOT EXISTS surgeon_runs (
517
517
  id TEXT PRIMARY KEY,
518
+ pass_type TEXT NOT NULL DEFAULT 'retirement',
519
+ project TEXT,
518
520
  started_at TEXT NOT NULL,
519
521
  completed_at TEXT,
522
+ status TEXT NOT NULL DEFAULT 'running',
523
+ input_tokens INTEGER DEFAULT 0,
524
+ output_tokens INTEGER DEFAULT 0,
525
+ estimated_cost_usd REAL DEFAULT 0,
526
+ model TEXT,
520
527
  actions_taken INTEGER DEFAULT 0,
521
- summary TEXT
528
+ actions_skipped INTEGER DEFAULT 0,
529
+ entries_retired INTEGER DEFAULT 0,
530
+ summary TEXT,
531
+ summary_json TEXT,
532
+ error TEXT,
533
+ dry_run INTEGER NOT NULL DEFAULT 1,
534
+ config_json TEXT
522
535
  )
523
536
  `;
537
+ var CREATE_SURGEON_RUN_ACTIONS_TABLE_SQL = `
538
+ CREATE TABLE IF NOT EXISTS surgeon_run_actions (
539
+ id TEXT PRIMARY KEY,
540
+ run_id TEXT NOT NULL REFERENCES surgeon_runs(id),
541
+ action_type TEXT NOT NULL,
542
+ entry_id TEXT,
543
+ entry_ids TEXT NOT NULL DEFAULT '[]',
544
+ reasoning TEXT NOT NULL DEFAULT '',
545
+ recall_delta TEXT,
546
+ created_at TEXT NOT NULL
547
+ )
548
+ `;
549
+ var CREATE_SURGEON_RUN_ACTIONS_RUN_ID_INDEX_SQL = `
550
+ CREATE INDEX IF NOT EXISTS idx_surgeon_run_actions_run_id
551
+ ON surgeon_run_actions(run_id)
552
+ `;
553
+ var CREATE_SURGEON_RUN_ACTIONS_ENTRY_ID_INDEX_SQL = `
554
+ CREATE INDEX IF NOT EXISTS idx_surgeon_run_actions_entry_id
555
+ ON surgeon_run_actions(entry_id)
556
+ `;
557
+ var CREATE_SURGEON_RUN_ACTIONS_CREATED_AT_INDEX_SQL = `
558
+ CREATE INDEX IF NOT EXISTS idx_surgeon_run_actions_created_at
559
+ ON surgeon_run_actions(created_at)
560
+ `;
524
561
  var CREATE_META_TABLE_SQL = `
525
562
  CREATE TABLE IF NOT EXISTS _meta (
526
563
  key TEXT PRIMARY KEY,
@@ -598,6 +635,7 @@ async function initSchema(db) {
598
635
  for (const statement of SCHEMA_STATEMENTS) {
599
636
  await db.execute(statement);
600
637
  }
638
+ await ensureSurgeonSchema(db);
601
639
  await db.execute({
602
640
  sql: `
603
641
  INSERT INTO _meta (key, value)
@@ -615,6 +653,45 @@ async function initSchema(db) {
615
653
  }
616
654
  await ensureVectorIndex(db);
617
655
  }
656
+ async function ensureSurgeonSchema(db) {
657
+ const columns = await db.execute("PRAGMA table_info('surgeon_runs')");
658
+ const existingColumns = new Set(
659
+ columns.rows.map((row) => {
660
+ const name = row.name;
661
+ return typeof name === "string" ? name : "";
662
+ }).filter((name) => name.length > 0)
663
+ );
664
+ const migrations = [
665
+ {
666
+ column: "pass_type",
667
+ sql: "ALTER TABLE surgeon_runs ADD COLUMN pass_type TEXT NOT NULL DEFAULT 'retirement'"
668
+ },
669
+ { column: "project", sql: "ALTER TABLE surgeon_runs ADD COLUMN project TEXT" },
670
+ {
671
+ column: "status",
672
+ sql: "ALTER TABLE surgeon_runs ADD COLUMN status TEXT NOT NULL DEFAULT 'completed'"
673
+ },
674
+ { column: "input_tokens", sql: "ALTER TABLE surgeon_runs ADD COLUMN input_tokens INTEGER DEFAULT 0" },
675
+ { column: "output_tokens", sql: "ALTER TABLE surgeon_runs ADD COLUMN output_tokens INTEGER DEFAULT 0" },
676
+ { column: "estimated_cost_usd", sql: "ALTER TABLE surgeon_runs ADD COLUMN estimated_cost_usd REAL DEFAULT 0" },
677
+ { column: "model", sql: "ALTER TABLE surgeon_runs ADD COLUMN model TEXT" },
678
+ { column: "actions_skipped", sql: "ALTER TABLE surgeon_runs ADD COLUMN actions_skipped INTEGER DEFAULT 0" },
679
+ { column: "entries_retired", sql: "ALTER TABLE surgeon_runs ADD COLUMN entries_retired INTEGER DEFAULT 0" },
680
+ { column: "summary_json", sql: "ALTER TABLE surgeon_runs ADD COLUMN summary_json TEXT" },
681
+ { column: "error", sql: "ALTER TABLE surgeon_runs ADD COLUMN error TEXT" },
682
+ { column: "dry_run", sql: "ALTER TABLE surgeon_runs ADD COLUMN dry_run INTEGER NOT NULL DEFAULT 1" },
683
+ { column: "config_json", sql: "ALTER TABLE surgeon_runs ADD COLUMN config_json TEXT" }
684
+ ];
685
+ for (const migration of migrations) {
686
+ if (!existingColumns.has(migration.column)) {
687
+ await db.execute(migration.sql);
688
+ }
689
+ }
690
+ await db.execute(CREATE_SURGEON_RUN_ACTIONS_TABLE_SQL);
691
+ await db.execute(CREATE_SURGEON_RUN_ACTIONS_RUN_ID_INDEX_SQL);
692
+ await db.execute(CREATE_SURGEON_RUN_ACTIONS_ENTRY_ID_INDEX_SQL);
693
+ await db.execute(CREATE_SURGEON_RUN_ACTIONS_CREATED_AT_INDEX_SQL);
694
+ }
618
695
  async function rebuildFts(db) {
619
696
  await db.execute("INSERT INTO entries_fts(entries_fts) VALUES ('rebuild')");
620
697
  }
@@ -893,6 +970,12 @@ var DEFAULT_CONFIG_DIR = path2.join(os.homedir(), ".agenr");
893
970
  var DEFAULT_DB_NAME = "knowledge.db";
894
971
  var CONFIG_DIR_MODE = 448;
895
972
  var CONFIG_FILE_MODE = 384;
973
+ var DEFAULT_SURGEON_COST_CAP = 15;
974
+ var DEFAULT_SURGEON_DAILY_COST_CAP = 75;
975
+ var DEFAULT_SURGEON_CONTEXT_LIMIT = 0;
976
+ var DEFAULT_SURGEON_RETIREMENT_PROTECT_RECALLED_DAYS = 14;
977
+ var DEFAULT_SURGEON_RETIREMENT_PROTECT_MIN_IMPORTANCE = 9;
978
+ var DEFAULT_SURGEON_SKIP_RECENTLY_EVALUATED_DAYS = 7;
896
979
  function isAgenrAuthMethod(value) {
897
980
  return AUTH_METHOD_SET.has(value);
898
981
  }
@@ -1430,7 +1513,23 @@ function wrapVectorError(error) {
1430
1513
  }
1431
1514
 
1432
1515
  export {
1516
+ buildActiveEntryClause,
1517
+ deserializeTags,
1518
+ readRequiredString,
1519
+ readOptionalString,
1520
+ readNumber,
1521
+ readBoolean,
1522
+ mapEntryRow,
1523
+ getEntry,
1524
+ retireEntry,
1525
+ updateEntry,
1433
1526
  createDatabase,
1527
+ DEFAULT_SURGEON_COST_CAP,
1528
+ DEFAULT_SURGEON_DAILY_COST_CAP,
1529
+ DEFAULT_SURGEON_CONTEXT_LIMIT,
1530
+ DEFAULT_SURGEON_RETIREMENT_PROTECT_RECALLED_DAYS,
1531
+ DEFAULT_SURGEON_RETIREMENT_PROTECT_MIN_IMPORTANCE,
1532
+ DEFAULT_SURGEON_SKIP_RECENTLY_EVALUATED_DAYS,
1434
1533
  isAgenrAuthMethod,
1435
1534
  authMethodToProvider,
1436
1535
  getAuthMethodDefinition,