@lmzhen/dsh-evolution-core 0.53.0 → 0.55.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 (53) hide show
  1. package/lib/{extract-plan-D4zO7dmD.js → extract-plan-ihQznLVT.js} +2 -1
  2. package/lib/extract.js +7 -7
  3. package/lib/index.js +795 -546
  4. package/lib/{limits-TD4Pv92Q.js → limits-DBg3UMkw.js} +11 -6
  5. package/lib/{skill-history-CZp8vhyL.js → mutation-storage-adapter-BM7mIJKp.js} +4 -647
  6. package/lib/mutations-1wLISSrY.js +592 -0
  7. package/lib/policy.js +9 -3
  8. package/lib/{quality-BLc6UQQb.js → quality-DNUVRbUm.js} +1 -1
  9. package/lib/{skill-health-BIpiPvw6.js → review-context-CXKwGGd8.js} +124 -183
  10. package/lib/runtime/plugin.js +92 -1
  11. package/lib/{session-projection-ByNxQi9O.js → session-projection-CbIKvDfJ.js} +3 -2
  12. package/lib/skill-history-B-DyIedq.js +646 -0
  13. package/lib/skills.js +12 -8
  14. package/lib/text-metrics-CyJhxWBs.js +132 -0
  15. package/lib/types/constants.d.ts +10 -5
  16. package/lib/types/constants.js +10 -5
  17. package/lib/types/drift-signals.d.ts +1 -4
  18. package/lib/types/drift-signals.js +14 -23
  19. package/lib/types/extract-request.js +3 -2
  20. package/lib/types/frontmatter.js +12 -8
  21. package/lib/types/index.d.ts +2 -1
  22. package/lib/types/index.js +2 -1
  23. package/lib/types/memory-store.d.ts +32 -6
  24. package/lib/types/memory-store.js +86 -30
  25. package/lib/types/mutation-unit.js +2 -1
  26. package/lib/types/params.js +6 -3
  27. package/lib/types/policy.d.ts +5 -0
  28. package/lib/types/policy.js +8 -2
  29. package/lib/types/prompts.d.ts +1 -1
  30. package/lib/types/prompts.js +1 -1
  31. package/lib/types/runtime/coherence.d.ts +27 -0
  32. package/lib/types/runtime/coherence.js +115 -0
  33. package/lib/types/runtime/plugin.js +2 -0
  34. package/lib/types/signals.js +3 -2
  35. package/lib/types/skill-health.d.ts +8 -5
  36. package/lib/types/skill-health.js +27 -28
  37. package/lib/types/skill-history.d.ts +2 -2
  38. package/lib/types/skill-history.js +7 -7
  39. package/lib/types/skill-lint.d.ts +1 -1
  40. package/lib/types/skill-lint.js +4 -4
  41. package/lib/types/skill-stats.d.ts +3 -1
  42. package/lib/types/skill-stats.js +2 -0
  43. package/lib/types/skill-store.js +2 -1
  44. package/lib/types/text-budgets.d.ts +150 -0
  45. package/lib/types/text-budgets.js +65 -0
  46. package/lib/types/text-metrics.d.ts +88 -0
  47. package/lib/types/text-metrics.js +131 -0
  48. package/lib/{usage-B1qveKi9.js → usage-e34VZPmK.js} +2 -515
  49. package/lib/write.js +3 -2
  50. package/package.json +1 -1
  51. package/lib/mutations-DQXddSJd.js +0 -75
  52. package/lib/types/cost.d.ts +0 -63
  53. package/lib/types/cost.js +0 -67
@@ -1,63 +0,0 @@
1
- /**
2
- * Context-cost accounting for skill bodies (design §5.2).
3
- *
4
- * A raw character count is a poor budget: the same 100k characters cost very
5
- * different amounts of context in Chinese-heavy prose and in English. The
6
- * weighted unit makes the two comparable, and the token range exists only to
7
- * make the load cost visible next to the character count — it is an ESTIMATE,
8
- * never a measurement.
9
- *
10
- * Accounting basis: the ON-DISK form (`skillMdOnDisk()`, the same view the
11
- * write limit uses), so a body that is exactly at the limit cannot read as
12
- * over-limit here and pass there (the v37 P2-1 deadlock class).
13
- */
14
- /** Token weight of one CJK / kana / full-width code unit on the LIMIT basis —
15
- * upstream's model-independent conversion is 2.75 chars/token for prose, and CJK
16
- * prose is ~1 token per character (the conservative end of the 0.6–1.0 range the
17
- * estimate side reports). Thresholds are compared on THIS basis so a borrowed
18
- * character line keeps its meaning; the estimate range below reports the spread. */
19
- export declare const TOKEN_CJK_WEIGHT = 1;
20
- /** Token weight of one non-CJK code unit on the LIMIT basis (1 / 2.75 ≈ 0.364). */
21
- export declare const TOKEN_ASCII_WEIGHT: number;
22
- /** Token-per-unit bounds of the estimate range (CJK: 0.6–1.0, non-CJK: 1/4–1/3).
23
- * The range is the 4-chars/token estimate family, so on ASCII-heavy bodies the
24
- * LIMIT-basis `tokens` point can sit above `tokensHigh` (1/2.75 > 1/3): the two
25
- * answer different questions and are never nested by construction. */
26
- export declare const COST_CJK_TOKEN_LOW = 0.6;
27
- export declare const COST_CJK_TOKEN_HIGH = 1;
28
- export declare const COST_ASCII_TOKEN_LOW = 0.25;
29
- export declare const COST_ASCII_TOKEN_HIGH: number;
30
- /** The token line a borrowed CHARACTER threshold draws for ONE body: 20k characters
31
- * of THIS composition, expressed in the same tokens `bodyCost` counts. Comparing
32
- * `tokens` against this line is deliberately equivalent to "chars >= line" — that
33
- * equivalence is what keeps a borrowed line's textual effect identical — while the
34
- * judgment itself, and every number reported, stays on the token scale.
35
- * @param lineChars - the borrowed character line (whole-body characters).
36
- * @param cost - the body's own cost breakdown.
37
- * @returns the equivalent token line (0 when the body is empty). */
38
- export declare function tokenLineFor(lineChars: number, cost: BodyCost): number;
39
- /** Cost of one body: raw counts, the weighted total, and the estimate range. */
40
- export interface BodyCost {
41
- /** Code units of the on-disk form — the same measure `maxSkillContentChars` bounds. */
42
- chars: number;
43
- /** Code units matched by the CJK ranges. */
44
- cjk: number;
45
- /** Code units that are not CJK (includes surrogate halves and syntax). */
46
- ascii: number;
47
- /** Single token count on the LIMIT basis: `cjk * TOKEN_CJK_WEIGHT + ascii *
48
- * TOKEN_ASCII_WEIGHT`, rounded. This is the number every threshold compares
49
- * against, so a threshold borrowed as a character line converts faithfully. */
50
- tokens: number;
51
- /** Lower bound of the token estimate. */
52
- tokensLow: number;
53
- /** Upper bound of the token estimate. */
54
- tokensHigh: number;
55
- }
56
- /**
57
- * Cost of one skill body.
58
- * @param content - the body text as written (trailing whitespace is normalized
59
- * away by the on-disk accounting, so callers need not pre-trim).
60
- * @returns the cost breakdown; an empty body answers all-zero.
61
- */
62
- export declare function bodyCost(content: string): BodyCost;
63
- //# sourceMappingURL=cost.d.ts.map
package/lib/types/cost.js DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * Context-cost accounting for skill bodies (design §5.2).
3
- *
4
- * A raw character count is a poor budget: the same 100k characters cost very
5
- * different amounts of context in Chinese-heavy prose and in English. The
6
- * weighted unit makes the two comparable, and the token range exists only to
7
- * make the load cost visible next to the character count — it is an ESTIMATE,
8
- * never a measurement.
9
- *
10
- * Accounting basis: the ON-DISK form (`skillMdOnDisk()`, the same view the
11
- * write limit uses), so a body that is exactly at the limit cannot read as
12
- * over-limit here and pass there (the v37 P2-1 deadlock class).
13
- */
14
- import { UPSTREAM_LIMIT_CHARS_PER_TOKEN } from "./constants.js";
15
- import { skillMdOnDisk } from "./frontmatter.js";
16
- /** Token weight of one CJK / kana / full-width code unit on the LIMIT basis —
17
- * upstream's model-independent conversion is 2.75 chars/token for prose, and CJK
18
- * prose is ~1 token per character (the conservative end of the 0.6–1.0 range the
19
- * estimate side reports). Thresholds are compared on THIS basis so a borrowed
20
- * character line keeps its meaning; the estimate range below reports the spread. */
21
- export const TOKEN_CJK_WEIGHT = 1;
22
- /** Token weight of one non-CJK code unit on the LIMIT basis (1 / 2.75 ≈ 0.364). */
23
- export const TOKEN_ASCII_WEIGHT = 1 / UPSTREAM_LIMIT_CHARS_PER_TOKEN;
24
- /** Token-per-unit bounds of the estimate range (CJK: 0.6–1.0, non-CJK: 1/4–1/3).
25
- * The range is the 4-chars/token estimate family, so on ASCII-heavy bodies the
26
- * LIMIT-basis `tokens` point can sit above `tokensHigh` (1/2.75 > 1/3): the two
27
- * answer different questions and are never nested by construction. */
28
- export const COST_CJK_TOKEN_LOW = 0.6;
29
- export const COST_CJK_TOKEN_HIGH = 1;
30
- export const COST_ASCII_TOKEN_LOW = 0.25;
31
- export const COST_ASCII_TOKEN_HIGH = 1 / 3;
32
- /** The token line a borrowed CHARACTER threshold draws for ONE body: 20k characters
33
- * of THIS composition, expressed in the same tokens `bodyCost` counts. Comparing
34
- * `tokens` against this line is deliberately equivalent to "chars >= line" — that
35
- * equivalence is what keeps a borrowed line's textual effect identical — while the
36
- * judgment itself, and every number reported, stays on the token scale.
37
- * @param lineChars - the borrowed character line (whole-body characters).
38
- * @param cost - the body's own cost breakdown.
39
- * @returns the equivalent token line (0 when the body is empty). */
40
- export function tokenLineFor(lineChars, cost) {
41
- if (cost.chars === 0)
42
- return 0;
43
- return Math.round((lineChars * cost.tokens) / cost.chars);
44
- }
45
- /** CJK ideographs, kana, full-width forms and CJK punctuation. */
46
- const CJK_RE = /[\u3000-\u303f\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff00-\uffef]/g;
47
- /**
48
- * Cost of one skill body.
49
- * @param content - the body text as written (trailing whitespace is normalized
50
- * away by the on-disk accounting, so callers need not pre-trim).
51
- * @returns the cost breakdown; an empty body answers all-zero.
52
- */
53
- export function bodyCost(content) {
54
- const onDisk = skillMdOnDisk(content);
55
- const cjk = [...onDisk.matchAll(CJK_RE)].length;
56
- const chars = onDisk.length;
57
- const ascii = chars - cjk;
58
- return {
59
- chars,
60
- cjk,
61
- ascii,
62
- tokens: Math.round(cjk * TOKEN_CJK_WEIGHT + ascii * TOKEN_ASCII_WEIGHT),
63
- tokensLow: Math.round(cjk * COST_CJK_TOKEN_LOW + ascii * COST_ASCII_TOKEN_LOW),
64
- tokensHigh: Math.round(cjk * COST_CJK_TOKEN_HIGH + ascii * COST_ASCII_TOKEN_HIGH),
65
- };
66
- }
67
- //# sourceMappingURL=cost.js.map