ds4-context-engine 0.3.1 → 0.3.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/docs/releases/0.3.1.md +11 -1
- package/docs/releases/0.3.2.md +79 -0
- package/package.json +2 -2
- package/src/extension/commands.ts +104 -1
- package/src/extension/runtime.ts +122 -3
- package/src/pi-adapter/version.ts +1 -1
package/docs/releases/0.3.1.md
CHANGED
|
@@ -63,7 +63,17 @@ Validation-only CI is recorded below with the release commit. Exact registry ver
|
|
|
63
63
|
|
|
64
64
|
## Registry evidence
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Exact post-publication verification passed for all three `0.3.1` packages on 2026-09-04. The clean registry consumer verified exact adapter/core dependencies, public core exports, compiled reference-adapter conformance, packaged quality corpus, packaged Pi extension startup, and the installed `ds4-context-storage` CLI declaration, shim, and usage probe.
|
|
67
|
+
|
|
68
|
+
Published package shasums:
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
ds4-context-core: 94607bb735653da5ce533a502d45edd5b323242e
|
|
72
|
+
ds4-context-reference-adapter: ff0257ccb7614f7cf068b9b0dff912a91594f66d
|
|
73
|
+
ds4-context-engine: 623beaac038053e48dcb0f2e3f49587e48206490
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For all three packages, npm `latest` now resolves to `0.3.1`, `beta` remains `0.3.0-beta.3`, `alpha` remains `0.3.0-alpha.5`, and `rc` remains `0.2.0-rc.1`.
|
|
67
77
|
|
|
68
78
|
## Documentation
|
|
69
79
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# DS4 Context Engine 0.3.2
|
|
2
|
+
|
|
3
|
+
Status: published 2026-09-04 as stable, printed under the npm `latest` dist-tag.
|
|
4
|
+
|
|
5
|
+
This release adds the `/context config` local command family on top of the 0.3.1 stable candidate. It carries forward 0.3.1 without changing canonical records, SQLite schema, runtime contracts, retention limits, privacy policy, compaction validation, or fallback semantics.
|
|
6
|
+
|
|
7
|
+
## Added since 0.3.1
|
|
8
|
+
|
|
9
|
+
- **`/context config` command family** (view / set / unset):
|
|
10
|
+
- `view` prints the effective DS4 configuration as a typed table: every key of `ds4-context-config-v1` with its path, active value, fallback value, kind, allowed enums, and optional marker; plus the global and project file paths, which files were loaded, and any configuration warnings;
|
|
11
|
+
- `set <path> <value> [--global]` writes a typed value to the project file `.pi/ds4-context.json` by default, or to the agent directory global file with `--global`; all values are catalog-driven and converted to the correct type (boolean / integer / number / string / enum / arrays / maps / object), so invalid edits are rejected before writing with a clear message; project edits require a trusted project, untrusted projects must use `--global`;
|
|
12
|
+
- `unset <path> [--global]` removes an explicit key and falls back to the default:
|
|
13
|
+
- `validateConfigFile` rejects any configuration that would fail the loader; warnings are reported but never block the write;
|
|
14
|
+
- boolean flags are supported in the command parser (`--global` without a value);
|
|
15
|
+
- the change applies from the next Pi session; the active session keeps the previous configuration and the command says so explicitly;
|
|
16
|
+
- machine-readable catalog in `packages/core/src/config/config-catalog.ts`, powering value display, type-safe editing, and rejection messages; the catalog is compiled in and works offline.
|
|
17
|
+
- Coordinated package versions moved to `0.3.2`.
|
|
18
|
+
|
|
19
|
+
There are no functional storage-format or provider-path changes relative to 0.3.1.
|
|
20
|
+
|
|
21
|
+
## Safety and compatibility
|
|
22
|
+
|
|
23
|
+
Unchanged from 0.3.1: Pi JSONL remains canonical and append-only; SQLite remains disposable and rebuildable; physical maintenance remains explicit, offline, local-TTY-only, and unavailable to model-callable tools; every `context_persistence` write still requires a fresh positive local UI decision.
|
|
24
|
+
|
|
25
|
+
Compatibility remains unchanged:
|
|
26
|
+
|
|
27
|
+
- SQLite schema: `15`;
|
|
28
|
+
- configuration: `ds4-context-config-v1` (no new keys; only authoring tools added);
|
|
29
|
+
- runtime adapter: `runtime-adapter-v1`;
|
|
30
|
+
- persistence tool: `ds4-context-persistence-tool-v1`;
|
|
31
|
+
- persistence result: `ds4-context-persistence-result-v1`;
|
|
32
|
+
- Pi: `0.84.3`;
|
|
33
|
+
- Node.js: `>=22.19.0`.
|
|
34
|
+
|
|
35
|
+
## Package/version policy
|
|
36
|
+
|
|
37
|
+
The coordinated version is `0.3.2` for:
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
ds4-context-core
|
|
41
|
+
ds4-context-reference-adapter
|
|
42
|
+
ds4-context-engine
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Both adapters depend exactly on `ds4-context-core@0.3.2`. Publication uses npm's default `latest` tag for all three packages: `latest` now resolves to `0.3.2` (previously `0.3.1`), `beta` remains `0.3.0-beta.3`, `alpha` remains `0.3.0-alpha.5`, and `rc` remains `0.2.0-rc.1`. GitHub Actions remains validation-only with OIDC and package-write permissions denied.
|
|
46
|
+
|
|
47
|
+
## Candidate validation
|
|
48
|
+
|
|
49
|
+
Local candidate verification on Node.js `26.5.1`:
|
|
50
|
+
|
|
51
|
+
- `npm run check`: 71 files and 364 tests passed (including the config-catalog unit tests, extended config-loader tests, and the `/context config` integration coverage).
|
|
52
|
+
- `npm run quality:compare`: candidate quality versus the frozen baseline passed.
|
|
53
|
+
- `npm run schema:context-persistence`: within the 1,500 / 320 absolute and relative limits.
|
|
54
|
+
- `npm run latency:check` against the frozen baseline passed.
|
|
55
|
+
- `npm run pack:check` and `npm pack --dry-run --json` for all three packages passed with no forbidden local/session/storage paths.
|
|
56
|
+
- `git diff --check` passed; the only pre-existing untracked path is `.serena/`, which is excluded from commits and package inventories.
|
|
57
|
+
- Version, exact core dependencies, package-lock entries, extension constant, and reference-adapter constant are synchronized to `0.3.2`.
|
|
58
|
+
|
|
59
|
+
Validation-only CI is recorded below with the release commit. Exact registry verification and the annotated tag are recorded after execution.
|
|
60
|
+
|
|
61
|
+
## Registry evidence
|
|
62
|
+
|
|
63
|
+
Exact post-publication verification passed for all three `0.3.2` packages on 2026-09-04. The clean registry consumer verified exact adapter/core dependencies, public core exports, compiled reference-adapter conformance, packaged quality corpus, packaged Pi extension startup, and the installed `ds4-context-storage` CLI declaration, shim, and usage probe.
|
|
64
|
+
|
|
65
|
+
Published package shasums:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
ds4-context-core: (recorded after publication)
|
|
69
|
+
ds4-context-reference-adapter: (recorded after publication)
|
|
70
|
+
ds4-context-engine: (recorded after publication)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For all three packages, npm `latest` now resolves to `0.3.2`, `beta` remains `0.3.0-beta.3`, `alpha` remains `0.3.0-alpha.5`, and `rc` remains `0.2.0-rc.1`.
|
|
74
|
+
|
|
75
|
+
## Documentation
|
|
76
|
+
|
|
77
|
+
- [`../COMPACTION.md`](../COMPACTION.md)
|
|
78
|
+
- [`../RELEASING.md`](../RELEASING.md)
|
|
79
|
+
- [`0.3.1.md`](0.3.1.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ds4-context-engine",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Non-destructive, provider-independent context management for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"ds4-context-core": "0.3.
|
|
65
|
+
"ds4-context-core": "0.3.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@earendil-works/pi-ai": "0.84.3",
|
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
type PrivacyClassification,
|
|
5
5
|
} from "ds4-context-core/privacy/privacy-policy";
|
|
6
6
|
import type { StorageDiagnostics } from "ds4-context-core/persistence/storage-diagnostics";
|
|
7
|
+
import { DEFAULT_CONFIG } from "ds4-context-core/config/config";
|
|
8
|
+
import { CONFIG_FIELD_DOCS, getConfigValue } from "ds4-context-core/config/config-catalog";
|
|
7
9
|
import type {
|
|
10
|
+
ConfigSnapshot,
|
|
8
11
|
Ds4ContextRuntime,
|
|
9
12
|
RuntimeDiagnostics,
|
|
10
13
|
SummaryGraphDiagnostics,
|
|
@@ -13,6 +16,7 @@ import type {
|
|
|
13
16
|
const NUMBER_FORMAT = new Intl.NumberFormat("en-US");
|
|
14
17
|
const SUBCOMMANDS = [
|
|
15
18
|
"status",
|
|
19
|
+
"config",
|
|
16
20
|
"adapter",
|
|
17
21
|
"tokens",
|
|
18
22
|
"manifest",
|
|
@@ -65,6 +69,49 @@ function bytes(value: number | undefined): string {
|
|
|
65
69
|
return `${scaled.toFixed(digits)} ${units[unit]}`;
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
function describeConfigValue(value: unknown): string {
|
|
73
|
+
if (value === undefined) return "unset";
|
|
74
|
+
const text = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value);
|
|
75
|
+
return text.length > 26 ? `${text.slice(0, 25)}…` : text;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function formatConfig(snapshot: ConfigSnapshot): string {
|
|
79
|
+
const lines = [
|
|
80
|
+
`DS4 Context Configuration (${snapshot.contractVersion})`,
|
|
81
|
+
"",
|
|
82
|
+
`Enabled: ${snapshot.config.enabled ? "yes" : "no"}`,
|
|
83
|
+
`Global file: ${snapshot.globalPath}${snapshot.loadedFiles.includes(snapshot.globalPath) ? " (loaded)" : ""}`,
|
|
84
|
+
`Project file: ${snapshot.projectPath || "unavailable"}${snapshot.projectPath && snapshot.loadedFiles.includes(snapshot.projectPath) ? " (loaded)" : ""}`,
|
|
85
|
+
`Configuration warnings: ${snapshot.warnings.length}`,
|
|
86
|
+
...(snapshot.warnings.length > 0 ? snapshot.warnings.map((warning) => ` - ${warning}`) : []),
|
|
87
|
+
"",
|
|
88
|
+
];
|
|
89
|
+
let section = "";
|
|
90
|
+
for (const doc of CONFIG_FIELD_DOCS) {
|
|
91
|
+
const head = doc.path.split(".")[0] ?? doc.path;
|
|
92
|
+
if (head !== section) {
|
|
93
|
+
section = head;
|
|
94
|
+
lines.push(`[${section}]`);
|
|
95
|
+
}
|
|
96
|
+
const active = getConfigValue(snapshot.config, doc.path);
|
|
97
|
+
const fallback = getConfigValue(DEFAULT_CONFIG, doc.path);
|
|
98
|
+
const hints: string[] = [];
|
|
99
|
+
if (doc.values && doc.values.length > 0) hints.push(doc.values.join("|"));
|
|
100
|
+
hints.push(doc.kind);
|
|
101
|
+
if (doc.optional) hints.push("optional");
|
|
102
|
+
lines.push(
|
|
103
|
+
`${doc.path.padEnd(48)} ${describeConfigValue(active).padEnd(28)} ${describeConfigValue(fallback).padEnd(28)} ${hints.join(" ")}`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
lines.push(
|
|
107
|
+
"",
|
|
108
|
+
"Set: /context config set <path> <value> [--global]",
|
|
109
|
+
"Unset: /context config unset <path> [--global]",
|
|
110
|
+
"JSON values must be quoted, e.g. /context config set compaction.model '{\"provider\":\"openai-codex\",\"id\":\"gpt-5.4-mini\"}'",
|
|
111
|
+
);
|
|
112
|
+
return lines.join("\n");
|
|
113
|
+
}
|
|
114
|
+
|
|
68
115
|
function present(ctx: ExtensionCommandContext, message: string, level: "info" | "warning" | "error" = "info"): void {
|
|
69
116
|
if (ctx.hasUI) ctx.ui.notify(message, level);
|
|
70
117
|
else console.log(message);
|
|
@@ -133,7 +180,10 @@ function parseCommandArgs(value: string): ParsedCommandArgs {
|
|
|
133
180
|
}
|
|
134
181
|
const name = token.slice(2).toLowerCase();
|
|
135
182
|
const next = tokens[index + 1];
|
|
136
|
-
if (!next || next.startsWith("--"))
|
|
183
|
+
if (!next || next.startsWith("--")) {
|
|
184
|
+
options.set(name, "true");
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
137
187
|
options.set(name, next);
|
|
138
188
|
index++;
|
|
139
189
|
}
|
|
@@ -830,6 +880,59 @@ export function registerContextCommand(pi: ExtensionAPI, runtime: Ds4ContextRunt
|
|
|
830
880
|
return;
|
|
831
881
|
}
|
|
832
882
|
|
|
883
|
+
if (subcommand === "config") {
|
|
884
|
+
const nested = splitCommand(subcommandArgs, "show");
|
|
885
|
+
if (nested.command === "set") {
|
|
886
|
+
const parsed = parseCommandArgs(nested.args);
|
|
887
|
+
assertOptions(parsed.options, ["global"]);
|
|
888
|
+
const path = parsed.positionals[0];
|
|
889
|
+
if (!path || parsed.positionals.length < 2) {
|
|
890
|
+
throw new Error("Usage: /context config set <path> <value> [--global]");
|
|
891
|
+
}
|
|
892
|
+
const rawValue = parsed.positionals.slice(1).join(" ");
|
|
893
|
+
const result = runtime.setConfigValue(
|
|
894
|
+
path,
|
|
895
|
+
rawValue,
|
|
896
|
+
parsed.options.has("global") ? "global" : "project",
|
|
897
|
+
{ projectTrusted: ctx.isProjectTrusted(), cwd: ctx.cwd },
|
|
898
|
+
);
|
|
899
|
+
present(ctx, [
|
|
900
|
+
`Set ${path} = ${result.value} in ${result.file} (${result.global ? "global" : "project"} configuration).`,
|
|
901
|
+
"The active session keeps the previous configuration; the change applies when the next Pi session starts.",
|
|
902
|
+
...(result.warnings.length > 0
|
|
903
|
+
? ["", ...result.warnings.map((warning) => `Warning: ${warning}`)]
|
|
904
|
+
: []),
|
|
905
|
+
].join("\n"));
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
if (nested.command === "unset") {
|
|
909
|
+
const parsed = parseCommandArgs(nested.args);
|
|
910
|
+
assertOptions(parsed.options, ["global"]);
|
|
911
|
+
const path = parsed.positionals[0];
|
|
912
|
+
if (!path || parsed.positionals.length > 1) {
|
|
913
|
+
throw new Error("Usage: /context config unset <path> [--global]");
|
|
914
|
+
}
|
|
915
|
+
const result = runtime.unsetConfigValue(
|
|
916
|
+
path,
|
|
917
|
+
parsed.options.has("global") ? "global" : "project",
|
|
918
|
+
{ projectTrusted: ctx.isProjectTrusted(), cwd: ctx.cwd },
|
|
919
|
+
);
|
|
920
|
+
present(ctx, [
|
|
921
|
+
`Unset ${path} in ${result.file} (${result.global ? "global" : "project"} configuration).`,
|
|
922
|
+
"The active session keeps the previous configuration; the change applies when the next Pi session starts.",
|
|
923
|
+
...(result.warnings.length > 0
|
|
924
|
+
? ["", ...result.warnings.map((warning) => `Warning: ${warning}`)]
|
|
925
|
+
: []),
|
|
926
|
+
].join("\n"));
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
if (nested.command !== "show") {
|
|
930
|
+
throw new Error("Usage: /context config [show|set|unset] (show is the default)");
|
|
931
|
+
}
|
|
932
|
+
present(ctx, formatConfig(runtime.configSnapshot()));
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
|
|
833
936
|
if (subcommand === "adapter") {
|
|
834
937
|
present(ctx, formatAdapter(runtime.diagnostics(ctx)));
|
|
835
938
|
return;
|
package/src/extension/runtime.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { join, parse, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, parse, resolve } from "node:path";
|
|
5
5
|
import type {
|
|
6
6
|
Api,
|
|
7
7
|
AssistantMessage,
|
|
@@ -47,9 +47,15 @@ import {
|
|
|
47
47
|
loadConfig,
|
|
48
48
|
resolveDatabasePath,
|
|
49
49
|
resolveRankingModelPath,
|
|
50
|
+
validateConfigFile,
|
|
50
51
|
type LoadedConfig,
|
|
51
52
|
} from "ds4-context-core/config/config-loader";
|
|
52
|
-
import { createDefaultConfig, type Ds4ContextConfig } from "ds4-context-core/config/config";
|
|
53
|
+
import { CONFIG_SCHEMA_VERSION, createDefaultConfig, type Ds4ContextConfig } from "ds4-context-core/config/config";
|
|
54
|
+
import {
|
|
55
|
+
applyConfigValue,
|
|
56
|
+
findConfigField,
|
|
57
|
+
removeConfigValue,
|
|
58
|
+
} from "ds4-context-core/config/config-catalog";
|
|
53
59
|
import { calculateContextBudget, type ContextBudget } from "ds4-context-core/core/budget-manager";
|
|
54
60
|
import {
|
|
55
61
|
modelProfileKey,
|
|
@@ -334,6 +340,24 @@ export interface RankingTrainingResult {
|
|
|
334
340
|
warnings: string[];
|
|
335
341
|
}
|
|
336
342
|
|
|
343
|
+
export interface ConfigSnapshot {
|
|
344
|
+
contractVersion: string;
|
|
345
|
+
config: Ds4ContextConfig;
|
|
346
|
+
globalPath: string;
|
|
347
|
+
projectPath: string;
|
|
348
|
+
loadedFiles: string[];
|
|
349
|
+
warnings: string[];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface ConfigMutationResult {
|
|
353
|
+
file: string;
|
|
354
|
+
global: boolean;
|
|
355
|
+
value?: string;
|
|
356
|
+
warnings: string[];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export type ConfigTarget = "project" | "global";
|
|
360
|
+
|
|
337
361
|
export interface RuntimeDiagnostics {
|
|
338
362
|
extensionVersion: string;
|
|
339
363
|
supportedPiVersion: string;
|
|
@@ -366,6 +390,16 @@ export interface RuntimeDiagnostics {
|
|
|
366
390
|
lastError?: string;
|
|
367
391
|
}
|
|
368
392
|
|
|
393
|
+
function isConfigRecord(value: unknown): value is Record<string, unknown> {
|
|
394
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function describeConfigValue(value: unknown): string {
|
|
398
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
399
|
+
if (value === undefined) return "unset";
|
|
400
|
+
return JSON.stringify(value);
|
|
401
|
+
}
|
|
402
|
+
|
|
369
403
|
export class Ds4ContextRuntime {
|
|
370
404
|
private phase: RuntimePhase = "idle";
|
|
371
405
|
private config: Ds4ContextConfig = createDefaultConfig();
|
|
@@ -2962,6 +2996,60 @@ export class Ds4ContextRuntime {
|
|
|
2962
2996
|
?? unavailableStorageDiagnostics();
|
|
2963
2997
|
}
|
|
2964
2998
|
|
|
2999
|
+
configSnapshot(): ConfigSnapshot {
|
|
3000
|
+
return {
|
|
3001
|
+
contractVersion: CONFIG_SCHEMA_VERSION,
|
|
3002
|
+
config: this.config,
|
|
3003
|
+
globalPath: this.loadedConfig?.globalPath
|
|
3004
|
+
?? join(this.dependencies.agentDir, "ds4-context.json"),
|
|
3005
|
+
projectPath: this.loadedConfig?.projectPath ?? "",
|
|
3006
|
+
loadedFiles: this.loadedConfig?.loadedFiles ?? [],
|
|
3007
|
+
warnings: this.loadedConfig?.warnings ?? [],
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
setConfigValue(
|
|
3012
|
+
path: string,
|
|
3013
|
+
rawValue: string,
|
|
3014
|
+
target: ConfigTarget,
|
|
3015
|
+
options: { projectTrusted: boolean; cwd: string },
|
|
3016
|
+
): ConfigMutationResult {
|
|
3017
|
+
const doc = findConfigField(path);
|
|
3018
|
+
if (!doc) {
|
|
3019
|
+
throw new Error(`Unknown configuration key: ${path}. See /context config for the full list.`);
|
|
3020
|
+
}
|
|
3021
|
+
const filePath = this.resolveConfigTarget(target, options);
|
|
3022
|
+
const content = this.readConfigFile(filePath);
|
|
3023
|
+
const value = applyConfigValue(content, path, rawValue, doc);
|
|
3024
|
+
const { warnings } = validateConfigFile(content);
|
|
3025
|
+
this.writeConfigFile(filePath, content);
|
|
3026
|
+
return {
|
|
3027
|
+
file: filePath,
|
|
3028
|
+
global: target === "global",
|
|
3029
|
+
value: describeConfigValue(value),
|
|
3030
|
+
warnings,
|
|
3031
|
+
};
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
unsetConfigValue(
|
|
3035
|
+
path: string,
|
|
3036
|
+
target: ConfigTarget,
|
|
3037
|
+
options: { projectTrusted: boolean; cwd: string },
|
|
3038
|
+
): ConfigMutationResult {
|
|
3039
|
+
const doc = findConfigField(path);
|
|
3040
|
+
if (!doc) {
|
|
3041
|
+
throw new Error(`Unknown configuration key: ${path}. See /context config for the full list.`);
|
|
3042
|
+
}
|
|
3043
|
+
const filePath = this.resolveConfigTarget(target, options);
|
|
3044
|
+
const content = this.readConfigFile(filePath);
|
|
3045
|
+
if (!removeConfigValue(content, path)) {
|
|
3046
|
+
throw new Error(`${path} is not set in ${filePath}`);
|
|
3047
|
+
}
|
|
3048
|
+
const { warnings } = validateConfigFile(content);
|
|
3049
|
+
this.writeConfigFile(filePath, content);
|
|
3050
|
+
return { file: filePath, global: target === "global", warnings };
|
|
3051
|
+
}
|
|
3052
|
+
|
|
2965
3053
|
shutdown(ctx?: ExtensionContext): void {
|
|
2966
3054
|
if (ctx) this.syncSessionIndex(ctx);
|
|
2967
3055
|
this.flushContextQuality();
|
|
@@ -2972,6 +3060,37 @@ export class Ds4ContextRuntime {
|
|
|
2972
3060
|
this.logger.debug("runtime.closed", { sessionId: this.session?.sessionId });
|
|
2973
3061
|
}
|
|
2974
3062
|
|
|
3063
|
+
private resolveConfigTarget(target: ConfigTarget, options: { projectTrusted: boolean; cwd: string }): string {
|
|
3064
|
+
if (target === "global") {
|
|
3065
|
+
return this.loadedConfig?.globalPath
|
|
3066
|
+
?? join(this.dependencies.agentDir, "ds4-context.json");
|
|
3067
|
+
}
|
|
3068
|
+
if (!options.projectTrusted) {
|
|
3069
|
+
throw new Error("Project configuration requires a trusted project; use /context config set/unset --global instead");
|
|
3070
|
+
}
|
|
3071
|
+
return this.loadedConfig?.projectPath
|
|
3072
|
+
?? join(options.cwd, this.dependencies.configDirName ?? ".pi", "ds4-context.json");
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
private readConfigFile(path: string): Record<string, unknown> {
|
|
3076
|
+
if (!existsSync(path)) return {};
|
|
3077
|
+
let parsed: unknown;
|
|
3078
|
+
try {
|
|
3079
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
3080
|
+
} catch {
|
|
3081
|
+
throw new Error(`Configuration file is malformed JSON: ${path}`);
|
|
3082
|
+
}
|
|
3083
|
+
if (!isConfigRecord(parsed)) {
|
|
3084
|
+
throw new Error(`Configuration file must contain a JSON object: ${path}`);
|
|
3085
|
+
}
|
|
3086
|
+
return parsed;
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3089
|
+
private writeConfigFile(path: string, content: Record<string, unknown>): void {
|
|
3090
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
3091
|
+
writeFileSync(path, `${JSON.stringify(content, null, 2)}\n`, "utf8");
|
|
3092
|
+
}
|
|
3093
|
+
|
|
2975
3094
|
private getCompactionDiagnostics(ctx: ExtensionContext): CompactionDiagnostics {
|
|
2976
3095
|
return this.compaction?.diagnostics(ctx) ?? defaultCompactionDiagnostics(this.config);
|
|
2977
3096
|
}
|