@cortexkit/opencode-magic-context 0.34.1 → 0.35.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.
- package/README.md +3 -1
- package/dist/agents/magic-context-prompt.d.ts +2 -1
- package/dist/agents/magic-context-prompt.d.ts.map +1 -1
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +3 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +42 -1
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-fvpfvt0w.js → conflict-warning-hook-p2pmhvn7.js} +2 -1
- package/dist/features/magic-context/context-authority.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/provider-output-failure.d.ts +15 -0
- package/dist/features/magic-context/dreamer/provider-output-failure.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +9 -5
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-gate.d.ts +8 -2
- package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +2 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/fail-closed-block.d.ts +2 -0
- package/dist/features/magic-context/fail-closed-block.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/mural/compress-cues.d.ts +13 -5
- package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
- package/dist/features/magic-context/mural/cue-validation.d.ts +7 -7
- package/dist/features/magic-context/mural/cue-validation.d.ts.map +1 -1
- package/dist/features/magic-context/mural/storage-mural-cues.d.ts +17 -7
- package/dist/features/magic-context/mural/storage-mural-cues.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +21 -3
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -14
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts +16 -2
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +1 -0
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +10 -3
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-state-sync.d.ts +1 -1
- package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-transport.d.ts +2 -1
- package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +5 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +22 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +19 -5
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +1 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +4 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index-0c9dmw9m.js +116 -0
- package/dist/{index-x8spt5wy.js → index-4anesz49.js} +849 -633
- package/dist/{index-dtas91s5.js → index-8aaadh98.js} +7 -119
- package/dist/{index-b563sga5.js → index-h8mk7vpa.js} +541 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1010 -840
- package/dist/plugin/hooks/create-session-hooks.d.ts +12 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts +1 -0
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts +4 -0
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-k72ejkkh.js → recomp-orchestrator-zc915ceq.js} +3 -2
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/prompt-surface-runtime.d.ts +43 -0
- package/dist/shared/prompt-surface-runtime.d.ts.map +1 -0
- package/dist/shared/prompt-surface.d.ts +49 -0
- package/dist/shared/prompt-surface.d.ts.map +1 -0
- package/dist/{storage-meta-session-xt41zbw4.js → storage-meta-session-53cjs6mr.js} +1 -1
- package/dist/tools/ctx-expand/tools.d.ts +1 -0
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-memory/tools.d.ts +1 -0
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts +1 -0
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts +1 -0
- package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts +1 -0
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/light-descriptions.d.ts +6 -0
- package/dist/tools/light-descriptions.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/agents/magic-context-prompt.test.ts +144 -0
- package/src/agents/magic-context-prompt.ts +53 -2
- package/src/config/index.test.ts +53 -0
- package/src/config/index.ts +4 -0
- package/src/config/project-security.test.ts +20 -0
- package/src/config/project-security.ts +23 -0
- package/src/config/schema/magic-context.test.ts +58 -0
- package/src/config/schema/magic-context.ts +61 -1
- package/src/shared/index.ts +2 -0
- package/src/shared/prompt-surface-a1-golden.md +458 -0
- package/src/shared/prompt-surface-runtime.test.ts +141 -0
- package/src/shared/prompt-surface-runtime.ts +250 -0
- package/src/shared/prompt-surface.test.ts +109 -0
- package/src/shared/prompt-surface.ts +138 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ContextDatabase } from "../../features/magic-context/storage";
|
|
2
|
+
import type { PromptSurfaceConfig } from "../../shared/prompt-surface";
|
|
3
|
+
import type { PromptSurfaceRuntime } from "../../shared/prompt-surface-runtime";
|
|
2
4
|
/**
|
|
3
5
|
* Clear all per-session cache entries the system-prompt handler maintains,
|
|
4
6
|
* including the module-scope user-profile/key-files maps and the per-handler
|
|
@@ -33,9 +35,9 @@ export declare function isMagicContextInternalAgent(systemPromptContent: string)
|
|
|
33
35
|
* Skips injection if guidance is already present (e.g., baked into the
|
|
34
36
|
* agent prompt by oh-my-opencode).
|
|
35
37
|
*
|
|
36
|
-
* 2. Detect system prompt changes for
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* 2. Detect system-prompt content or prompt-surface preset changes for
|
|
39
|
+
* cache-flush triggering. The hash transition is the semantic boundary at
|
|
40
|
+
* which queued operations can ride the same HARD fold.
|
|
39
41
|
*/
|
|
40
42
|
export declare function createSystemPromptHashHandler(deps: {
|
|
41
43
|
db: ContextDatabase;
|
|
@@ -48,6 +50,13 @@ export declare function createSystemPromptHashHandler(deps: {
|
|
|
48
50
|
memoryEnabled?: boolean;
|
|
49
51
|
/** Optional language from user config for the main agent's generated text. */
|
|
50
52
|
language?: string;
|
|
53
|
+
promptSurface?: PromptSurfaceConfig;
|
|
54
|
+
promptSurfaceRuntime?: PromptSurfaceRuntime;
|
|
55
|
+
/** Recover the session's latest model when the transform input omits it. */
|
|
56
|
+
resolveModel?: (sessionId: string) => {
|
|
57
|
+
providerID: string;
|
|
58
|
+
modelID: string;
|
|
59
|
+
} | undefined;
|
|
51
60
|
/**
|
|
52
61
|
* One-shot signal that disk-backed adjuncts (user profile, key files,
|
|
53
62
|
* sticky date) need to be re-read on this pass.
|
|
@@ -57,8 +66,9 @@ export declare function createSystemPromptHashHandler(deps: {
|
|
|
57
66
|
*/
|
|
58
67
|
systemPromptRefreshSessions: Set<string>;
|
|
59
68
|
/**
|
|
60
|
-
* Producer side: when this handler detects a real prompt-content
|
|
61
|
-
* change, it adds the session to all three sets
|
|
69
|
+
* Producer side: when this handler detects a real prompt-content or
|
|
70
|
+
* prompt-surface-preset hash change, it adds the session to all three sets
|
|
71
|
+
* so downstream consumers
|
|
62
72
|
* (transform `prepareCompartmentInjection`, postprocess heuristics)
|
|
63
73
|
* react on the same cycle. The hash change usually pairs with a new
|
|
64
74
|
* agent identity, so all three are appropriate.
|
|
@@ -103,6 +113,10 @@ export declare function createSystemPromptHashHandler(deps: {
|
|
|
103
113
|
}): {
|
|
104
114
|
handler: (input: {
|
|
105
115
|
sessionID?: string;
|
|
116
|
+
model?: {
|
|
117
|
+
providerID?: string;
|
|
118
|
+
modelID?: string;
|
|
119
|
+
};
|
|
106
120
|
}, output: {
|
|
107
121
|
system: string[];
|
|
108
122
|
}) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt-hash.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/system-prompt-hash.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,eAAe,EAGvB,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"system-prompt-hash.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/system-prompt-hash.ts"],"names":[],"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AAM,EAAE,MAAM,CAAC,CAAC;IAC1C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,4EAA4E;IAC5E,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,mEAAmE;IACnE,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,mEAAmE;IACnE,kCAAkC,CAAC,EAAE,MAAM,CAAC;IAC5C,yFAAyF;IACzF,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC;sEACkE;IAClE,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAChD,GAAG;IACA,OAAO,EAAE,CACL,KAAK,EAAE;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE;YAAE,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACrD,EACD,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C,CAgVA"}
|
|
@@ -5,6 +5,7 @@ type ContextUsageCacheEntry = {
|
|
|
5
5
|
usage: ContextUsage;
|
|
6
6
|
updatedAt: number;
|
|
7
7
|
lastResponseTime?: number;
|
|
8
|
+
hasUsageTokens?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare function loadContextUsage(contextUsageMap: Map<string, ContextUsageCacheEntry>, db: ContextDatabase, sessionId: string): ContextUsage;
|
|
10
11
|
export declare function resolveSchedulerDecision(scheduler: Scheduler, sessionMeta: SessionMeta, contextUsage: ContextUsage, sessionId: string, modelKey?: string, contextLimit?: number): "execute" | "defer";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-context-state.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/transform-context-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGpF,KAAK,sBAAsB,GAAG;IAC1B,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"transform-context-state.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/transform-context-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGpF,KAAK,sBAAsB,GAAG;IAC1B,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAYF,wBAAgB,gBAAgB,CAC5B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,EACpD,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,MAAM,GAClB,YAAY,CAmCd;AAED,wBAAgB,wBAAwB,CACpC,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACtB,SAAS,GAAG,OAAO,CAmBrB"}
|
|
@@ -3,6 +3,7 @@ import { type ContextDatabase } from "../../features/magic-context/storage";
|
|
|
3
3
|
import type { Tagger } from "../../features/magic-context/tagger";
|
|
4
4
|
import type { ContextUsage } from "../../features/magic-context/types";
|
|
5
5
|
import type { PluginContext } from "../../plugin/types";
|
|
6
|
+
import type { PromptSurfaceConfig } from "../../shared/prompt-surface";
|
|
6
7
|
import type { LiveModelBySession } from "./hook-handlers";
|
|
7
8
|
import { type RustModeModuleClient } from "./rust-mode-transform";
|
|
8
9
|
export { EmergencyFailClosedError } from "./emergency-fail-closed";
|
|
@@ -47,6 +48,7 @@ export interface TransformDeps {
|
|
|
47
48
|
usage: ContextUsage;
|
|
48
49
|
updatedAt: number;
|
|
49
50
|
lastResponseTime?: number;
|
|
51
|
+
hasUsageTokens?: boolean;
|
|
50
52
|
}>;
|
|
51
53
|
db: ContextDatabase;
|
|
52
54
|
/**
|
|
@@ -198,6 +200,8 @@ export interface TransformDeps {
|
|
|
198
200
|
maybeAutoEmbedSession?: (sessionId: string) => void;
|
|
199
201
|
/** Resolved project mode. Rust mode bypasses every TS mutation below. */
|
|
200
202
|
transformMode?: "ts" | "rust";
|
|
203
|
+
/** Prompt-surface routing and USER description overrides forwarded to Rust mode. */
|
|
204
|
+
promptSurface?: PromptSurfaceConfig;
|
|
201
205
|
/** Module transport injected by the hook; tests use a deterministic mock. */
|
|
202
206
|
rustModeModuleClient?: RustModeModuleClient;
|
|
203
207
|
/** Test-only opt-out for transform-wire fixtures without the authority protocol. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/transform.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAGxE,OAAO,EACH,KAAK,eAAe,EAYvB,MAAM,sCAAsC,CAAC;AAgB9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM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
|
4
|
+
let result = "";
|
|
5
|
+
let inString = false;
|
|
6
|
+
let escaped = false;
|
|
7
|
+
let inLineComment = false;
|
|
8
|
+
let inBlockComment = false;
|
|
9
|
+
for (let index = 0;index < content.length; index += 1) {
|
|
10
|
+
const char = content[index];
|
|
11
|
+
const next = content[index + 1];
|
|
12
|
+
if (inLineComment) {
|
|
13
|
+
if (char === `
|
|
14
|
+
`) {
|
|
15
|
+
inLineComment = false;
|
|
16
|
+
result += char;
|
|
17
|
+
}
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (inBlockComment) {
|
|
21
|
+
if (char === "*" && next === "/") {
|
|
22
|
+
inBlockComment = false;
|
|
23
|
+
index += 1;
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (inString) {
|
|
28
|
+
result += char;
|
|
29
|
+
if (escaped) {
|
|
30
|
+
escaped = false;
|
|
31
|
+
} else if (char === "\\") {
|
|
32
|
+
escaped = true;
|
|
33
|
+
} else if (char === '"') {
|
|
34
|
+
inString = false;
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (char === '"') {
|
|
39
|
+
inString = true;
|
|
40
|
+
result += char;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (char === "/" && next === "/") {
|
|
44
|
+
inLineComment = true;
|
|
45
|
+
index += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (char === "/" && next === "*") {
|
|
49
|
+
inBlockComment = true;
|
|
50
|
+
index += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
result += char;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
function stripTrailingCommas(content) {
|
|
58
|
+
let result = "";
|
|
59
|
+
let inString = false;
|
|
60
|
+
let escaped = false;
|
|
61
|
+
for (let index = 0;index < content.length; index += 1) {
|
|
62
|
+
const char = content[index];
|
|
63
|
+
if (inString) {
|
|
64
|
+
result += char;
|
|
65
|
+
if (escaped) {
|
|
66
|
+
escaped = false;
|
|
67
|
+
} else if (char === "\\") {
|
|
68
|
+
escaped = true;
|
|
69
|
+
} else if (char === '"') {
|
|
70
|
+
inString = false;
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (char === '"') {
|
|
75
|
+
inString = true;
|
|
76
|
+
result += char;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (char === ",") {
|
|
80
|
+
let lookahead = index + 1;
|
|
81
|
+
while (lookahead < content.length && /\s/.test(content[lookahead] ?? "")) {
|
|
82
|
+
lookahead += 1;
|
|
83
|
+
}
|
|
84
|
+
const next = content[lookahead];
|
|
85
|
+
if (next === "}" || next === "]") {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
result += char;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
function parseJsonc(content) {
|
|
94
|
+
const normalized = stripTrailingCommas(stripJsonComments(content));
|
|
95
|
+
return JSON.parse(normalized);
|
|
96
|
+
}
|
|
97
|
+
function readJsoncFile(filePath) {
|
|
98
|
+
try {
|
|
99
|
+
return parseJsonc(readFileSync(filePath, "utf-8"));
|
|
100
|
+
} catch (_error) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function detectConfigFile(basePath) {
|
|
105
|
+
const jsoncPath = `${basePath}.jsonc`;
|
|
106
|
+
const jsonPath = `${basePath}.json`;
|
|
107
|
+
if (existsSync(jsoncPath)) {
|
|
108
|
+
return { format: "jsonc", path: jsoncPath };
|
|
109
|
+
}
|
|
110
|
+
if (existsSync(jsonPath)) {
|
|
111
|
+
return { format: "json", path: jsonPath };
|
|
112
|
+
}
|
|
113
|
+
return { format: "none", path: jsoncPath };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { stripJsonComments, parseJsonc, readJsoncFile, detectConfigFile };
|