groundswell 0.0.2 → 1.0.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/LICENSE +21 -0
- package/README.md +26 -9
- package/dist/cache/cache-key.d.ts +86 -0
- package/dist/cache/cache-key.d.ts.map +1 -0
- package/dist/cache/cache-key.js +204 -0
- package/dist/cache/cache-key.js.map +1 -0
- package/dist/cache/cache.d.ts +104 -0
- package/dist/cache/cache.d.ts.map +1 -0
- package/dist/cache/cache.js +179 -0
- package/dist/cache/cache.js.map +1 -0
- package/{src/cache/index.ts → dist/cache/index.d.ts} +1 -1
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/core/agent.d.ts +203 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +833 -0
- package/dist/core/agent.js.map +1 -0
- package/{src/core/context.ts → dist/core/context.d.ts} +16 -67
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +80 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/event-tree.d.ts +72 -0
- package/dist/core/event-tree.d.ts.map +1 -0
- package/dist/core/event-tree.js +211 -0
- package/dist/core/event-tree.js.map +1 -0
- package/{src/core/factory.ts → dist/core/factory.d.ts} +6 -27
- package/dist/core/factory.d.ts.map +1 -0
- package/dist/core/factory.js +110 -0
- package/dist/core/factory.js.map +1 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +2 -10
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +50 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +91 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/mcp-handler.d.ts +127 -0
- package/dist/core/mcp-handler.d.ts.map +1 -0
- package/dist/core/mcp-handler.js +323 -0
- package/dist/core/mcp-handler.js.map +1 -0
- package/dist/core/prompt.d.ts +80 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +120 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/workflow-context.d.ts +61 -0
- package/dist/core/workflow-context.d.ts.map +1 -0
- package/dist/core/workflow-context.js +358 -0
- package/dist/core/workflow-context.js.map +1 -0
- package/dist/core/workflow.d.ts +543 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +986 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/debugger/event-replayer.d.ts +422 -0
- package/dist/debugger/event-replayer.d.ts.map +1 -0
- package/dist/debugger/event-replayer.js +639 -0
- package/dist/debugger/event-replayer.js.map +1 -0
- package/dist/debugger/index.d.ts +2 -0
- package/dist/debugger/index.d.ts.map +1 -0
- package/{src/debugger/index.ts → dist/debugger/index.js} +1 -0
- package/dist/debugger/index.js.map +1 -0
- package/dist/debugger/tree-debugger.d.ts +240 -0
- package/dist/debugger/tree-debugger.d.ts.map +1 -0
- package/dist/debugger/tree-debugger.js +620 -0
- package/dist/debugger/tree-debugger.js.map +1 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/{src/decorators/index.ts → dist/decorators/index.js} +1 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/observed-state.d.ts +32 -0
- package/dist/decorators/observed-state.d.ts.map +1 -0
- package/dist/decorators/observed-state.js +79 -0
- package/dist/decorators/observed-state.js.map +1 -0
- package/dist/decorators/step.d.ts +15 -0
- package/dist/decorators/step.d.ts.map +1 -0
- package/dist/decorators/step.js +192 -0
- package/dist/decorators/step.js.map +1 -0
- package/dist/decorators/task.d.ts +50 -0
- package/dist/decorators/task.d.ts.map +1 -0
- package/dist/decorators/task.js +118 -0
- package/dist/decorators/task.js.map +1 -0
- package/dist/examples/index.d.ts +3 -0
- package/dist/examples/index.d.ts.map +1 -0
- package/{src/examples/index.ts → dist/examples/index.js} +1 -0
- package/dist/examples/index.js.map +1 -0
- package/dist/examples/tdd-orchestrator.d.ts +15 -0
- package/dist/examples/tdd-orchestrator.d.ts.map +1 -0
- package/dist/examples/tdd-orchestrator.js +121 -0
- package/dist/examples/tdd-orchestrator.js.map +1 -0
- package/dist/examples/test-cycle-workflow.d.ts +14 -0
- package/dist/examples/test-cycle-workflow.d.ts.map +1 -0
- package/dist/examples/test-cycle-workflow.js +116 -0
- package/dist/examples/test-cycle-workflow.js.map +1 -0
- package/dist/harnesses/claude-code-harness.d.ts +391 -0
- package/dist/harnesses/claude-code-harness.d.ts.map +1 -0
- package/dist/harnesses/claude-code-harness.js +1076 -0
- package/dist/harnesses/claude-code-harness.js.map +1 -0
- package/dist/harnesses/harness-registry.d.ts +440 -0
- package/dist/harnesses/harness-registry.d.ts.map +1 -0
- package/dist/harnesses/harness-registry.js +543 -0
- package/dist/harnesses/harness-registry.js.map +1 -0
- package/dist/harnesses/index.d.ts +12 -0
- package/dist/harnesses/index.d.ts.map +1 -0
- package/dist/harnesses/index.js +11 -0
- package/dist/harnesses/index.js.map +1 -0
- package/dist/harnesses/pi-harness.d.ts +219 -0
- package/dist/harnesses/pi-harness.d.ts.map +1 -0
- package/dist/harnesses/pi-harness.js +676 -0
- package/dist/harnesses/pi-harness.js.map +1 -0
- package/dist/harnesses/pi-schema-converter.d.ts +24 -0
- package/dist/harnesses/pi-schema-converter.d.ts.map +1 -0
- package/dist/harnesses/pi-schema-converter.js +81 -0
- package/dist/harnesses/pi-schema-converter.js.map +1 -0
- package/dist/harnesses/register-defaults.d.ts +24 -0
- package/dist/harnesses/register-defaults.d.ts.map +1 -0
- package/dist/harnesses/register-defaults.js +40 -0
- package/dist/harnesses/register-defaults.js.map +1 -0
- package/dist/harnesses/session-store.d.ts +201 -0
- package/dist/harnesses/session-store.d.ts.map +1 -0
- package/dist/harnesses/session-store.js +254 -0
- package/dist/harnesses/session-store.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/reflection/index.d.ts +5 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/{src/reflection/index.ts → dist/reflection/index.js} +1 -1
- package/dist/reflection/index.js.map +1 -0
- package/dist/reflection/reflection.d.ts +84 -0
- package/dist/reflection/reflection.d.ts.map +1 -0
- package/dist/reflection/reflection.js +344 -0
- package/dist/reflection/reflection.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/introspection.d.ts +165 -0
- package/dist/tools/introspection.d.ts.map +1 -0
- package/dist/tools/introspection.js +324 -0
- package/dist/tools/introspection.js.map +1 -0
- package/dist/types/agent.d.ts +1317 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +423 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/decorators.d.ts +40 -0
- package/dist/types/decorators.d.ts.map +1 -0
- package/dist/types/decorators.js +2 -0
- package/dist/types/decorators.js.map +1 -0
- package/dist/types/error-strategy.d.ts +13 -0
- package/dist/types/error-strategy.d.ts.map +1 -0
- package/dist/types/error-strategy.js +2 -0
- package/dist/types/error-strategy.js.map +1 -0
- package/dist/types/error.d.ts +20 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +2 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/events.d.ts +113 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/harnesses.d.ts +474 -0
- package/dist/types/harnesses.d.ts.map +1 -0
- package/dist/types/harnesses.js +2 -0
- package/dist/types/harnesses.js.map +1 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/logging.d.ts +24 -0
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/types/logging.js +2 -0
- package/dist/types/logging.js.map +1 -0
- package/dist/types/observer.d.ts +18 -0
- package/dist/types/observer.d.ts.map +1 -0
- package/dist/types/observer.js +2 -0
- package/dist/types/observer.js.map +1 -0
- package/dist/types/prompt.d.ts +31 -0
- package/dist/types/prompt.d.ts.map +1 -0
- package/dist/types/prompt.js +6 -0
- package/dist/types/prompt.js.map +1 -0
- package/dist/types/providers.d.ts +691 -0
- package/dist/types/providers.d.ts.map +1 -0
- package/dist/types/providers.js +14 -0
- package/dist/types/providers.js.map +1 -0
- package/dist/types/reflection.d.ts +96 -0
- package/dist/types/reflection.d.ts.map +1 -0
- package/dist/types/reflection.js +24 -0
- package/dist/types/reflection.js.map +1 -0
- package/dist/types/restart.d.ts +132 -0
- package/dist/types/restart.d.ts.map +1 -0
- package/dist/types/restart.js +2 -0
- package/dist/types/restart.js.map +1 -0
- package/dist/types/sdk-primitives.d.ts +118 -0
- package/dist/types/sdk-primitives.d.ts.map +1 -0
- package/dist/types/sdk-primitives.js +6 -0
- package/dist/types/sdk-primitives.js.map +1 -0
- package/{src/types/snapshot.ts → dist/types/snapshot.d.ts} +5 -5
- package/dist/types/snapshot.d.ts.map +1 -0
- package/dist/types/snapshot.js +2 -0
- package/dist/types/snapshot.js.map +1 -0
- package/dist/types/streaming.d.ts +194 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +67 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/workflow-context.d.ts +275 -0
- package/dist/types/workflow-context.d.ts.map +1 -0
- package/dist/types/workflow-context.js +8 -0
- package/dist/types/workflow-context.js.map +1 -0
- package/dist/types/workflow.d.ts +30 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/dist/types/workflow.js +2 -0
- package/dist/types/workflow.js.map +1 -0
- package/dist/utils/agent-validation.d.ts +88 -0
- package/dist/utils/agent-validation.d.ts.map +1 -0
- package/dist/utils/agent-validation.js +87 -0
- package/dist/utils/agent-validation.js.map +1 -0
- package/dist/utils/delay.d.ts +7 -0
- package/dist/utils/delay.d.ts.map +1 -0
- package/dist/utils/delay.js +9 -0
- package/dist/utils/delay.js.map +1 -0
- package/dist/utils/harness-config.d.ts +180 -0
- package/dist/utils/harness-config.d.ts.map +1 -0
- package/dist/utils/harness-config.js +311 -0
- package/dist/utils/harness-config.js.map +1 -0
- package/dist/utils/id.d.ts +6 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +12 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/model-spec.d.ts +110 -0
- package/dist/utils/model-spec.d.ts.map +1 -0
- package/dist/utils/model-spec.js +149 -0
- package/dist/utils/model-spec.js.map +1 -0
- package/dist/utils/observable.d.ts +54 -0
- package/dist/utils/observable.d.ts.map +1 -0
- package/dist/utils/observable.js +82 -0
- package/dist/utils/observable.js.map +1 -0
- package/dist/utils/provider-config.d.ts +10 -0
- package/dist/utils/provider-config.d.ts.map +1 -0
- package/dist/utils/provider-config.js +10 -0
- package/dist/utils/provider-config.js.map +1 -0
- package/dist/utils/restart-analysis.d.ts +202 -0
- package/dist/utils/restart-analysis.d.ts.map +1 -0
- package/dist/utils/restart-analysis.js +426 -0
- package/dist/utils/restart-analysis.js.map +1 -0
- package/dist/utils/session-serialization.d.ts +118 -0
- package/dist/utils/session-serialization.d.ts.map +1 -0
- package/dist/utils/session-serialization.js +217 -0
- package/dist/utils/session-serialization.js.map +1 -0
- package/dist/utils/workflow-error-utils.d.ts +22 -0
- package/dist/utils/workflow-error-utils.d.ts.map +1 -0
- package/dist/utils/workflow-error-utils.js +45 -0
- package/dist/utils/workflow-error-utils.js.map +1 -0
- package/package.json +34 -5
- package/.claude/commands/subtask-planning/prp-base-create.md +0 -120
- package/.claude/commands/subtask-planning/prp-base-execute.md +0 -65
- package/.claude/commands/task-breakdown.md +0 -94
- package/.claude/settings.local.json +0 -9
- package/.claude/system_prompts/task-breakdown.md +0 -101
- package/CHANGELOG.md +0 -188
- package/PRD.md +0 -543
- package/PRPs/001-hierarchical-workflow-engine.md +0 -2438
- package/PRPs/PRDs/002-agent-prompt.md +0 -390
- package/PRPs/PRDs/003-agent-prompt.md +0 -943
- package/PRPs/PRDs/004-agent-prompt.md +0 -1136
- package/PRPs/PRDs/tasks-001.json +0 -492
- package/PRPs/README.md +0 -83
- package/PRPs/templates/prp_base.md +0 -222
- package/docs/agent.md +0 -422
- package/docs/prompt.md +0 -419
- package/docs/workflow.md +0 -600
- package/examples/README.md +0 -258
- package/examples/examples/01-basic-workflow.ts +0 -100
- package/examples/examples/02-decorator-options.ts +0 -217
- package/examples/examples/03-parent-child.ts +0 -241
- package/examples/examples/04-observers-debugger.ts +0 -340
- package/examples/examples/05-error-handling.ts +0 -387
- package/examples/examples/06-concurrent-tasks.ts +0 -352
- package/examples/examples/07-agent-loops.ts +0 -432
- package/examples/examples/08-sdk-features.ts +0 -667
- package/examples/examples/09-reflection.ts +0 -573
- package/examples/examples/10-introspection.ts +0 -550
- package/examples/examples/11-reparenting-workflows.ts +0 -269
- package/examples/index.ts +0 -147
- package/examples/utils/helpers.ts +0 -57
- package/package-lock.json +0 -2398
- package/plan/001_d3bb02af4886/TEST_RESULTS.md +0 -259
- package/plan/001_d3bb02af4886/backlog.json +0 -867
- package/plan/001_d3bb02af4886/bug_fix_tasks.json +0 -484
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S1/PRP.md +0 -488
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S2/PRP.md +0 -581
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S3/PRP.md +0 -687
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S1/PRP.md +0 -492
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/PRP.md +0 -932
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/concurrent_error_testing_patterns.md +0 -1109
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/vitest_concurrent_testing.md +0 -802
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/workflow_engine_test_references.md +0 -603
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S1/PRP.md +0 -564
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S3/PRP.md +0 -518
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S4/PRP.md +0 -1252
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/PRP.md +0 -364
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/CODEBASE_INVENTORY.md +0 -114
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/DECORATOR_DOCUMENTATION_PATTERNS.md +0 -205
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/PRD_LOCATION_ANALYSIS.md +0 -199
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/ULTRATHINK_PRP_PLAN.md +0 -134
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/PRP.md +0 -495
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/research/console_error_inventory.md +0 -435
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S2/PRP.md +0 -506
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S3/PRP.md +0 -612
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/PRP.md +0 -558
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/research/external_research.md +0 -788
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S2/PRP.md +0 -460
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S3/PRP.md +0 -454
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/PRP.md +0 -520
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/RECOMMENDATION.md +0 -417
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/external_workflow_engines_research.md +0 -760
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/security_implications_analysis.md +0 -245
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S2/PRP.md +0 -792
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/PRP.md +0 -535
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/TEST_EXECUTION_REPORT.md +0 -190
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/PRP.md +0 -654
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/TEST_FIX_REPORT.md +0 -227
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/KEY_FINDINGS.md +0 -345
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/QUICK_REFERENCE.md +0 -193
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/test_maintenance_research.md +0 -1323
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/BREAKING_CHANGES_AUDIT.md +0 -1011
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/PRP.md +0 -927
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S2/PRP.md +0 -505
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/architecture/logger_child_signature_analysis.md +0 -401
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/child_implementation_research.md +0 -142
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/test_patterns_research.md +0 -112
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/vitest_patterns_research.md +0 -159
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/PRP.md +0 -549
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/VERIFICATION_REPORT.md +0 -368
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/edge_case_analysis.md +0 -172
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/usage_inventory.md +0 -175
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S2/PRP.md +0 -696
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S4/PRP.md +0 -860
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/PRP.md +0 -1066
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01-testing-aggregated-errors.md +0 -1103
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01_typescript_error_aggregation_patterns.md +0 -789
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02-error-merge-strategy-testing-guide.md +0 -1098
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02_aggregate_error_patterns.md +0 -1037
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03-promise-allsettled-testing-patterns.md +0 -916
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03_error_merging_strategies.md +0 -1045
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/04_github_stackoverflow_examples.md +0 -890
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/05_comprehensive_summary.md +0 -822
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/INDEX.md +0 -668
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/QUICK_REFERENCE.md +0 -706
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/README.md +0 -265
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/RESEARCH_REPORT.md +0 -655
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S4/research/vitest_testing_patterns.md +0 -1103
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T3S2/PRP.md +0 -426
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/PRP.md +0 -506
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/QUICK_REFERENCE.md +0 -114
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/RESEARCH_SUMMARY.md +0 -316
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/vitest_observer_error_logging_best_practices.md +0 -754
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S3/PRP.md +0 -612
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/PRP.md +0 -719
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/README.md +0 -215
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/analysis.md +0 -765
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S3/PRP.md +0 -718
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/DECISION.md +0 -149
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/PRP.md +0 -470
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/ULTRATHINK_PLAN.md +0 -332
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/codebase_workflow_name_analysis.md +0 -167
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/external_best_practices.md +0 -265
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/validation_patterns.md +0 -273
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S1/workflow_engine_ancestry_api_research.md +0 -760
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S3-PRP.md +0 -434
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S1/PRP.md +0 -717
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/PRP.md +0 -472
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/VALIDATION_REPORT.md +0 -125
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/research/ULTRATHINK_PRP_PLAN.md +0 -301
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/error-logging-best-practices.md +0 -1170
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/research_typescript_partial_and_overloads.md +0 -940
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-quick-reference.md +0 -151
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-research.md +0 -650
- package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/prd_snapshot.md +0 -259
- package/plan/001_d3bb02af4886/bugfix/P1M1T1S1/PRP.md +0 -457
- package/plan/001_d3bb02af4886/bugfix/RESEARCH_SUMMARY.md +0 -346
- package/plan/001_d3bb02af4886/bugfix/architecture/codebase_structure.md +0 -311
- package/plan/001_d3bb02af4886/bugfix/architecture/concurrent_execution_best_practices.md +0 -1565
- package/plan/001_d3bb02af4886/bugfix/architecture/error_handling_patterns.md +0 -288
- package/plan/001_d3bb02af4886/bugfix/architecture/promise_all_analysis.md +0 -741
- package/plan/001_d3bb02af4886/docs/PRP/P1M1T1S4-functional-workflow-error-state-capture-test.md +0 -652
- package/plan/001_d3bb02af4886/docs/PRP/P1P2-PRP.md +0 -527
- package/plan/001_d3bb02af4886/docs/PRP/P3P4-PRP.md +0 -1388
- package/plan/001_d3bb02af4886/docs/PRP/P4P5-PRP.md +0 -1136
- package/plan/001_d3bb02af4886/docs/PRP/PRP.md +0 -527
- package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S1-PRP.md +0 -415
- package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S2-PRP.md +0 -378
- package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S4-PRP.md +0 -713
- package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M2T1S4-PRP.md +0 -370
- package/plan/001_d3bb02af4886/docs/PRP_P1M3T1S3.md +0 -499
- package/plan/001_d3bb02af4886/docs/TEST_RESULTS.md +0 -230
- package/plan/001_d3bb02af4886/docs/architecture/external_deps.md +0 -358
- package/plan/001_d3bb02af4886/docs/architecture/system_context.md +0 -242
- package/plan/001_d3bb02af4886/docs/bugfix/ANALYSIS_PRD_VS_IMPLEMENTATION.md +0 -1134
- package/plan/001_d3bb02af4886/docs/bugfix/GAP_ANALYSIS_SUMMARY.md +0 -179
- package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/PRP.md +0 -629
- package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/validation-report.md +0 -214
- package/plan/001_d3bb02af4886/docs/bugfix/PRP_P1M4T2S3.md +0 -629
- package/plan/001_d3bb02af4886/docs/bugfix/bugfix_PRP.md +0 -529
- package/plan/001_d3bb02af4886/docs/bugfix/bugfix_QUICK_REFERENCE.md +0 -142
- package/plan/001_d3bb02af4886/docs/bugfix/bugfix_README.md +0 -304
- package/plan/001_d3bb02af4886/docs/bugfix/bugfix_TEST_RESULTS.md +0 -558
- package/plan/001_d3bb02af4886/docs/bugfix/bugfix_VALIDATION_SUMMARY.md +0 -256
- package/plan/001_d3bb02af4886/docs/bugfix/system_context.md +0 -346
- package/plan/001_d3bb02af4886/docs/bugfix-architecture/bug_analysis.md +0 -415
- package/plan/001_d3bb02af4886/docs/bugfix-architecture/implementation_patterns.md +0 -489
- package/plan/001_d3bb02af4886/docs/bugfix-architecture/system_context.md +0 -218
- package/plan/001_d3bb02af4886/docs/bugfix_INITIATION_SUMMARY.md +0 -380
- package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_PATTERNS.md +0 -1923
- package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_QUICK_REF.md +0 -319
- package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/codebase-context.md +0 -115
- package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/cycle-detection-algorithms.md +0 -134
- package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/test-patterns.md +0 -153
- package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/workflow-class.md +0 -132
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_BEST_PRACTICES.md +0 -716
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_QUICK_REF.md +0 -186
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/GROUNDSWELL_DECORATOR_EXAMPLES.md +0 -604
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/INDEX.md +0 -213
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/codebase_structure.md +0 -30
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/existing_test_pattern.md +0 -56
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/getRootObservers_implementation.md +0 -53
- package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/test_conventions.md +0 -49
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/PRP.md +0 -958
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/QUICK_REFERENCE.md +0 -339
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/README.md +0 -305
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/SUMMARY.md +0 -433
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/bidirectional-tree-consistency-testing.md +0 -1574
- package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/test-pattern-examples.md +0 -1014
- package/plan/001_d3bb02af4886/docs/research/P1P2/LRU_CACHE_BEST_PRACTICES.md +0 -1929
- package/plan/001_d3bb02af4886/docs/research/P1P2/LRU_CACHE_CODE_PATTERNS.md +0 -857
- package/plan/001_d3bb02af4886/docs/research/P1P2/LRU_CACHE_INTEGRATION_GUIDE.md +0 -738
- package/plan/001_d3bb02af4886/docs/research/P1P2/LRU_CACHE_RESEARCH_INDEX.md +0 -424
- package/plan/001_d3bb02af4886/docs/research/P1P2/REFLECTION_INDEX.md +0 -291
- package/plan/001_d3bb02af4886/docs/research/P1P2/REFLECTION_RESEARCH_REPORT.md +0 -1342
- package/plan/001_d3bb02af4886/docs/research/P1P2/RESEARCH_SUMMARY.md +0 -342
- package/plan/001_d3bb02af4886/docs/research/P1P2/anthropic-sdk.md +0 -174
- package/plan/001_d3bb02af4886/docs/research/P1P2/async-local-storage.md +0 -200
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-code-patterns.md +0 -1205
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-decision-matrix.md +0 -421
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-implementation-guide.md +0 -1341
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-integration-guide.md +0 -834
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-patterns.md +0 -1468
- package/plan/001_d3bb02af4886/docs/research/P1P2/reflection-quick-reference.md +0 -558
- package/plan/001_d3bb02af4886/docs/research/P1P2/zod-schema.md +0 -152
- package/plan/001_d3bb02af4886/docs/research/P3P4/caching-lru.md +0 -116
- package/plan/001_d3bb02af4886/docs/research/P3P4/introspection-tools.md +0 -177
- package/plan/001_d3bb02af4886/docs/research/P3P4/reflection-patterns.md +0 -117
- package/plan/001_d3bb02af4886/docs/research/P4P5/RESEARCH_SUMMARY.md +0 -151
- package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_QUICK_REF.md +0 -376
- package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_RESEARCH.md +0 -1507
- package/plan/001_d3bb02af4886/docs/research/bugfix_typescript_patterns.md +0 -949
- package/plan/001_d3bb02af4886/docs/research/error-testing-research.md +0 -619
- package/plan/001_d3bb02af4886/docs/research/error_handling_patterns.md +0 -723
- package/plan/001_d3bb02af4886/docs/research/general/INTROSPECTION_RESEARCH_SUMMARY.md +0 -378
- package/plan/001_d3bb02af4886/docs/research/general/README-INTROSPECTION.md +0 -352
- package/plan/001_d3bb02af4886/docs/research/general/agent-introspection-patterns.md +0 -1085
- package/plan/001_d3bb02af4886/docs/research/general/introspection-security-guide.md +0 -984
- package/plan/001_d3bb02af4886/docs/research/general/introspection-tool-examples.md +0 -875
- package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/PRP_TEMPLATE.md +0 -460
- package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/QUICK_REFERENCE.md +0 -324
- package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/README.md +0 -175
- package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/RESEARCH_REPORT.md +0 -499
- package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/SUMMARY.md +0 -163
- package/plan/001_d3bb02af4886/prd_snapshot.md +0 -543
- package/plan/bugfix/BUG_FIX_SUMMARY.md +0 -961
- package/scripts/generate-llms-full.ts +0 -206
- package/src/__tests__/adversarial/attachChild-performance.test.ts +0 -216
- package/src/__tests__/adversarial/circular-reference.test.ts +0 -101
- package/src/__tests__/adversarial/complex-circular-reference.test.ts +0 -139
- package/src/__tests__/adversarial/concurrent-task-failures.test.ts +0 -571
- package/src/__tests__/adversarial/deep-analysis.test.ts +0 -729
- package/src/__tests__/adversarial/deep-hierarchy-stress.test.ts +0 -213
- package/src/__tests__/adversarial/e2e-prd-validation.test.ts +0 -448
- package/src/__tests__/adversarial/edge-case.test.ts +0 -703
- package/src/__tests__/adversarial/error-merge-strategy.test.ts +0 -760
- package/src/__tests__/adversarial/incremental-performance.test.ts +0 -140
- package/src/__tests__/adversarial/node-map-update-benchmarks.test.ts +0 -457
- package/src/__tests__/adversarial/observer-propagation.test.ts +0 -487
- package/src/__tests__/adversarial/parent-validation.test.ts +0 -143
- package/src/__tests__/adversarial/prd-12-2-compliance.test.ts +0 -611
- package/src/__tests__/adversarial/prd-compliance.test.ts +0 -731
- package/src/__tests__/compatibility/backward-compatibility.test.ts +0 -1572
- package/src/__tests__/helpers/index.ts +0 -18
- package/src/__tests__/helpers/tree-verification.ts +0 -257
- package/src/__tests__/integration/agent-workflow.test.ts +0 -256
- package/src/__tests__/integration/bidirectional-consistency.test.ts +0 -847
- package/src/__tests__/integration/observer-logging.test.ts +0 -643
- package/src/__tests__/integration/tree-mirroring.test.ts +0 -151
- package/src/__tests__/integration/workflow-reparenting.test.ts +0 -303
- package/src/__tests__/unit/agent.test.ts +0 -169
- package/src/__tests__/unit/cache-key.test.ts +0 -182
- package/src/__tests__/unit/cache.test.ts +0 -172
- package/src/__tests__/unit/context.test.ts +0 -217
- package/src/__tests__/unit/decorators.test.ts +0 -100
- package/src/__tests__/unit/introspection-tools.test.ts +0 -277
- package/src/__tests__/unit/logger.test.ts +0 -293
- package/src/__tests__/unit/observable.test.ts +0 -321
- package/src/__tests__/unit/prompt.test.ts +0 -135
- package/src/__tests__/unit/reflection.test.ts +0 -210
- package/src/__tests__/unit/tree-debugger-incremental.test.ts +0 -170
- package/src/__tests__/unit/tree-debugger.test.ts +0 -85
- package/src/__tests__/unit/utils/workflow-error-utils.test.ts +0 -209
- package/src/__tests__/unit/workflow-detachChild.test.ts +0 -100
- package/src/__tests__/unit/workflow-emitEvent-childDetached.test.ts +0 -153
- package/src/__tests__/unit/workflow-isDescendantOf.test.ts +0 -180
- package/src/__tests__/unit/workflow.test.ts +0 -357
- package/src/cache/cache-key.ts +0 -244
- package/src/cache/cache.ts +0 -236
- package/src/core/agent.ts +0 -593
- package/src/core/event-tree.ts +0 -260
- package/src/core/logger.ts +0 -112
- package/src/core/mcp-handler.ts +0 -184
- package/src/core/prompt.ts +0 -150
- package/src/core/workflow-context.ts +0 -351
- package/src/core/workflow.ts +0 -540
- package/src/debugger/tree-debugger.ts +0 -255
- package/src/decorators/observed-state.ts +0 -95
- package/src/decorators/step.ts +0 -139
- package/src/decorators/task.ts +0 -159
- package/src/examples/tdd-orchestrator.ts +0 -65
- package/src/examples/test-cycle-workflow.ts +0 -64
- package/src/index.ts +0 -142
- package/src/reflection/reflection.ts +0 -407
- package/src/tools/index.ts +0 -36
- package/src/tools/introspection.ts +0 -464
- package/src/types/agent.ts +0 -90
- package/src/types/decorators.ts +0 -32
- package/src/types/error-strategy.ts +0 -13
- package/src/types/error.ts +0 -20
- package/src/types/events.ts +0 -75
- package/src/types/index.ts +0 -55
- package/src/types/logging.ts +0 -24
- package/src/types/observer.ts +0 -18
- package/src/types/prompt.ts +0 -40
- package/src/types/reflection.ts +0 -117
- package/src/types/sdk-primitives.ts +0 -128
- package/src/types/workflow-context.ts +0 -163
- package/src/types/workflow.ts +0 -37
- package/src/utils/id.ts +0 -11
- package/src/utils/index.ts +0 -4
- package/src/utils/observable.ts +0 -106
- package/src/utils/workflow-error-utils.ts +0 -56
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Groundswell Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Hierarchical workflow orchestration engine with full observability.
|
|
|
8
8
|
npm install groundswell
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
**Requirements:** Node.js
|
|
11
|
+
**Requirements:** Node.js 20+, TypeScript 5.2+
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
@@ -61,30 +61,41 @@ const result = await workflow.run();
|
|
|
61
61
|
|
|
62
62
|
### Agent with Prompt
|
|
63
63
|
|
|
64
|
+
> [!IMPORTANT]
|
|
65
|
+
> Groundswell v2.0: `agent.prompt()` now returns `AgentResponse<T>`.
|
|
66
|
+
> See the [Migration Guide](docs/migration-guide-agent-response.md) if upgrading.
|
|
67
|
+
|
|
64
68
|
```typescript
|
|
65
69
|
import { createAgent, createPrompt } from 'groundswell';
|
|
66
70
|
import { z } from 'zod';
|
|
67
71
|
|
|
68
|
-
const agent = createAgent({
|
|
69
|
-
name: 'AnalysisAgent',
|
|
70
|
-
enableCache: true,
|
|
71
|
-
});
|
|
72
|
+
const agent = createAgent({ name: 'AnalysisAgent' });
|
|
72
73
|
|
|
73
74
|
const prompt = createPrompt({
|
|
74
|
-
user: 'Analyze this code
|
|
75
|
-
data: { code: 'function foo() { return 42; }' },
|
|
75
|
+
user: 'Analyze this code',
|
|
76
76
|
responseFormat: z.object({
|
|
77
77
|
bugs: z.array(z.string()),
|
|
78
78
|
severity: z.enum(['low', 'medium', 'high']),
|
|
79
79
|
}),
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
const
|
|
83
|
-
|
|
82
|
+
const response = await agent.prompt(prompt);
|
|
83
|
+
if (response.status === 'error') {
|
|
84
|
+
throw new Error(response.error.message);
|
|
85
|
+
}
|
|
86
|
+
console.log(response.data.bugs);
|
|
84
87
|
```
|
|
85
88
|
|
|
89
|
+
**Why AgentResponse?**
|
|
90
|
+
- Type-safe validated responses with error handling
|
|
91
|
+
- Observable metadata (tokens, timing, cache hits)
|
|
92
|
+
- Consistent API across all agent operations
|
|
93
|
+
|
|
86
94
|
## Documentation
|
|
87
95
|
|
|
96
|
+
- [Migration Guide](docs/migration-guide-agent-response.md) - Upgrading from v1.x ⚠️
|
|
97
|
+
- [Harnesses](docs/harnesses.md) - Pluggable agent runtime (pi default, claude-code optional)
|
|
98
|
+
- [Provider → Harness Migration](docs/migration-provider-to-harness.md) - v1.2 vocabulary migration
|
|
88
99
|
- [Workflows](docs/workflow.md) - Hierarchical task orchestration
|
|
89
100
|
- [Agents](docs/agent.md) - LLM execution with caching and reflection
|
|
90
101
|
- [Prompts](docs/prompt.md) - Type-safe prompt definitions with Zod
|
|
@@ -301,6 +312,12 @@ See [examples/](examples/) for source code.
|
|
|
301
312
|
|
|
302
313
|
Contributions and issues are welcome.
|
|
303
314
|
|
|
315
|
+
### Releasing
|
|
316
|
+
|
|
317
|
+
Releases are automated with [release-please](https://github.com/googleapis/release-please). When `feat:` / `fix:` / `BREAKING CHANGE` commits land on `main`, release-please opens a release PR that bumps the version, updates `CHANGELOG.md`, and tags a release. Merging that PR publishes to npm.
|
|
318
|
+
|
|
319
|
+
One-time setup: add an **`NPM_TOKEN`** secret to the repository (an npm *automation* access token, or a granular access token with publish permission).
|
|
320
|
+
|
|
304
321
|
## Support
|
|
305
322
|
|
|
306
323
|
If Groundswell helps you build something great, consider fueling future development:
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Key Generation - Deterministic key generation for LLM response caching
|
|
3
|
+
*
|
|
4
|
+
* Uses SHA-256 hashing with deterministic JSON serialization to ensure
|
|
5
|
+
* identical inputs always produce identical cache keys.
|
|
6
|
+
*/
|
|
7
|
+
import type { Tool, MCPServer, Skill } from '../types/index.js';
|
|
8
|
+
import type { HarnessId, ModelProviderId } from '../types/harnesses.js';
|
|
9
|
+
import type { z } from 'zod';
|
|
10
|
+
/**
|
|
11
|
+
* Inputs used to generate a cache key
|
|
12
|
+
*/
|
|
13
|
+
export interface CacheKeyInputs {
|
|
14
|
+
/** User message content */
|
|
15
|
+
user: string;
|
|
16
|
+
/** Data passed to the prompt */
|
|
17
|
+
data?: Record<string, unknown>;
|
|
18
|
+
/** System prompt */
|
|
19
|
+
system?: string;
|
|
20
|
+
/** Model identifier */
|
|
21
|
+
model: string;
|
|
22
|
+
/**
|
|
23
|
+
* Agent runtime identifier (PRD §7.2 / §7.14.5 cache isolation).
|
|
24
|
+
*
|
|
25
|
+
* Optional during the harness migration window: the Agent cache build-site (P3.M1.T2.S3)
|
|
26
|
+
* does not yet pass it, so omitting it preserves the pre-task key. Once P3.M1.T2.S3 rewires
|
|
27
|
+
* `agent.ts` to always pass the resolved harness, this field may be tightened to required.
|
|
28
|
+
* When provided, it becomes a component of the SHA-256 cache key so `pi` and `claude-code`
|
|
29
|
+
* runs never share cache entries.
|
|
30
|
+
*/
|
|
31
|
+
harness?: HarnessId;
|
|
32
|
+
/**
|
|
33
|
+
* LLM host / model provider (PRD §7.8 / §7.14.5 cache isolation).
|
|
34
|
+
*
|
|
35
|
+
* The LLM-vendor axis (NOT the harness) — e.g. 'anthropic', 'openai', 'google', 'zai', or
|
|
36
|
+
* any open-set provider string. Optional; resolved from the ModelSpec. When provided, it
|
|
37
|
+
* becomes a component of the SHA-256 cache key so provider-qualified models with colliding
|
|
38
|
+
* bare ids get distinct entries.
|
|
39
|
+
*/
|
|
40
|
+
provider?: ModelProviderId;
|
|
41
|
+
/** Temperature setting */
|
|
42
|
+
temperature?: number;
|
|
43
|
+
/** Maximum tokens */
|
|
44
|
+
maxTokens?: number;
|
|
45
|
+
/** Tools available to the agent */
|
|
46
|
+
tools?: Tool[];
|
|
47
|
+
/** MCP servers */
|
|
48
|
+
mcps?: MCPServer[];
|
|
49
|
+
/** Skills */
|
|
50
|
+
skills?: Skill[];
|
|
51
|
+
/** Zod response format schema */
|
|
52
|
+
responseFormat?: z.ZodType;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Deterministically stringify a value with sorted object keys
|
|
56
|
+
*
|
|
57
|
+
* Unlike JSON.stringify, this function guarantees consistent output
|
|
58
|
+
* regardless of key insertion order by sorting all object keys.
|
|
59
|
+
*
|
|
60
|
+
* @param value - Value to stringify
|
|
61
|
+
* @returns Deterministic JSON string
|
|
62
|
+
* @throws TypeError if circular reference detected
|
|
63
|
+
*/
|
|
64
|
+
export declare function deterministicStringify(value: unknown): string;
|
|
65
|
+
/**
|
|
66
|
+
* Generate a hash from a Zod schema's internal definition
|
|
67
|
+
*
|
|
68
|
+
* Zod schemas are functions that cannot be directly serialized.
|
|
69
|
+
* This extracts the schema's _def property which contains the
|
|
70
|
+
* schema structure and hashes it.
|
|
71
|
+
*
|
|
72
|
+
* @param schema - Zod schema to hash
|
|
73
|
+
* @returns SHA-256 hex digest of the schema definition
|
|
74
|
+
*/
|
|
75
|
+
export declare function getSchemaHash(schema: z.ZodType | undefined): string;
|
|
76
|
+
/**
|
|
77
|
+
* Generate a deterministic cache key from prompt execution inputs
|
|
78
|
+
*
|
|
79
|
+
* The key is a 64-character SHA-256 hex digest that uniquely identifies
|
|
80
|
+
* a specific combination of prompt, data, configuration, and tools.
|
|
81
|
+
*
|
|
82
|
+
* @param inputs - Cache key inputs
|
|
83
|
+
* @returns 64-character hex SHA-256 digest
|
|
84
|
+
*/
|
|
85
|
+
export declare function generateCacheKey(inputs: CacheKeyInputs): string;
|
|
86
|
+
//# sourceMappingURL=cache-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.d.ts","sourceRoot":"","sources":["../../src/cache/cache-key.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,oBAAoB;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,kBAAkB;IAClB,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;IACnB,aAAa;IACb,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,iCAAiC;IACjC,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA2D7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,MAAM,CAqBnE;AAoDD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAqD/D"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Key Generation - Deterministic key generation for LLM response caching
|
|
3
|
+
*
|
|
4
|
+
* Uses SHA-256 hashing with deterministic JSON serialization to ensure
|
|
5
|
+
* identical inputs always produce identical cache keys.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
/**
|
|
9
|
+
* Deterministically stringify a value with sorted object keys
|
|
10
|
+
*
|
|
11
|
+
* Unlike JSON.stringify, this function guarantees consistent output
|
|
12
|
+
* regardless of key insertion order by sorting all object keys.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Value to stringify
|
|
15
|
+
* @returns Deterministic JSON string
|
|
16
|
+
* @throws TypeError if circular reference detected
|
|
17
|
+
*/
|
|
18
|
+
export function deterministicStringify(value) {
|
|
19
|
+
const seen = new WeakSet();
|
|
20
|
+
function stringify(val) {
|
|
21
|
+
if (val === null)
|
|
22
|
+
return 'null';
|
|
23
|
+
if (val === undefined)
|
|
24
|
+
return 'undefined';
|
|
25
|
+
if (typeof val === 'string')
|
|
26
|
+
return JSON.stringify(val);
|
|
27
|
+
if (typeof val === 'number') {
|
|
28
|
+
if (Number.isNaN(val))
|
|
29
|
+
return 'NaN';
|
|
30
|
+
if (!Number.isFinite(val))
|
|
31
|
+
return val > 0 ? 'Infinity' : '-Infinity';
|
|
32
|
+
return String(val);
|
|
33
|
+
}
|
|
34
|
+
if (typeof val === 'boolean')
|
|
35
|
+
return String(val);
|
|
36
|
+
if (typeof val === 'function')
|
|
37
|
+
return 'function';
|
|
38
|
+
if (typeof val === 'symbol')
|
|
39
|
+
return 'symbol';
|
|
40
|
+
if (typeof val === 'bigint')
|
|
41
|
+
return `${val}n`;
|
|
42
|
+
if (typeof val === 'object') {
|
|
43
|
+
if (seen.has(val)) {
|
|
44
|
+
throw new TypeError('Converting circular structure to JSON');
|
|
45
|
+
}
|
|
46
|
+
seen.add(val);
|
|
47
|
+
let result;
|
|
48
|
+
if (Array.isArray(val)) {
|
|
49
|
+
result = '[' + val.map(stringify).join(',') + ']';
|
|
50
|
+
}
|
|
51
|
+
else if (val instanceof Date) {
|
|
52
|
+
result = JSON.stringify(val.toISOString());
|
|
53
|
+
}
|
|
54
|
+
else if (val instanceof Map) {
|
|
55
|
+
const entries = Array.from(val.entries())
|
|
56
|
+
.sort(([a], [b]) => String(a).localeCompare(String(b)))
|
|
57
|
+
.map(([k, v]) => `[${stringify(k)},${stringify(v)}]`);
|
|
58
|
+
result = `Map{${entries.join(',')}}`;
|
|
59
|
+
}
|
|
60
|
+
else if (val instanceof Set) {
|
|
61
|
+
const values = Array.from(val)
|
|
62
|
+
.map(stringify)
|
|
63
|
+
.sort();
|
|
64
|
+
result = `Set{${values.join(',')}}`;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Regular object - sort keys
|
|
68
|
+
const keys = Object.keys(val).sort();
|
|
69
|
+
const pairs = keys.map((k) => JSON.stringify(k) +
|
|
70
|
+
':' +
|
|
71
|
+
stringify(val[k]));
|
|
72
|
+
result = '{' + pairs.join(',') + '}';
|
|
73
|
+
}
|
|
74
|
+
seen.delete(val);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
return String(val);
|
|
78
|
+
}
|
|
79
|
+
return stringify(value);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generate a hash from a Zod schema's internal definition
|
|
83
|
+
*
|
|
84
|
+
* Zod schemas are functions that cannot be directly serialized.
|
|
85
|
+
* This extracts the schema's _def property which contains the
|
|
86
|
+
* schema structure and hashes it.
|
|
87
|
+
*
|
|
88
|
+
* @param schema - Zod schema to hash
|
|
89
|
+
* @returns SHA-256 hex digest of the schema definition
|
|
90
|
+
*/
|
|
91
|
+
export function getSchemaHash(schema) {
|
|
92
|
+
if (!schema) {
|
|
93
|
+
return 'no-schema';
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
// Access Zod's internal _def property
|
|
97
|
+
const def = schema._def;
|
|
98
|
+
if (!def) {
|
|
99
|
+
return 'unknown-schema';
|
|
100
|
+
}
|
|
101
|
+
// Create a simplified representation of the schema
|
|
102
|
+
const schemaRep = extractSchemaStructure(def);
|
|
103
|
+
const serialized = deterministicStringify(schemaRep);
|
|
104
|
+
return createHash('sha256').update(serialized, 'utf8').digest('hex');
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Fallback for schemas that can't be introspected
|
|
108
|
+
return 'fallback-schema';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extract a serializable structure from a Zod schema definition
|
|
113
|
+
*/
|
|
114
|
+
function extractSchemaStructure(def) {
|
|
115
|
+
if (def === null || def === undefined) {
|
|
116
|
+
return def;
|
|
117
|
+
}
|
|
118
|
+
if (typeof def !== 'object') {
|
|
119
|
+
return def;
|
|
120
|
+
}
|
|
121
|
+
const typedDef = def;
|
|
122
|
+
const result = {};
|
|
123
|
+
// Extract key properties that define schema structure
|
|
124
|
+
if ('typeName' in typedDef) {
|
|
125
|
+
result.typeName = typedDef.typeName;
|
|
126
|
+
}
|
|
127
|
+
if ('shape' in typedDef && typeof typedDef.shape === 'function') {
|
|
128
|
+
// Object schema - extract shape
|
|
129
|
+
try {
|
|
130
|
+
const shape = typedDef.shape();
|
|
131
|
+
result.shape = Object.fromEntries(Object.entries(shape).map(([key, value]) => [
|
|
132
|
+
key,
|
|
133
|
+
extractSchemaStructure(value?._def),
|
|
134
|
+
]));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
result.shape = 'complex-shape';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if ('type' in typedDef && typedDef.type && typeof typedDef.type === 'object') {
|
|
141
|
+
result.type = extractSchemaStructure(typedDef.type._def);
|
|
142
|
+
}
|
|
143
|
+
if ('values' in typedDef) {
|
|
144
|
+
result.values = typedDef.values;
|
|
145
|
+
}
|
|
146
|
+
if ('checks' in typedDef && Array.isArray(typedDef.checks)) {
|
|
147
|
+
result.checks = typedDef.checks.map((check) => check.kind);
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Generate a deterministic cache key from prompt execution inputs
|
|
153
|
+
*
|
|
154
|
+
* The key is a 64-character SHA-256 hex digest that uniquely identifies
|
|
155
|
+
* a specific combination of prompt, data, configuration, and tools.
|
|
156
|
+
*
|
|
157
|
+
* @param inputs - Cache key inputs
|
|
158
|
+
* @returns 64-character hex SHA-256 digest
|
|
159
|
+
*/
|
|
160
|
+
export function generateCacheKey(inputs) {
|
|
161
|
+
// Build normalized representation with sorted arrays
|
|
162
|
+
const normalized = {
|
|
163
|
+
user: inputs.user,
|
|
164
|
+
model: inputs.model,
|
|
165
|
+
};
|
|
166
|
+
// PRD §7.14.5: incorporate the harness + provider axes for cross-harness/provider isolation.
|
|
167
|
+
// Conditional append (matches the optional-field pattern below) — omitting them yields the
|
|
168
|
+
// exact pre-task key, so the Agent build-site stays green until P3.M1.T2.S3 rewires it.
|
|
169
|
+
if (inputs.harness !== undefined) {
|
|
170
|
+
normalized.harness = inputs.harness;
|
|
171
|
+
}
|
|
172
|
+
if (inputs.provider !== undefined) {
|
|
173
|
+
normalized.provider = inputs.provider;
|
|
174
|
+
}
|
|
175
|
+
// Include optional fields only if defined
|
|
176
|
+
if (inputs.data !== undefined) {
|
|
177
|
+
normalized.data = inputs.data;
|
|
178
|
+
}
|
|
179
|
+
if (inputs.system !== undefined) {
|
|
180
|
+
normalized.system = inputs.system;
|
|
181
|
+
}
|
|
182
|
+
if (inputs.temperature !== undefined) {
|
|
183
|
+
normalized.temperature = inputs.temperature;
|
|
184
|
+
}
|
|
185
|
+
if (inputs.maxTokens !== undefined) {
|
|
186
|
+
normalized.maxTokens = inputs.maxTokens;
|
|
187
|
+
}
|
|
188
|
+
// Sort tool/mcp/skill names for determinism
|
|
189
|
+
if (inputs.tools && inputs.tools.length > 0) {
|
|
190
|
+
normalized.tools = inputs.tools.map((t) => t.name).sort();
|
|
191
|
+
}
|
|
192
|
+
if (inputs.mcps && inputs.mcps.length > 0) {
|
|
193
|
+
normalized.mcps = inputs.mcps.map((m) => m.name).sort();
|
|
194
|
+
}
|
|
195
|
+
if (inputs.skills && inputs.skills.length > 0) {
|
|
196
|
+
normalized.skills = inputs.skills.map((s) => s.name).sort();
|
|
197
|
+
}
|
|
198
|
+
// Include schema hash
|
|
199
|
+
normalized.schemaHash = getSchemaHash(inputs.responseFormat);
|
|
200
|
+
// Generate SHA-256 hash
|
|
201
|
+
const serialized = deterministicStringify(normalized);
|
|
202
|
+
return createHash('sha256').update(serialized, 'utf8').digest('hex');
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=cache-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.js","sourceRoot":"","sources":["../../src/cache/cache-key.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,O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UAAU,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5D,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,UAAU,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1D,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9D,CAAC;IAED,sBAAsB;IACtB,UAAU,CAAC,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAE7D,wBAAwB;IACxB,MAAM,UAAU,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;IACtD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLMCache - LRU cache for LLM responses with size and TTL limits
|
|
3
|
+
*
|
|
4
|
+
* Wraps the lru-cache package to provide:
|
|
5
|
+
* - Item count limits
|
|
6
|
+
* - Memory size limits
|
|
7
|
+
* - Time-based expiration (TTL)
|
|
8
|
+
* - Prefix-based cache busting for related entries
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Cache configuration options
|
|
12
|
+
*/
|
|
13
|
+
export interface CacheConfig {
|
|
14
|
+
/** Maximum number of items in cache (default: 1000) */
|
|
15
|
+
maxItems?: number;
|
|
16
|
+
/** Maximum cache size in bytes (default: 50MB) */
|
|
17
|
+
maxSizeBytes?: number;
|
|
18
|
+
/** Default TTL in milliseconds (default: 1 hour) */
|
|
19
|
+
defaultTTLMs?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Cache performance metrics
|
|
23
|
+
*/
|
|
24
|
+
export interface CacheMetrics {
|
|
25
|
+
/** Number of cache hits */
|
|
26
|
+
hits: number;
|
|
27
|
+
/** Number of cache misses */
|
|
28
|
+
misses: number;
|
|
29
|
+
/** Current number of items in cache */
|
|
30
|
+
size: number;
|
|
31
|
+
/** Current cache size in bytes (estimated) */
|
|
32
|
+
sizeBytes: number;
|
|
33
|
+
/** Hit rate percentage */
|
|
34
|
+
hitRate: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* LLMCache - High-performance LRU cache for LLM responses
|
|
38
|
+
*/
|
|
39
|
+
export declare class LLMCache<T = unknown> {
|
|
40
|
+
private readonly cache;
|
|
41
|
+
private readonly prefixIndex;
|
|
42
|
+
private readonly config;
|
|
43
|
+
private hitCount;
|
|
44
|
+
private missCount;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new LLMCache instance
|
|
47
|
+
* @param config Cache configuration
|
|
48
|
+
*/
|
|
49
|
+
constructor(config?: CacheConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Get a value from the cache
|
|
52
|
+
* @param key Cache key
|
|
53
|
+
* @returns Cached value or undefined if not found
|
|
54
|
+
*/
|
|
55
|
+
get(key: string): Promise<T | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Set a value in the cache
|
|
58
|
+
* @param key Cache key
|
|
59
|
+
* @param value Value to cache
|
|
60
|
+
* @param options Optional TTL override and prefix for grouping
|
|
61
|
+
*/
|
|
62
|
+
set(key: string, value: T, options?: {
|
|
63
|
+
ttl?: number;
|
|
64
|
+
prefix?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a key exists in the cache (without affecting LRU order)
|
|
68
|
+
* @param key Cache key
|
|
69
|
+
* @returns True if key exists
|
|
70
|
+
*/
|
|
71
|
+
has(key: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Remove a specific key from the cache
|
|
74
|
+
* @param key Cache key to remove
|
|
75
|
+
*/
|
|
76
|
+
bust(key: string): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Remove all keys with a given prefix
|
|
79
|
+
* @param prefix Prefix to match
|
|
80
|
+
*/
|
|
81
|
+
bustPrefix(prefix: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Clear the entire cache
|
|
84
|
+
*/
|
|
85
|
+
clear(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Get cache performance metrics
|
|
88
|
+
* @returns Current cache metrics
|
|
89
|
+
*/
|
|
90
|
+
metrics(): CacheMetrics;
|
|
91
|
+
/**
|
|
92
|
+
* Get the number of items in the cache
|
|
93
|
+
*/
|
|
94
|
+
get size(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Get all keys in the cache
|
|
97
|
+
*/
|
|
98
|
+
keys(): IterableIterator<string>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Default singleton cache instance
|
|
102
|
+
*/
|
|
103
|
+
export declare const defaultCache: LLMCache<unknown>;
|
|
104
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,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ACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;CAGjC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,mBAAiB,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLMCache - LRU cache for LLM responses with size and TTL limits
|
|
3
|
+
*
|
|
4
|
+
* Wraps the lru-cache package to provide:
|
|
5
|
+
* - Item count limits
|
|
6
|
+
* - Memory size limits
|
|
7
|
+
* - Time-based expiration (TTL)
|
|
8
|
+
* - Prefix-based cache busting for related entries
|
|
9
|
+
*/
|
|
10
|
+
import { LRUCache } from 'lru-cache';
|
|
11
|
+
/**
|
|
12
|
+
* LLMCache - High-performance LRU cache for LLM responses
|
|
13
|
+
*/
|
|
14
|
+
export class LLMCache {
|
|
15
|
+
cache;
|
|
16
|
+
prefixIndex;
|
|
17
|
+
config;
|
|
18
|
+
hitCount = 0;
|
|
19
|
+
missCount = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new LLMCache instance
|
|
22
|
+
* @param config Cache configuration
|
|
23
|
+
*/
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = {
|
|
26
|
+
maxItems: config.maxItems ?? 1000,
|
|
27
|
+
maxSizeBytes: config.maxSizeBytes ?? 52_428_800, // 50MB
|
|
28
|
+
defaultTTLMs: config.defaultTTLMs ?? 3_600_000, // 1 hour
|
|
29
|
+
};
|
|
30
|
+
this.prefixIndex = new Map();
|
|
31
|
+
this.cache = new LRUCache({
|
|
32
|
+
max: this.config.maxItems,
|
|
33
|
+
maxSize: this.config.maxSizeBytes,
|
|
34
|
+
sizeCalculation: (entry) => {
|
|
35
|
+
// Estimate size based on JSON serialization
|
|
36
|
+
try {
|
|
37
|
+
return JSON.stringify(entry.value).length;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Fallback for non-serializable values
|
|
41
|
+
return 1000;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
ttl: this.config.defaultTTLMs,
|
|
45
|
+
updateAgeOnGet: true,
|
|
46
|
+
allowStale: false,
|
|
47
|
+
dispose: (entry, key) => {
|
|
48
|
+
// Clean up prefix index on eviction
|
|
49
|
+
if (entry.prefix) {
|
|
50
|
+
const keys = this.prefixIndex.get(entry.prefix);
|
|
51
|
+
if (keys) {
|
|
52
|
+
keys.delete(key);
|
|
53
|
+
if (keys.size === 0) {
|
|
54
|
+
this.prefixIndex.delete(entry.prefix);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a value from the cache
|
|
63
|
+
* @param key Cache key
|
|
64
|
+
* @returns Cached value or undefined if not found
|
|
65
|
+
*/
|
|
66
|
+
async get(key) {
|
|
67
|
+
const entry = this.cache.get(key);
|
|
68
|
+
if (entry) {
|
|
69
|
+
this.hitCount++;
|
|
70
|
+
return entry.value;
|
|
71
|
+
}
|
|
72
|
+
this.missCount++;
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set a value in the cache
|
|
77
|
+
* @param key Cache key
|
|
78
|
+
* @param value Value to cache
|
|
79
|
+
* @param options Optional TTL override and prefix for grouping
|
|
80
|
+
*/
|
|
81
|
+
async set(key, value, options) {
|
|
82
|
+
const entry = {
|
|
83
|
+
value,
|
|
84
|
+
prefix: options?.prefix,
|
|
85
|
+
};
|
|
86
|
+
const cacheOptions = {};
|
|
87
|
+
if (options?.ttl !== undefined) {
|
|
88
|
+
cacheOptions.ttl = options.ttl;
|
|
89
|
+
}
|
|
90
|
+
this.cache.set(key, entry, cacheOptions);
|
|
91
|
+
// Track prefix for bulk invalidation
|
|
92
|
+
if (options?.prefix) {
|
|
93
|
+
let keys = this.prefixIndex.get(options.prefix);
|
|
94
|
+
if (!keys) {
|
|
95
|
+
keys = new Set();
|
|
96
|
+
this.prefixIndex.set(options.prefix, keys);
|
|
97
|
+
}
|
|
98
|
+
keys.add(key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if a key exists in the cache (without affecting LRU order)
|
|
103
|
+
* @param key Cache key
|
|
104
|
+
* @returns True if key exists
|
|
105
|
+
*/
|
|
106
|
+
has(key) {
|
|
107
|
+
return this.cache.has(key);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Remove a specific key from the cache
|
|
111
|
+
* @param key Cache key to remove
|
|
112
|
+
*/
|
|
113
|
+
async bust(key) {
|
|
114
|
+
const entry = this.cache.peek(key);
|
|
115
|
+
if (entry?.prefix) {
|
|
116
|
+
const keys = this.prefixIndex.get(entry.prefix);
|
|
117
|
+
if (keys) {
|
|
118
|
+
keys.delete(key);
|
|
119
|
+
if (keys.size === 0) {
|
|
120
|
+
this.prefixIndex.delete(entry.prefix);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.cache.delete(key);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove all keys with a given prefix
|
|
128
|
+
* @param prefix Prefix to match
|
|
129
|
+
*/
|
|
130
|
+
async bustPrefix(prefix) {
|
|
131
|
+
const keys = this.prefixIndex.get(prefix);
|
|
132
|
+
if (keys) {
|
|
133
|
+
for (const key of keys) {
|
|
134
|
+
this.cache.delete(key);
|
|
135
|
+
}
|
|
136
|
+
this.prefixIndex.delete(prefix);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Clear the entire cache
|
|
141
|
+
*/
|
|
142
|
+
async clear() {
|
|
143
|
+
this.cache.clear();
|
|
144
|
+
this.prefixIndex.clear();
|
|
145
|
+
this.hitCount = 0;
|
|
146
|
+
this.missCount = 0;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get cache performance metrics
|
|
150
|
+
* @returns Current cache metrics
|
|
151
|
+
*/
|
|
152
|
+
metrics() {
|
|
153
|
+
const total = this.hitCount + this.missCount;
|
|
154
|
+
return {
|
|
155
|
+
hits: this.hitCount,
|
|
156
|
+
misses: this.missCount,
|
|
157
|
+
size: this.cache.size,
|
|
158
|
+
sizeBytes: this.cache.calculatedSize ?? 0,
|
|
159
|
+
hitRate: total > 0 ? (this.hitCount / total) * 100 : 0,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get the number of items in the cache
|
|
164
|
+
*/
|
|
165
|
+
get size() {
|
|
166
|
+
return this.cache.size;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get all keys in the cache
|
|
170
|
+
*/
|
|
171
|
+
keys() {
|
|
172
|
+
return this.cache.keys();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Default singleton cache instance
|
|
177
|
+
*/
|
|
178
|
+
export const defaultCache = new LLMCache();
|
|
179
|
+
//# sourceMappingURL=cache.js.map
|