@lmzhen/dsh-evolution-core 0.26.15 → 0.27.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 (116) 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 +777 -840
  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} +2 -2
  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.d.ts +2 -0
  25. package/lib/types/curator.js +346 -0
  26. package/lib/types/diagnostics.d.ts +26 -0
  27. package/lib/types/diagnostics.js +23 -0
  28. package/lib/types/document-body.js +91 -0
  29. package/lib/types/drift-signals.js +319 -0
  30. package/lib/types/env.js +25 -0
  31. package/lib/types/errors.d.ts +4 -1
  32. package/lib/types/errors.js +59 -0
  33. package/lib/types/events.js +16 -0
  34. package/lib/types/evidence.js +65 -0
  35. package/lib/types/evolution-events.js +479 -0
  36. package/lib/types/fold-untrusted.js +44 -0
  37. package/lib/types/frontmatter.js +623 -0
  38. package/lib/types/fuzzy-match.js +135 -0
  39. package/lib/types/gates.js +51 -0
  40. package/lib/types/guards.js +27 -0
  41. package/lib/types/health-baseline.js +63 -0
  42. package/lib/types/http-routes.d.ts +67 -35
  43. package/lib/types/http-routes.js +135 -0
  44. package/lib/types/index.d.ts +13 -2
  45. package/lib/types/index.js +101 -0
  46. package/lib/types/instance-scope.js +69 -0
  47. package/lib/types/io.js +675 -0
  48. package/lib/types/learn-prompt.js +42 -0
  49. package/lib/types/limits.js +63 -0
  50. package/lib/types/live.js +107 -0
  51. package/lib/types/long-runs.js +96 -0
  52. package/lib/types/memory-store.d.ts +0 -16
  53. package/lib/types/memory-store.js +606 -0
  54. package/lib/types/mutations.js +95 -0
  55. package/lib/types/namespace-migration.js +156 -0
  56. package/lib/types/numeric.js +47 -0
  57. package/lib/types/opt-in.js +101 -0
  58. package/lib/types/package-identity.d.ts +14 -0
  59. package/lib/types/package-identity.js +47 -0
  60. package/lib/types/params.js +328 -0
  61. package/lib/types/payload.js +36 -0
  62. package/lib/types/platform-line.generated.d.ts +10 -0
  63. package/lib/types/platform-line.generated.js +12 -0
  64. package/lib/types/platform-services.d.ts +2 -2
  65. package/lib/types/platform-services.js +52 -0
  66. package/lib/types/probe.d.ts +9 -3
  67. package/lib/types/probe.js +122 -0
  68. package/lib/types/prompts.js +409 -0
  69. package/lib/types/quality.js +308 -0
  70. package/lib/types/reachability.d.ts +46 -0
  71. package/lib/types/reachability.js +122 -0
  72. package/lib/types/redact.js +257 -0
  73. package/lib/types/reference-rewrite.js +144 -0
  74. package/lib/types/reports.js +110 -0
  75. package/lib/types/restrictor.d.ts +11 -0
  76. package/lib/types/restrictor.js +48 -0
  77. package/lib/types/review-channel.js +59 -0
  78. package/lib/types/run-registry.js +345 -0
  79. package/lib/types/scope.js +7 -0
  80. package/lib/types/serial.js +17 -0
  81. package/lib/types/session-fold.d.ts +15 -0
  82. package/lib/types/session-fold.js +28 -0
  83. package/lib/types/session-projection.js +295 -0
  84. package/lib/types/signals.js +209 -0
  85. package/lib/types/skill-discovery.js +66 -0
  86. package/lib/types/skill-health.js +134 -0
  87. package/lib/types/skill-history.js +745 -0
  88. package/lib/types/skill-lint.js +112 -0
  89. package/lib/types/skill-reads.js +67 -0
  90. package/lib/types/skill-row-cells.js +123 -0
  91. package/lib/types/skill-store.d.ts +34 -3
  92. package/lib/types/skill-store.js +3528 -0
  93. package/lib/types/state-store.js +60 -0
  94. package/lib/types/store-ledger.d.ts +44 -0
  95. package/lib/types/store-ledger.js +117 -0
  96. package/lib/types/subagent/channel.d.ts +4 -0
  97. package/lib/types/subagent/channel.js +131 -0
  98. package/lib/types/subagent/index.d.ts +4 -0
  99. package/lib/types/subagent/index.js +5 -0
  100. package/lib/types/subagent/readiness.d.ts +6 -0
  101. package/lib/types/subagent/readiness.js +35 -0
  102. package/lib/types/subagent/types.d.ts +58 -0
  103. package/lib/types/subagent/types.js +2 -0
  104. package/lib/types/threats.js +338 -0
  105. package/lib/types/tool-dispatch.d.ts +5 -0
  106. package/lib/types/tool-dispatch.js +535 -0
  107. package/lib/types/tree-write.d.ts +53 -0
  108. package/lib/types/tree-write.js +40 -0
  109. package/lib/types/unit-members.js +121 -0
  110. package/lib/types/usage.js +474 -0
  111. package/lib/types/write-authority.d.ts +87 -0
  112. package/lib/types/write-authority.js +23 -0
  113. package/lib/types/write-gates.d.ts +111 -0
  114. package/lib/types/write-gates.js +344 -0
  115. package/lib/types/write-inventory.js +158 -0
  116. package/package.json +39 -11
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Shared library for the dsh-evolution plugin family.
3
+ *
4
+ * Pure stores, prompts, signals, lifecycle logic, threat scanning, IO seam
5
+ * types, and session-event augmentations. This package ships no runtime
6
+ * plugin and no `./invariant` companion (v37 S2.1); consumers import named
7
+ * exports from the package root so published npm bundles never depend on
8
+ * source subpaths.
9
+ *
10
+ * ## Layer map (OPT-28, 2026-09) — locate code by LAYER, not by directory
11
+ *
12
+ * This one physical package carries THREE architecture layers of the family;
13
+ * when adding or looking for something, go by the export's layer:
14
+ *
15
+ * - **Cross-cutting basics** — `state-store.ts` (env roots — the single
16
+ * source of DSH-home semantics), `serial.ts`, `numeric.ts`, `constants.ts`,
17
+ * `mutations.ts`, `events.ts`, `gates.ts`, `errors.ts` (the error-code table),
18
+ * `payload.ts` (which of `facts`/`content` is the payload — one rule for the whole family).
19
+ * - **Security primitives** — `threats.ts` (content threat scanner),
20
+ * `redact.ts` (credential masking at model boundaries),
21
+ * `fold-untrusted.ts` (untrusted text must not become prompt structure). Consumers:
22
+ * evolution-policy/threat, both stores, review, maintenance.
23
+ * - **Core domain stores/logic** — `skill-store.ts` (skill tree engine +
24
+ * IO-seam consumer), `memory-store.ts`, `usage.ts`, `curator.ts`,
25
+ * `quality.ts`, `signals.ts`, `skill-reads.ts` (the read-before-write rule, shared by the
26
+ * tool path and the review's plan path), `drift-signals.ts`, `skill-health.ts`,
27
+ * `composition/composer.ts`, `prompts.ts`, `learn-prompt.ts`,
28
+ * `evolution-events.ts`, `evidence.ts` (which session frames count as content, for the plan
29
+ * path's evidence-class report), `session-projection.ts` (the live per-session units the family's
30
+ * log-shaped readers read instead of re-reading the session log), `io.ts` (the ctx.evolutionIo
31
+ * seam itself).
32
+ * @module @lmzhen/dsh-evolution-core
33
+ */
34
+ export * from "./citations.js";
35
+ // G1/1.1: the ONE authority behind a write (its type and the authorityFrom builder).
36
+ export * from "./tree-write.js";
37
+ export * from "./package-identity.js";
38
+ export * from "./write-authority.js";
39
+ export * from "./write-gates.js";
40
+ export * from "./reference-rewrite.js";
41
+ export * from "./cost.js";
42
+ export * from "./skill-lint.js";
43
+ export * from "./health-baseline.js";
44
+ export * from "./curator.js";
45
+ export * from "./evolution-events.js";
46
+ export * from "./fuzzy-match.js";
47
+ export * from "./gates.js";
48
+ export * from "./guards.js";
49
+ export * from "./http-routes.js";
50
+ export * from "./events.js";
51
+ export * from "./env.js";
52
+ export * from "./errors.js";
53
+ export * from "./io.js";
54
+ export * from "./learn-prompt.js";
55
+ export * from "./memory-store.js";
56
+ export * from "./mutations.js";
57
+ export * from "./prompts.js";
58
+ export * from "./quality.js";
59
+ export * from "./redact.js";
60
+ export * from "./review-channel.js";
61
+ export * from "./run-registry.js";
62
+ export * from "./reports.js";
63
+ export * from "./long-runs.js";
64
+ export * from "./serial.js";
65
+ export * from "./probe.js";
66
+ export * from "./platform-services.js";
67
+ export * from "./instance-scope.js";
68
+ export * from "./write-inventory.js";
69
+ export * from "./scope.js";
70
+ export * from "./skill-health.js";
71
+ export * from "./signals.js";
72
+ export * from "./skill-reads.js";
73
+ export * from "./skill-row-cells.js";
74
+ export * from "./document-body.js";
75
+ export * from "./evidence.js";
76
+ export * from "./session-projection.js";
77
+ export * from "./drift-signals.js";
78
+ export * from "./skill-history.js";
79
+ export * from "./unit-members.js";
80
+ export * from "./skill-store.js";
81
+ export * from "./store-ledger.js";
82
+ export * from "./reachability.js";
83
+ export * from "./state-store.js";
84
+ export * from "./threats.js";
85
+ export * from "./tool-dispatch.js";
86
+ export * from "./usage.js";
87
+ export * from "./constants.js";
88
+ export * from "./params.js";
89
+ export * from "./namespace-migration.js";
90
+ export * from "./live.js";
91
+ export * from "./numeric.js";
92
+ export * from "./opt-in.js";
93
+ export * from "./payload.js";
94
+ export * from "./fold-untrusted.js";
95
+ // G0 contract surface: /subagent types + state probe, /composition preset constants.
96
+ export * from "./subagent/index.js";
97
+ export { EVOLUTION_PRESET_IDS, REVIEWER_PRESET_ID, MAINTAINER_PRESET_ID, RESTRICTED_TOOLS_ROW_ID, RESTRICTOR_MODULE, RESTRICTED_PRESET_DISPLAY, } from "./composition/index.js";
98
+ export * from "./diagnostics.js";
99
+ export * from "./platform-line.generated.js";
100
+ export * from "./session-fold.js";
101
+ //# sourceMappingURL=index.js.map
@@ -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