dsh-context-compression-improved 0.10.5 → 0.11.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 (85) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/CHANGELOG.zh.md +9 -0
  3. package/README.de.md +1 -1
  4. package/assets/dshfind-card.svg +33 -0
  5. package/docs/shallow-teaching-preset-template.md +46 -0
  6. package/package.json +6 -6
  7. package/packages/selector/dsh.plugin.json +2 -2
  8. package/packages/selector/lib/client.d.ts +8 -0
  9. package/packages/selector/lib/client.js +212 -3
  10. package/packages/selector/lib/index.js +1 -1
  11. package/packages/selector/lib/profiles.d.ts +34 -0
  12. package/packages/selector/lib/pruner.d.ts +55 -0
  13. package/packages/selector/lib/pruner.js +1925 -303
  14. package/packages/selector/lib/savings-integral.js +126 -3
  15. package/packages/selector/lib/tool-result.js +9 -1
  16. package/packages/selector/package.json +21 -21
  17. package/packages/selector/src/client/CompressionProfileControls.tsx +33 -0
  18. package/packages/selector/src/client/CompressionProfileSelector.tsx +2 -0
  19. package/packages/selector/src/client/decode.ts +5 -1
  20. package/packages/selector/src/client/index.ts +4 -0
  21. package/packages/selector/src/client/locales/de.ts +7 -0
  22. package/packages/selector/src/client/locales/es.ts +7 -0
  23. package/packages/selector/src/client/locales/fr.ts +7 -0
  24. package/packages/selector/src/client/locales/it.ts +7 -0
  25. package/packages/selector/src/client/locales/ja.ts +7 -0
  26. package/packages/selector/src/client/locales/ko.ts +7 -0
  27. package/packages/selector/src/client/locales/ru.ts +7 -0
  28. package/packages/selector/src/client/locales.ts +14 -0
  29. package/packages/selector/src/client/monitor-fab.ts +14 -0
  30. package/packages/selector/src/client/settings-section.tsx +9 -2
  31. package/packages/selector/src/profiles.ts +103 -0
  32. package/packages/selector/src/pruner.ts +310 -4
  33. package/packages/selector/src/runtime/audit.ts +1 -0
  34. package/packages/selector/src/runtime/config.ts +88 -1
  35. package/packages/selector/src/runtime/fold-router.ts +143 -0
  36. package/packages/selector/src/runtime/monitor.ts +31 -0
  37. package/packages/selector/src/runtime/reducers.ts +1 -1
  38. package/packages/selector/src/runtime/sediment-card.ts +126 -0
  39. package/packages/selector/src/runtime/sediment-clock.ts +87 -0
  40. package/packages/selector/src/runtime/sediment-guard.ts +136 -0
  41. package/packages/selector/src/runtime/sediment-publish.ts +144 -0
  42. package/packages/selector/src/runtime/sediment-span.ts +170 -0
  43. package/packages/selector/src/runtime/sediment.ts +209 -0
  44. package/packages/selector/src/runtime/shallow-tools.ts +342 -0
  45. package/packages/selector/src/runtime/tool-names.ts +6 -0
  46. package/packages/selector/src/runtime/triage/masks.ts +128 -0
  47. package/packages/selector/src/runtime/triage/shallow.ts +132 -0
  48. package/packages/selector/src/runtime/triage/signals.ts +167 -0
  49. package/packages/selector/src/runtime/triage/types.ts +125 -0
  50. package/packages/selector/src/runtime/types.ts +28 -0
  51. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +231 -0
  52. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +236 -0
  53. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +220 -0
  54. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +140 -0
  55. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +117 -0
  56. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +67 -0
  57. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +119 -0
  58. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +119 -0
  59. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +131 -0
  60. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +196 -0
  61. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +71 -0
  62. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +126 -0
  63. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +86 -0
  64. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +50 -0
  65. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +102 -0
  66. package/packages/selector/tests/public/package-contract.client.spec.ts +7 -4
  67. package/packages/selector/tests/runtime/fold-router.spec.ts +140 -0
  68. package/packages/selector/tests/runtime/sediment-card.spec.ts +111 -0
  69. package/packages/selector/tests/runtime/sediment-config.spec.ts +56 -0
  70. package/packages/selector/tests/runtime/sediment-guard.spec.ts +71 -0
  71. package/packages/selector/tests/runtime/sediment-masks.spec.ts +95 -0
  72. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +166 -0
  73. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +65 -0
  74. package/packages/selector/tests/runtime/sediment-publish.spec.ts +142 -0
  75. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +158 -0
  76. package/packages/selector/tests/runtime/sediment-settings.spec.ts +73 -0
  77. package/packages/selector/tests/runtime/sediment-signals.spec.ts +124 -0
  78. package/packages/selector/tests/runtime/sediment-span.spec.ts +92 -0
  79. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +135 -0
  80. package/packages/selector/tests/settings-seat.client.spec.ts +1 -1
  81. package/scripts/hosts.d.mts +3 -0
  82. package/scripts/hosts.mjs +3 -1
  83. package/scripts/sediment-latency-report.mjs +63 -0
  84. package/scripts/verify-release.mjs +7 -2
  85. package/$null +0 -1
@@ -0,0 +1,124 @@
1
+ /**
2
+ * T1.1/T1.3/T1.5 red tests: line-A signal rules (plan cci-sedimentation-triage).
3
+ * Base block signals are the five structural variants; the line pool is
4
+ * DECOUPLED from block classification so soft-failure blocks (exit 0 with
5
+ * error lines in the body) still land verbatim lines — the round-1 62.4%
6
+ * recall regression anchor.
7
+ */
8
+ import { describe, expect, it } from 'vitest'
9
+ import {
10
+ blockFailureVerdict,
11
+ linePool,
12
+ mergeExtraPatterns,
13
+ } from '../../src/runtime/triage/signals.ts'
14
+
15
+ describe('blockFailureVerdict (base structural set, T1.1)', () => {
16
+ it('flags the five structural failure signals', () => {
17
+ expect(blockFailureVerdict('[stderr] something broke\nexit code tail', false).hard).toBe(true)
18
+ expect(blockFailureVerdict('ran tests\n[exit code: 1]', false).hard).toBe(true)
19
+ expect(blockFailureVerdict('ran build\n[Command finished with exit code 2]', false).hard).toBe(true)
20
+ expect(blockFailureVerdict('exit_code=7', false).hard).toBe(true)
21
+ expect(blockFailureVerdict('{"stdout":"boom","exitCode":1}', false).hard).toBe(true)
22
+ expect(blockFailureVerdict('anything', true).hard).toBe(true)
23
+ })
24
+
25
+ it('exit code 0 forms are NOT hard failures', () => {
26
+ expect(blockFailureVerdict('ok output\n[exit code: 0]', false).hard).toBe(false)
27
+ expect(blockFailureVerdict('[Command finished with exit code 0]', false).hard).toBe(false)
28
+ expect(blockFailureVerdict('exit_code=0', false).hard).toBe(false)
29
+ expect(blockFailureVerdict('{"stdout":"fine","exitCode":0}', false).hard).toBe(false)
30
+ })
31
+
32
+ it('records which rule ids fired for audit', () => {
33
+ const verdict = blockFailureVerdict('boom\n[exit code: 3]', false)
34
+ expect(verdict.ruleIds).toContain('sig:exit-code-bracket')
35
+ })
36
+ })
37
+
38
+ describe('linePool (verbatim capture, decoupled from block class, T1.3)', () => {
39
+ it('captures the classic failure line family', () => {
40
+ const text = [
41
+ 'normal narration line',
42
+ 'Error: cannot resolve module X',
43
+ 'Exception: in thread "main"',
44
+ 'Traceback (most recent call last):',
45
+ 'FAILED tests/foo.py::test_bar',
46
+ 'panic: runtime error: nil pointer',
47
+ 'AssertionError: expected 1 to be 2',
48
+ ].join('\n')
49
+ const pool = linePool(text, { seq: 42, role: 'tool', hardFailure: false })
50
+ const captured = pool.map(line => line.text)
51
+ expect(captured).toHaveLength(6)
52
+ expect(captured.every(line => !line.startsWith('normal narration'))).toBe(true)
53
+ expect(pool.every(line => line.seq === 42 && line.role === 'tool')).toBe(true)
54
+ })
55
+
56
+ it('soft-failure anchor: exit 0 block with error lines still yields pool lines (round-1 regression)', () => {
57
+ const soft = 'npm test output\nError: 1 test failed\n[exit code: 0]'
58
+ expect(blockFailureVerdict(soft, false).hard).toBe(false)
59
+ const pool = linePool(soft, { seq: 7, role: 'tool', hardFailure: false })
60
+ expect(pool.map(line => line.text)).toContain('Error: 1 test failed')
61
+ })
62
+
63
+ it('caps lines at 240 codepoints plus the ellipsis marker and marks truncation', () => {
64
+ const long = `Error: ${'x'.repeat(300)}`
65
+ const pool = linePool(long, { seq: 1, role: 'tool', hardFailure: true })
66
+ const line = pool[0]
67
+ if (line === undefined) throw new Error('expected one pooled line')
68
+ expect(line.text.length).toBeLessThanOrEqual(245)
69
+ expect(Array.from(line.text.replace(/ …$/, '')).length).toBe(240)
70
+ expect(line.truncated).toBe(true)
71
+ })
72
+
73
+ it('dedupes identical lines within one block', () => {
74
+ const text = 'Error: dup\nError: dup\nFAILED a\nFAILED a'
75
+ expect(linePool(text, { seq: 2, role: 'tool', hardFailure: true })).toHaveLength(2)
76
+ })
77
+
78
+ it('carries ruleId and hardFailure onto every line', () => {
79
+ const pool = linePool('Error: boom', { seq: 3, role: 'assistant', hardFailure: true })
80
+ const line = pool[0]
81
+ if (line === undefined) throw new Error('expected one pooled line')
82
+ expect(line.ruleId).toBe('line:failure-classic')
83
+ expect(line.hardFailure).toBe(true)
84
+ })
85
+ })
86
+
87
+ describe('mergeExtraPatterns (append-only slot, T1.5)', () => {
88
+ it('default extras capture TOOL_TIMEOUT / killed / OOM / assert-context lines', () => {
89
+ const patterns = mergeExtraPatterns([])
90
+ const text = [
91
+ 'Error: tool call timed out after 25000ms',
92
+ 'process was killed by OOM killer',
93
+ 'expected value to be truthy but got: false',
94
+ ].join('\n')
95
+ const pool = linePool(text, { seq: 9, role: 'tool', hardFailure: true, extraPatterns: patterns })
96
+ // line 1 already hits the classic family; lines 2-3 must be captured by extras.
97
+ expect(pool.some(line => line.text.startsWith('process was killed'))).toBe(true)
98
+ expect(pool.some(line => line.text.startsWith('expected value'))).toBe(true)
99
+ })
100
+
101
+ it('clearing user extras keeps base + default extras alive — the base is never removable (M3)', () => {
102
+ const cleared = mergeExtraPatterns([])
103
+ const pool = linePool('FAILED a\nKilled', { seq: 1, role: 'tool', hardFailure: true, extraPatterns: cleared })
104
+ expect(pool.map(line => line.text)).toEqual(['FAILED a', 'Killed'])
105
+ const withUser = mergeExtraPatterns(['npm ERR!'])
106
+ const pool2 = linePool('npm ERR! code 1', { seq: 1, role: 'tool', hardFailure: false, extraPatterns: withUser })
107
+ expect(pool2).toHaveLength(1)
108
+ })
109
+
110
+ it('user extras are additive only: base lines still match without them', () => {
111
+ const patterns = mergeExtraPatterns(['zzz-nothing-matches-this'])
112
+ const pool = linePool('Error: classic', { seq: 1, role: 'tool', hardFailure: false, extraPatterns: patterns })
113
+ expect(pool).toHaveLength(1)
114
+ })
115
+
116
+ it('invalid regex entries are skipped, never thrown (profiles rejects upstream)', () => {
117
+ const patterns = mergeExtraPatterns(['(unclosed', 'valid\\d+'])
118
+ const pool = linePool('valid123', { seq: 1, role: 'tool', hardFailure: false, extraPatterns: patterns })
119
+ expect(pool).toHaveLength(1)
120
+ const line = pool[0]
121
+ if (line === undefined) throw new Error('expected one pooled line')
122
+ expect(line.ruleId).toContain('ext:user:')
123
+ })
124
+ })
@@ -0,0 +1,92 @@
1
+ /**
2
+ * T3.2 (span half) red tests: reason gate, tail-kept rounds, span bounds,
3
+ * and end-to-end triage over a projected turn (plan Phase 3).
4
+ */
5
+ import { describe, expect, it } from 'vitest'
6
+ import { planTurnSpan, triageSpanBlocks, type SurfaceEvent } from '../../src/runtime/sediment-span.ts'
7
+ import { mergeExtraPatterns } from '../../src/runtime/triage/signals.ts'
8
+
9
+ const RULES = mergeExtraPatterns([])
10
+
11
+ function turn(events: SurfaceEvent[]): SurfaceEvent[] {
12
+ return [...events, { seq: 99, type: 'turn/end', text: '', reasonKind: 'completed' }]
13
+ }
14
+
15
+ const a = (seq: number, toolCalls = 0, text = ''): SurfaceEvent =>
16
+ ({ seq, type: 'assistant/message', text, toolCalls })
17
+ const t = (seq: number, text: string, toolName?: string, argsJson?: string, isError = false): SurfaceEvent =>
18
+ ({ seq, type: 'tool/result', text, ...(toolName === undefined ? {} : { toolName }), ...(argsJson === undefined ? {} : { argsJson }), isError })
19
+
20
+ describe('planTurnSpan (T3.3)', () => {
21
+ const bigRead = `import fs from "node:fs"\n${' const x = compute(i)\n'.repeat(120)}`
22
+
23
+ const threeRoundTurn: SurfaceEvent[] = turn([
24
+ { seq: 1, type: 'user/message', text: 'fix the build' },
25
+ a(2, 1), t(3, 'no errors yet', 'pwsh', '{"command":"npm run build"}'),
26
+ a(4, 1), t(5, bigRead, 'read', JSON.stringify({ file_path: 'src/big.ts' })),
27
+ a(6, 1), t(7, 'Error: TS2345 not assignable', 'pwsh', '{"command":"tsc"}', false),
28
+ a(8, 0, '修好了:tsc 的 TS2345 由类型收窄解决,构建通过。'.repeat(6)),
29
+ ])
30
+
31
+ it('tail-kept: last round and closing stay out of the span', () => {
32
+ const plan = planTurnSpan(threeRoundTurn)
33
+ expect(plan.completed).toBe(true)
34
+ expect(plan.startSeq).toBe(2)
35
+ expect(plan.endSeq).toBe(5) // round2 end; round3 (6,7) kept
36
+ expect(plan.blocks.map(block => block.seq)).toEqual([2, 3, 4, 5])
37
+ expect(plan.keptSeqs).toEqual(expect.arrayContaining([1, 6, 7, 8]))
38
+ expect(plan.closingText).toContain('修好了')
39
+ })
40
+
41
+ it('reason gate: non-completed turns are flagged not-replaceable', () => {
42
+ const interrupted = threeRoundTurn.map(event =>
43
+ event.type === 'turn/end' ? { ...event, reasonKind: 'interrupted' } : event)
44
+ expect(planTurnSpan(interrupted).completed).toBe(false)
45
+ })
46
+
47
+ it('single-round turns leave an empty span (nothing to cut before the kept round)', () => {
48
+ const single = turn([
49
+ { seq: 1, type: 'user/message', text: 'hi' },
50
+ a(2, 1), t(3, 'output', 'pwsh', '{"command":"ls"}'),
51
+ a(4, 0, 'listed.'),
52
+ ])
53
+ const plan = planTurnSpan(single)
54
+ expect(plan.startSeq).toBeNull()
55
+ expect(plan.blocks).toHaveLength(0)
56
+ })
57
+
58
+ it('tailRoundsKept=0 puts every round into the span', () => {
59
+ const plan = planTurnSpan(threeRoundTurn, { tailRoundsKept: 0 })
60
+ expect(plan.endSeq).toBe(7)
61
+ })
62
+ })
63
+
64
+ describe('triageSpanBlocks (end-to-end line assignment)', () => {
65
+ it('assigns manifest to write results, skeleton to big reads, pool lines to failures', () => {
66
+ const bigRead = `import fs from "node:fs"\n${' const x = compute(i)\n'.repeat(200)}`
67
+ const events = [
68
+ { seq: 1, type: 'user/message', text: 'go' },
69
+ { seq: 2, type: 'assistant/message', text: '', toolCalls: 1 },
70
+ { seq: 3, type: 'tool/result', text: 'File written', toolName: 'write', argsJson: JSON.stringify({ file_path: 'src/a.ts' }) },
71
+ { seq: 4, type: 'assistant/message', text: '', toolCalls: 1 },
72
+ { seq: 5, type: 'tool/result', text: bigRead, toolName: 'read', argsJson: JSON.stringify({ file_path: 'src/big.ts' }) },
73
+ { seq: 6, type: 'assistant/message', text: '', toolCalls: 1 },
74
+ { seq: 7, type: 'tool/result', text: 'Error: TS2345 failed\n[exit code: 2]', toolName: 'pwsh', argsJson: '{"command":"tsc"}' },
75
+ { seq: 8, type: 'assistant/message', text: 'fixed: narrowed the union type at the call site, tsc passes now.', toolCalls: 0 },
76
+ { seq: 99, type: 'turn/end', text: '', reasonKind: 'completed' },
77
+ ] as const satisfies SurfaceEvent[]
78
+ const plan = planTurnSpan([...events], { tailRoundsKept: 0 })
79
+ const triage = triageSpanBlocks(plan, RULES)
80
+ const bySeq = new Map(triage.map(result => [result.poolLines[0]?.seq ?? result.mask?.seq ?? -1, result]))
81
+ const writeBlock = triage.find(result => result.mask?.kind === 'manifest')
82
+ expect(writeBlock?.mask?.kind).toBe('manifest')
83
+ const readBlock = triage.find(result => result.mask?.kind === 'skeleton')
84
+ expect(readBlock?.mask?.kind).toBe('skeleton')
85
+ const failBlock = triage.find(result => result.poolLines.some(line => line.text.includes('TS2345')))
86
+ expect(failBlock).toBeDefined()
87
+ const failLine = failBlock?.poolLines[0]
88
+ if (failLine === undefined) throw new Error('expected pooled failure line')
89
+ expect(failLine.hardFailure).toBe(true)
90
+ expect(bySeq.size).toBeGreaterThan(0)
91
+ })
92
+ })
@@ -0,0 +1,135 @@
1
+ /**
2
+ * T4.7/T4.8/T4.11/T4.12 red tests: shallow primitives and tool-side pure cores
3
+ * (plan cci-sedimentation-triage Phase 4.5).
4
+ */
5
+ import { describe, expect, it } from 'vitest'
6
+ import {
7
+ buildShallowFooter,
8
+ classifyShallowSample,
9
+ evaluateDiscardGuard,
10
+ normalizeToolPath,
11
+ renderCheckpointLine,
12
+ } from '../../src/runtime/triage/shallow.ts'
13
+ import { buildShallowView, parseReadCoverage } from '../../src/runtime/shallow-tools.ts'
14
+ import { skeletonFromRead } from '../../src/runtime/triage/masks.ts'
15
+
16
+ describe('normalizeToolPath (pairing key, three shapes)', () => {
17
+ it('unifies drive letters, separators, and relative segments', () => {
18
+ expect(normalizeToolPath('E:\\Repo\\A\\b.ts')).toBe('e:/Repo/A/b.ts')
19
+ expect(normalizeToolPath('./src/app.ts')).toBe('src/app.ts')
20
+ expect(normalizeToolPath('src/../src/app.ts')).toBe('src/app.ts')
21
+ expect(normalizeToolPath('E:/Repo//A/./b.ts')).toBe('e:/Repo/A/b.ts')
22
+ // case of the path TAIL is preserved (filesystems may be case-sensitive)
23
+ expect(normalizeToolPath('e:/repo/App.TS')).toBe('e:/repo/App.TS')
24
+ })
25
+ })
26
+
27
+ describe('classifyShallowSample (T4.12 five families)', () => {
28
+ it('routes JSON / TS source / CSV / markdown / unknown-large correctly', () => {
29
+ expect(classifyShallowSample('{"a":1', '.json', 9_000).method).toBe('json-skeleton')
30
+ expect(classifyShallowSample('import x from "y"\n', '.ts', 9_000).method).toBe('code-skeleton')
31
+ expect(classifyShallowSample('name,size\na,1\nb,2\nc,3', '.csv', 9_000).method).toBe('csv-header')
32
+ expect(classifyShallowSample('# Title\nbody', '.md', 9_000).method).toBe('toc-lines')
33
+ expect(classifyShallowSample('random bytes', '.bin', 9_000).method).toBe('toc-lines')
34
+ expect(classifyShallowSample('tiny', '', 30).method).toBe('head-tail')
35
+ })
36
+ })
37
+
38
+ describe('evaluateDiscardGuard (T4.7 asymmetric guard)', () => {
39
+ const mapFull = { seq: 10, path: 'E:\\repo\\big.ts', coverage: { kind: 'full' } as const }
40
+
41
+ it('refuses map discard when the covering read is a slice (window-gap and full-map shapes)', () => {
42
+ expect(evaluateDiscardGuard({
43
+ map: mapFull,
44
+ covering: { seq: 20, path: 'e:/repo/big.ts', coverage: { kind: 'slice', from: 100, to: 300 } },
45
+ }).allowed).toBe(false)
46
+ })
47
+ it('allows map discard under a full covering read, path case/shape differing', () => {
48
+ const verdict = evaluateDiscardGuard({
49
+ map: mapFull,
50
+ covering: { seq: 20, path: 'E:/repo/big.ts', coverage: { kind: 'full' } },
51
+ })
52
+ expect(verdict.allowed).toBe(true)
53
+ })
54
+ it('window containment for a map that covers a window', () => {
55
+ const mapWindow = { seq: 10, path: 'a.ts', coverage: { kind: 'slice', from: 50, to: 150 } as const }
56
+ expect(evaluateDiscardGuard({
57
+ map: mapWindow,
58
+ covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 40, to: 160 } },
59
+ }).allowed).toBe(true)
60
+ expect(evaluateDiscardGuard({
61
+ map: mapWindow,
62
+ covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 60, to: 140 } },
63
+ }).allowed).toBe(false)
64
+ })
65
+ it('path mismatch refuses before any coverage math', () => {
66
+ expect(evaluateDiscardGuard({
67
+ map: mapFull,
68
+ covering: { seq: 20, path: 'e:/repo/other.ts', coverage: { kind: 'full' } },
69
+ }).reason).toContain('path-mismatch')
70
+ })
71
+ })
72
+
73
+ describe('buildShallowView (T4.11 checkpoint layer)', () => {
74
+ const code = `import fs from "node:fs"\n${' const v = compute()\n'.repeat(200)}export function go() { return 1 }`
75
+
76
+ it('code-skeleton view carries the four checkpoint fields', () => {
77
+ const { body, checkpoint } = buildShallowView(code, 'code-skeleton', 'E:\\src\\big.ts', 77)
78
+ expect(body).toContain('import fs')
79
+ expect(body).toContain('elided')
80
+ expect(checkpoint).not.toBeNull()
81
+ expect(checkpoint?.path).toBe('e:/src/big.ts')
82
+ expect(checkpoint?.coverage).toContain('lines')
83
+ expect(checkpoint?.ref).toBe('event/77')
84
+ expect(checkpoint?.fingerprint).toMatch(/^[0-9a-f]+-[0-9a-f]+$/)
85
+ })
86
+ it('json-skeleton lists keys, csv-header keeps rows count, toc-lines keeps headings', () => {
87
+ const json = buildShallowView(JSON.stringify({ a: { b: 1 }, list: [1, 2] }), 'json-skeleton', 'x.json', 1)
88
+ expect(json.body).toContain('a.b')
89
+ expect(json.body).toContain('list[] (2)')
90
+ const csv = buildShallowView('h1,h2\n1,2\n3,4\n5,6', 'csv-header', 'x.csv', 1)
91
+ expect(csv.body).toContain('1 data rows elided')
92
+ const md = buildShallowView('# A\ntext\n## B\nmore', 'toc-lines', 'x.md', 1)
93
+ expect(md.body).toContain('## B')
94
+ })
95
+ })
96
+
97
+ describe('parseReadCoverage (pairing input)', () => {
98
+ it('bare read is full; offset/limit is a window; broken args match nothing', () => {
99
+ expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts' }))).toEqual({ kind: 'full' })
100
+ expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts', offset: 100, limit: 50 })))
101
+ .toEqual({ kind: 'slice', from: 101, to: 150 })
102
+ expect(parseReadCoverage('{broken')).toMatchObject({ kind: 'slice', to: 0 })
103
+ })
104
+ })
105
+
106
+ describe('footer and checkpoint rendering (T4.8 data-shaped teaching)', () => {
107
+ const checkpoint = {
108
+ path: 'e:/src/big.ts', coverage: '900 lines', ref: 'session://s1/event/77', fingerprint: '3c-91',
109
+ }
110
+ it('footer names the sibling ref, the saving, and forbids reconstitution', () => {
111
+ const footer = buildShallowFooter(checkpoint, 1_800)
112
+ expect(footer).toContain('session://s1/event/77')
113
+ expect(footer).toContain('1800')
114
+ expect(footer).toContain('不要凭本行推测补写')
115
+ })
116
+ it('checkpoint line keeps all four fields on one line', () => {
117
+ const line = renderCheckpointLine(checkpoint)
118
+ for (const part of ['e:/src/big.ts', '900 lines', 'session://s1/event/77', '3c-91']) {
119
+ expect(line).toContain(part)
120
+ }
121
+ expect(line.split('\n')).toHaveLength(1)
122
+ })
123
+ })
124
+
125
+ describe('skeletonFromRead checkpoint back-compat', () => {
126
+ const padded = `import fs from "node:fs"\n${' const x = 1\n'.repeat(400)}`
127
+ it('stays checkpoint-free without a path (existing callers unaffected)', () => {
128
+ const verdict = skeletonFromRead(padded, 5)
129
+ expect(verdict?.kind === 'skeleton' && verdict.checkpoint === undefined).toBe(true)
130
+ })
131
+ it('gains the checkpoint with a path', () => {
132
+ const verdict = skeletonFromRead(padded, 5, 'src/a.ts')
133
+ expect(verdict?.kind === 'skeleton' && verdict.checkpoint?.path).toBe('src/a.ts')
134
+ })
135
+ })
@@ -114,7 +114,7 @@ describe('settings-seat contract (settings.section + input-bar session view bind
114
114
  expect((options['label'] as () => string)()).toBe('nav')
115
115
  expect(typeof options['inject']).toBe('function')
116
116
  const face = (options['inject'] as () => Record<string, unknown>)()
117
- expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePtcCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'select', 'resetCustom', 'resetPtcCustom'].sort())
117
+ expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePtcCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'saveSediment', 'select', 'resetCustom', 'resetPtcCustom'].sort())
118
118
  expect(component).toBe(ContextCompressionSettingsSection)
119
119
  })
120
120
 
@@ -0,0 +1,3 @@
1
+ /** Type declarations for the JS-only hosts.mjs single source. */
2
+ export declare const supportedHosts: readonly string[]
3
+ export declare const selectorDshPeers: readonly string[]
package/scripts/hosts.mjs CHANGED
@@ -33,7 +33,9 @@ export const supportedHosts = Object.freeze([
33
33
  '0.2.1-rc.2', '0.2.1-rc.3', '0.2.1-rc.4', '0.2.1-rc.5',
34
34
  '0.2.2-rc.1',
35
35
  ])
36
- export const peerRange = supportedHosts.join(' || ')
36
+ export const peerRange = `>=${supportedHosts[0]} <0.3.0-0`
37
+ /** 已实测宿主细胞:仅供 README 展示 / 矩阵脚本,不再下发给 peer。 */
38
+ export const hostCells = supportedHosts.join(' || ')
37
39
  /** 显式偏离:devDeps 钉 rc.1(见文件头)。 */
38
40
  export const developmentHost = '0.2.0-rc.1'
39
41
 
@@ -0,0 +1,63 @@
1
+ // T5.3 turn-tail fold latency report (plan cci-sedimentation-triage, M18).
2
+ //
3
+ // Data source: the single observability line emitted by the pruner's fold
4
+ // channel on every fold attempt:
5
+ // context-compression sediment fold (<session>): tier=<t> ok=<b> latencyMs=<n>[ reason=<r>]
6
+ // Feed it any capture of host stdout/stderr (the Host logger has no file sink;
7
+ // `dsh … 2>&1 | tee run.log` or the desktop console capture is the intake).
8
+ //
9
+ // Usage: node scripts/sediment-latency-report.mjs <logfile> [more logs…]
10
+ // Exit 0 with "insufficient samples" note until ≥50 attempts are accumulated —
11
+ // the ≥50 threshold is an acceptance gate, not a crash gate.
12
+
13
+ const files = process.argv.slice(2)
14
+ if (files.length === 0) {
15
+ console.error('usage: node scripts/sediment-latency-report.mjs <logfile> [more logs…]')
16
+ process.exit(2)
17
+ }
18
+
19
+ const LINE = /context-compression sediment fold \(([^)]+)\): tier=(\S+) ok=(true|false) latencyMs=(\d+)(?: reason=(\S+))?/g
20
+
21
+ const samples = []
22
+ for (const file of files) {
23
+ const { readFileSync } = await import('node:fs')
24
+ const text = readFileSync(file, 'utf8')
25
+ for (const m of text.matchAll(LINE)) {
26
+ samples.push({
27
+ session: m[1],
28
+ tier: m[2],
29
+ ok: m[3] === 'true',
30
+ latencyMs: Number(m[4]),
31
+ reason: m[5],
32
+ })
33
+ }
34
+ }
35
+
36
+ const pct = (sorted, p) => {
37
+ if (sorted.length === 0) return 0
38
+ const idx = Math.min(sorted.length - 1, Math.ceil(p * sorted.length) - 1)
39
+ return sorted[Math.max(0, idx)]
40
+ }
41
+
42
+ const okLat = samples.filter(s => s.ok).map(s => s.latencyMs).sort((a, b) => a - b)
43
+ const allLat = samples.map(s => s.latencyMs).sort((a, b) => a - b)
44
+ const byTier = {}
45
+ for (const s of samples) (byTier[s.tier] ??= []).push(s)
46
+
47
+ console.log(`fold attempts: ${samples.length} (ok=${samples.filter(s => s.ok).length}) from ${files.length} log file(s)`)
48
+ console.log(`latency ok-only : p50=${pct(okLat, 0.5)}ms p95=${pct(okLat, 0.95)}ms p99=${pct(okLat, 0.99)}ms max=${okLat.at(-1) ?? 0}ms`)
49
+ console.log(`latency all : p50=${pct(allLat, 0.5)}ms p95=${pct(allLat, 0.95)}ms p99=${pct(allLat, 0.99)}ms`)
50
+ for (const [tier, list] of Object.entries(byTier)) {
51
+ const lats = list.filter(s => s.ok).map(s => s.latencyMs).sort((a, b) => a - b)
52
+ console.log(`tier ${tier.padEnd(8)}: n=${list.length} ok=${list.filter(s => s.ok).length} p99=${pct(lats, 0.99)}ms`)
53
+ }
54
+ const reasons = {}
55
+ for (const s of samples.filter(x => !x.ok && x.reason !== undefined)) {
56
+ reasons[s.reason] = (reasons[s.reason] ?? 0) + 1
57
+ }
58
+ for (const [reason, n] of Object.entries(reasons).sort((a, b) => b[1] - a[1])) {
59
+ console.log(`fail reason ${reason}: ${n}`)
60
+ }
61
+ if (samples.length < 50) {
62
+ console.log(`NOTE: M18 requires >=50 attempts; ${50 - samples.length} more to accumulate.`)
63
+ }
@@ -160,8 +160,13 @@ for (const peer of selectorDshPeers) {
160
160
  if (selectorPackage.engines?.dsh?.split(' || ').length !== supportedHosts.length) {
161
161
  fail(`selector engines.dsh must carry the ${supportedHosts.length}-rc supportedHosts enum`)
162
162
  }
163
- if (rootPackage.engines?.dsh?.split(' || ').length !== supportedHosts.length) {
164
- fail(`root engines.dsh must carry the ${supportedHosts.length}-rc supportedHosts enum (install-surface gate)`)
163
+ // v0.10.5 decision: the ROOT install-surface manifest declares a semver RANGE
164
+ // (">=lower <upper") instead of the per-rc enum; the selector package keeps
165
+ // the enum for the peer-consistency surface. Verify the range SHAPE here —
166
+ // the peer-equality loop below still pins every root dsh-* peer to the same
167
+ // range string, so a drift between peers and engines keeps failing the gate.
168
+ if (!/^>=\S+ <\S+$/.test(String(rootPackage.engines?.dsh ?? ''))) {
169
+ fail('root engines.dsh must carry the install-surface range (">=lower <upper"), per the 0.10.5 range switch')
165
170
  }
166
171
  for (const peer of Object.keys(rootPackage.peerDependencies ?? {})) {
167
172
  if (rootPackage.peerDependencies[peer] !== rootPackage.engines.dsh) {
package/$null DELETED
@@ -1 +0,0 @@
1
- fatal: no upstream configured for branch 'main'