@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,158 @@
1
+ /**
2
+ * B3 / G4 (0.3.78): the persisted-write inventory — WHICH file the family
3
+ * writes, WHO writes it, and WHAT keeps two writers apart.
4
+ *
5
+ * The table lives in `persisted-write-inventory.json` at the package root so
6
+ * the TypeScript side, the architecture gate (`verify-arch-guards` rule N20)
7
+ * and the regression specs read ONE file (the row-overrides.json pattern).
8
+ *
9
+ * "What keeps two writers apart" has exactly three answers in this family:
10
+ * - `transact` — the IO backend's cross-process write lock (transactIo);
11
+ * - `write-lock` — the per-target `<path>.lock` protocol of the skill tree;
12
+ * - `instance-claim` — the per-home single-instance claim (instance-scope.ts),
13
+ * for a writer whose sweeps cannot be expressed as one locked file.
14
+ * A site that answers with NONE of them is the "two instances, one file" class:
15
+ * a per-instance serial queue looks like serialization and is not.
16
+ * @module @lmzhen/dsh-evolution-core/src/write-inventory
17
+ */
18
+ import { readFileSync } from 'node:fs';
19
+ import { fileURLToPath } from 'node:url';
20
+ const SITES_URL = new URL('../persisted-write-inventory.json', import.meta.url);
21
+ const SERIALIZATIONS = ['transact', 'write-lock', 'instance-claim'];
22
+ /** Parse + validate the table. A malformed table throws at import: a table the
23
+ * gate cannot read must never degrade into "no declared write sites". */
24
+ function parseTable(raw) {
25
+ // The input is UNKNOWN JSON, so each narrowing below is a real runtime check (and each later check
26
+ // is written so the previous one already excluded its negation — the linter rejects tautologies).
27
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
28
+ throw new Error('evolution-core: persisted-write-inventory.json must be an object with { symbols, sites }');
29
+ }
30
+ const table = raw;
31
+ // typeof null === 'object', so the null test stays — and it comes FIRST: after `typeof !== 'object'`
32
+ // TypeScript has already dropped null, and the linter is right to call that test a tautology.
33
+ if (table.symbols === null || typeof table.symbols !== 'object' || Array.isArray(table.symbols)) {
34
+ throw new Error('evolution-core: persisted-write-inventory.json needs a symbols legend (the roots every path is written against)');
35
+ }
36
+ for (const [symbol, entry] of Object.entries(table.symbols)) {
37
+ const problems = [];
38
+ if (!symbol.startsWith('<') || !symbol.endsWith('>'))
39
+ problems.push('symbol name (must be <name>)');
40
+ if (entry === null || typeof entry !== 'object')
41
+ problems.push('entry');
42
+ else {
43
+ const symbolEntry = entry;
44
+ if (typeof symbolEntry.resolver !== 'string' || symbolEntry.resolver === '')
45
+ problems.push('resolver');
46
+ if (symbolEntry.segments !== undefined
47
+ && (!Array.isArray(symbolEntry.segments) || symbolEntry.segments.some(segment => typeof segment !== 'string')))
48
+ problems.push('segments');
49
+ }
50
+ if (problems.length > 0) {
51
+ throw new Error(`evolution-core: persisted-write-inventory.json symbol ${symbol} is malformed (missing/invalid: ${problems.join(', ')})`);
52
+ }
53
+ }
54
+ if (!Array.isArray(table.sites))
55
+ throw new Error('evolution-core: persisted-write-inventory.json needs a sites array');
56
+ const sites = [];
57
+ for (const [index, entry] of table.sites.entries()) {
58
+ const site = entry;
59
+ const problems = [];
60
+ if (typeof site.id !== 'string' || site.id === '')
61
+ problems.push('id');
62
+ if (typeof site.path !== 'string' || site.path === '')
63
+ problems.push('path');
64
+ if (typeof site.writer !== 'string' || site.writer === '')
65
+ problems.push('writer');
66
+ if (typeof site.marker !== 'string' || site.marker === '')
67
+ problems.push('marker');
68
+ if (typeof site.serializedBy !== 'string' || !SERIALIZATIONS.includes(site.serializedBy))
69
+ problems.push('serializedBy');
70
+ if (site.serializedBy === 'instance-claim' && typeof site.instance !== 'string')
71
+ problems.push('instance');
72
+ if (!Array.isArray(site.state))
73
+ problems.push('state');
74
+ if (problems.length > 0) {
75
+ throw new Error(`evolution-core: persisted-write-inventory.json entry ${index} is malformed (missing/invalid: ${problems.join(', ')})`);
76
+ }
77
+ sites.push({
78
+ id: site.id,
79
+ path: site.path,
80
+ writer: site.writer,
81
+ serializedBy: site.serializedBy,
82
+ marker: site.marker,
83
+ ...(typeof site.instance === 'string' ? { instance: site.instance } : {}),
84
+ state: site.state,
85
+ note: typeof site.note === 'string' ? site.note : '',
86
+ });
87
+ }
88
+ const ids = new Set(sites.map(site => site.id));
89
+ if (ids.size !== sites.length)
90
+ throw new Error('evolution-core: persisted-write-inventory.json declares duplicate site ids');
91
+ // Every entry was validated above, so the unknown JSON is now the table's own shape.
92
+ return { symbols: table.symbols, sites };
93
+ }
94
+ /** Instance keys held by writer services — the single source shared by the
95
+ * claim site and the inventory row that declares it (rule N20 checks the row's
96
+ * `instance` names one of these). */
97
+ export const INSTANCE_KEYS = {
98
+ /** The per-home curator: report writing + the retention sweep. */
99
+ curator: 'evolution-curator',
100
+ };
101
+ // Both caches are READONLY on purpose: the table's own shape is readonly, and copying it into a
102
+ // mutable array would be a second source of truth for the same rows.
103
+ let cachedSites;
104
+ let cachedSymbols;
105
+ /**
106
+ * The declared persisted write sites, in file order.
107
+ *
108
+ * v43 audit (S2-3 / P1-10): this used to be a module-scope readFileSync plus
109
+ * parse, so an unshipped asset threw AT IMPORT — one absent file took the whole
110
+ * family's load down (0.3.79 shipped a tarball without this asset and every
111
+ * package failed to load). The read is lazy now: importing the package never
112
+ * fails on this asset, while the first caller still gets a loud, descriptive
113
+ * failure instead of an empty table ("no declared write sites" would silently
114
+ * disable rule N20).
115
+ * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
116
+ * reads the JSON asset directly; the tests are the only in-tree consumers.
117
+ * @returns the sites, in file order.
118
+ */
119
+ export function persistedWriteSites() {
120
+ if (cachedSites !== undefined)
121
+ return cachedSites;
122
+ let raw;
123
+ try {
124
+ raw = readFileSync(fileURLToPath(SITES_URL), 'utf8');
125
+ }
126
+ catch (error) {
127
+ const cause = error instanceof Error ? error.message : String(error);
128
+ throw new Error(`evolution-core: persisted-write-inventory.json is unreadable (${cause}) — the package asset is missing or was not shipped; the write-inventory rules cannot be evaluated without it`);
129
+ }
130
+ const table = parseTable(JSON.parse(raw));
131
+ cachedSites = table.sites;
132
+ cachedSymbols = table.symbols;
133
+ return table.sites;
134
+ }
135
+ /** The inventory's symbol legend — the roots every declared path is written against, with the
136
+ * segments the gate checks against the resolver's source.
137
+ * @internal no production caller — the gates read the JSON asset directly. */
138
+ export function writePathSymbols() {
139
+ persistedWriteSites();
140
+ return cachedSymbols ?? {};
141
+ }
142
+ /** Sites serialized by the per-home instance claim, with their instance keys.
143
+ * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
144
+ * reads the JSON asset directly; the tests are the only in-tree consumers. */
145
+ export function instanceClaimedWriteSites() {
146
+ return persistedWriteSites().filter((site) => site.serializedBy === 'instance-claim');
147
+ }
148
+ /** One declared site by id. An undeclared id throws — a stale caller must fail
149
+ * loud rather than read "nothing is declared".
150
+ * @internal S2.4 (PLAN 2026-09-16): no production caller — the arch guard
151
+ * reads the JSON asset directly; the tests are the only in-tree consumers. */
152
+ export function persistedWriteSite(id) {
153
+ const site = persistedWriteSites().find(candidate => candidate.id === id);
154
+ if (site === undefined)
155
+ throw new Error(`evolution-core: no persisted write site "${id}" in persisted-write-inventory.json`);
156
+ return site;
157
+ }
158
+ //# sourceMappingURL=write-inventory.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.26.15",
4
+ "version": "0.27.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -18,12 +18,28 @@
18
18
  "types": "./lib/types/index.d.ts",
19
19
  "default": "./lib/index.js"
20
20
  },
21
+ "./composition": {
22
+ "types": "./lib/types/composition/index.d.ts",
23
+ "default": "./lib/composition/index.js"
24
+ },
25
+ "./subagent": {
26
+ "types": "./lib/types/subagent/index.d.ts",
27
+ "default": "./lib/subagent/index.js"
28
+ },
29
+ "./http-routes": {
30
+ "types": "./lib/types/http-routes.d.ts",
31
+ "default": "./lib/http-routes.js"
32
+ },
33
+ "./restrictor": {
34
+ "types": "./lib/types/restrictor.d.ts",
35
+ "default": "./lib/restrictor.js"
36
+ },
21
37
  "./package.json": "./package.json",
22
38
  "./row-overrides.json": "./row-overrides.json",
23
39
  "./persisted-write-inventory.json": "./persisted-write-inventory.json"
24
40
  },
25
41
  "files": [
26
- "lib/*.js",
42
+ "lib/**/*.js",
27
43
  "lib/types/**/*.d.ts",
28
44
  "row-overrides.json",
29
45
  "persisted-write-inventory.json"
@@ -31,18 +47,30 @@
31
47
  "license": "MIT",
32
48
  "dependencies": {
33
49
  "yaml": "^2.4.2",
34
- "zod": "^4.4.3"
50
+ "zod": "^4.4.3",
51
+ "js-yaml": "^4.1.0"
35
52
  },
36
53
  "peerDependencies": {
37
- "@deepseek-ai/cordis": "^4.0.1",
38
- "@deepseek-ai/dsh-scope": "^0.2.0-rc.1",
39
- "@deepseek-ai/dsh-session": "^0.2.0-rc.1",
40
- "@deepseek-ai/dsh-session-projection": "^0.2.0-rc.1"
54
+ "@deepseek-ai/cordis": "^4.0.5",
55
+ "@deepseek-ai/dsh-scope": "^0.2.1-rc.1",
56
+ "@deepseek-ai/dsh-session": "^0.2.1-rc.1",
57
+ "@deepseek-ai/dsh-session-projection": "^0.2.1-rc.1",
58
+ "@deepseek-ai/dsh-agent": "^0.2.1-rc.1",
59
+ "@deepseek-ai/dsh-subagent": "^0.2.1-rc.1",
60
+ "@deepseek-ai/dsh-tools": "^0.2.1-rc.1"
41
61
  },
42
62
  "devDependencies": {
43
- "@deepseek-ai/cordis": "^4.0.1",
44
- "@deepseek-ai/dsh-scope": "^0.2.0-rc.1",
45
- "@deepseek-ai/dsh-session": "^0.2.0-rc.1",
46
- "@deepseek-ai/dsh-session-projection": "^0.2.0-rc.1"
63
+ "@deepseek-ai/cordis": "^4.0.5",
64
+ "@deepseek-ai/dsh-scope": "^0.2.1-rc.1",
65
+ "@deepseek-ai/dsh-session": "^0.2.1-rc.1",
66
+ "@deepseek-ai/dsh-session-projection": "^0.2.1-rc.1",
67
+ "@deepseek-ai/dsh-agent": "^0.2.1-rc.1",
68
+ "@deepseek-ai/dsh-subagent": "^0.2.1-rc.1",
69
+ "@deepseek-ai/dsh-tools": "^0.2.1-rc.1",
70
+ "@types/js-yaml": "^4.0.9",
71
+ "js-yaml": "^4.1.0"
72
+ },
73
+ "engines": {
74
+ "dsh": ">=0.2.1-rc.1 <0.2.2-0"
47
75
  }
48
76
  }