@lmzhen/dsh-evolution-core 0.26.26 → 0.27.1

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 (107) hide show
  1. package/README.md +16 -1
  2. package/lib/composition/index.js +3 -0
  3. package/lib/composition-D8Y3-ROd.js +604 -0
  4. package/lib/ensure-MEYMj9jn.js +222 -0
  5. package/lib/errors-Br2-uUSK.js +57 -0
  6. package/lib/http-routes-BP-S3KV-.js +149 -0
  7. package/lib/http-routes.js +2 -0
  8. package/lib/index.js +66 -850
  9. package/lib/restrictor.js +37 -0
  10. package/lib/subagent/index.js +186 -0
  11. package/lib/types/citations.js +192 -0
  12. package/lib/types/{preset-composition.d.ts → composition/composer.d.ts} +1 -1
  13. package/lib/types/composition/composer.js +681 -0
  14. package/lib/types/composition/ensure.d.ts +10 -0
  15. package/lib/types/composition/ensure.js +95 -0
  16. package/lib/types/composition/index.d.ts +5 -0
  17. package/lib/types/composition/index.js +7 -0
  18. package/lib/types/composition/preset-ids.d.ts +17 -0
  19. package/lib/types/composition/preset-ids.js +21 -0
  20. package/lib/types/composition/restricted-preset.d.ts +36 -0
  21. package/lib/types/composition/restricted-preset.js +42 -0
  22. package/lib/types/constants.js +223 -0
  23. package/lib/types/cost.js +67 -0
  24. package/lib/types/curator.js +346 -0
  25. package/lib/types/diagnostics.d.ts +26 -0
  26. package/lib/types/diagnostics.js +23 -0
  27. package/lib/types/document-body.js +91 -0
  28. package/lib/types/drift-signals.js +319 -0
  29. package/lib/types/env.js +25 -0
  30. package/lib/types/errors.d.ts +4 -1
  31. package/lib/types/errors.js +59 -0
  32. package/lib/types/events.js +16 -0
  33. package/lib/types/evidence.js +65 -0
  34. package/lib/types/evolution-events.js +479 -0
  35. package/lib/types/fold-untrusted.js +44 -0
  36. package/lib/types/frontmatter.js +623 -0
  37. package/lib/types/fuzzy-match.js +135 -0
  38. package/lib/types/gates.js +51 -0
  39. package/lib/types/guards.js +27 -0
  40. package/lib/types/health-baseline.js +63 -0
  41. package/lib/types/http-routes.d.ts +67 -35
  42. package/lib/types/http-routes.js +135 -0
  43. package/lib/types/index.d.ts +7 -2
  44. package/lib/types/index.js +101 -0
  45. package/lib/types/instance-scope.js +69 -0
  46. package/lib/types/io.js +675 -0
  47. package/lib/types/learn-prompt.js +42 -0
  48. package/lib/types/limits.js +63 -0
  49. package/lib/types/live.js +107 -0
  50. package/lib/types/long-runs.js +96 -0
  51. package/lib/types/memory-store.d.ts +0 -16
  52. package/lib/types/memory-store.js +606 -0
  53. package/lib/types/mutations.js +95 -0
  54. package/lib/types/namespace-migration.js +156 -0
  55. package/lib/types/numeric.js +47 -0
  56. package/lib/types/opt-in.js +101 -0
  57. package/lib/types/package-identity.js +47 -0
  58. package/lib/types/params.js +328 -0
  59. package/lib/types/payload.js +36 -0
  60. package/lib/types/platform-line.generated.d.ts +10 -0
  61. package/lib/types/platform-line.generated.js +12 -0
  62. package/lib/types/platform-services.d.ts +2 -2
  63. package/lib/types/platform-services.js +52 -0
  64. package/lib/types/probe.js +122 -0
  65. package/lib/types/prompts.js +409 -0
  66. package/lib/types/quality.js +308 -0
  67. package/lib/types/reachability.js +122 -0
  68. package/lib/types/redact.js +257 -0
  69. package/lib/types/reference-rewrite.js +144 -0
  70. package/lib/types/reports.js +110 -0
  71. package/lib/types/restrictor.d.ts +11 -0
  72. package/lib/types/restrictor.js +48 -0
  73. package/lib/types/review-channel.js +59 -0
  74. package/lib/types/run-registry.js +345 -0
  75. package/lib/types/scope.js +7 -0
  76. package/lib/types/serial.js +17 -0
  77. package/lib/types/session-fold.d.ts +15 -0
  78. package/lib/types/session-fold.js +28 -0
  79. package/lib/types/session-projection.js +295 -0
  80. package/lib/types/signals.js +209 -0
  81. package/lib/types/skill-discovery.js +66 -0
  82. package/lib/types/skill-health.js +134 -0
  83. package/lib/types/skill-history.js +745 -0
  84. package/lib/types/skill-lint.js +112 -0
  85. package/lib/types/skill-reads.js +67 -0
  86. package/lib/types/skill-row-cells.js +123 -0
  87. package/lib/types/skill-store.js +3528 -0
  88. package/lib/types/state-store.js +60 -0
  89. package/lib/types/store-ledger.js +117 -0
  90. package/lib/types/subagent/channel.d.ts +4 -0
  91. package/lib/types/subagent/channel.js +131 -0
  92. package/lib/types/subagent/index.d.ts +4 -0
  93. package/lib/types/subagent/index.js +5 -0
  94. package/lib/types/subagent/readiness.d.ts +6 -0
  95. package/lib/types/subagent/readiness.js +35 -0
  96. package/lib/types/subagent/types.d.ts +58 -0
  97. package/lib/types/subagent/types.js +2 -0
  98. package/lib/types/threats.js +338 -0
  99. package/lib/types/tool-dispatch.d.ts +5 -0
  100. package/lib/types/tool-dispatch.js +535 -0
  101. package/lib/types/tree-write.js +40 -0
  102. package/lib/types/unit-members.js +121 -0
  103. package/lib/types/usage.js +474 -0
  104. package/lib/types/write-authority.js +23 -0
  105. package/lib/types/write-gates.js +344 -0
  106. package/lib/types/write-inventory.js +158 -0
  107. package/package.json +39 -11
@@ -0,0 +1,69 @@
1
+ /**
2
+ * B3 / G4 (0.3.78): the family's single-instance contract, made explicit.
3
+ *
4
+ * Every persisted sidecar is written under TWO assumptions: the IO backend's
5
+ * cross-process write lock serializes different processes, and exactly ONE
6
+ * instance of each writer service exists per evolution home. The second half
7
+ * was implicit — `makeSerialQueue()` and the module-scope stores are
8
+ * per-instance, so two rows writing one home interleave inside one file (the
9
+ * "two instances, one file" class). This module makes that half enforceable: a
10
+ * writer CLAIMS its key while mounted and releases it on dispose, and a second
11
+ * claimant is told who holds the key instead of silently racing it.
12
+ *
13
+ * The claim is keyed by the HOME, not by the process: the contended resource is
14
+ * the sidecar directory, so two instances resolving different homes (an
15
+ * isolated test fixture, a second DSH_HOME) do not contend, while two rows on
16
+ * one profile do.
17
+ *
18
+ * ## Scope (v43 FLOW2-1) — this registry is PER PROCESS
19
+ *
20
+ * `claims` below is a module-scope Map: two ROWS over one home in ONE process
21
+ * contend, while the SAME home in another process gets its own Map and is
22
+ * granted the key. That is by construction, not a gap to close here — the
23
+ * cross-process half of the contract is the IO backend's write lock
24
+ * (`transactIo`, core/io.ts), which serializes a per-target read-modify-write.
25
+ * The FLOW2-1 finding was three call sites reading a GRANTED claim as "no other
26
+ * process can be doing this work", so the caller contract is stated here:
27
+ * - granted means "no other row OF THIS PROCESS owns the key";
28
+ * - `instanceHolder()` answers "who holds it HERE"; `undefined` also covers
29
+ * "held by another process";
30
+ * - a foreign holder's LIVENESS cannot be decided from a claim at all (no pid
31
+ * is recorded here): a consumer that needs that decision must carry a pid in
32
+ * its own credential and probe it (`isProcessAlive`, core/io.ts), or state
33
+ * that its action is destructive.
34
+ * @module @lmzhen/dsh-evolution-core/src/instance-scope
35
+ */
36
+ /** home+key -> holder, IN THIS PROCESS ONLY. The Map is module-scope, so two
37
+ * processes never share it: this half cannot exclude another process (v43
38
+ * FLOW2-1) — the cross-process half is the write lock, see
39
+ * persisted-write-inventory.json. It is still the whole point for the case it
40
+ * was written for: two ROWS of one process writing one home. */
41
+ const claims = new Map();
42
+ /** `<home> :: <key>` — the registry key, exported so diagnostics name the
43
+ * same unit the claim does. */
44
+ export function instanceClaimKey(home, key) {
45
+ return `${home} :: ${key}`;
46
+ }
47
+ /** Take the claim for `key` at `home`. Grants while it is free or already
48
+ * held BY `owner` — remounting the same instance is not a second instance. */
49
+ export function claimInstance(home, key, owner) {
50
+ const id = instanceClaimKey(home, key);
51
+ const current = claims.get(id);
52
+ if (current === undefined || current === owner) {
53
+ claims.set(id, owner);
54
+ return { granted: true, key: id, holder: owner };
55
+ }
56
+ return { granted: false, key: id, holder: current };
57
+ }
58
+ /** Release only the claim `owner` took — never another instance's. */
59
+ export function releaseInstance(home, key, owner) {
60
+ const id = instanceClaimKey(home, key);
61
+ if (claims.get(id) === owner)
62
+ claims.delete(id);
63
+ }
64
+ /** The current holder of `key` at `home`, IN THIS PROCESS, or undefined
65
+ * (which also covers "another process holds it" — v43 FLOW2-1). */
66
+ export function instanceHolder(home, key) {
67
+ return claims.get(instanceClaimKey(home, key));
68
+ }
69
+ //# sourceMappingURL=instance-scope.js.map