@lmzhen/dsh-evolution-core 0.46.0 → 0.48.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 (101) hide show
  1. package/lib/authority-plugin.js +1 -1
  2. package/lib/composition/index.js +3 -3
  3. package/lib/{composition-Da8NfRI7.js → composition-Cqjbho0t.js} +1 -1
  4. package/lib/{ensure-C5Mo1dbB.js → ensure-CAjLGd9f.js} +1 -2
  5. package/lib/http-routes.js +21 -96
  6. package/lib/index.js +47 -246
  7. package/lib/{io-AmUf4lVY.js → io-GxghO3Ip.js} +30 -70
  8. package/lib/io-node.js +1 -1
  9. package/lib/io-registry.js +1 -35
  10. package/lib/{mutation-authority-DeJ_Wz14.js → mutation-authority-l57R626O.js} +17 -15
  11. package/lib/{mutations-DwvbjRHF.js → mutations-DQXddSJd.js} +1 -1
  12. package/lib/{numeric-DLeLvvGb.js → numeric-D8js3sqC.js} +1 -5
  13. package/lib/platform/index.js +1 -1
  14. package/lib/{platform-CFA12Jam.js → platform-Cc9cNt5j.js} +4 -28
  15. package/lib/policy.js +1 -1
  16. package/lib/runtime/plugin.js +21 -43
  17. package/lib/{session-projection-EB7mUOlJ.js → session-projection-DSXnUNZG.js} +3 -21
  18. package/lib/{skill-health-D1pZGk5V.js → skill-health-DP8z9TPf.js} +4 -25
  19. package/lib/{skill-history-CjypdYqv.js → skill-history-CxrDE3Rb.js} +54 -102
  20. package/lib/skills.js +166 -184
  21. package/lib/subagent/index.js +4 -10
  22. package/lib/types/authority.d.ts +2 -0
  23. package/lib/types/authority.js +5 -0
  24. package/lib/types/composition/preset-ids.d.ts +0 -1
  25. package/lib/types/composition/preset-ids.js +0 -1
  26. package/lib/types/constants.d.ts +0 -4
  27. package/lib/types/constants.js +0 -4
  28. package/lib/types/contract.d.ts +0 -5
  29. package/lib/types/curator.d.ts +0 -1
  30. package/lib/types/curator.js +0 -1
  31. package/lib/types/document-body.d.ts +0 -12
  32. package/lib/types/document-body.js +0 -14
  33. package/lib/types/health-baseline.d.ts +0 -13
  34. package/lib/types/health-baseline.js +0 -20
  35. package/lib/types/home-fence.d.ts +2 -0
  36. package/lib/types/home-fence.js +11 -1
  37. package/lib/types/http-routes.d.ts +9 -4
  38. package/lib/types/http-routes.js +36 -116
  39. package/lib/types/index.d.ts +0 -3
  40. package/lib/types/index.js +0 -3
  41. package/lib/types/io-registry.d.ts +0 -16
  42. package/lib/types/io-registry.js +0 -27
  43. package/lib/types/io.d.ts +6 -54
  44. package/lib/types/io.js +35 -65
  45. package/lib/types/journal-protocol.d.ts +0 -15
  46. package/lib/types/journal-protocol.js +1 -19
  47. package/lib/types/lease-store.d.ts +1 -1
  48. package/lib/types/lease-store.js +4 -15
  49. package/lib/types/live.d.ts +0 -12
  50. package/lib/types/live.js +0 -18
  51. package/lib/types/memory-store.d.ts +0 -1
  52. package/lib/types/memory-store.js +13 -6
  53. package/lib/types/mutation-authority.js +5 -0
  54. package/lib/types/mutation-unit.d.ts +1 -1
  55. package/lib/types/mutation-unit.js +14 -31
  56. package/lib/types/params.d.ts +11 -29
  57. package/lib/types/params.js +13 -60
  58. package/lib/types/platform/llm.d.ts +2 -3
  59. package/lib/types/platform/llm.js +3 -10
  60. package/lib/types/platform/projections.d.ts +4 -5
  61. package/lib/types/platform/projections.js +4 -18
  62. package/lib/types/probe.d.ts +0 -3
  63. package/lib/types/probe.js +0 -7
  64. package/lib/types/run-registry.js +10 -12
  65. package/lib/types/runtime/llm.js +2 -2
  66. package/lib/types/runtime/platform.d.ts +7 -11
  67. package/lib/types/runtime/platform.js +13 -19
  68. package/lib/types/runtime/plugin.d.ts +1 -1
  69. package/lib/types/runtime/plugin.js +6 -4
  70. package/lib/types/runtime/projections.js +1 -2
  71. package/lib/types/session-fold.d.ts +0 -8
  72. package/lib/types/session-fold.js +0 -5
  73. package/lib/types/session-projection.js +2 -2
  74. package/lib/types/skill-discovery.d.ts +0 -2
  75. package/lib/types/skill-discovery.js +1 -2
  76. package/lib/types/skill-health.d.ts +29 -1
  77. package/lib/types/skill-history.d.ts +0 -24
  78. package/lib/types/skill-history.js +0 -41
  79. package/lib/types/skill-lint.d.ts +0 -3
  80. package/lib/types/skill-lint.js +0 -12
  81. package/lib/types/skill-store.d.ts +6 -0
  82. package/lib/types/skill-store.js +130 -142
  83. package/lib/types/subagent/readiness.d.ts +0 -1
  84. package/lib/types/subagent/readiness.js +2 -8
  85. package/lib/types/tool-dispatch.d.ts +1 -16
  86. package/lib/types/tool-dispatch.js +0 -18
  87. package/lib/types/unit-journal.d.ts +1 -1
  88. package/lib/types/unit-journal.js +20 -15
  89. package/lib/types/unit-storage.d.ts +1 -1
  90. package/lib/types/unit-storage.js +5 -16
  91. package/lib/types/write-inventory.d.ts +0 -4
  92. package/lib/types/write-inventory.js +0 -9
  93. package/lib/types/write-kernel.d.ts +3 -4
  94. package/lib/types/write-kernel.js +13 -25
  95. package/lib/write.js +2 -2
  96. package/package.json +1 -1
  97. package/persisted-write-inventory.json +72 -9
  98. package/lib/types/fold-untrusted.d.ts +0 -35
  99. package/lib/types/fold-untrusted.js +0 -44
  100. package/lib/types/unit-recovery.d.ts +0 -5
  101. package/lib/types/unit-recovery.js +0 -12
@@ -58,39 +58,5 @@ var EvolutionIoRegistry = class extends Service {
58
58
  return first;
59
59
  }
60
60
  };
61
- const mediumObservations = /* @__PURE__ */ new WeakMap();
62
- /**
63
- * The read-only face of the marker: what served THIS registry, without resolving anything.
64
- * @param registry - the seam registry the caller already holds.
65
- * @returns `known` with the observation, or `unknown` when nothing resolved through this registry yet.
66
- */
67
- function describeMedium(registry) {
68
- const observation = mediumObservations.get(registry);
69
- if (observation === void 0) return { state: "unknown" };
70
- return {
71
- state: "known",
72
- requested: observation.requested,
73
- resolved: observation.resolved,
74
- via: observation.via
75
- };
76
- }
77
- function preferProvider(registry, names) {
78
- for (const name of names) try {
79
- const resolved = registry.provider(name);
80
- mediumObservations.set(registry, {
81
- requested: names,
82
- resolved: name,
83
- via: "preference"
84
- });
85
- return resolved;
86
- } catch {}
87
- const fallback = registry.provider();
88
- mediumObservations.set(registry, {
89
- requested: names,
90
- resolved: void 0,
91
- via: "default"
92
- });
93
- return fallback;
94
- }
95
61
  //#endregion
96
- export { EvolutionIoRegistry, EvolutionIoRegistry as default, describeMedium, preferProvider };
62
+ export { EvolutionIoRegistry, EvolutionIoRegistry as default };
@@ -1,4 +1,4 @@
1
- import { i as isProcessAlive } from "./io-AmUf4lVY.js";
1
+ import { a as isProcessAlive, c as transactIo } from "./io-GxghO3Ip.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { mkdir, readFile, rm } from "node:fs/promises";
4
4
  import { dirname, join, resolve } from "node:path";
@@ -95,6 +95,11 @@ var HomeAuthority = class {
95
95
  if (context?.owner === this) return context.scopes.has(scope);
96
96
  return (this.held.get(scope) ?? 0) > 0;
97
97
  }
98
+ /** True only when THIS async call context already holds `scope` (re-entrant nesting). */
99
+ holdsInContext(scope) {
100
+ const context = CONTEXT.getStore();
101
+ return context?.owner === this && context.scopes.has(scope);
102
+ }
98
103
  /** True while this instance holds the home lock for any scope. */
99
104
  get holding() {
100
105
  return this.held.size > 0;
@@ -338,9 +343,15 @@ var HomeFence = class {
338
343
  get releaseFailure() {
339
344
  return this.authority.releaseFailure;
340
345
  }
346
+ /** True only when this async call context already holds the home tree scope. */
347
+ holdsTree() {
348
+ return this.authority.holdsInContext("tree");
349
+ }
341
350
  async run(body) {
351
+ const invoke = async () => await body(lockView(this.authority));
342
352
  try {
343
- return await this.authority.runExclusive("tree", async () => await body(lockView(this.authority)));
353
+ if (this.authority.holdsInContext("tree")) return await this.authority.runNested("tree", invoke);
354
+ return await this.authority.runExclusive("tree", invoke);
344
355
  } catch (error) {
345
356
  throw classify(error);
346
357
  }
@@ -375,16 +386,6 @@ function parseLease(raw) {
375
386
  return;
376
387
  }
377
388
  }
378
- async function transact(io, path, task) {
379
- if (io.transact !== void 0) {
380
- await io.transact(path, task);
381
- return;
382
- }
383
- const current = await io.readText(path);
384
- const next = task(current);
385
- if (next === null) await io.remove(path);
386
- else if (next !== current) await io.writeText(path, next);
387
- }
388
389
  function tokenOf(record) {
389
390
  return {
390
391
  id: record.id,
@@ -417,7 +418,7 @@ var LeaseStore = class {
417
418
  const now = this.now();
418
419
  let created;
419
420
  let holder;
420
- await transact(this.io, path, (raw) => {
421
+ await transactIo(this.io, path, (raw) => {
421
422
  const current = parseLease(raw);
422
423
  if (current !== void 0 && current.state === "active" && now < current.expiresAt) {
423
424
  holder = current;
@@ -458,7 +459,7 @@ var LeaseStore = class {
458
459
  async renew(token, ttlMs = this.ttlMs) {
459
460
  const path = this.path(token.runId);
460
461
  let next = null;
461
- await transact(this.io, path, (raw) => {
462
+ await transactIo(this.io, path, (raw) => {
462
463
  const current = parseLease(raw);
463
464
  if (current === void 0 || current.state !== "active" || current.id !== token.id || current.epoch !== token.epoch) return raw;
464
465
  const now = this.now();
@@ -473,7 +474,7 @@ var LeaseStore = class {
473
474
  }
474
475
  async release(token) {
475
476
  const path = this.path(token.runId);
476
- await transact(this.io, path, (raw) => {
477
+ await transactIo(this.io, path, (raw) => {
477
478
  const current = parseLease(raw);
478
479
  if (current === void 0 || current.id !== token.id || current.epoch !== token.epoch) return raw;
479
480
  return JSON.stringify({
@@ -508,6 +509,7 @@ var MutationAuthority = class {
508
509
  /** Adapter for MutationUnit call sites that accept a lock port. It is the fence, no more. */
509
510
  get mutationLock() {
510
511
  return { acquire: async () => {
512
+ if (this.fence.holdsTree()) return { release: async () => {} };
511
513
  const lease = await this.fence.acquire();
512
514
  return { release: async () => {
513
515
  await lease.release();
@@ -1,4 +1,4 @@
1
- import { a as nodeEvolutionIo, s as transactIo } from "./io-AmUf4lVY.js";
1
+ import { c as transactIo, o as nodeEvolutionIo } from "./io-GxghO3Ip.js";
2
2
  import { n as isRecord } from "./guards-3f02mnf2.js";
3
3
  import { join } from "node:path";
4
4
  import { createHash } from "node:crypto";
@@ -100,7 +100,6 @@ const UPSTREAM_LIMIT_CHARS_PER_TOKEN = 2.75;
100
100
  * tokenization is needed"), matching upstream's ESTIMATE-side heuristic — "~4
101
101
  * chars/token is the usual English heuristic" (\`agent/prompt_builder.py:1179\`).
102
102
  * Estimates use this; limits use the constant above. */
103
- const PLATFORM_ESTIMATE_CHARS_PER_TOKEN = 4;
104
103
  const MAX_SKILL_FILE_BYTES = 1048576;
105
104
  const DEFAULT_REVIEW_MEMORY_INTERVAL = 10;
106
105
  const DEFAULT_REVIEW_SKILL_INTERVAL = 10;
@@ -137,8 +136,6 @@ const DEFAULT_SKILL_CONTENT_CHARS = MAX_SKILL_CONTENT_CHARS;
137
136
  /** P3-19 (v14): defaults that were written twice (schema `.default()` AND the
138
137
  * clamp fallback literal) now have one home per value. */
139
138
  const DEFAULT_REVIEW_TIMEOUT_MS = 12e4;
140
- const DEFAULT_REVIEW_CONTEXT_MESSAGES = 60;
141
- const DEFAULT_REVIEW_MESSAGE_CHARS = 2e3;
142
139
  const DEFAULT_CURATOR_BOOT_GRACE_SECONDS = 10;
143
140
  const DEFAULT_CURATOR_REVIEW_MAX_TOKENS = 2048;
144
141
  /** Threat-scan WINDOW SIZE (not a total cap — E-12: the whole text is scanned in
@@ -179,7 +176,6 @@ const AUTHORING_DESCRIPTION_BAR = 60;
179
176
  * this default only governs compositions that do not override it. It is NOT a refusal threshold:
180
177
  * the only refusal is `MAX_DESCRIPTION_LENGTH` / the row's `maxDescriptionLength`, and the catalog
181
178
  * cut is a view, not a validation. See tool-skill-manage/README.md for the three-number table. */
182
- const PLATFORM_CATALOG_DESCRIPTION_DEFAULT = 500;
183
179
  /** The split hint both size refusals share (0.5.0 V1). The same sentence used to
184
180
  * be copied into validateFrontmatter AND the patch path, and neither copy named
185
181
  * where the content should go — the upstream cap message names the destination
@@ -321,4 +317,4 @@ function clampedNumber(value, fallback, opts) {
321
317
  return value;
322
318
  }
323
319
  //#endregion
324
- export { UPSTREAM_LIMIT_CHARS_PER_TOKEN as $, DEFAULT_STALE_AFTER_DAYS as A, MAX_SKILL_CONTENT_CHARS as B, DEFAULT_REVIEW_MESSAGE_CHARS as C, DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS as D, DEFAULT_SKILL_CONTENT_CHARS as E, DEFAULT_USER_CHAR_LIMIT as F, PLATFORM_CATALOG_DESCRIPTION_DEFAULT as G, MAX_SKILL_NAME_LENGTH as H, ENTRY_DELIMITER as I, SKILLS_GUIDANCE_SECTION_ORDER as J, PLATFORM_ESTIMATE_CHARS_PER_TOKEN as K, EVOLUTION_WRITE_TOOLS as L, DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS as M, DEFAULT_SUBSTANTIVE_MIN_USER_CHARS as N, DEFAULT_SKILL_REVIEW_TRIGGER as O, DEFAULT_THREAT_MAX_SCAN_CHARS as P, SUPPORT_SPRAWL_FILES as Q, FORBIDDEN_CONTROL_KEYS as R, DEFAULT_REVIEW_MEMORY_INTERVAL as S, DEFAULT_REVIEW_TIMEOUT_MS as T, MAX_TIMER_DELAY_MS as U, MAX_SKILL_FILE_BYTES as V, MEMORY_GUIDANCE_SECTION_ORDER as W, SKILL_NAME_RE as X, SKILL_ACTION_REQUIRED_FIELDS as Y, SUPPORT_DIRS as Z, DEFAULT_CURATOR_REVIEW_MAX_TOKENS as _, DEFAULT_SKILL_LIMITS as a, DEFAULT_PROBE_TIMEOUT_MS as b, policyStageLimits as c, CONTENT_SPLIT_HINT as d, DEFAULT_ARCHIVE_AFTER_DAYS as f, DEFAULT_CURATOR_MODEL as g, DEFAULT_CURATOR_INTERVAL_HOURS as h, DEFAULT_REFERENCE_REWRITE_POLICY as i, DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS as j, DEFAULT_SKILL_VERSION_KEEP as k, AUTHORING_DESCRIPTION_BAR as l, DEFAULT_CURATOR_BOOT_GRACE_SECONDS as m, DEFAULT_ARCHIVE_RETENTION_POLICY as n, DEFAULT_SUPPORT_FILE_CHAR_POLICY as o, DEFAULT_CONSOLIDATION_FAILURES as p, PROTECTED_BUILTIN_SKILLS as q, DEFAULT_CITATION_POLICY as r, POLICY_STAGE_DEFAULTS as s, clampedNumber as t, AUTHORING_SPLIT_LINE_CHARS as u, DEFAULT_MEMORY_CHAR_LIMIT as v, DEFAULT_REVIEW_SKILL_INTERVAL as w, DEFAULT_REVIEW_CONTEXT_MESSAGES as x, DEFAULT_MIN_IDLE_HOURS as y, MAX_DESCRIPTION_LENGTH as z };
320
+ export { DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS as A, MAX_SKILL_NAME_LENGTH as B, DEFAULT_REVIEW_TIMEOUT_MS as C, DEFAULT_SKILL_VERSION_KEEP as D, DEFAULT_SKILL_REVIEW_TRIGGER as E, EVOLUTION_WRITE_TOOLS as F, SKILL_ACTION_REQUIRED_FIELDS as G, MEMORY_GUIDANCE_SECTION_ORDER as H, FORBIDDEN_CONTROL_KEYS as I, SUPPORT_SPRAWL_FILES as J, SKILL_NAME_RE as K, MAX_DESCRIPTION_LENGTH as L, DEFAULT_THREAT_MAX_SCAN_CHARS as M, DEFAULT_USER_CHAR_LIMIT as N, DEFAULT_STALE_AFTER_DAYS as O, ENTRY_DELIMITER as P, MAX_SKILL_CONTENT_CHARS as R, DEFAULT_REVIEW_SKILL_INTERVAL as S, DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS as T, PROTECTED_BUILTIN_SKILLS as U, MAX_TIMER_DELAY_MS as V, SKILLS_GUIDANCE_SECTION_ORDER as W, UPSTREAM_LIMIT_CHARS_PER_TOKEN as Y, DEFAULT_CURATOR_REVIEW_MAX_TOKENS as _, DEFAULT_SKILL_LIMITS as a, DEFAULT_PROBE_TIMEOUT_MS as b, policyStageLimits as c, CONTENT_SPLIT_HINT as d, DEFAULT_ARCHIVE_AFTER_DAYS as f, DEFAULT_CURATOR_MODEL as g, DEFAULT_CURATOR_INTERVAL_HOURS as h, DEFAULT_REFERENCE_REWRITE_POLICY as i, DEFAULT_SUBSTANTIVE_MIN_USER_CHARS as j, DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS as k, AUTHORING_DESCRIPTION_BAR as l, DEFAULT_CURATOR_BOOT_GRACE_SECONDS as m, DEFAULT_ARCHIVE_RETENTION_POLICY as n, DEFAULT_SUPPORT_FILE_CHAR_POLICY as o, DEFAULT_CONSOLIDATION_FAILURES as p, SUPPORT_DIRS as q, DEFAULT_CITATION_POLICY as r, POLICY_STAGE_DEFAULTS as s, clampedNumber as t, AUTHORING_SPLIT_LINE_CHARS as u, DEFAULT_MEMORY_CHAR_LIMIT as v, DEFAULT_SKILL_CONTENT_CHARS as w, DEFAULT_REVIEW_MEMORY_INTERVAL as x, DEFAULT_MIN_IDLE_HOURS as y, MAX_SKILL_FILE_BYTES as z };
@@ -1,4 +1,4 @@
1
1
  import { t as presetsPort } from "../presets-C8vuCuNA.js";
2
- import { a as createUserMessage, c as domainTable, d as EvolutionLlmError, f as llmPort, i as createToolResultMessage, l as escapeText, m as projectionPort, n as DomainError, o as defineDomain, p as modelRoute, r as SessionId, s as defineTool, t as BlockAssembler, u as scopeOf } from "../platform-CFA12Jam.js";
2
+ import { a as createUserMessage, c as domainTable, d as EvolutionLlmError, f as llmPort, i as createToolResultMessage, l as escapeText, m as projectionPort, n as DomainError, o as defineDomain, p as modelRoute, r as SessionId, s as defineTool, t as BlockAssembler, u as scopeOf } from "../platform-Cc9cNt5j.js";
3
3
  import { n as toolsPort, t as registerEvolutionTool } from "../tools-DzcNFex2.js";
4
4
  export { BlockAssembler, DomainError, EvolutionLlmError, SessionId, createToolResultMessage, createUserMessage, defineDomain, defineTool, domainTable, escapeText, llmPort, modelRoute, presetsPort, projectionPort, registerEvolutionTool, scopeOf, toolsPort };
@@ -5,7 +5,6 @@ import { escapeText } from "@deepseek-ai/dsh-skill";
5
5
  import { BlockAssembler, createToolResultMessage, createUserMessage } from "@deepseek-ai/dsh-llm";
6
6
  import { SessionId } from "@deepseek-ai/dsh-session";
7
7
  //#region lib/types/platform/projections.js
8
- const isThenable = (value) => (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
9
8
  const isHandle = (value) => value !== null && typeof value === "object" && typeof value.stateOf === "function" && typeof value.dispose === "function";
10
9
  /** Resolve the projection port; undefined means the host has no projection registry. */
11
10
  function projectionPort(ctx) {
@@ -21,8 +20,7 @@ function projectionPort(ctx) {
21
20
  return shape === "unrecognised" ? reason : void 0;
22
21
  },
23
22
  async register(definition) {
24
- const raw = registry.register(definition);
25
- const resolved = isThenable(raw) ? await raw : raw;
23
+ const resolved = await registry.register(definition);
26
24
  if (isHandle(resolved)) {
27
25
  shape = "handle";
28
26
  reason = void 0;
@@ -31,18 +29,8 @@ function projectionPort(ctx) {
31
29
  dispose: () => resolved.dispose()
32
30
  };
33
31
  }
34
- if (resolved === raw && typeof raw === "function" && typeof registry.stateOf === "function") {
35
- shape = "legacy";
36
- reason = void 0;
37
- return {
38
- stateOf: (session) => registry.stateOf?.(session, definition.key),
39
- dispose: async () => {
40
- raw();
41
- }
42
- };
43
- }
44
32
  shape = "unrecognised";
45
- reason = "sessionProjections.register returned " + (resolved === null ? "null" : typeof resolved) + " with neither a projection handle nor a legacy disposer";
33
+ reason = "sessionProjections.register returned " + (resolved === null ? "null" : typeof resolved) + " without a projection handle";
46
34
  return {
47
35
  stateOf: () => void 0,
48
36
  dispose: async () => {}
@@ -80,20 +68,8 @@ function llmPort(ctx) {
80
68
  const port = {
81
69
  async *stream(request) {
82
70
  const options = toOptions(request);
83
- if (llm.stream !== void 0) {
84
- yield* llm.stream(options);
85
- return;
86
- }
87
- if (llm.prepareCall !== void 0) {
88
- const call = await llm.prepareCall(options, request.signal);
89
- yield* call.stream({
90
- ...call.config,
91
- messages: request.messages,
92
- ...request.signal === void 0 ? {} : { signal: request.signal }
93
- });
94
- return;
95
- }
96
- throw new EvolutionLlmError("transport", "llm service has neither stream nor prepareCall");
71
+ if (llm.stream === void 0) throw new EvolutionLlmError("transport", "llm service has no stream()");
72
+ yield* llm.stream(options);
97
73
  },
98
74
  async completeText(request) {
99
75
  let text = "";
package/lib/policy.js CHANGED
@@ -1,4 +1,4 @@
1
- import { E as DEFAULT_SKILL_CONTENT_CHARS, F as DEFAULT_USER_CHAR_LIMIT, L as EVOLUTION_WRITE_TOOLS, R as FORBIDDEN_CONTROL_KEYS, g as DEFAULT_CURATOR_MODEL, i as DEFAULT_REFERENCE_REWRITE_POLICY, n as DEFAULT_ARCHIVE_RETENTION_POLICY, o as DEFAULT_SUPPORT_FILE_CHAR_POLICY, q as PROTECTED_BUILTIN_SKILLS, r as DEFAULT_CITATION_POLICY, s as POLICY_STAGE_DEFAULTS, t as clampedNumber, v as DEFAULT_MEMORY_CHAR_LIMIT } from "./numeric-DLeLvvGb.js";
1
+ import { F as EVOLUTION_WRITE_TOOLS, I as FORBIDDEN_CONTROL_KEYS, N as DEFAULT_USER_CHAR_LIMIT, U as PROTECTED_BUILTIN_SKILLS, g as DEFAULT_CURATOR_MODEL, i as DEFAULT_REFERENCE_REWRITE_POLICY, n as DEFAULT_ARCHIVE_RETENTION_POLICY, o as DEFAULT_SUPPORT_FILE_CHAR_POLICY, r as DEFAULT_CITATION_POLICY, s as POLICY_STAGE_DEFAULTS, t as clampedNumber, v as DEFAULT_MEMORY_CHAR_LIMIT, w as DEFAULT_SKILL_CONTENT_CHARS } from "./numeric-D8js3sqC.js";
2
2
  import { t as asRecord } from "./guards-3f02mnf2.js";
3
3
  import { n as toolsPort } from "./tools-DzcNFex2.js";
4
4
  import { Service } from "@deepseek-ai/cordis";
@@ -1,6 +1,6 @@
1
- import { a as evolutionSignalsProjection, i as evolutionReadsProjection, n as evolutionEvidenceProjection, r as evolutionProjectionHistoryProjection, t as evolutionActivityProjection } from "../session-projection-EB7mUOlJ.js";
1
+ import { a as evolutionSignalsProjection, i as evolutionReadsProjection, n as evolutionEvidenceProjection, r as evolutionProjectionHistoryProjection, t as evolutionActivityProjection } from "../session-projection-DSXnUNZG.js";
2
2
  import { t as presetsPort } from "../presets-C8vuCuNA.js";
3
- import { d as EvolutionLlmError, f as llmPort, m as projectionPort, p as modelRoute } from "../platform-CFA12Jam.js";
3
+ import { d as EvolutionLlmError, f as llmPort, m as projectionPort, p as modelRoute } from "../platform-Cc9cNt5j.js";
4
4
  import { n as toolsPort } from "../tools-DzcNFex2.js";
5
5
  import { Service } from "@deepseek-ai/cordis";
6
6
  //#region lib/types/runtime/llm.js
@@ -17,7 +17,7 @@ var EvolutionLlm = class extends Service {
17
17
  }
18
18
  [Service.init]() {
19
19
  const platform = this.ctx.get("evolutionPlatform");
20
- this.port = platform?.ports?.llm ?? llmPort(this.ctx);
20
+ this.port = platform?.ports.llm;
21
21
  if (this.port === void 0) this.ctx.logger.warn("evolution-core-runtime: llm service unavailable; model calls fail with llm-unavailable");
22
22
  }
23
23
  /** Whether the platform llm service is mounted. */
@@ -79,44 +79,22 @@ var EvolutionLlm = class extends Service {
79
79
  /** Domain service owning the host port table. */
80
80
  var EvolutionPlatform = class extends Service {
81
81
  static inject = [];
82
- ports;
82
+ resolved;
83
83
  constructor(ctx) {
84
84
  super(ctx, "evolutionPlatform");
85
- this.ports = {
86
- projections: projectionPort(ctx),
87
- llm: llmPort(ctx),
88
- tools: toolsPort(ctx),
89
- presets: presetsPort(ctx)
90
- };
91
85
  }
92
- /** True when the two services the runtime cannot work without are present. */
93
- ready() {
94
- return this.ports.projections !== void 0 && this.ports.llm !== void 0;
95
- }
96
- /** One row per optional host service; absent services stay visible, not silent. */
97
- capabilities() {
98
- return [
99
- {
100
- name: "projections",
101
- available: this.ports.projections !== void 0,
102
- ...this.ports.projections === void 0 ? { reason: "sessionProjections unavailable" } : {}
103
- },
104
- {
105
- name: "llm",
106
- available: this.ports.llm !== void 0,
107
- ...this.ports.llm === void 0 ? { reason: "llm unavailable" } : {}
108
- },
109
- {
110
- name: "tools",
111
- available: this.ports.tools !== void 0,
112
- ...this.ports.tools === void 0 ? { reason: "tools unavailable" } : {}
113
- },
114
- {
115
- name: "presets",
116
- available: this.ports.presets !== void 0,
117
- ...this.ports.presets === void 0 ? { reason: "agentPresets unavailable" } : {}
118
- }
119
- ];
86
+ /**
87
+ * Resolve the host ports on first use and keep that answer for the service
88
+ * lifetime. Consumers read this one table; they never fall back to a direct
89
+ * platform import (the second resolution D7 removed).
90
+ */
91
+ get ports() {
92
+ return this.resolved ??= {
93
+ projections: projectionPort(this.ctx),
94
+ llm: llmPort(this.ctx),
95
+ tools: toolsPort(this.ctx),
96
+ presets: presetsPort(this.ctx)
97
+ };
120
98
  }
121
99
  };
122
100
  //#endregion
@@ -136,7 +114,7 @@ var EvolutionProjections = class extends Service {
136
114
  super(ctx, "evolutionProjections");
137
115
  }
138
116
  async [Service.init]() {
139
- const port = this.ctx.get("evolutionPlatform")?.ports?.projections ?? projectionPort(this.ctx);
117
+ const port = this.ctx.get("evolutionPlatform")?.ports.projections;
140
118
  if (port === void 0) {
141
119
  this.markDegraded("sessionProjections service unavailable");
142
120
  return;
@@ -195,10 +173,10 @@ var EvolutionProjections = class extends Service {
195
173
  //#region lib/types/runtime/plugin.js
196
174
  const name = "evolution-core-runtime";
197
175
  /** @param ctx - the composition context that owns the runtime services. */
198
- function apply(ctx) {
199
- ctx.plugin(EvolutionPlatform);
200
- ctx.plugin(EvolutionProjections);
201
- ctx.plugin(EvolutionLlm);
176
+ async function apply(ctx) {
177
+ await ctx.plugin(EvolutionPlatform);
178
+ await ctx.plugin(EvolutionProjections);
179
+ await ctx.plugin(EvolutionLlm);
202
180
  }
203
181
  //#endregion
204
182
  export { apply, name };
@@ -502,7 +502,6 @@ function isSkillReadToolName(name) {
502
502
  return SKILL_READ_TOOL_NAMES.has(name);
503
503
  }
504
504
  /** Tool names whose dispatch opens a code program, i.e. whose sub-dispatches are \`program\`. */
505
- const PROGRAM_TOOL_NAMES = new Set(["run_code"]);
506
505
  /**
507
506
  * Does this signal read one skill, and did it not fail?
508
507
  * @param signal - a normalized dispatch.
@@ -651,14 +650,6 @@ function isSkillToolName(name) {
651
650
  return SKILL_TOOL_NAMES.has(name);
652
651
  }
653
652
  /**
654
- * Does this dispatched tool name open a code program?
655
- * @param name - the dispatched tool name.
656
- * @returns \`true\` for the tool whose sub-dispatches are \`program\` kind.
657
- */
658
- function isProgramToolName(name) {
659
- return PROGRAM_TOOL_NAMES.has(name);
660
- }
661
- /**
662
653
  * Assert that a payload really is the dispatch event it claims to be.
663
654
  *
664
655
  * The normalizer is deliberately lenient (it also folds persisted logs, where a
@@ -687,15 +678,6 @@ function assertDispatchPayload(event) {
687
678
  if (event.type === "tool/result") return;
688
679
  throw new ToolDispatchPayloadError(`${event.type} is not a platform dispatch event; compare signal.kind instead of event types`);
689
680
  }
690
- /**
691
- * Total dispatches in a log, deduplicated.
692
- * @param events - the log, oldest first.
693
- * @returns the number of distinct dispatches, one per dispatch regardless of
694
- * how many events carried it.
695
- */
696
- function countDispatches(events) {
697
- return foldToolDispatches(events).length;
698
- }
699
681
  //#endregion
700
682
  //#region lib/types/evidence.js
701
683
  /**
@@ -1038,7 +1020,7 @@ const readsStateSchema = z.object({ reads: z.array(z.object({
1038
1020
  failed: z.boolean(),
1039
1021
  file: z.string().nullable().optional(),
1040
1022
  tool: z.string().optional()
1041
- }).strict()) }).strict();
1023
+ }).strict()).max(512) }).strict();
1042
1024
  const signalsStateSchema = z.object({
1043
1025
  through: z.number().int().min(-1).max(Number.MAX_SAFE_INTEGER),
1044
1026
  lastEventTime: z.number().nonnegative().max(MAX_TIMESTAMP_MS),
@@ -1137,7 +1119,7 @@ const evolutionReadsProjection = {
1137
1119
  arguments: step.arguments,
1138
1120
  ok: step.outcome?.ok
1139
1121
  }) ?? null;
1140
- return { reads: [...state.reads, {
1122
+ return { reads: [...state.reads.slice(-511), {
1141
1123
  key: step.key,
1142
1124
  skill,
1143
1125
  failed: step.outcome?.ok === false
@@ -1247,4 +1229,4 @@ function sessionEvidenceIndex(ctx, session) {
1247
1229
  return { has: (seq) => Number.isInteger(seq) && seq >= 0 && seq <= through && !bookkeeping.includes(seq) };
1248
1230
  }
1249
1231
  //#endregion
1250
- export { countDispatches as A, supportFileReadFromPath as B, PTC_DISPATCH_EVENT as C, assertDispatchPayload as D, ToolDispatchPayloadError as E, isProgramToolName as F, KEEP_LINE_RE as G, CITATION_SUPPORT_DIRS as H, isSkillReadToolName as I, scanBodyHooks as J, isFileShapedPath as K, isSkillToolName as L, dispatchPathOf as M, dispatchStepOf as N, collectReadSkillNames as O, foldToolDispatches as P, readDispatchSignal as R, NATIVE_RESULT_EVENT as S, ToolDispatchNormalizer as T, DEFAULT_CITATION_REF_BUDGET as U, supportFileReadOf as V, HOOK_LINE_RE as W, isBookkeepingFrame as _, evolutionSignalsProjection as a, MODEL_SESSION_EVENT_TYPES as b, sessionLastEventTime as c, advanceReview as d, foldTurnEvent as f, evidenceKindIndex as g, observeEvent as h, evolutionReadsProjection as i, dispatchKeyOf as j, collectReadSupportFiles as k, sessionReadNames as l, initialTurnFold as m, evolutionEvidenceProjection as n, isProjectableSession as o, foldTurnEvents as p, resolveCitations as q, evolutionProjectionHistoryProjection as r, sessionEvidenceIndex as s, evolutionActivityProjection as t, sessionTurnSignals as u, DEFAULT_SUPPORT_READ_TOOL_NAMES as v, PTC_DISPATCH_START_EVENT as w, NATIVE_CALL_EVENT as x, DISPATCH_EVENT_TYPES as y, skillReadNameOf as z };
1232
+ export { dispatchKeyOf as A, CITATION_SUPPORT_DIRS as B, PTC_DISPATCH_EVENT as C, assertDispatchPayload as D, ToolDispatchPayloadError as E, isSkillToolName as F, resolveCitations as G, HOOK_LINE_RE as H, readDispatchSignal as I, scanBodyHooks as K, skillReadNameOf as L, dispatchStepOf as M, foldToolDispatches as N, collectReadSkillNames as O, isSkillReadToolName as P, supportFileReadFromPath as R, NATIVE_RESULT_EVENT as S, ToolDispatchNormalizer as T, KEEP_LINE_RE as U, DEFAULT_CITATION_REF_BUDGET as V, isFileShapedPath as W, isBookkeepingFrame as _, evolutionSignalsProjection as a, MODEL_SESSION_EVENT_TYPES as b, sessionLastEventTime as c, advanceReview as d, foldTurnEvent as f, evidenceKindIndex as g, observeEvent as h, evolutionReadsProjection as i, dispatchPathOf as j, collectReadSupportFiles as k, sessionReadNames as l, initialTurnFold as m, evolutionEvidenceProjection as n, isProjectableSession as o, foldTurnEvents as p, evolutionProjectionHistoryProjection as r, sessionEvidenceIndex as s, evolutionActivityProjection as t, sessionTurnSignals as u, DEFAULT_SUPPORT_READ_TOOL_NAMES as v, PTC_DISPATCH_START_EVENT as w, NATIVE_CALL_EVENT as x, DISPATCH_EVENT_TYPES as y, supportFileReadOf as z };
@@ -1,6 +1,6 @@
1
- import { a as nodeEvolutionIo, s as transactIo } from "./io-AmUf4lVY.js";
2
- import { B as supportFileReadFromPath, O as collectReadSkillNames, k as collectReadSupportFiles, l as sessionReadNames, o as isProjectableSession, q as resolveCitations, v as DEFAULT_SUPPORT_READ_TOOL_NAMES } from "./session-projection-EB7mUOlJ.js";
3
- import { $ as UPSTREAM_LIMIT_CHARS_PER_TOKEN, P as DEFAULT_THREAT_MAX_SCAN_CHARS, X as SKILL_NAME_RE, a as DEFAULT_SKILL_LIMITS, d as CONTENT_SPLIT_HINT, t as clampedNumber, u as AUTHORING_SPLIT_LINE_CHARS } from "./numeric-DLeLvvGb.js";
1
+ import { c as transactIo, o as nodeEvolutionIo } from "./io-GxghO3Ip.js";
2
+ import { G as resolveCitations, O as collectReadSkillNames, R as supportFileReadFromPath, k as collectReadSupportFiles, l as sessionReadNames, o as isProjectableSession, v as DEFAULT_SUPPORT_READ_TOOL_NAMES } from "./session-projection-DSXnUNZG.js";
3
+ import { K as SKILL_NAME_RE, M as DEFAULT_THREAT_MAX_SCAN_CHARS, Y as UPSTREAM_LIMIT_CHARS_PER_TOKEN, a as DEFAULT_SKILL_LIMITS, d as CONTENT_SPLIT_HINT, t as clampedNumber, u as AUTHORING_SPLIT_LINE_CHARS } from "./numeric-D8js3sqC.js";
4
4
  import { n as isRecord } from "./guards-3f02mnf2.js";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
6
6
  import { dirname, join } from "node:path";
@@ -906,18 +906,6 @@ function h2Sections(body) {
906
906
  for (const row of rows) row.count = rows.filter((other) => other.title === row.title).length;
907
907
  return rows;
908
908
  }
909
- /**
910
- * The sections a restructure proposal may name: heading unique, section non-empty. Derived from
911
- * `h2Sections`, i.e. from the SAME scan the store validates against.
912
- * @param body - the markdown after the frontmatter block.
913
- * @returns move-ready pairs in document order; empty when nothing qualifies.
914
- */
915
- function restructureCandidates(body) {
916
- return h2Sections(body).filter((section) => section.count === 1 && section.end > section.start + 1).map((section) => ({
917
- heading: section.title,
918
- toFile: "references/" + section.title.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/g, "-").replace(/^-+|-+$/g, "") + ".md"
919
- }));
920
- }
921
909
  //#endregion
922
910
  //#region lib/types/section-selection.js
923
911
  const LF$1 = String.fromCharCode(10);
@@ -1891,15 +1879,6 @@ function diffFindings(before, after) {
1891
1879
  resolved: before.filter((f) => !afterByRule.has(f.rule)).map((f) => f.rule)
1892
1880
  };
1893
1881
  }
1894
- /** Support files = markdown files under references/ (contract §4: unit frozen, underscore-prefixed
1895
- * excluded). Paths are supplied by the caller — this module never touches the filesystem. */
1896
- function countReferenceFiles(paths) {
1897
- return paths.filter((p) => {
1898
- const n = p.replace(/\\/g, "/");
1899
- if (!(n.includes("/references/") || n.startsWith("references/")) || !n.endsWith(".md")) return false;
1900
- return !n.slice(n.lastIndexOf("/") + 1).startsWith("_");
1901
- }).length;
1902
- }
1903
1882
  //#endregion
1904
1883
  //#region lib/types/evolution-events.js
1905
1884
  /**
@@ -2941,4 +2920,4 @@ function assessStructureHealth(snapshot, thresholds = DEFAULT_HEALTH_THRESHOLDS)
2941
2920
  };
2942
2921
  }
2943
2922
  //#endregion
2944
- export { bumpUse as $, listEventArchives as A, normalizeFrontmatter as At, COST_ASCII_TOKEN_LOW as B, describeReferenceRewrite as Bt, EVENT_ARCHIVE_PREFIX as C, readingStats as Ct, appendEvolutionEvent as D, exceedsContentLimit as Dt, EVENT_LOG_VERSION as E, ensureSkillFrontmatter as Et, RULES as F, validateFrontmatter as Ft, bodyCost as G, isUnreadWrite as Gt, COST_CJK_TOKEN_LOW as H, planRehoming as Ht, countReferenceFiles as I, yamlPlainScalarNeedsQuotes as It, SUPPRESSED_FILE_VERSION as J, DEFAULT_WRITE_CONFIRM_MODE as Jt, tokenLineFor as K, sessionReadSkillNames as Kt, diffFindings as L, externalRefs as Lt, readEvolutionEvents as M, relatedSkillNames as Mt, readEvolutionTimeline as N, shrinksOverLimit as Nt, eventsFile as O, frontmatterBlock as Ot, retainEventArchives as P, skillMdOnDisk as Pt, bumpSupportRead as Q, lintSkill as R, supportRefs as Rt, trimPatternBoundaries as S, h2Sections as St, EVENT_LOG_ROTATE_AT as T, authoringFeedback as Tt, TOKEN_ASCII_WEIGHT as U, READ_REQUIRED_ACTIONS as Ut, COST_CJK_TOKEN_HIGH as V, planReferenceRewrite as Vt, TOKEN_CJK_WEIGHT as W, filterUnreadSkillOps as Wt, applyCuratorMetaFields as X, authorityFrom as Xt, applyCuratorLifecycleFields as Y, DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS as Yt, bumpPatch as Z, scanThreats as _, usageObserved as _t, lintBody as a, idleDays as at, FUZZY_MAX_WORK as b, selectSections as bt, clearReviewChannel as c, loadUsage as ct, sweepReviewChannelSessions as d, normalizeUsageRecord as dt, bumpView as et, PATTERN_OVERLAP as f, saveSuppressedNames as ft, scanMemoryThreats as g, usageFile as gt, scanContentThreats as h, updateSuppressedNames as ht, assessStructureHealth as i, getRecord as it, parseEvolutionEvents as j, parseFrontmatter as jt, evolutionEventPayloadIssue as k, frontmatterCatalogInvalid as kt, isReviewChannelSession as l, markAgentCreated as lt, evaluateThreat as m, suppressedFile as mt, HEALTH_STAMP_RE as n, emptyRecord as nt, currentReviewContext as o, latestActivityAt as ot, THREAT_EXEMPTION_HINT as p, saveUsage as pt, MAX_SUPPORT_READ_PATHS as q, sessionReadSupportFiles as qt, MIN_STAMP_BODY_CHARS as r, foldCuratorFields as rt, withReviewContext as s, loadSuppressedNames as st, DEFAULT_HEALTH_THRESHOLDS as t, daysSinceIso as tt, markReviewChannel as u, mutateUsage as ut, makeSerialQueue as v, planExtract as vt, EVENT_LOG_RETAIN_ARCHIVES as w, restructureCandidates as wt, fuzzyPatch as x, displayBodyOf as xt, FUZZY_MAX_PATTERN_CHARS as y, projectExtractBodies as yt, COST_ASCII_TOKEN_HIGH as z, applyReferenceRewrite as zt };
2923
+ export { bumpView as $, listEventArchives as A, relatedSkillNames as At, COST_CJK_TOKEN_HIGH as B, planRehoming as Bt, EVENT_ARCHIVE_PREFIX as C, authoringFeedback as Ct, appendEvolutionEvent as D, frontmatterCatalogInvalid as Dt, EVENT_LOG_VERSION as E, frontmatterBlock as Et, RULES as F, externalRefs as Ft, tokenLineFor as G, sessionReadSupportFiles as Gt, TOKEN_ASCII_WEIGHT as H, filterUnreadSkillOps as Ht, diffFindings as I, supportRefs as It, applyCuratorLifecycleFields as J, authorityFrom as Jt, MAX_SUPPORT_READ_PATHS as K, DEFAULT_WRITE_CONFIRM_MODE as Kt, lintSkill as L, applyReferenceRewrite as Lt, readEvolutionEvents as M, skillMdOnDisk as Mt, readEvolutionTimeline as N, validateFrontmatter as Nt, eventsFile as O, normalizeFrontmatter as Ot, retainEventArchives as P, yamlPlainScalarNeedsQuotes as Pt, bumpUse as Q, COST_ASCII_TOKEN_HIGH as R, describeReferenceRewrite as Rt, trimPatternBoundaries as S, readingStats as St, EVENT_LOG_ROTATE_AT as T, exceedsContentLimit as Tt, TOKEN_CJK_WEIGHT as U, isUnreadWrite as Ut, COST_CJK_TOKEN_LOW as V, READ_REQUIRED_ACTIONS as Vt, bodyCost as W, sessionReadSkillNames as Wt, bumpPatch as X, applyCuratorMetaFields as Y, bumpSupportRead as Z, scanThreats as _, planExtract as _t, lintBody as a, latestActivityAt as at, FUZZY_MAX_WORK as b, displayBodyOf as bt, clearReviewChannel as c, markAgentCreated as ct, sweepReviewChannelSessions as d, saveSuppressedNames as dt, daysSinceIso as et, PATTERN_OVERLAP as f, saveUsage as ft, scanMemoryThreats as g, usageObserved as gt, scanContentThreats as h, usageFile as ht, assessStructureHealth as i, idleDays as it, parseEvolutionEvents as j, shrinksOverLimit as jt, evolutionEventPayloadIssue as k, parseFrontmatter as kt, isReviewChannelSession as l, mutateUsage as lt, evaluateThreat as m, updateSuppressedNames as mt, HEALTH_STAMP_RE as n, foldCuratorFields as nt, currentReviewContext as o, loadSuppressedNames as ot, THREAT_EXEMPTION_HINT as p, suppressedFile as pt, SUPPRESSED_FILE_VERSION as q, DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS as qt, MIN_STAMP_BODY_CHARS as r, getRecord as rt, withReviewContext as s, loadUsage as st, DEFAULT_HEALTH_THRESHOLDS as t, emptyRecord as tt, markReviewChannel as u, normalizeUsageRecord as ut, makeSerialQueue as v, projectExtractBodies as vt, EVENT_LOG_RETAIN_ARCHIVES as w, ensureSkillFrontmatter as wt, fuzzyPatch as x, h2Sections as xt, FUZZY_MAX_PATTERN_CHARS as y, selectSections as yt, COST_ASCII_TOKEN_LOW as z, planReferenceRewrite as zt };