@yadsh/dsh-kv-persist 0.1.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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/compatibility.json +16 -0
  4. package/cordis.patch.yml +4 -0
  5. package/docs/dsh-kv-persist.md +3311 -0
  6. package/lib/backends/llama-cpp/backend.d.ts +20 -0
  7. package/lib/backends/llama-cpp/backend.d.ts.map +1 -0
  8. package/lib/backends/llama-cpp/backend.js +37 -0
  9. package/lib/backends/llama-cpp/backend.js.map +1 -0
  10. package/lib/backends/llama-cpp/client.d.ts +31 -0
  11. package/lib/backends/llama-cpp/client.d.ts.map +1 -0
  12. package/lib/backends/llama-cpp/client.js +120 -0
  13. package/lib/backends/llama-cpp/client.js.map +1 -0
  14. package/lib/backends/llama-cpp/discovery.d.ts +20 -0
  15. package/lib/backends/llama-cpp/discovery.d.ts.map +1 -0
  16. package/lib/backends/llama-cpp/discovery.js +33 -0
  17. package/lib/backends/llama-cpp/discovery.js.map +1 -0
  18. package/lib/backends/llama-cpp/types.d.ts +30 -0
  19. package/lib/backends/llama-cpp/types.d.ts.map +1 -0
  20. package/lib/backends/llama-cpp/types.js +9 -0
  21. package/lib/backends/llama-cpp/types.js.map +1 -0
  22. package/lib/backends/types.d.ts +52 -0
  23. package/lib/backends/types.d.ts.map +1 -0
  24. package/lib/backends/types.js +6 -0
  25. package/lib/backends/types.js.map +1 -0
  26. package/lib/config.d.ts +258 -0
  27. package/lib/config.d.ts.map +1 -0
  28. package/lib/config.js +169 -0
  29. package/lib/config.js.map +1 -0
  30. package/lib/coordinator/checkpoint-policy.d.ts +19 -0
  31. package/lib/coordinator/checkpoint-policy.d.ts.map +1 -0
  32. package/lib/coordinator/checkpoint-policy.js +40 -0
  33. package/lib/coordinator/checkpoint-policy.js.map +1 -0
  34. package/lib/coordinator/circuit-breaker.d.ts +29 -0
  35. package/lib/coordinator/circuit-breaker.d.ts.map +1 -0
  36. package/lib/coordinator/circuit-breaker.js +62 -0
  37. package/lib/coordinator/circuit-breaker.js.map +1 -0
  38. package/lib/coordinator/coordinator.d.ts +74 -0
  39. package/lib/coordinator/coordinator.d.ts.map +1 -0
  40. package/lib/coordinator/coordinator.js +542 -0
  41. package/lib/coordinator/coordinator.js.map +1 -0
  42. package/lib/coordinator/slot-lease.d.ts +22 -0
  43. package/lib/coordinator/slot-lease.d.ts.map +1 -0
  44. package/lib/coordinator/slot-lease.js +38 -0
  45. package/lib/coordinator/slot-lease.js.map +1 -0
  46. package/lib/coordinator/state-machine.d.ts +65 -0
  47. package/lib/coordinator/state-machine.d.ts.map +1 -0
  48. package/lib/coordinator/state-machine.js +40 -0
  49. package/lib/coordinator/state-machine.js.map +1 -0
  50. package/lib/errors.d.ts +82 -0
  51. package/lib/errors.d.ts.map +1 -0
  52. package/lib/errors.js +113 -0
  53. package/lib/errors.js.map +1 -0
  54. package/lib/index.d.ts +26 -0
  55. package/lib/index.d.ts.map +1 -0
  56. package/lib/index.js +17 -0
  57. package/lib/index.js.map +1 -0
  58. package/lib/logging/dsh-home.d.ts +13 -0
  59. package/lib/logging/dsh-home.d.ts.map +1 -0
  60. package/lib/logging/dsh-home.js +18 -0
  61. package/lib/logging/dsh-home.js.map +1 -0
  62. package/lib/logging/index.d.ts +10 -0
  63. package/lib/logging/index.d.ts.map +1 -0
  64. package/lib/logging/index.js +10 -0
  65. package/lib/logging/index.js.map +1 -0
  66. package/lib/logging/plugin-logger.d.ts +94 -0
  67. package/lib/logging/plugin-logger.d.ts.map +1 -0
  68. package/lib/logging/plugin-logger.js +397 -0
  69. package/lib/logging/plugin-logger.js.map +1 -0
  70. package/lib/observability/diagnostics.d.ts +37 -0
  71. package/lib/observability/diagnostics.d.ts.map +1 -0
  72. package/lib/observability/diagnostics.js +75 -0
  73. package/lib/observability/diagnostics.js.map +1 -0
  74. package/lib/observability/metrics.d.ts +38 -0
  75. package/lib/observability/metrics.d.ts.map +1 -0
  76. package/lib/observability/metrics.js +29 -0
  77. package/lib/observability/metrics.js.map +1 -0
  78. package/lib/service.d.ts +231 -0
  79. package/lib/service.d.ts.map +1 -0
  80. package/lib/service.js +232 -0
  81. package/lib/service.js.map +1 -0
  82. package/lib/snapshots/fingerprint.d.ts +53 -0
  83. package/lib/snapshots/fingerprint.d.ts.map +1 -0
  84. package/lib/snapshots/fingerprint.js +69 -0
  85. package/lib/snapshots/fingerprint.js.map +1 -0
  86. package/lib/snapshots/manifest.d.ts +51 -0
  87. package/lib/snapshots/manifest.d.ts.map +1 -0
  88. package/lib/snapshots/manifest.js +0 -0
  89. package/lib/snapshots/manifest.js.map +1 -0
  90. package/lib/snapshots/naming.d.ts +18 -0
  91. package/lib/snapshots/naming.d.ts.map +1 -0
  92. package/lib/snapshots/naming.js +33 -0
  93. package/lib/snapshots/naming.js.map +1 -0
  94. package/lib/snapshots/repository.d.ts +52 -0
  95. package/lib/snapshots/repository.d.ts.map +1 -0
  96. package/lib/snapshots/repository.js +270 -0
  97. package/lib/snapshots/repository.js.map +1 -0
  98. package/package.json +83 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-plugins 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 ADDED
@@ -0,0 +1,110 @@
1
+ # @yadsh/dsh-kv-persist
2
+
3
+ `dsh-kv-persist` keeps local LLM sessions warm across session switches and restarts.
4
+
5
+ It maps DeepSeek Harness sessions to persistent inference-cache snapshots and
6
+ restores them when a session becomes active again. The initial backend uses
7
+ llama.cpp's slot save/restore API, allowing large agent contexts to resume
8
+ without repeating a full prompt prefill.
9
+
10
+ KV state is treated strictly as an optimization: DSH's session log remains the
11
+ source of truth, and any missing, stale, or incompatible cache automatically
12
+ falls back to normal inference. The model never knows this plugin exists.
13
+
14
+ ## Features
15
+
16
+ - Maps DSH sessions (`sessionId` + provider + model) to llama.cpp slot
17
+ snapshots via `GET /slots` and `POST /slots/{id}?action=save|restore|erase`.
18
+ - Lazy restore: nothing is loaded until the session's first managed request;
19
+ resident sessions run with zero disk I/O and zero management calls.
20
+ - Save-before-switch, idle checkpoints, and shutdown/flush checkpoints, with
21
+ dirty generations and save coalescing instead of a naive boolean.
22
+ - Runtime compatibility gate: snapshots restored only when the server
23
+ instance, provider, model, and `runtimeKey` generation match; the rest are
24
+ marked invalid and skipped, never deleted.
25
+ - Cold fallback everywhere: persistence failures degrade to ordinary
26
+ inference; optional strict mode is the only failure path.
27
+ - Circuit breaker stops a broken backend from costing latency on every
28
+ request.
29
+ - Auxiliary requests (session titles, compaction) are coordinated so they
30
+ never pollute or hijack a session's slot ownership.
31
+ - Structured `kv.*` logging, in-memory metrics, `status()` and `doctor()`
32
+ diagnostics on the service.
33
+
34
+ ## Requirements
35
+
36
+ - DeepSeek Harness >= 0.1.1-rc.2 < 0.2.0
37
+ - A llama.cpp `llama-server` started with `--slots --slot-save-path <dir>`
38
+ and `--parallel 1` for the single-slot mode (see the [design doc](./docs/dsh-kv-persist.md) §6).
39
+ - Node.js >= 22
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ dsh plugin add @yadsh/dsh-kv-persist
45
+ ```
46
+
47
+ From sources:
48
+
49
+ ```bash
50
+ pnpm nx run @yadsh/dsh-kv-persist:build
51
+ ```
52
+
53
+ ## Configuration
54
+
55
+ Configure the plugin under the `kv-persist` key in the DSH profile. Only
56
+ providers listed under `providers` are ever coordinated.
57
+
58
+ | Option | Type | Default | Description |
59
+ | --- | --- | --- | --- |
60
+ | `enabled` | boolean | `true` | Master switch; `false` passes everything through. |
61
+ | `backend.baseURL` | string | `http://127.0.0.1:8080` | llama-server management endpoint. |
62
+ | `backend.apiKey` | string | `""` | Bearer key for the management API; never logged. |
63
+ | `backend.requestTimeoutMs` | number | `15000` | Bounded timeout per persistence call. |
64
+ | `providers` | string[] | `[]` | Managed provider routes; empty = plugin inert. |
65
+ | `mode` | `"single-slot"` | `"single-slot"` | v0.1 supports single-slot only. |
66
+ | `slotId` | number | `0` | Physical slot used in single-slot mode. |
67
+ | `runtimeKey` | string | `""` | Runtime identity escape hatch; changing it hides old snapshots (they are kept, not deleted). |
68
+ | `checkpoint.onSwitch` | boolean | `true` | Save a dirty slot before reassignment. |
69
+ | `checkpoint.onShutdown` | boolean | `true` | Final checkpoint on plugin disposal. |
70
+ | `checkpoint.onSessionFlush` | boolean | `true` | Checkpoint on the session flush event. |
71
+ | `checkpoint.idleMs` | number | `30000` | Idle checkpoint delay; `0` disables. |
72
+ | `checkpoint.onTurnEnd` | boolean | `false` | Checkpoint after every user turn. |
73
+ | `checkpoint.onStepEnd` | boolean | `false` | Reserved for per-step checkpoints. |
74
+ | `restore.enabled` | boolean | `true` | Restore compatible snapshots lazily. |
75
+ | `restore.verify` | boolean | `true` | Reject restores reporting `n_restored <= 0`. |
76
+ | `failure.strict` | boolean | `false` | Turn restore failures into request failures. |
77
+ | `failure.maxConsecutiveFailures` | number | `3` | Failures before the circuit opens. |
78
+ | `failure.cooldownMs` | number | `60000` | Circuit open duration. |
79
+ | `metadata.path` | string | `$DSH_HOME/cache/dsh-kv-persist` | Manifest storage directory. |
80
+ | `logging.level` | `"debug" \| "info" \| "off"` | `"info"` | Structured `kv.*` event verbosity. |
81
+
82
+ Full configuration rationale: [design doc §35](./docs/dsh-kv-persist.md).
83
+
84
+ ## Compatibility
85
+
86
+ - DeepSeek Harness `>=0.1.1-rc.2 <0.2.0` (see `compatibility.json`)
87
+ - Node.js >= 22
88
+ - llama.cpp server with the slots management API enabled
89
+
90
+ ## Development
91
+
92
+ ```bash
93
+ pnpm nx run @yadsh/dsh-kv-persist:lint
94
+ pnpm nx run @yadsh/dsh-kv-persist:typecheck
95
+ pnpm nx run @yadsh/dsh-kv-persist:test
96
+ pnpm nx run @yadsh/dsh-kv-persist:build
97
+ pnpm nx run @yadsh/dsh-kv-persist:verify
98
+ ```
99
+
100
+ Optional end-to-end check against a live server (no GPU in CI):
101
+
102
+ ```bash
103
+ DSH_KV_TEST_LLAMA_URL=http://127.0.0.1:8080 pnpm --filter @yadsh/dsh-kv-persist test:llama
104
+ ```
105
+
106
+ See [SPEC.md](./SPEC.md) for the product contract and implementation status.
107
+
108
+ ## License
109
+
110
+ MIT
@@ -0,0 +1,16 @@
1
+ {
2
+ "deepseekHarness": {
3
+ "channel": "next",
4
+ "range": ">=0.1.1-rc.2 <0.2.0",
5
+ "testedReleases": [
6
+ "0.1.1-rc.2"
7
+ ],
8
+ "requiredHostFeatures": [
9
+ "llm/stream",
10
+ "session/flush",
11
+ "session/disposed",
12
+ "session/event"
13
+ ]
14
+ },
15
+ "node": ">=22"
16
+ }
@@ -0,0 +1,4 @@
1
+ # The DSH plugin manager discovers this bundle through package.json.
2
+ - insert:
3
+ - id: dsh-kv-persist
4
+ name: "@yadsh/dsh-kv-persist"