pi-blackhole 0.4.2 → 0.4.3

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 (87) hide show
  1. package/README.md +15 -0
  2. package/dist/index.js +11660 -0
  3. package/dist/index.js.map +1 -0
  4. package/example-config.json +1 -1
  5. package/index.ts +37 -63
  6. package/package.json +21 -9
  7. package/src/commands/cleanup.ts +279 -240
  8. package/src/commands/memory.ts +236 -184
  9. package/src/commands/pi-vcc.ts +202 -152
  10. package/src/commands/vcc-recall.ts +126 -95
  11. package/src/core/brief.ts +167 -33
  12. package/src/core/build-sections.ts +8 -2
  13. package/src/core/config-env.ts +117 -0
  14. package/src/core/content.ts +31 -7
  15. package/src/core/drill-down.ts +41 -11
  16. package/src/core/filter-noise.ts +9 -3
  17. package/src/core/format-recall.ts +15 -6
  18. package/src/core/format.ts +14 -4
  19. package/src/core/lineage.ts +9 -3
  20. package/src/core/load-messages.ts +24 -5
  21. package/src/core/normalize.ts +38 -14
  22. package/src/core/recall-scope.ts +11 -3
  23. package/src/core/render-entries.ts +22 -6
  24. package/src/core/sanitize.ts +5 -1
  25. package/src/core/search-entries.ts +111 -19
  26. package/src/core/settings.ts +1 -3
  27. package/src/core/summarize.ts +42 -21
  28. package/src/core/unified-config.ts +549 -411
  29. package/src/extract/commits.ts +4 -2
  30. package/src/extract/files.ts +10 -5
  31. package/src/extract/goals.ts +7 -2
  32. package/src/hooks/before-compact.ts +210 -88
  33. package/src/om/agents/dropper/agent.ts +380 -265
  34. package/src/om/agents/dropper/coverage.ts +102 -82
  35. package/src/om/agents/observer/agent.ts +242 -206
  36. package/src/om/agents/reflector/agent.ts +212 -153
  37. package/src/om/cleanup.ts +239 -218
  38. package/src/om/clipboard.ts +59 -51
  39. package/src/om/compaction-trigger.ts +448 -333
  40. package/src/om/config.ts +13 -6
  41. package/src/om/configure-overlay.ts +518 -355
  42. package/src/om/consolidation.ts +1460 -953
  43. package/src/om/cooldown.ts +75 -65
  44. package/src/om/debug-log.ts +86 -68
  45. package/src/om/ids.ts +1 -1
  46. package/src/om/ledger/fold.ts +89 -78
  47. package/src/om/ledger/progress.ts +181 -153
  48. package/src/om/ledger/projection.ts +248 -185
  49. package/src/om/ledger/recall.ts +247 -196
  50. package/src/om/ledger/render-summary.ts +79 -50
  51. package/src/om/ledger/types.ts +146 -117
  52. package/src/om/model-budget.ts +23 -13
  53. package/src/om/pending.ts +243 -179
  54. package/src/om/provider-stream.ts +52 -7
  55. package/src/om/retryable-error.ts +12 -16
  56. package/src/om/reverse-recall.ts +97 -91
  57. package/src/om/runtime.ts +474 -375
  58. package/src/om/serialize.ts +190 -166
  59. package/src/om/status-overlay.ts +246 -195
  60. package/src/om/tokens.ts +28 -21
  61. package/src/pi-base/blackhole-settings.ts +437 -0
  62. package/src/pi-base/config-manager.ts +440 -0
  63. package/src/pi-base/config.ts +469 -0
  64. package/src/pi-base/env.ts +43 -0
  65. package/src/pi-base/paths.ts +47 -0
  66. package/src/pi-base/settings/body.ts +1648 -0
  67. package/src/pi-base/settings/fields/action.ts +43 -0
  68. package/src/pi-base/settings/fields/boolean.ts +47 -0
  69. package/src/pi-base/settings/fields/custom.ts +72 -0
  70. package/src/pi-base/settings/fields/enum.ts +310 -0
  71. package/src/pi-base/settings/fields/index.ts +46 -0
  72. package/src/pi-base/settings/fields/model.ts +452 -0
  73. package/src/pi-base/settings/fields/string.ts +527 -0
  74. package/src/pi-base/settings/fields/text.ts +115 -0
  75. package/src/pi-base/settings/frame.ts +197 -0
  76. package/src/pi-base/settings/index.ts +77 -0
  77. package/src/pi-base/settings/inline-edit.ts +313 -0
  78. package/src/pi-base/settings/modal.ts +152 -0
  79. package/src/pi-base/settings/types.ts +500 -0
  80. package/src/pi-base/settings/validate-field.ts +113 -0
  81. package/src/pi-base/shell.ts +117 -0
  82. package/src/pi-base/types.ts +6 -0
  83. package/src/pi-base/ui.ts +32 -0
  84. package/src/tools/recall.ts +347 -225
  85. package/src/types.ts +20 -3
  86. package/tsup.config.ts +23 -0
  87. package/vitest.config.ts +15 -15
@@ -96,7 +96,7 @@
96
96
  "observationsPoolTargetTokens": 10000,
97
97
  "reflectorInputMaxTokens": 80000,
98
98
  "dropperInputMaxTokens": 80000,
99
- "dropperPressureThreshold": 0.70,
99
+ "dropperPressureThreshold": 0.7,
100
100
  "observerChunkMaxTokens": 40000,
101
101
  "observerPreambleMaxTokens": 0,
102
102
  "agentMaxTurns": 16,
package/index.ts CHANGED
@@ -16,69 +16,43 @@ import { registerConsolidationTrigger } from "./src/om/consolidation.js";
16
16
  import { registerCompactionTrigger } from "./src/om/compaction-trigger.js";
17
17
  import { registerRecallTool } from "./src/tools/recall";
18
18
  import { Runtime } from "./src/om/runtime.js";
19
+ import { captureRegisteredProviderStreams } from "./src/om/provider-stream.js";
19
20
 
20
21
  export default (pi: ExtensionAPI) => {
21
- // ── Bridge: capture custom provider stream functions for jiti-loaded agents ──
22
- // pi-blackhole's consolidation agents are loaded via jiti with moduleCache: false,
23
- // which creates a separate pi-ai instance whose apiProviderRegistry lacks custom
24
- // providers (e.g., claude-bridge registered by other extensions). This bridge stores
25
- // streamSimple functions in a Symbol.for() global so agents can access them without
26
- // going through pi-ai's registry.
27
- //
28
- // There are two mechanisms:
29
- // 1. Wrap pi.registerProvider to capture streamSimple at registration time.
30
- // This handles providers registered AFTER our factory runs.
31
- // 2. On agent_start, scan modelRegistry.registeredProviders for any providers
32
- // that registered BEFORE our factory ran (different extension load order).
33
- const PROVIDER_STREAMS_KEY = Symbol.for("pi-blackhole:provider-streams");
34
- const providerStreams: Map<string, Function> = (globalThis as any)[PROVIDER_STREAMS_KEY] ??= new Map();
35
-
36
- const origRegisterProvider = pi.registerProvider.bind(pi);
37
- pi.registerProvider = ((name: string, config: any) => {
38
- if (config && config.streamSimple && config.api) {
39
- providerStreams.set(config.api, config.streamSimple);
40
- }
41
- origRegisterProvider(name, config);
42
- }) as typeof pi.registerProvider;
43
-
44
- // Fallback: on agent_start, capture providers that registered before our wrapper
45
- // (handles the case where pi-blackhole loads after another provider extension).
46
- // Uses a dedicated flag instead of checking providerStreams.size so the scan
47
- // always runs once even if the wrapper already captured some providers.
48
- let hasScannedFallback = false;
49
- pi.on("agent_start", (_event: unknown, ctx: any) => {
50
- if (hasScannedFallback) return;
51
- hasScannedFallback = true
52
- // modelRegistry.registeredProviders is declared private in TypeScript but is a
53
- // regular JS class field at runtime. We access it via bracket notation for
54
- // future-proofing against potential #private migration.
55
- const registry = (ctx as any)?.modelRegistry;
56
- const registered: Map<string, any> | undefined = registry?.["registeredProviders"];
57
- if (registered && typeof registered.forEach === "function") {
58
- registered.forEach((config: any, _name: string) => {
59
- if (config && config.streamSimple && config.api && !providerStreams.has(config.api)) {
60
- providerStreams.set(config.api, config.streamSimple);
61
- }
62
- });
63
- }
64
- });
65
-
66
- scaffoldSettings();
67
-
68
- const omRuntime = new Runtime();
69
-
70
- // Observational memory: background consolidation pipeline
71
- registerConsolidationTrigger(pi, omRuntime); // agent_start + turn_end → observer/reflector/dropper
72
- registerCompactionTrigger(pi, omRuntime); // agent_end → auto-compaction
73
-
74
- // Pi-vcc: compaction + om injection
75
- registerBeforeCompactHook(pi, omRuntime); // session_before_compact → pi-vcc + om content
76
-
77
- // Commands
78
- registerPiVccCommand(pi, omRuntime); // /pi-vcc (needs runtime for noAutoCompact flush)
79
- registerMemoryCommand(pi, omRuntime); // /blackhole-memory [status|view|full]
80
- registerVccRecallCommand(pi); // /blackhole-recall <query>
81
-
82
- // Tools
83
- registerRecallTool(pi); // unified recall (#N + [12char])
22
+ // ── Bridge: capture custom provider stream functions for jiti-loaded agents ──
23
+ // pi-blackhole's consolidation agents are loaded via jiti with moduleCache: false,
24
+ // which creates a separate pi-ai instance whose apiProviderRegistry lacks custom
25
+ // providers (e.g., claude-bridge registered by other extensions). This bridge stores
26
+ // streamSimple functions in a Symbol.for() global so agents can access them without
27
+ // going through pi-ai's registry.
28
+ //
29
+ // Capture custom provider streams from Pi's model registry before each run.
30
+ // This works regardless of extension load order and includes providers added
31
+ // after startup.
32
+ const PROVIDER_STREAMS_KEY = Symbol.for("pi-blackhole:provider-streams");
33
+ const providerStreams: Map<string, Function> = ((globalThis as any)[
34
+ PROVIDER_STREAMS_KEY
35
+ ] ??= new Map());
36
+ pi.on("agent_start", (_event: unknown, ctx: any) => {
37
+ captureRegisteredProviderStreams(ctx.modelRegistry, providerStreams);
38
+ });
39
+
40
+ scaffoldSettings();
41
+
42
+ const omRuntime = new Runtime();
43
+
44
+ // Observational memory: background consolidation pipeline
45
+ registerConsolidationTrigger(pi, omRuntime); // agent_start + turn_end observer/reflector/dropper
46
+ registerCompactionTrigger(pi, omRuntime); // agent_end auto-compaction
47
+
48
+ // Pi-vcc: compaction + om injection
49
+ registerBeforeCompactHook(pi, omRuntime); // session_before_compact → pi-vcc + om content
50
+
51
+ // Commands
52
+ registerPiVccCommand(pi, omRuntime); // /pi-vcc (needs runtime for noAutoCompact flush)
53
+ registerMemoryCommand(pi, omRuntime); // /blackhole-memory [status|view|full]
54
+ registerVccRecallCommand(pi); // /blackhole-recall <query>
55
+
56
+ // Tools
57
+ registerRecallTool(pi); // unified recall (#N + [12char])
84
58
  };
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
2
  "name": "pi-blackhole",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "packageManager": "pnpm@11.2.2",
5
5
  "description": "Unified compaction + observational memory extension for Pi — compresses conversation context while preserving durable observations and reflections",
6
6
  "license": "MIT",
7
- "main": "index.ts",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
8
9
  "files": [
10
+ "dist/",
9
11
  "*.ts",
10
12
  "src/**/*.ts",
11
13
  "!src/**/*.test.ts",
12
14
  "!tests/",
15
+ "tsup.config.ts",
13
16
  "LICENSE",
14
17
  "README.md",
15
18
  "example-config.json"
16
19
  ],
17
20
  "scripts": {
18
- "check": "tsc --noEmit",
19
- "lint": "eslint src/"
21
+ "build": "tsup",
22
+ "typecheck": "tsc --noEmit",
23
+ "lint": "eslint .",
24
+ "format": "prettier --write .",
25
+ "format:check": "prettier --check .",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "check": "pnpm typecheck && pnpm lint",
29
+ "prepare": "node scripts/prepare.mjs"
20
30
  },
21
31
  "keywords": [
22
32
  "pi-package",
@@ -47,19 +57,21 @@
47
57
  },
48
58
  "pi": {
49
59
  "extensions": [
50
- "./index.ts"
60
+ "./dist/index.js"
51
61
  ]
52
62
  },
53
63
  "devDependencies": {
54
- "@earendil-works/pi-agent-core": "0.81.1",
55
- "@earendil-works/pi-ai": "0.81.1",
56
- "@earendil-works/pi-coding-agent": "0.81.1",
57
- "@earendil-works/pi-tui": "0.81.1",
64
+ "@earendil-works/pi-agent-core": "0.83.0",
65
+ "@earendil-works/pi-ai": "0.83.0",
66
+ "@earendil-works/pi-coding-agent": "0.83.0",
67
+ "@earendil-works/pi-tui": "0.83.0",
58
68
  "@typescript-eslint/eslint-plugin": "8.60.0",
59
69
  "@typescript-eslint/parser": "8.60.0",
60
70
  "eslint": "9.39.4",
61
71
  "husky": "9.1.7",
72
+ "tsup": "^8.5.1",
62
73
  "lint-staged": "15.5.2",
74
+ "prettier": "3.9.6",
63
75
  "typebox": "1.1.38",
64
76
  "typescript": "5.9.3",
65
77
  "vitest": "4.1.9"