@qmediat.io/gemini-code-context-mcp 1.0.2 → 1.2.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/CHANGELOG.md +87 -0
- package/dist/auth/credentials-store.d.ts.map +1 -1
- package/dist/auth/credentials-store.js +8 -2
- package/dist/auth/credentials-store.js.map +1 -1
- package/dist/cache/cache-manager.d.ts +31 -0
- package/dist/cache/cache-manager.d.ts.map +1 -1
- package/dist/cache/cache-manager.js +105 -0
- package/dist/cache/cache-manager.js.map +1 -1
- package/dist/cache/ttl-watcher.d.ts +2 -0
- package/dist/cache/ttl-watcher.d.ts.map +1 -1
- package/dist/cache/ttl-watcher.js +60 -25
- package/dist/cache/ttl-watcher.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -1
- package/dist/config.js.map +1 -1
- package/dist/gemini/models.d.ts.map +1 -1
- package/dist/gemini/models.js +34 -25
- package/dist/gemini/models.js.map +1 -1
- package/dist/indexer/globs.d.ts +24 -1
- package/dist/indexer/globs.d.ts.map +1 -1
- package/dist/indexer/globs.js +70 -4
- package/dist/indexer/globs.js.map +1 -1
- package/dist/indexer/workspace-validation.d.ts +54 -0
- package/dist/indexer/workspace-validation.d.ts.map +1 -0
- package/dist/indexer/workspace-validation.js +206 -0
- package/dist/indexer/workspace-validation.js.map +1 -0
- package/dist/manifest/db.d.ts +50 -0
- package/dist/manifest/db.d.ts.map +1 -1
- package/dist/manifest/db.js +74 -1
- package/dist/manifest/db.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +7 -0
- package/dist/server.js.map +1 -1
- package/dist/tools/ask.tool.d.ts +25 -1
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +267 -27
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts +24 -1
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +188 -31
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/registry.d.ts +37 -6
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +30 -6
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/reindex.tool.d.ts.map +1 -1
- package/dist/tools/reindex.tool.js +10 -0
- package/dist/tools/reindex.tool.js.map +1 -1
- package/dist/tools/shared/thinking.d.ts +63 -0
- package/dist/tools/shared/thinking.d.ts.map +1 -0
- package/dist/tools/shared/thinking.js +62 -0
- package/dist/tools/shared/thinking.js.map +1 -0
- package/dist/utils/cost-estimator.d.ts +21 -0
- package/dist/utils/cost-estimator.d.ts.map +1 -1
- package/dist/utils/cost-estimator.js +43 -6
- package/dist/utils/cost-estimator.js.map +1 -1
- package/package.json +3 -3
package/dist/gemini/models.js
CHANGED
|
@@ -8,32 +8,41 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { logger } from '../utils/logger.js';
|
|
10
10
|
import { listAvailableModels } from './model-registry.js';
|
|
11
|
+
/**
|
|
12
|
+
* Substrings in a model ID that disqualify it as a general-purpose text-gen
|
|
13
|
+
* target for our `ask` / `code` tools. The list covers:
|
|
14
|
+
*
|
|
15
|
+
* - Modality add-ons that share `pro`/`flash` tokens with text models
|
|
16
|
+
* (`image`, `tts`, `vision`, `audio`) — these fail on arbitrary prompts.
|
|
17
|
+
* - Non-text-gen Gemini families whose IDs happen to contain `pro`:
|
|
18
|
+
* `banana` (Google's "nano-banana" image-gen family), `lyria` (music
|
|
19
|
+
* generation), `research` (Deep Research — a specialised agent, not a
|
|
20
|
+
* drop-in conversational model), and `customtools` (variant that requires
|
|
21
|
+
* a `tools` param on every call and returns errors without one).
|
|
22
|
+
*
|
|
23
|
+
* Maintained as a single source of truth so every alias filters consistently.
|
|
24
|
+
* When Google ships a new non-text-gen family under a `pro`/`flash` name,
|
|
25
|
+
* add the disambiguating substring here — no per-alias edits needed.
|
|
26
|
+
*/
|
|
27
|
+
const NON_TEXT_GEN_MARKERS = [
|
|
28
|
+
'image',
|
|
29
|
+
'tts',
|
|
30
|
+
'vision',
|
|
31
|
+
'audio',
|
|
32
|
+
'banana',
|
|
33
|
+
'lyria',
|
|
34
|
+
'research',
|
|
35
|
+
'customtools',
|
|
36
|
+
];
|
|
37
|
+
function isTextGenModel(m) {
|
|
38
|
+
return !NON_TEXT_GEN_MARKERS.some((marker) => m.id.includes(marker));
|
|
39
|
+
}
|
|
11
40
|
const ALIASES = {
|
|
12
|
-
'latest-pro': (models) => models.find((m) => m.id.includes('pro') &&
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'latest-pro-thinking': (models) => models.find((m) => m.id.includes('pro') &&
|
|
18
|
-
m.supportsThinking &&
|
|
19
|
-
!m.id.includes('image') &&
|
|
20
|
-
!m.id.includes('tts')) ??
|
|
21
|
-
models.find((m) => m.id.includes('pro') &&
|
|
22
|
-
!m.id.includes('image') &&
|
|
23
|
-
!m.id.includes('tts') &&
|
|
24
|
-
!m.id.includes('vision') &&
|
|
25
|
-
!m.id.includes('audio')),
|
|
26
|
-
'latest-flash': (models) => models.find((m) => m.id.includes('flash') &&
|
|
27
|
-
!m.id.includes('image') &&
|
|
28
|
-
!m.id.includes('tts') &&
|
|
29
|
-
!m.id.includes('lite') &&
|
|
30
|
-
!m.id.includes('vision') &&
|
|
31
|
-
!m.id.includes('audio')),
|
|
32
|
-
'latest-lite': (models) => models.find((m) => m.id.includes('lite') &&
|
|
33
|
-
!m.id.includes('image') &&
|
|
34
|
-
!m.id.includes('tts') &&
|
|
35
|
-
!m.id.includes('vision') &&
|
|
36
|
-
!m.id.includes('audio')),
|
|
41
|
+
'latest-pro': (models) => models.find((m) => m.id.includes('pro') && isTextGenModel(m)),
|
|
42
|
+
'latest-pro-thinking': (models) => models.find((m) => m.id.includes('pro') && m.supportsThinking && isTextGenModel(m)) ??
|
|
43
|
+
models.find((m) => m.id.includes('pro') && isTextGenModel(m)),
|
|
44
|
+
'latest-flash': (models) => models.find((m) => m.id.includes('flash') && !m.id.includes('lite') && isTextGenModel(m)),
|
|
45
|
+
'latest-lite': (models) => models.find((m) => m.id.includes('lite') && isTextGenModel(m)),
|
|
37
46
|
};
|
|
38
47
|
export function isAlias(value) {
|
|
39
48
|
return value in ALIASES;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/gemini/models.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAkB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,MAAM,
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/gemini/models.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAkB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,oBAAoB,GAAG;IAC3B,OAAO;IACP,KAAK;IACL,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,OAAO;IACP,UAAU;IACV,aAAa;CACL,CAAC;AAEX,SAAS,cAAc,CAAC,CAAY;IAClC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,OAAO,GAAG;IACd,YAAY,EAAE,CAAC,MAAmB,EAAyB,EAAE,CAC3D,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;IAC/D,qBAAqB,EAAE,CAAC,MAAmB,EAAyB,EAAE,CACpE,MAAM,CAAC,IAAI,CAAC,CA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IAAI,CACT,UAAU,SAAS,uDAAuD,QAAQ,CAAC,EAAE,IAAI,CAC1F,CAAC;IACF,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,QAAQ,CAAC,EAAE;QACrB,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,QAAQ,CAAC,eAAe;QACzC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAY,CAAC;AACzC,CAAC"}
|
package/dist/indexer/globs.d.ts
CHANGED
|
@@ -7,7 +7,30 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** File extensions included by default — source code + prose + infra. */
|
|
9
9
|
export declare const DEFAULT_INCLUDE_EXTENSIONS: readonly string[];
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Path fragments excluded regardless of depth.
|
|
12
|
+
*
|
|
13
|
+
* Matched by `isPathExcluded` (below) against the workspace-relative POSIX path
|
|
14
|
+
* in three modes: exact equality, `${dir}/` prefix, and `/${dir}/` substring.
|
|
15
|
+
* Entries are therefore typically directory *basenames* (`node_modules`,
|
|
16
|
+
* `.ssh`), but multi-segment fragments like `.config/gcloud` also match
|
|
17
|
+
* correctly — the matcher sees the full relative path, not just `dirent.name`.
|
|
18
|
+
*
|
|
19
|
+
* Two classes of entries:
|
|
20
|
+
* - **Build / cache artefacts** — indexing them wastes tokens on derived output
|
|
21
|
+
* (no value to Gemini).
|
|
22
|
+
* - **Secret-bearing directories** (`.ssh`, `.aws`, `.gnupg`, `.kube`, …) — if a
|
|
23
|
+
* user or prompt-injected agent points `workspace` at `$HOME`, we refuse to
|
|
24
|
+
* even walk these even if `workspace-validation.ts` is bypassed. Defense in
|
|
25
|
+
* depth against credential exfiltration through the Files API upload path.
|
|
26
|
+
*
|
|
27
|
+
* Entries here are ALWAYS excluded: `isFileIncluded` checks `isPathExcluded`
|
|
28
|
+
* first, and `defaultMatchConfig` only ever APPENDS extra excludes supplied by
|
|
29
|
+
* the caller. Tool-level `includeGlobs` cannot re-include a directory that is
|
|
30
|
+
* in this list — if a repo has a legitimately-named dir that collides with
|
|
31
|
+
* one of these, the fix is to rename the dir or fork the list, not to try to
|
|
32
|
+
* punch through via `includeGlobs`.
|
|
33
|
+
*/
|
|
11
34
|
export declare const DEFAULT_EXCLUDE_DIRS: readonly string[];
|
|
12
35
|
/** Files excluded by full relpath suffix (supports either `node_modules` prefix or literal suffix). */
|
|
13
36
|
export declare const DEFAULT_EXCLUDE_FILE_NAMES: readonly string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globs.d.ts","sourceRoot":"","sources":["../../src/indexer/globs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yEAAyE;AACzE,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAoFvD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"globs.d.ts","sourceRoot":"","sources":["../../src/indexer/globs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yEAAyE;AACzE,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAoFvD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAoEjD,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAmBvD,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AA0BD,wBAAgB,kBAAkB,CAChC,KAAK,GAAE;IAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GACjF,WAAW,CAgBb;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAO5E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAgB5E"}
|
package/dist/indexer/globs.js
CHANGED
|
@@ -91,12 +91,33 @@ export const DEFAULT_INCLUDE_EXTENSIONS = [
|
|
|
91
91
|
'.graphql',
|
|
92
92
|
'.gql',
|
|
93
93
|
];
|
|
94
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Path fragments excluded regardless of depth.
|
|
96
|
+
*
|
|
97
|
+
* Matched by `isPathExcluded` (below) against the workspace-relative POSIX path
|
|
98
|
+
* in three modes: exact equality, `${dir}/` prefix, and `/${dir}/` substring.
|
|
99
|
+
* Entries are therefore typically directory *basenames* (`node_modules`,
|
|
100
|
+
* `.ssh`), but multi-segment fragments like `.config/gcloud` also match
|
|
101
|
+
* correctly — the matcher sees the full relative path, not just `dirent.name`.
|
|
102
|
+
*
|
|
103
|
+
* Two classes of entries:
|
|
104
|
+
* - **Build / cache artefacts** — indexing them wastes tokens on derived output
|
|
105
|
+
* (no value to Gemini).
|
|
106
|
+
* - **Secret-bearing directories** (`.ssh`, `.aws`, `.gnupg`, `.kube`, …) — if a
|
|
107
|
+
* user or prompt-injected agent points `workspace` at `$HOME`, we refuse to
|
|
108
|
+
* even walk these even if `workspace-validation.ts` is bypassed. Defense in
|
|
109
|
+
* depth against credential exfiltration through the Files API upload path.
|
|
110
|
+
*
|
|
111
|
+
* Entries here are ALWAYS excluded: `isFileIncluded` checks `isPathExcluded`
|
|
112
|
+
* first, and `defaultMatchConfig` only ever APPENDS extra excludes supplied by
|
|
113
|
+
* the caller. Tool-level `includeGlobs` cannot re-include a directory that is
|
|
114
|
+
* in this list — if a repo has a legitimately-named dir that collides with
|
|
115
|
+
* one of these, the fix is to rename the dir or fork the list, not to try to
|
|
116
|
+
* punch through via `includeGlobs`.
|
|
117
|
+
*/
|
|
95
118
|
export const DEFAULT_EXCLUDE_DIRS = [
|
|
119
|
+
// Dependencies / build output
|
|
96
120
|
'node_modules',
|
|
97
|
-
'.git',
|
|
98
|
-
'.hg',
|
|
99
|
-
'.svn',
|
|
100
121
|
'dist',
|
|
101
122
|
'build',
|
|
102
123
|
'out',
|
|
@@ -125,9 +146,47 @@ export const DEFAULT_EXCLUDE_DIRS = [
|
|
|
125
146
|
'obj',
|
|
126
147
|
'.DS_Store',
|
|
127
148
|
'.terraform',
|
|
149
|
+
// VCS internals
|
|
150
|
+
'.git',
|
|
151
|
+
'.hg',
|
|
152
|
+
'.svn',
|
|
153
|
+
'.jj',
|
|
154
|
+
// Secret-bearing directories — never index, never upload.
|
|
155
|
+
'.ssh',
|
|
156
|
+
'.aws',
|
|
157
|
+
'.gnupg',
|
|
158
|
+
'.gpg',
|
|
159
|
+
'.kube',
|
|
160
|
+
'.docker',
|
|
161
|
+
'.1password',
|
|
162
|
+
'.pki',
|
|
163
|
+
'.gcloud',
|
|
164
|
+
'.azure',
|
|
165
|
+
'.config/gcloud',
|
|
166
|
+
'.config/azure',
|
|
167
|
+
'Keychains', // macOS: `Library/Keychains`
|
|
168
|
+
// Home-level user directories — defense in depth. If a caller somehow
|
|
169
|
+
// ends up scanning `$HOME` despite `validateWorkspacePath`'s home-reject
|
|
170
|
+
// (e.g. a symlinked sibling that points back at home, or a future MCP
|
|
171
|
+
// host pattern we haven't seen), these are the top offenders: privacy-
|
|
172
|
+
// hostile, massive, and guaranteed not to be part of any legitimate
|
|
173
|
+
// codebase. Refusing them blunts the blast radius even in the edge cases
|
|
174
|
+
// where the root guard doesn't fire.
|
|
175
|
+
'.Trash', // macOS: Finder trash — large, privacy-sensitive
|
|
176
|
+
'Trash', // Linux variants: `~/.local/share/Trash/files`
|
|
177
|
+
'Library', // macOS: app support / caches / prefs — huge, not a codebase
|
|
178
|
+
'Downloads',
|
|
179
|
+
'Desktop',
|
|
180
|
+
'Documents',
|
|
181
|
+
'Movies', // macOS
|
|
182
|
+
'Music', // macOS / Linux
|
|
183
|
+
'Pictures',
|
|
184
|
+
'Videos',
|
|
185
|
+
'Public', // macOS
|
|
128
186
|
];
|
|
129
187
|
/** Files excluded by full relpath suffix (supports either `node_modules` prefix or literal suffix). */
|
|
130
188
|
export const DEFAULT_EXCLUDE_FILE_NAMES = [
|
|
189
|
+
// Lockfiles / build metadata
|
|
131
190
|
'package-lock.json',
|
|
132
191
|
'yarn.lock',
|
|
133
192
|
'pnpm-lock.yaml',
|
|
@@ -138,6 +197,13 @@ export const DEFAULT_EXCLUDE_FILE_NAMES = [
|
|
|
138
197
|
'composer.lock',
|
|
139
198
|
'.DS_Store',
|
|
140
199
|
'Thumbs.db',
|
|
200
|
+
// Secret-bearing files (belt + suspenders on top of directory excludes).
|
|
201
|
+
'.netrc',
|
|
202
|
+
'.pypirc',
|
|
203
|
+
'.npmrc',
|
|
204
|
+
'.pgpass',
|
|
205
|
+
'.git-credentials',
|
|
206
|
+
'credentials', // AWS, qmediat, gcloud all use this filename in config dirs
|
|
141
207
|
];
|
|
142
208
|
/**
|
|
143
209
|
* Normalise an `includeGlobs` entry. Accepts three shapes per the tool schema:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globs.js","sourceRoot":"","sources":["../../src/indexer/globs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,UAAU;IACV,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,SAAS;IACT,MAAM;IACN,QAAQ;IACR,UAAU;IACV,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,QAAQ;IACR,IAAI;IACJ,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,gBAAgB;IAChB,OAAO;IACP,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,cAAc;IACd,MAAM;IACN,gBAAgB;IAChB,KAAK;IACL,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,YAAY;IACZ,UAAU;IACV,KAAK;IACL,KAAK;IACL,MAAM;IACN,eAAe;IACf,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,MAAM;CACP,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"globs.js","sourceRoot":"","sources":["../../src/indexer/globs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,UAAU;IACV,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,SAAS;IACT,MAAM;IACN,QAAQ;IACR,UAAU;IACV,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,QAAQ;IACR,IAAI;IACJ,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAA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AO,KAAK,CAAC;IAC1C,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC3C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC1C,CAAC;aAAM,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard against arbitrary-path indexing.
|
|
3
|
+
*
|
|
4
|
+
* The tools accept a `workspace` argument that flows directly into
|
|
5
|
+
* `scanWorkspace`, which recursively reads + hashes + uploads matching files
|
|
6
|
+
* to the Gemini Files API. Without validation, a malicious or prompt-injected
|
|
7
|
+
* MCP client can redirect that pipeline at `$HOME`, `/etc`, or anywhere else
|
|
8
|
+
* the server process has read access — exfiltrating local secrets.
|
|
9
|
+
*
|
|
10
|
+
* Validation passes if ANY of:
|
|
11
|
+
*
|
|
12
|
+
* 1. The path is under `process.cwd()` (the MCP host's working directory is
|
|
13
|
+
* itself a trust signal — the user launched us there).
|
|
14
|
+
* 2. The path contains at least one recognised workspace marker
|
|
15
|
+
* (`.git`, `package.json`, `Cargo.toml`, etc.) at its root.
|
|
16
|
+
* 3. `GEMINI_CODE_CONTEXT_ALLOW_NONWORKSPACE=true` is set — escape hatch for
|
|
17
|
+
* users with genuinely unconventional roots (CI sandboxes, build dirs).
|
|
18
|
+
*
|
|
19
|
+
* Otherwise we throw with a user-visible message explaining the check.
|
|
20
|
+
*
|
|
21
|
+
* This is defense in depth, not a silver bullet: a workspace with `.git` inside
|
|
22
|
+
* `$HOME/.ssh` would still pass, and attackers who control the path AND can
|
|
23
|
+
* plant a marker bypass the check. The goal is to stop the common accidental
|
|
24
|
+
* and prompt-injection paths, not every conceivable abuse.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Files / dirs at a path root that strongly suggest it's a real codebase.
|
|
28
|
+
* Scoped to things that appear in the ROOT — per-file markers deeper in the
|
|
29
|
+
* tree (README.md, .gitignore) aren't reliable signals.
|
|
30
|
+
*
|
|
31
|
+
* The list deliberately omits weak signals like editor scratch files
|
|
32
|
+
* (`.projectile`) — this is a security guard, not a "feels like a project"
|
|
33
|
+
* heuristic. Stronger signals only: a VCS dir, a build/dependency manifest
|
|
34
|
+
* with structure, or a known polyglot marker (Dockerfile, Makefile, flake.nix
|
|
35
|
+
* are kept because they're load-bearing single-file projects, not editor
|
|
36
|
+
* fragments).
|
|
37
|
+
*/
|
|
38
|
+
export declare const WORKSPACE_MARKERS: readonly string[];
|
|
39
|
+
export declare class WorkspaceValidationError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Throw `WorkspaceValidationError` if `workspaceRoot` is not a plausible
|
|
44
|
+
* codebase root. Intended to be called from tool entry points after
|
|
45
|
+
* `resolve(input.workspace ?? cwd)` but before any filesystem scan.
|
|
46
|
+
*
|
|
47
|
+
* The check is performed against the **canonical** path (`fs.realpath`),
|
|
48
|
+
* not the literal argument. Without this, a symlink under cwd pointing at
|
|
49
|
+
* `/etc` (or `$HOME`, or anywhere else) would pass the cwd-descendant test
|
|
50
|
+
* — defeating the purpose of the guard. Resolving to the canonical path
|
|
51
|
+
* first means the cwd ancestry test sees the real target every time.
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateWorkspacePath(workspaceRoot: string): void;
|
|
54
|
+
//# sourceMappingURL=workspace-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-validation.d.ts","sourceRoot":"","sources":["../../src/indexer/workspace-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAqCrC,CAAC;AAEX,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CA6GjE"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard against arbitrary-path indexing.
|
|
3
|
+
*
|
|
4
|
+
* The tools accept a `workspace` argument that flows directly into
|
|
5
|
+
* `scanWorkspace`, which recursively reads + hashes + uploads matching files
|
|
6
|
+
* to the Gemini Files API. Without validation, a malicious or prompt-injected
|
|
7
|
+
* MCP client can redirect that pipeline at `$HOME`, `/etc`, or anywhere else
|
|
8
|
+
* the server process has read access — exfiltrating local secrets.
|
|
9
|
+
*
|
|
10
|
+
* Validation passes if ANY of:
|
|
11
|
+
*
|
|
12
|
+
* 1. The path is under `process.cwd()` (the MCP host's working directory is
|
|
13
|
+
* itself a trust signal — the user launched us there).
|
|
14
|
+
* 2. The path contains at least one recognised workspace marker
|
|
15
|
+
* (`.git`, `package.json`, `Cargo.toml`, etc.) at its root.
|
|
16
|
+
* 3. `GEMINI_CODE_CONTEXT_ALLOW_NONWORKSPACE=true` is set — escape hatch for
|
|
17
|
+
* users with genuinely unconventional roots (CI sandboxes, build dirs).
|
|
18
|
+
*
|
|
19
|
+
* Otherwise we throw with a user-visible message explaining the check.
|
|
20
|
+
*
|
|
21
|
+
* This is defense in depth, not a silver bullet: a workspace with `.git` inside
|
|
22
|
+
* `$HOME/.ssh` would still pass, and attackers who control the path AND can
|
|
23
|
+
* plant a marker bypass the check. The goal is to stop the common accidental
|
|
24
|
+
* and prompt-injection paths, not every conceivable abuse.
|
|
25
|
+
*/
|
|
26
|
+
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
27
|
+
import { homedir } from 'node:os';
|
|
28
|
+
import { isAbsolute, join, sep as pathSep, relative } from 'node:path';
|
|
29
|
+
/**
|
|
30
|
+
* Files / dirs at a path root that strongly suggest it's a real codebase.
|
|
31
|
+
* Scoped to things that appear in the ROOT — per-file markers deeper in the
|
|
32
|
+
* tree (README.md, .gitignore) aren't reliable signals.
|
|
33
|
+
*
|
|
34
|
+
* The list deliberately omits weak signals like editor scratch files
|
|
35
|
+
* (`.projectile`) — this is a security guard, not a "feels like a project"
|
|
36
|
+
* heuristic. Stronger signals only: a VCS dir, a build/dependency manifest
|
|
37
|
+
* with structure, or a known polyglot marker (Dockerfile, Makefile, flake.nix
|
|
38
|
+
* are kept because they're load-bearing single-file projects, not editor
|
|
39
|
+
* fragments).
|
|
40
|
+
*/
|
|
41
|
+
export const WORKSPACE_MARKERS = [
|
|
42
|
+
// VCS
|
|
43
|
+
'.git',
|
|
44
|
+
'.hg',
|
|
45
|
+
'.svn',
|
|
46
|
+
'.jj',
|
|
47
|
+
// JS / TS
|
|
48
|
+
'package.json',
|
|
49
|
+
'deno.json',
|
|
50
|
+
'deno.jsonc',
|
|
51
|
+
'bun.lockb',
|
|
52
|
+
// Python
|
|
53
|
+
'pyproject.toml',
|
|
54
|
+
'setup.py',
|
|
55
|
+
'setup.cfg',
|
|
56
|
+
'requirements.txt',
|
|
57
|
+
'Pipfile',
|
|
58
|
+
// Go / Rust / C family
|
|
59
|
+
'go.mod',
|
|
60
|
+
'Cargo.toml',
|
|
61
|
+
'CMakeLists.txt',
|
|
62
|
+
'Makefile',
|
|
63
|
+
// JVM
|
|
64
|
+
'pom.xml',
|
|
65
|
+
'build.gradle',
|
|
66
|
+
'build.gradle.kts',
|
|
67
|
+
'settings.gradle',
|
|
68
|
+
'settings.gradle.kts',
|
|
69
|
+
// Ruby / PHP / Elixir
|
|
70
|
+
'Gemfile',
|
|
71
|
+
'composer.json',
|
|
72
|
+
'mix.exs',
|
|
73
|
+
// Infra / misc
|
|
74
|
+
'Dockerfile',
|
|
75
|
+
'flake.nix',
|
|
76
|
+
'shell.nix',
|
|
77
|
+
'build.zig',
|
|
78
|
+
];
|
|
79
|
+
export class WorkspaceValidationError extends Error {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = 'WorkspaceValidationError';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** True if `child` is `cwd` itself or a descendant of it. Case-sensitive on POSIX, case-preserving on Windows via `path.relative`. */
|
|
86
|
+
function isUnderCwd(child, cwd = process.cwd()) {
|
|
87
|
+
const rel = relative(cwd, child);
|
|
88
|
+
if (rel === '' || rel === '.')
|
|
89
|
+
return true;
|
|
90
|
+
if (rel === '..')
|
|
91
|
+
return false;
|
|
92
|
+
if (rel.startsWith(`..${pathSep}`))
|
|
93
|
+
return false;
|
|
94
|
+
if (isAbsolute(rel))
|
|
95
|
+
return false; // different drive on Windows
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Throw `WorkspaceValidationError` if `workspaceRoot` is not a plausible
|
|
100
|
+
* codebase root. Intended to be called from tool entry points after
|
|
101
|
+
* `resolve(input.workspace ?? cwd)` but before any filesystem scan.
|
|
102
|
+
*
|
|
103
|
+
* The check is performed against the **canonical** path (`fs.realpath`),
|
|
104
|
+
* not the literal argument. Without this, a symlink under cwd pointing at
|
|
105
|
+
* `/etc` (or `$HOME`, or anywhere else) would pass the cwd-descendant test
|
|
106
|
+
* — defeating the purpose of the guard. Resolving to the canonical path
|
|
107
|
+
* first means the cwd ancestry test sees the real target every time.
|
|
108
|
+
*/
|
|
109
|
+
export function validateWorkspacePath(workspaceRoot) {
|
|
110
|
+
if (!isAbsolute(workspaceRoot)) {
|
|
111
|
+
throw new WorkspaceValidationError(`workspace must be an absolute path (got '${workspaceRoot}')`);
|
|
112
|
+
}
|
|
113
|
+
// Canonicalise BEFORE any cwd / marker check — see the doc-comment above
|
|
114
|
+
// for the symlink-bypass rationale. `realpathSync` throws ENOENT for
|
|
115
|
+
// missing paths, EACCES for unreadable parents, ELOOP for circular
|
|
116
|
+
// symlinks; we surface each with a precise message instead of mapping
|
|
117
|
+
// them all onto "does not exist".
|
|
118
|
+
let canonical;
|
|
119
|
+
try {
|
|
120
|
+
canonical = realpathSync(workspaceRoot);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
const code = err.code;
|
|
124
|
+
const reason = code === 'ENOENT'
|
|
125
|
+
? 'does not exist'
|
|
126
|
+
: code === 'EACCES'
|
|
127
|
+
? 'is not accessible (permission denied)'
|
|
128
|
+
: code === 'ELOOP'
|
|
129
|
+
? 'is part of a symlink cycle'
|
|
130
|
+
: `could not be resolved (${code ?? 'unknown error'})`;
|
|
131
|
+
throw new WorkspaceValidationError(`workspace '${workspaceRoot}' ${reason}`);
|
|
132
|
+
}
|
|
133
|
+
let isDir = false;
|
|
134
|
+
try {
|
|
135
|
+
isDir = statSync(canonical).isDirectory();
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
// Should not normally fire — realpath succeeded — but defensive: surface
|
|
139
|
+
// as a regular validation error rather than letting an unexpected stat
|
|
140
|
+
// failure leak out as an unhandled exception.
|
|
141
|
+
throw new WorkspaceValidationError(`workspace '${workspaceRoot}' resolved to '${canonical}' but stat failed: ${String(err)}`);
|
|
142
|
+
}
|
|
143
|
+
if (!isDir) {
|
|
144
|
+
throw new WorkspaceValidationError(`workspace '${workspaceRoot}' resolved to '${canonical}' which is not a directory`);
|
|
145
|
+
}
|
|
146
|
+
// Canonicalise cwd too so the ancestry check compares like-with-like.
|
|
147
|
+
// macOS has common cwd symlinks: `/var → /private/var`, `/tmp → /private/tmp`.
|
|
148
|
+
// Without this, a workspace legitimately under cwd (after realpath on both
|
|
149
|
+
// sides agrees) gets rejected because `relative('/var/foo', '/private/var/foo/ws')`
|
|
150
|
+
// returns `'../../private/var/foo/ws'`, which fails the cwd-descendant test.
|
|
151
|
+
// If the `realpathSync(process.cwd())` call itself fails (unlikely — cwd
|
|
152
|
+
// removed mid-flight, EACCES), fall back to the raw `process.cwd()` to
|
|
153
|
+
// preserve the previous behaviour rather than introduce a new hard failure.
|
|
154
|
+
let canonicalCwd;
|
|
155
|
+
try {
|
|
156
|
+
canonicalCwd = realpathSync(process.cwd());
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
canonicalCwd = process.cwd();
|
|
160
|
+
}
|
|
161
|
+
// Refuse the user's home directory as a workspace even when it happens to
|
|
162
|
+
// BE the MCP host's cwd. The canonical MCP launch pattern (this project's
|
|
163
|
+
// own README recommends it, and `~/.claude.json` installs use it) sets
|
|
164
|
+
// `cwd: $HOME` specifically to sidestep an npx-in-same-repo conflict —
|
|
165
|
+
// a side-effect is that an `ask`/`code`/`reindex` call with `workspace`
|
|
166
|
+
// omitted falls through to `process.cwd() === $HOME` and then passes the
|
|
167
|
+
// cwd-ancestry check here, scanning everything under `$HOME` (Desktop,
|
|
168
|
+
// Documents, Downloads, .Trash, etc.) and uploading matched files to the
|
|
169
|
+
// Gemini Files API.
|
|
170
|
+
//
|
|
171
|
+
// No legitimate caller wants `$HOME` as a "project root" — it has no
|
|
172
|
+
// single-codebase structure, the scan cost scales with years of
|
|
173
|
+
// accumulated personal files, and exposure is privacy-hostile. Reject
|
|
174
|
+
// explicitly with a message that tells the caller what to do instead
|
|
175
|
+
// (pass `workspace` with a real project path).
|
|
176
|
+
//
|
|
177
|
+
// This check fires BEFORE the cwd-ancestry test because the point is to
|
|
178
|
+
// reject even when the path would otherwise pass. The marker-root escape
|
|
179
|
+
// below still applies to OTHER paths that happen to equal home via
|
|
180
|
+
// `HOME=/` shenanigans — but `$HOME` itself is refused unconditionally.
|
|
181
|
+
let canonicalHome = null;
|
|
182
|
+
try {
|
|
183
|
+
canonicalHome = realpathSync(homedir());
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// If we can't resolve home (unlikely — process has no HOME env?), fall
|
|
187
|
+
// through and let the normal cwd / marker checks decide. Not a security
|
|
188
|
+
// hole — attacker can't make our process forget home to bypass.
|
|
189
|
+
}
|
|
190
|
+
if (canonicalHome !== null && canonical === canonicalHome) {
|
|
191
|
+
throw new WorkspaceValidationError(`Refusing to scan '${workspaceRoot}' — it resolves to the user's home directory ('${canonical}'). This is almost certainly a misconfiguration: the MCP server's cwd is $HOME (standard launch pattern) and no explicit 'workspace' argument was passed, so the tool would recursively index Desktop, Documents, Downloads, .Trash, and every other directory under home. Pass 'workspace' explicitly to the tool with a real project root (a path containing .git, package.json, Cargo.toml, go.mod, pyproject.toml, etc.).`);
|
|
192
|
+
}
|
|
193
|
+
if (isUnderCwd(canonical, canonicalCwd))
|
|
194
|
+
return;
|
|
195
|
+
for (const marker of WORKSPACE_MARKERS) {
|
|
196
|
+
if (existsSync(join(canonical, marker)))
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (process.env.GEMINI_CODE_CONTEXT_ALLOW_NONWORKSPACE === 'true') {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const sample = WORKSPACE_MARKERS.slice(0, 5).join(', ');
|
|
203
|
+
throw new WorkspaceValidationError(`Refusing to scan '${workspaceRoot}'${canonical !== workspaceRoot ? ` (resolves to '${canonical}')` : ''}: path is not under the host's cwd and contains no recognised workspace marker ` +
|
|
204
|
+
`(${sample}, …). If intentional, set GEMINI_CODE_CONTEXT_ALLOW_NONWORKSPACE=true.`);
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=workspace-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-validation.js","sourceRoot":"","sources":["../../src/indexer/workspace-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,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AAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,IAAI,wBAAwB,CAChC,qBAAqB,aAAa,IAAI,SAAS,KAAK,aAAa,CAAC,CAAC,CAAC,kBAAkB,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,iFAAiF;QACvL,IAAI,MAAM,wEAAwE,CACrF,CAAC;AACJ,CAAC"}
|
package/dist/manifest/db.d.ts
CHANGED
|
@@ -24,6 +24,56 @@ export declare class ManifestDb {
|
|
|
24
24
|
*/
|
|
25
25
|
findFileRowByHash(workspaceRoot: string, contentHash: string, nowMs: number): FileRow | null;
|
|
26
26
|
insertUsageMetric(metric: UsageMetricRow): void;
|
|
27
|
+
/**
|
|
28
|
+
* Atomically check the daily budget and — if there's headroom — reserve
|
|
29
|
+
* an estimate against it, so concurrent tool calls can't all pass the
|
|
30
|
+
* pre-check and then collectively overshoot the cap.
|
|
31
|
+
*
|
|
32
|
+
* Implemented as a `BEGIN IMMEDIATE`-backed SQLite transaction:
|
|
33
|
+
*
|
|
34
|
+
* 1. SUM existing `cost_usd_micro` since UTC midnight (includes
|
|
35
|
+
* previously-reserved but not yet finalized rows, so concurrent
|
|
36
|
+
* reservations see each other).
|
|
37
|
+
* 2. If `spent + estimate > cap`, rollback and return `rejected`.
|
|
38
|
+
* 3. Otherwise INSERT a row with the estimate. The caller receives its
|
|
39
|
+
* primary-key `id` and is expected to later `finalizeBudgetReservation`
|
|
40
|
+
* (on successful call) or `cancelBudgetReservation` (on failure).
|
|
41
|
+
*
|
|
42
|
+
* `dailyBudgetMicros` of `Number.POSITIVE_INFINITY` disables the check and
|
|
43
|
+
* should not be passed here — the caller should branch on `Number.isFinite`
|
|
44
|
+
* and skip the reservation entirely (plain `insertUsageMetric` after the
|
|
45
|
+
* call is enough when there's no cap).
|
|
46
|
+
*/
|
|
47
|
+
reserveBudget(args: {
|
|
48
|
+
workspaceRoot: string;
|
|
49
|
+
toolName: string;
|
|
50
|
+
model: string;
|
|
51
|
+
estimatedCostMicros: number;
|
|
52
|
+
dailyBudgetMicros: number;
|
|
53
|
+
nowMs: number;
|
|
54
|
+
}): {
|
|
55
|
+
id: number;
|
|
56
|
+
} | {
|
|
57
|
+
rejected: true;
|
|
58
|
+
spentMicros: number;
|
|
59
|
+
capMicros: number;
|
|
60
|
+
estimateMicros: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Replace the placeholder values on a reservation row with the measured
|
|
64
|
+
* cost and token counts after a tool call completes successfully.
|
|
65
|
+
*/
|
|
66
|
+
finalizeBudgetReservation(reservationId: number, data: {
|
|
67
|
+
cachedTokens: number;
|
|
68
|
+
uncachedTokens: number;
|
|
69
|
+
costUsdMicro: number;
|
|
70
|
+
durationMs: number;
|
|
71
|
+
}): void;
|
|
72
|
+
/**
|
|
73
|
+
* Drop a reservation row when the tool call failed before producing any
|
|
74
|
+
* billable output. Idempotent — calling with an unknown id is a no-op.
|
|
75
|
+
*/
|
|
76
|
+
cancelBudgetReservation(reservationId: number): void;
|
|
27
77
|
/** Sum costs spent today (UTC) in USD micros. */
|
|
28
78
|
todaysCostMicros(nowMs: number): number;
|
|
29
79
|
/** Aggregate stats for a workspace — powers the `status` tool. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/manifest/db.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/manifest/db.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA6FzE,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAe;gBAEtB,YAAY,CAAC,EAA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