ds4-context-engine 0.1.2 → 0.2.0-beta.2
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.
- package/README.md +84 -14
- package/docs/ARCHITECTURE.md +42 -16
- package/docs/CONTEXT_MANIFEST.md +3 -1
- package/docs/CONTEXT_PLANNER.md +9 -1
- package/docs/CONTEXT_QUALITY.md +91 -0
- package/docs/HYBRID_RETRIEVAL.md +117 -0
- package/docs/LEARNED_RANKING.md +90 -0
- package/docs/LOCAL_KV_REUSE.md +131 -0
- package/docs/MEMORY_AND_PINS.md +11 -5
- package/docs/PORTABLE_CORE.md +15 -8
- package/docs/PROJECT_KNOWLEDGE.md +26 -16
- package/docs/RELEASING.md +18 -13
- package/docs/RETRIEVAL.md +1 -1
- package/docs/ROADMAP_0.2.0.md +15 -1
- package/docs/RUNTIME_ADAPTER_KIT.md +145 -0
- package/docs/STORAGE.md +37 -7
- package/package.json +12 -7
- package/quality/corpus-v1.json +208 -0
- package/quality/semantic-corpus-v1.json +84 -0
- package/quality/symbol-corpus-v1.json +38 -0
- package/scripts/compare-context-quality.mjs +23 -0
- package/src/extension/commands.ts +213 -1
- package/src/extension/index.ts +1 -0
- package/src/extension/runtime.ts +622 -16
- package/src/pi-adapter/local-embedding.ts +132 -0
- package/src/pi-adapter/memory-adapter.ts +18 -8
- package/src/pi-adapter/project-memory-sync.ts +499 -0
- package/src/pi-adapter/ranking-adapter.ts +72 -0
- package/src/pi-adapter/runtime-contract.ts +86 -0
- package/src/pi-adapter/version.ts +3 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"corpusVersion": "ds4-quality-corpus-v1",
|
|
4
|
+
"description": "Synthetic metadata-only replay fixtures for deterministic DS4 context-quality comparisons.",
|
|
5
|
+
"fixtures": [
|
|
6
|
+
{
|
|
7
|
+
"schemaVersion": 1,
|
|
8
|
+
"corpusVersion": "ds4-quality-corpus-v1",
|
|
9
|
+
"sampleId": "fixture:retrieval-budget",
|
|
10
|
+
"plannerVersion": "managed-v1",
|
|
11
|
+
"profileKey": "fixture/model-128k",
|
|
12
|
+
"task": {
|
|
13
|
+
"taskId": "task:retrieval-budget",
|
|
14
|
+
"taskType": "debugging",
|
|
15
|
+
"queryTags": ["exact-symbol", "historical-decision"]
|
|
16
|
+
},
|
|
17
|
+
"expectedEvidenceSourceIds": ["entry:decision-a"],
|
|
18
|
+
"candidates": [
|
|
19
|
+
{
|
|
20
|
+
"id": "candidate:current-a",
|
|
21
|
+
"kind": "current",
|
|
22
|
+
"tokens": 80,
|
|
23
|
+
"groupId": "group:current-a",
|
|
24
|
+
"sourceIds": ["entry:request-a"],
|
|
25
|
+
"staticScore": 1000,
|
|
26
|
+
"candidateScore": 1000,
|
|
27
|
+
"currentRequest": true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "candidate:recent-a",
|
|
31
|
+
"kind": "recent",
|
|
32
|
+
"tokens": 120,
|
|
33
|
+
"groupId": "group:recent-a",
|
|
34
|
+
"sourceIds": ["entry:recent-a"],
|
|
35
|
+
"staticScore": 100,
|
|
36
|
+
"candidateScore": 40
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "candidate:retrieval-a",
|
|
40
|
+
"kind": "retrieval",
|
|
41
|
+
"tokens": 100,
|
|
42
|
+
"groupId": "group:retrieval-a",
|
|
43
|
+
"sourceIds": ["entry:decision-a"],
|
|
44
|
+
"staticScore": 85,
|
|
45
|
+
"candidateScore": 180
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"totalBudgetTokens": 210,
|
|
49
|
+
"categoryBudgets": {
|
|
50
|
+
"recent": 160,
|
|
51
|
+
"retrieval": 120
|
|
52
|
+
},
|
|
53
|
+
"outcomeLabels": ["expected:decision-recovered"]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"schemaVersion": 1,
|
|
57
|
+
"corpusVersion": "ds4-quality-corpus-v1",
|
|
58
|
+
"sampleId": "fixture:atomic-tools",
|
|
59
|
+
"plannerVersion": "managed-v1",
|
|
60
|
+
"profileKey": "fixture/model-32k",
|
|
61
|
+
"task": {
|
|
62
|
+
"taskId": "task:atomic-tools",
|
|
63
|
+
"taskType": "tool-debugging",
|
|
64
|
+
"queryTags": ["atomic-tool-group"]
|
|
65
|
+
},
|
|
66
|
+
"expectedEvidenceSourceIds": ["entry:tool-call", "entry:tool-result"],
|
|
67
|
+
"candidates": [
|
|
68
|
+
{
|
|
69
|
+
"id": "candidate:current-b",
|
|
70
|
+
"kind": "current",
|
|
71
|
+
"tokens": 40,
|
|
72
|
+
"groupId": "group:current-b",
|
|
73
|
+
"sourceIds": ["entry:request-b"],
|
|
74
|
+
"staticScore": 1000,
|
|
75
|
+
"candidateScore": 1000,
|
|
76
|
+
"currentRequest": true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"id": "candidate:tool-call",
|
|
80
|
+
"kind": "retrieval",
|
|
81
|
+
"tokens": 60,
|
|
82
|
+
"groupId": "group:tool-exchange",
|
|
83
|
+
"sourceIds": ["entry:tool-call"],
|
|
84
|
+
"staticScore": 90,
|
|
85
|
+
"candidateScore": 120
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"id": "candidate:tool-result",
|
|
89
|
+
"kind": "retrieval",
|
|
90
|
+
"tokens": 100,
|
|
91
|
+
"groupId": "group:tool-exchange",
|
|
92
|
+
"sourceIds": ["entry:tool-result"],
|
|
93
|
+
"staticScore": 90,
|
|
94
|
+
"candidateScore": 120
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "candidate:background-b",
|
|
98
|
+
"kind": "recent",
|
|
99
|
+
"tokens": 170,
|
|
100
|
+
"groupId": "group:background-b",
|
|
101
|
+
"sourceIds": ["entry:background-b"],
|
|
102
|
+
"staticScore": 80,
|
|
103
|
+
"candidateScore": 20
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"totalBudgetTokens": 220,
|
|
107
|
+
"categoryBudgets": {
|
|
108
|
+
"recent": 180,
|
|
109
|
+
"retrieval": 180
|
|
110
|
+
},
|
|
111
|
+
"outcomeLabels": ["expected:atomic-selection"]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"schemaVersion": 1,
|
|
115
|
+
"corpusVersion": "ds4-quality-corpus-v1",
|
|
116
|
+
"sampleId": "fixture:duplicate-evidence",
|
|
117
|
+
"plannerVersion": "managed-v1",
|
|
118
|
+
"profileKey": "fixture/model-200k",
|
|
119
|
+
"task": {
|
|
120
|
+
"taskId": "task:duplicate-evidence",
|
|
121
|
+
"taskType": "refactoring",
|
|
122
|
+
"queryTags": ["decision-recall", "duplicate-control"]
|
|
123
|
+
},
|
|
124
|
+
"expectedEvidenceSourceIds": ["entry:decision-b", "entry:decision-c"],
|
|
125
|
+
"candidates": [
|
|
126
|
+
{
|
|
127
|
+
"id": "candidate:current-c",
|
|
128
|
+
"kind": "current",
|
|
129
|
+
"tokens": 50,
|
|
130
|
+
"groupId": "group:current-c",
|
|
131
|
+
"sourceIds": ["entry:request-c"],
|
|
132
|
+
"staticScore": 1000,
|
|
133
|
+
"candidateScore": 1000,
|
|
134
|
+
"currentRequest": true
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"id": "candidate:decision-b-primary",
|
|
138
|
+
"kind": "retrieval",
|
|
139
|
+
"tokens": 80,
|
|
140
|
+
"groupId": "group:decision-b-primary",
|
|
141
|
+
"sourceIds": ["entry:decision-b"],
|
|
142
|
+
"staticScore": 100,
|
|
143
|
+
"candidateScore": 100
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"id": "candidate:decision-b-duplicate",
|
|
147
|
+
"kind": "retrieval",
|
|
148
|
+
"tokens": 80,
|
|
149
|
+
"groupId": "group:decision-b-duplicate",
|
|
150
|
+
"sourceIds": ["entry:decision-b"],
|
|
151
|
+
"staticScore": 99,
|
|
152
|
+
"candidateScore": 10
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"id": "candidate:decision-c",
|
|
156
|
+
"kind": "retrieval",
|
|
157
|
+
"tokens": 80,
|
|
158
|
+
"groupId": "group:decision-c",
|
|
159
|
+
"sourceIds": ["entry:decision-c"],
|
|
160
|
+
"staticScore": 98,
|
|
161
|
+
"candidateScore": 99
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"totalBudgetTokens": 210,
|
|
165
|
+
"categoryBudgets": {
|
|
166
|
+
"retrieval": 160
|
|
167
|
+
},
|
|
168
|
+
"outcomeLabels": ["expected:no-duplicate"]
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"schemaVersion": 1,
|
|
172
|
+
"corpusVersion": "ds4-quality-corpus-v1",
|
|
173
|
+
"sampleId": "fixture:mandatory-overflow",
|
|
174
|
+
"plannerVersion": "managed-v1",
|
|
175
|
+
"profileKey": "fixture/model-32k",
|
|
176
|
+
"task": {
|
|
177
|
+
"taskId": "task:mandatory-overflow",
|
|
178
|
+
"taskType": "overflow-safety",
|
|
179
|
+
"queryTags": ["fail-open", "current-request"]
|
|
180
|
+
},
|
|
181
|
+
"expectedEvidenceSourceIds": [],
|
|
182
|
+
"candidates": [
|
|
183
|
+
{
|
|
184
|
+
"id": "candidate:current-d",
|
|
185
|
+
"kind": "current",
|
|
186
|
+
"tokens": 300,
|
|
187
|
+
"groupId": "group:current-d",
|
|
188
|
+
"sourceIds": ["entry:request-d"],
|
|
189
|
+
"staticScore": 1000,
|
|
190
|
+
"candidateScore": 1000,
|
|
191
|
+
"currentRequest": true
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"id": "candidate:history-d",
|
|
195
|
+
"kind": "history",
|
|
196
|
+
"tokens": 50,
|
|
197
|
+
"groupId": "group:history-d",
|
|
198
|
+
"sourceIds": ["entry:history-d"],
|
|
199
|
+
"staticScore": 10,
|
|
200
|
+
"candidateScore": 10
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"totalBudgetTokens": 200,
|
|
204
|
+
"categoryBudgets": {},
|
|
205
|
+
"outcomeLabels": ["expected:fail-open"]
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"corpusVersion": "ds4-semantic-corpus-v1",
|
|
4
|
+
"baseQualityCorpusVersion": "ds4-quality-corpus-v1",
|
|
5
|
+
"description": "Synthetic sanitized M16 retrieval fixtures evaluated with the M14 evidence recall and irrelevant-token metrics.",
|
|
6
|
+
"fixtures": [
|
|
7
|
+
{
|
|
8
|
+
"id": "semantic-auth-renewal",
|
|
9
|
+
"query": "renew authorization credentials after expiry",
|
|
10
|
+
"exactIdentifiers": [],
|
|
11
|
+
"expectedEvidenceIds": ["evidence:auth-refresh"],
|
|
12
|
+
"maxResults": 1,
|
|
13
|
+
"candidates": [
|
|
14
|
+
{
|
|
15
|
+
"id": "evidence:auth-refresh",
|
|
16
|
+
"text": "OAuth token refresh handles expired authentication secrets.",
|
|
17
|
+
"tokens": 24
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "evidence:schema",
|
|
21
|
+
"text": "SQLite migration creates a project metadata table.",
|
|
22
|
+
"tokens": 28
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "semantic-cache-reuse",
|
|
28
|
+
"query": "reuse previously computed responses to reduce latency",
|
|
29
|
+
"exactIdentifiers": [],
|
|
30
|
+
"expectedEvidenceIds": ["evidence:cache"],
|
|
31
|
+
"maxResults": 1,
|
|
32
|
+
"candidates": [
|
|
33
|
+
{
|
|
34
|
+
"id": "evidence:cache",
|
|
35
|
+
"text": "Memoized output caching avoids repeated work and improves performance.",
|
|
36
|
+
"tokens": 30
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "evidence:logging",
|
|
40
|
+
"text": "Structured logs record request metadata for diagnostics.",
|
|
41
|
+
"tokens": 26
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "exact-path-priority",
|
|
47
|
+
"query": "inspect src/Auth.ts before changing token renewal",
|
|
48
|
+
"exactIdentifiers": ["src/Auth.ts"],
|
|
49
|
+
"expectedEvidenceIds": ["evidence:exact-path"],
|
|
50
|
+
"maxResults": 1,
|
|
51
|
+
"candidates": [
|
|
52
|
+
{
|
|
53
|
+
"id": "evidence:exact-path",
|
|
54
|
+
"text": "src/Auth.ts exports a small compatibility wrapper.",
|
|
55
|
+
"tokens": 20
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "evidence:semantic-neighbor",
|
|
59
|
+
"text": "Authentication credential refresh renews expired OAuth tokens.",
|
|
60
|
+
"tokens": 34
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "semantic-storage-failure",
|
|
66
|
+
"query": "debug persistence failures in the local datastore",
|
|
67
|
+
"exactIdentifiers": [],
|
|
68
|
+
"expectedEvidenceIds": ["evidence:sqlite-error"],
|
|
69
|
+
"maxResults": 1,
|
|
70
|
+
"candidates": [
|
|
71
|
+
{
|
|
72
|
+
"id": "evidence:sqlite-error",
|
|
73
|
+
"text": "SQLite database exceptions are isolated and fall back safely.",
|
|
74
|
+
"tokens": 32
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"id": "evidence:ui",
|
|
78
|
+
"text": "Terminal colors and status labels are rendered by the UI.",
|
|
79
|
+
"tokens": 30
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"corpusVersion": "ds4-symbol-corpus-v1",
|
|
4
|
+
"fixtures": [
|
|
5
|
+
{
|
|
6
|
+
"id": "typescript-comments-and-methods",
|
|
7
|
+
"language": "typescript",
|
|
8
|
+
"filePath": "src/service.ts",
|
|
9
|
+
"content": "import { Client } from \"./client.js\";\n// class PhantomComment {}\nconst sample = \"function PhantomString() {}\";\nexport class Service {\n async run(client: Client): Promise<Result> {\n return client.execute();\n }\n}\n",
|
|
10
|
+
"expectedSymbols": ["sample", "Service", "Service.run"],
|
|
11
|
+
"forbiddenSymbols": ["PhantomComment", "PhantomString"]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": "javascript-declarations",
|
|
15
|
+
"language": "javascript",
|
|
16
|
+
"filePath": "src/worker.js",
|
|
17
|
+
"content": "const text = 'class StringOnly {}';\nexport function buildWorker(options) {\n return createWorker(options);\n}\nexport const stopWorker = () => terminateWorker();\n",
|
|
18
|
+
"expectedSymbols": ["text", "buildWorker", "stopWorker"],
|
|
19
|
+
"forbiddenSymbols": ["StringOnly"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"id": "python-indentation",
|
|
23
|
+
"language": "python",
|
|
24
|
+
"filePath": "src/processor.py",
|
|
25
|
+
"content": "from app.client import Client\n# def phantom_comment(): pass\nclass Processor:\n def process(self, client: Client):\n return client.execute()\n\ndef create_processor():\n return Processor()\n",
|
|
26
|
+
"expectedSymbols": ["Processor", "Processor.process", "create_processor"],
|
|
27
|
+
"forbiddenSymbols": ["phantom_comment"]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "go-receiver-method",
|
|
31
|
+
"language": "go",
|
|
32
|
+
"filePath": "service/service.go",
|
|
33
|
+
"content": "package service\n\nimport (\n \"context\"\n \"example/client\"\n)\n\n// type Phantom struct{}\ntype Service struct { client *client.Client }\n\nfunc (s *Service) Run(ctx context.Context) error {\n return s.client.Execute(ctx)\n}\n",
|
|
34
|
+
"expectedSymbols": ["Service", "Service.Run"],
|
|
35
|
+
"forbiddenSymbols": ["Phantom"]
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import {
|
|
5
|
+
compareQualityStrategies,
|
|
6
|
+
staticRankingStrategy,
|
|
7
|
+
taskWeightedCandidateStrategy,
|
|
8
|
+
} from "ds4-context-core/quality/context-quality";
|
|
9
|
+
import { stableStringify } from "ds4-context-core/shared/stable-json";
|
|
10
|
+
|
|
11
|
+
const corpusUrl = new URL("../quality/corpus-v1.json", import.meta.url);
|
|
12
|
+
const corpus = JSON.parse(readFileSync(fileURLToPath(corpusUrl), "utf8"));
|
|
13
|
+
const startedAt = performance.now();
|
|
14
|
+
const report = compareQualityStrategies(corpus, [
|
|
15
|
+
staticRankingStrategy(),
|
|
16
|
+
taskWeightedCandidateStrategy(),
|
|
17
|
+
]);
|
|
18
|
+
const durationMs = performance.now() - startedAt;
|
|
19
|
+
|
|
20
|
+
process.stdout.write(`${stableStringify(report)}\n`);
|
|
21
|
+
if (process.argv.includes("--timing")) {
|
|
22
|
+
process.stderr.write(`quality comparison wall-clock: ${durationMs.toFixed(3)} ms\n`);
|
|
23
|
+
}
|