@animalabs/agent-framework 0.13.0 → 0.15.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 (95) hide show
  1. package/dist/src/agent.d.ts +10 -0
  2. package/dist/src/agent.d.ts.map +1 -1
  3. package/dist/src/agent.js +39 -0
  4. package/dist/src/agent.js.map +1 -1
  5. package/dist/src/framework.d.ts +36 -6
  6. package/dist/src/framework.d.ts.map +1 -1
  7. package/dist/src/framework.js +451 -83
  8. package/dist/src/framework.js.map +1 -1
  9. package/dist/src/gate/event-gate.d.ts +55 -1
  10. package/dist/src/gate/event-gate.d.ts.map +1 -1
  11. package/dist/src/gate/event-gate.js +41 -1
  12. package/dist/src/gate/event-gate.js.map +1 -1
  13. package/dist/src/gate/index.d.ts +1 -1
  14. package/dist/src/gate/index.d.ts.map +1 -1
  15. package/dist/src/gate/index.js +1 -1
  16. package/dist/src/gate/index.js.map +1 -1
  17. package/dist/src/index.d.ts +1 -1
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js.map +1 -1
  20. package/dist/src/modules/history/index.d.ts +69 -0
  21. package/dist/src/modules/history/index.d.ts.map +1 -0
  22. package/dist/src/modules/history/index.js +519 -0
  23. package/dist/src/modules/history/index.js.map +1 -0
  24. package/dist/src/modules/history/search-regex-worker.d.ts +23 -0
  25. package/dist/src/modules/history/search-regex-worker.d.ts.map +1 -0
  26. package/dist/src/modules/history/search-regex-worker.js +57 -0
  27. package/dist/src/modules/history/search-regex-worker.js.map +1 -0
  28. package/dist/src/modules/index.d.ts +1 -0
  29. package/dist/src/modules/index.d.ts.map +1 -1
  30. package/dist/src/modules/index.js +1 -0
  31. package/dist/src/modules/index.js.map +1 -1
  32. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  33. package/dist/src/modules/workspace/index.js +42 -1
  34. package/dist/src/modules/workspace/index.js.map +1 -1
  35. package/dist/src/modules/workspace/types.d.ts +5 -0
  36. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  37. package/dist/src/modules/workspace/types.js.map +1 -1
  38. package/dist/src/tool-image-ledger.d.ts +175 -0
  39. package/dist/src/tool-image-ledger.d.ts.map +1 -0
  40. package/dist/src/tool-image-ledger.js +257 -0
  41. package/dist/src/tool-image-ledger.js.map +1 -0
  42. package/dist/src/tool-result-history.d.ts +15 -2
  43. package/dist/src/tool-result-history.d.ts.map +1 -1
  44. package/dist/src/tool-result-history.js +16 -9
  45. package/dist/src/tool-result-history.js.map +1 -1
  46. package/dist/src/types/agent.d.ts +10 -0
  47. package/dist/src/types/agent.d.ts.map +1 -1
  48. package/dist/src/types/trace.d.ts +4 -0
  49. package/dist/src/types/trace.d.ts.map +1 -1
  50. package/dist/test/event-gate.test.js +84 -1
  51. package/dist/test/event-gate.test.js.map +1 -1
  52. package/dist/test/history-module.test.d.ts +2 -0
  53. package/dist/test/history-module.test.d.ts.map +1 -0
  54. package/dist/test/history-module.test.js +449 -0
  55. package/dist/test/history-module.test.js.map +1 -0
  56. package/dist/test/kv-unified-open-flight-retry.test.d.ts +2 -0
  57. package/dist/test/kv-unified-open-flight-retry.test.d.ts.map +1 -0
  58. package/dist/test/kv-unified-open-flight-retry.test.js +189 -0
  59. package/dist/test/kv-unified-open-flight-retry.test.js.map +1 -0
  60. package/dist/test/kv-unified-wiring.test.js +39 -0
  61. package/dist/test/kv-unified-wiring.test.js.map +1 -1
  62. package/dist/test/puppet-tool-call.test.js +114 -1
  63. package/dist/test/puppet-tool-call.test.js.map +1 -1
  64. package/dist/test/puppet-turn-reservation.test.d.ts +2 -0
  65. package/dist/test/puppet-turn-reservation.test.d.ts.map +1 -0
  66. package/dist/test/puppet-turn-reservation.test.js +139 -0
  67. package/dist/test/puppet-turn-reservation.test.js.map +1 -0
  68. package/dist/test/save-recent-image.test.d.ts +26 -0
  69. package/dist/test/save-recent-image.test.d.ts.map +1 -0
  70. package/dist/test/save-recent-image.test.js +736 -0
  71. package/dist/test/save-recent-image.test.js.map +1 -0
  72. package/dist/test/tool-result-spill.test.js +114 -0
  73. package/dist/test/tool-result-spill.test.js.map +1 -1
  74. package/dist/test/turn-trigger-provenance.test.js +17 -0
  75. package/dist/test/turn-trigger-provenance.test.js.map +1 -1
  76. package/dist/test/workspace-read-text.test.d.ts +2 -0
  77. package/dist/test/workspace-read-text.test.d.ts.map +1 -0
  78. package/dist/test/workspace-read-text.test.js +101 -0
  79. package/dist/test/workspace-read-text.test.js.map +1 -0
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +3 -3
  82. package/src/agent.ts +41 -0
  83. package/src/framework.ts +519 -95
  84. package/src/gate/event-gate.ts +71 -3
  85. package/src/gate/index.ts +1 -1
  86. package/src/index.ts +1 -1
  87. package/src/modules/history/index.ts +613 -0
  88. package/src/modules/history/search-regex-worker.ts +76 -0
  89. package/src/modules/index.ts +2 -0
  90. package/src/modules/workspace/index.ts +42 -1
  91. package/src/modules/workspace/types.ts +5 -0
  92. package/src/tool-image-ledger.ts +334 -0
  93. package/src/tool-result-history.ts +30 -9
  94. package/src/types/agent.ts +10 -0
  95. package/src/types/trace.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animalabs/agent-framework",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Multi-agent framework with pluggable modules, persistent state, and concurrent tool execution",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,8 +46,8 @@
46
46
  "author": "Anima Research",
47
47
  "license": "MIT",
48
48
  "dependencies": {
49
- "@animalabs/chronicle": "^0.3.0",
50
- "@animalabs/context-manager": "^0.8.0",
49
+ "@animalabs/chronicle": "^0.4.0",
50
+ "@animalabs/context-manager": "^0.9.2",
51
51
  "@animalabs/membrane": "^0.5.78",
52
52
  "chokidar": "^4.0.3",
53
53
  "discord.js": "^14.25.1",
package/src/agent.ts CHANGED
@@ -99,6 +99,11 @@ export class Agent {
99
99
  private _state: AgentState = { status: 'idle' };
100
100
  private _inferenceStartedAt = 0;
101
101
  private _streamId = 0;
102
+ /** kv-unified receipt flights opened by the CURRENT activation and not yet
103
+ * settled by a usage event. Held on the agent (not only in the stream's
104
+ * closure) so the next activation can close whatever its predecessor left
105
+ * open — see failOpenKvSubmissions. */
106
+ private kvOpenQueue: Array<{ submissionId: string; wireReceipt: CacheWireReceipt }> | null = null;
102
107
  lastStreamInputTokens = 0;
103
108
  /** Real prefix size of the last usage event: fresh + cache creation +
104
109
  * cache read. THE window-shaped number — `lastStreamInputTokens` alone
@@ -730,6 +735,19 @@ export class Agent {
730
735
  throw new Error(`Agent ${this.name} cannot start stream in state ${this._state.status}`);
731
736
  }
732
737
 
738
+ // A new activation supersedes every receipt flight the previous one left
739
+ // open. Membrane fires the kv-unified wire receipt per provider attempt,
740
+ // BEFORE the adapter call; only that attempt's usage event settles it.
741
+ // When the attempt dies without usage (transport error, idle timeout,
742
+ // framework cancel for a budget restart or endTurn) the flight stays open
743
+ // until the old driveStream's `finally` runs — and every successor path
744
+ // (error-policy retry, budget restart, the next wake after an abort)
745
+ // starts the new stream BEFORE that `finally`. The successor's first
746
+ // receipt then met the ledger's single-flight guard and failed the
747
+ // recovery itself: "kv-unified submission devops:46:…:4 is still in
748
+ // flight" (devops agent, 2026-09-16 07:33Z, no provider error logged).
749
+ this.failOpenKvSubmissions();
750
+
733
751
  this._streamId++;
734
752
  this._inferenceStartedAt = Date.now();
735
753
  this.lastStreamInputTokens = 0;
@@ -753,6 +771,7 @@ export class Agent {
753
771
  const kvQueue: Array<{ submissionId: string; wireReceipt: CacheWireReceipt }> = [];
754
772
  let kvCall = 0;
755
773
  if (kvEnabled) {
774
+ this.kvOpenQueue = kvQueue;
756
775
  const layoutHash = stableHash(request.messages);
757
776
  const kvRequest = request as NormalizedRequest & KvUnifiedRequestHooks;
758
777
  kvRequest.onCacheWireReceipt = (receipt) => {
@@ -791,6 +810,28 @@ export class Agent {
791
810
  };
792
811
  }
793
812
 
813
+ /** Close every kv-unified receipt flight the previous activation left
814
+ * unsettled. Idempotent: the framework's driveStream `finally` drains the
815
+ * same per-stream queue, so whichever runs first empties it and the other
816
+ * finds nothing. Failing an already-settled id is a no-op in the ledger. */
817
+ private failOpenKvSubmissions(): void {
818
+ const open = this.kvOpenQueue?.splice(0) ?? [];
819
+ this.kvOpenQueue = null;
820
+ if (open.length === 0) return;
821
+ const strategy = (this.contextManager as unknown as { getStrategy?: () => unknown })
822
+ .getStrategy?.() as { reportKvUnifiedFailed?: (submissionId: string) => void } | undefined;
823
+ for (const { submissionId } of open) {
824
+ console.error(
825
+ `[kv-unified] ${this.name}: closing receipt flight ${submissionId} left open by the previous activation`,
826
+ );
827
+ try {
828
+ strategy?.reportKvUnifiedFailed?.(submissionId);
829
+ } catch (err) {
830
+ console.error(`[kv-unified] ${this.name}: could not close flight ${submissionId}:`, err);
831
+ }
832
+ }
833
+ }
834
+
794
835
  /**
795
836
  * Transition to waiting_for_tools when stream yields tool calls.
796
837
  * Called by framework's driveStream.