agentschat-mcp 0.36.25 → 0.36.27
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 +7 -0
- package/README.md +10 -10
- package/codex/README.md +4 -4
- package/codex/app-server.ts +101 -22
- package/codex/bots-config.ts +32 -11
- package/codex/bridge.ts +127 -28
- package/codex/config.ts +137 -21
- package/codex/gui-channel.ts +66 -9
- package/codex/inbox-sync.ts +77 -12
- package/codex/loop-grants.ts +49 -11
- package/codex/manager.ts +108 -27
- package/codex/owner.ts +106 -9
- package/codex/processes.ts +51 -7
- package/codex/run.ts +70 -17
- package/codex/runtime-home.ts +51 -11
- package/codex/thread-history.ts +87 -30
- package/codex/transport.ts +135 -22
- package/connector/README.md +1 -1
- package/connector/auth.ts +57 -5
- package/connector/backfill.ts +92 -10
- package/connector/descriptor.ts +27 -1
- package/connector/identities.ts +82 -14
- package/connector/ingest.ts +11 -2
- package/connector/normalize.ts +32 -12
- package/connector/run.ts +314 -67
- package/connector/server.ts +95 -26
- package/cordis.patch.yml +4 -2
- package/dist/codex-bots.js +437 -75
- package/dist/codex-bridge.js +2111 -582
- package/dist/connector.js +1300 -493
- package/dist/dsh.js +1789 -299
- package/dist/muse.js +967 -221
- package/dist/server.js +4410 -919
- package/dsh/README.md +1 -1
- package/dsh/client.js +7 -5
- package/dsh/identity-ui/client.js +7 -5
- package/dsh/identity-ui/index.js +43 -8
- package/dsh/inbound-bridge/index.js +677 -154
- package/dsh/src/cli.ts +430 -91
- package/dsh/src/patch.ts +295 -15
- package/dsh/tests/dsh-hardening-127.test.ts +207 -0
- package/dsh/tests/dsh.test.ts +1174 -3
- package/muse/scripts/ensure-muse-wakes.mjs +5 -3
- package/muse/scripts/muse-wake-receiver.mjs +4 -1
- package/muse/src/bridge.ts +54 -13
- package/muse/src/cli.ts +226 -41
- package/muse/src/client.ts +249 -34
- package/muse/src/config.ts +128 -12
- package/muse/src/policy.ts +28 -8
- package/muse/src/types.ts +1 -0
- package/muse/src/typing.ts +18 -1
- package/muse/src/wake.ts +237 -35
- package/muse/tests/bridge.test.mjs +131 -0
- package/muse/tests/client.test.mjs +327 -0
- package/muse/tests/config.test.mjs +78 -1
- package/muse/tests/hardening.test.mjs +199 -0
- package/muse/tests/hardening126.test.mjs +292 -0
- package/muse/tests/policy.test.mjs +83 -1
- package/muse/tests/wake.test.mjs +134 -6
- package/package.json +3 -3
- package/scripts/ensure-grok-wakes.mjs +93 -8
- package/scripts/example-url-wake-receiver.mjs +254 -61
- package/scripts/grok-bind-register.sh +38 -8
- package/skills/onboarding.md +15 -15
- package/src/argcheck.ts +113 -33
- package/src/cli.mjs +100 -16
- package/src/dedup.ts +57 -8
- package/src/grok-bind.ts +182 -33
- package/src/heartbeat.ts +39 -11
- package/src/identity-guard.ts +93 -20
- package/src/identity.ts +67 -11
- package/src/mentions.ts +26 -5
- package/src/onboarding-status.ts +134 -11
- package/src/profile-selection.ts +299 -18
- package/src/profile-store.ts +248 -30
- package/src/read-cursor.ts +280 -9
- package/src/reconnect.ts +98 -2
- package/src/redact.ts +34 -15
- package/src/rest-cli.ts +713 -159
- package/src/server.ts +286 -94
- package/src/session-bind.ts +777 -134
- package/src/session-route.ts +183 -12
- package/src/team-lead-skill.ts +3 -0
- package/src/timestamps.ts +56 -23
- package/src/tool-annotations.ts +10 -1
- package/src/wake.ts +510 -91
package/src/profile-selection.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { lstatSync, readFileSync, readlinkSync, realpathSync, statSync, type Stats } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, isAbsolute, join, parse, relative, resolve } from "node:path";
|
|
3
4
|
|
|
4
5
|
export interface ProjectProfileSelection {
|
|
5
6
|
selector: string;
|
|
@@ -9,37 +10,317 @@ export interface ProjectProfileSelection {
|
|
|
9
10
|
wsUrl?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
const MAX_PROJECT_CONFIG_BYTES = 64 * 1024;
|
|
14
|
+
const MAX_PROJECT_PROFILE_BYTES = 1_048_576;
|
|
15
|
+
const FORBIDDEN_CREDENTIAL_KEYS = new Set([
|
|
16
|
+
"token",
|
|
17
|
+
"access_token",
|
|
18
|
+
"refresh_token",
|
|
19
|
+
"id_token",
|
|
20
|
+
"oauth_token",
|
|
21
|
+
"api_token",
|
|
22
|
+
"key",
|
|
23
|
+
"api_key",
|
|
24
|
+
"agent_key",
|
|
25
|
+
"private_key",
|
|
26
|
+
"secret",
|
|
27
|
+
"client_secret",
|
|
28
|
+
"webhook_secret",
|
|
29
|
+
"password",
|
|
30
|
+
"authorization",
|
|
31
|
+
"bearer",
|
|
32
|
+
"cookie",
|
|
33
|
+
]);
|
|
34
|
+
const PROTOTYPE_KEYS = new Set([
|
|
35
|
+
"__proto__",
|
|
36
|
+
"constructor",
|
|
37
|
+
"prototype",
|
|
38
|
+
...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase()),
|
|
39
|
+
]);
|
|
40
|
+
const WINDOWS_DEVICE_STEM_RE = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
|
|
41
|
+
const RESERVED_SIDECAR_STEMS = new Set([
|
|
42
|
+
"grok-binds",
|
|
43
|
+
"grok-binds.meta",
|
|
44
|
+
"grok-binds-meta",
|
|
45
|
+
"grok-binds_meta",
|
|
46
|
+
"session-binds",
|
|
47
|
+
"session-binds.meta",
|
|
48
|
+
"session-binds-meta",
|
|
49
|
+
"session-binds_meta",
|
|
50
|
+
"agy-binds",
|
|
51
|
+
"agy-binds.meta",
|
|
52
|
+
"agy-binds-meta",
|
|
53
|
+
"agy-binds_meta",
|
|
54
|
+
"agy-session-binds",
|
|
55
|
+
"agy-session-binds.meta",
|
|
56
|
+
"agy-session-binds_meta",
|
|
57
|
+
"identity-guard",
|
|
58
|
+
"cursor",
|
|
59
|
+
"read-cursors",
|
|
60
|
+
"mention-timestamps",
|
|
61
|
+
"wake-pids",
|
|
62
|
+
"config",
|
|
63
|
+
"codex-bots",
|
|
64
|
+
"dsh",
|
|
65
|
+
"muse",
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
function safeLstat(target: string): Stats | undefined {
|
|
69
|
+
try {
|
|
70
|
+
return lstatSync(target);
|
|
71
|
+
} catch (err: any) {
|
|
72
|
+
if (err && err.code === "ENOENT") return undefined;
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const PROJECT_CONTROL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
|
|
78
|
+
|
|
79
|
+
function isAllowedDarwinSystemLink(dirPath: string): boolean {
|
|
80
|
+
if (process.platform !== "darwin") return false;
|
|
81
|
+
if (dirPath !== "/var" && dirPath !== "/tmp" && dirPath !== "/etc") return false;
|
|
82
|
+
try {
|
|
83
|
+
const expected = `/private${dirPath}`;
|
|
84
|
+
return (
|
|
85
|
+
readlinkSync(dirPath) === `private${dirPath}` &&
|
|
86
|
+
realpathSync(dirPath) === expected &&
|
|
87
|
+
!lstatSync("/private").isSymbolicLink() &&
|
|
88
|
+
lstatSync("/private").isDirectory() &&
|
|
89
|
+
!lstatSync(expected).isSymbolicLink() &&
|
|
90
|
+
statSync(expected).isDirectory()
|
|
91
|
+
);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function hasSafeRawDotDotSegments(rawPath: string, baseDir?: string): boolean {
|
|
98
|
+
if (!rawPath.includes("..")) return true;
|
|
99
|
+
const baseAbs = isAbsolute(rawPath) ? rawPath : `${baseDir ? resolve(baseDir) : process.cwd()}/${rawPath}`;
|
|
100
|
+
const root = parse(baseAbs).root;
|
|
101
|
+
const rawParts = baseAbs.slice(root.length).split(/[\\/]+/).filter(Boolean);
|
|
102
|
+
let cur = root;
|
|
103
|
+
for (const part of rawParts) {
|
|
104
|
+
if (part === ".") continue;
|
|
105
|
+
if (part === "..") {
|
|
106
|
+
cur = resolve(cur, "..");
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
cur = join(cur, part);
|
|
110
|
+
try {
|
|
111
|
+
const st = lstatSync(cur);
|
|
112
|
+
if (st.isSymbolicLink()) {
|
|
113
|
+
if (isAllowedDarwinSystemLink(cur)) continue;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!st.isDirectory()) return false;
|
|
117
|
+
} catch (err: any) {
|
|
118
|
+
if (err && err.code === "ENOENT") continue;
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function hasSafeDirChain(dirPath: string, baseDir?: string): boolean {
|
|
126
|
+
if (!dirPath || PROJECT_CONTROL_RE.test(dirPath)) return false;
|
|
127
|
+
if (!hasSafeRawDotDotSegments(dirPath, baseDir)) return false;
|
|
128
|
+
const abs = baseDir && !isAbsolute(dirPath) ? resolve(baseDir, dirPath) : resolve(dirPath);
|
|
129
|
+
const root = parse(abs).root;
|
|
130
|
+
const rel = abs.slice(root.length);
|
|
131
|
+
const segments = rel.split(/[\\/]+/).filter(Boolean);
|
|
132
|
+
let cur = root;
|
|
133
|
+
for (let i = 0; i < segments.length; i++) {
|
|
134
|
+
cur = join(cur, segments[i]!);
|
|
135
|
+
let st: Stats;
|
|
136
|
+
try {
|
|
137
|
+
st = lstatSync(cur);
|
|
138
|
+
} catch (err: any) {
|
|
139
|
+
if (err && err.code === "ENOENT") return true;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (st.isSymbolicLink()) {
|
|
143
|
+
if (isAllowedDarwinSystemLink(cur)) continue;
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (!st.isDirectory()) return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function isLoopbackHost(hostname: string): boolean {
|
|
152
|
+
const lower = hostname.toLowerCase().replace(/\.$/, "");
|
|
153
|
+
return lower === "127.0.0.1" || lower === "localhost" || lower === "[::1]" || lower === "::1";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isUnsafeMetadataOrLinkLocalHost(hostname: string): boolean {
|
|
157
|
+
const lower = hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
158
|
+
if (
|
|
159
|
+
lower === "metadata.google.internal" ||
|
|
160
|
+
lower.endsWith(".metadata.google.internal") ||
|
|
161
|
+
lower === "metadata" ||
|
|
162
|
+
lower === "metadata.goog" ||
|
|
163
|
+
lower.endsWith(".metadata.goog") ||
|
|
164
|
+
lower === "instance-data" ||
|
|
165
|
+
lower === "100.100.100.200" ||
|
|
166
|
+
lower === "0.0.0.0" ||
|
|
167
|
+
lower === "::" ||
|
|
168
|
+
lower === "0:0:0:0:0:0:0:0" ||
|
|
169
|
+
lower === "fd00:ec2::254"
|
|
170
|
+
) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(lower)) {
|
|
174
|
+
const [a, b] = lower.split(".").map(Number);
|
|
175
|
+
if (a === 0 || (a === 169 && b === 254)) return true;
|
|
176
|
+
}
|
|
177
|
+
if (/^fe[89ab][0-9a-f]*:/.test(lower)) return true;
|
|
178
|
+
const mappedPrefix = lower.match(/^(?:::ffff:|0:0:0:0:0:ffff:|0:0:0:0:ffff:0:)(.+)$/);
|
|
179
|
+
if (mappedPrefix) {
|
|
180
|
+
const tail = mappedPrefix[1]!;
|
|
181
|
+
if (/^[0-9a-f]{1,4}$/.test(tail)) return true;
|
|
182
|
+
const zeroMatch = tail.match(/^0+:(.+)$/);
|
|
183
|
+
const afterZero = zeroMatch ? zeroMatch[1]! : "";
|
|
184
|
+
const tailParts = afterZero && (afterZero.includes(".") || afterZero.includes(":")) ? afterZero : tail;
|
|
185
|
+
if (tailParts === "0.0.0.0" || tailParts === "100.100.100.200" || /^0\.\d+\.\d+\.\d+$/.test(tailParts)) return true;
|
|
186
|
+
if (/^169\.254\.\d{1,3}\.\d{1,3}$/.test(tailParts)) return true;
|
|
187
|
+
const hexMatch = tailParts.match(/^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
|
|
188
|
+
if (hexMatch) {
|
|
189
|
+
const hi = parseInt(hexMatch[1]!, 16);
|
|
190
|
+
const lo = parseInt(hexMatch[2]!, 16);
|
|
191
|
+
if (((hi >> 8) & 0xff) === 0) return true;
|
|
192
|
+
if (((hi >> 8) & 0xff) === 169 && (hi & 0xff) === 254) return true;
|
|
193
|
+
if (hi === 0x6464 && lo === 0x64c8) return true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function isSafeProjectAgentId(id: string): boolean {
|
|
200
|
+
return (
|
|
201
|
+
id.length > 0 &&
|
|
202
|
+
id.length <= 128 &&
|
|
203
|
+
id !== "." &&
|
|
204
|
+
!id.includes("..") &&
|
|
205
|
+
!/[\/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(id) &&
|
|
206
|
+
!/(?:%2e|%2f|%5c|%00)/i.test(id) &&
|
|
207
|
+
!PROTOTYPE_KEYS.has(id.toLowerCase())
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
12
211
|
/** Read only this project's binding. Never scan parents or choose a sibling bot. */
|
|
13
212
|
export function projectProfileSelector(cwd: string): ProjectProfileSelection | undefined {
|
|
14
|
-
|
|
213
|
+
if (!cwd || PROJECT_CONTROL_RE.test(cwd) || !hasSafeRawDotDotSegments(cwd)) {
|
|
214
|
+
throw new Error("Refusing symlinked or non-directory project .agentschat");
|
|
215
|
+
}
|
|
216
|
+
const resolvedCwd = resolve(cwd);
|
|
217
|
+
const projectDir = join(resolvedCwd, ".agentschat");
|
|
218
|
+
const dirStat = safeLstat(projectDir);
|
|
219
|
+
if (!dirStat) return undefined;
|
|
220
|
+
if (dirStat.isSymbolicLink() || !dirStat.isDirectory() || !hasSafeDirChain(projectDir)) {
|
|
221
|
+
throw new Error("Refusing symlinked or non-directory project .agentschat");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const config = join(projectDir, "config.json");
|
|
15
225
|
let doc: any = {};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
226
|
+
const configStat = safeLstat(config);
|
|
227
|
+
if (configStat) {
|
|
228
|
+
if (configStat.isSymbolicLink() || !configStat.isFile() || configStat.size > MAX_PROJECT_CONFIG_BYTES) {
|
|
229
|
+
throw new Error("Invalid project .agentschat/config.json; repair it before choosing an identity");
|
|
230
|
+
}
|
|
231
|
+
let raw: string;
|
|
232
|
+
try {
|
|
233
|
+
raw = readFileSync(config, "utf8");
|
|
234
|
+
doc = JSON.parse(raw);
|
|
235
|
+
} catch {
|
|
236
|
+
throw new Error("Invalid project .agentschat/config.json; repair it before choosing an identity");
|
|
237
|
+
}
|
|
19
238
|
if (!doc || typeof doc !== "object" || Array.isArray(doc)) throw new Error("Invalid project identity configuration");
|
|
239
|
+
if (
|
|
240
|
+
Object.prototype.hasOwnProperty.call(doc, "__proto__") ||
|
|
241
|
+
Object.keys(doc).some((k) => PROTOTYPE_KEYS.has(k.toLowerCase()) || FORBIDDEN_CREDENTIAL_KEYS.has(k.toLowerCase()))
|
|
242
|
+
) {
|
|
243
|
+
throw new Error("Credentials must not be stored in project .agentschat/config.json");
|
|
244
|
+
}
|
|
20
245
|
for (const field of ["profile", "agent_id", "api_url", "ws_url"]) {
|
|
21
|
-
if (doc[field] !== undefined && (typeof doc[field] !== "string" || !doc[field].trim()
|
|
246
|
+
if (doc[field] !== undefined && (typeof doc[field] !== "string" || !doc[field].trim() || PROJECT_CONTROL_RE.test(doc[field]))) {
|
|
247
|
+
throw new Error(`Invalid project ${field}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (doc.agent_id !== undefined && !isSafeProjectAgentId((doc.agent_id as string).trim())) {
|
|
251
|
+
throw new Error("Invalid project agent_id");
|
|
22
252
|
}
|
|
23
253
|
for (const [field, protocols] of [["api_url", ["https:", "http:"]], ["ws_url", ["wss:", "ws:"]]] as const) {
|
|
24
254
|
if (doc[field] === undefined) continue;
|
|
255
|
+
const rawUrl = (doc[field] as string).trim();
|
|
25
256
|
let url: URL;
|
|
26
|
-
try { url = new URL(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
257
|
+
try { url = new URL(rawUrl); } catch { throw new Error(`Invalid project ${field}`); }
|
|
258
|
+
const portBad = /:0+(?:\/|$)/.test(rawUrl) || (url.port !== "" && (!Number.isInteger(Number(url.port)) || Number(url.port) < 1 || Number(url.port) > 65535));
|
|
259
|
+
if (
|
|
260
|
+
portBad ||
|
|
261
|
+
!(protocols as readonly string[]).includes(url.protocol) ||
|
|
262
|
+
url.username ||
|
|
263
|
+
url.password ||
|
|
264
|
+
url.search ||
|
|
265
|
+
url.hash ||
|
|
266
|
+
isUnsafeMetadataOrLinkLocalHost(url.hostname) ||
|
|
267
|
+
(!url.protocol.endsWith("s:") && !isLoopbackHost(url.hostname))
|
|
268
|
+
) {
|
|
269
|
+
throw new Error(`Invalid project ${field}: require TLS (except loopback), safe host, and no credentials/query`);
|
|
270
|
+
}
|
|
30
271
|
}
|
|
31
272
|
}
|
|
32
273
|
const settings = {
|
|
33
|
-
...(doc.agent_id !== undefined ? { agentId: doc.agent_id as string } : {}),
|
|
34
|
-
...(doc.api_url !== undefined ? { apiUrl: doc.api_url as string } : {}),
|
|
35
|
-
...(doc.ws_url !== undefined ? { wsUrl: doc.ws_url as string } : {}),
|
|
274
|
+
...(doc.agent_id !== undefined ? { agentId: (doc.agent_id as string).trim() } : {}),
|
|
275
|
+
...(doc.api_url !== undefined ? { apiUrl: (doc.api_url as string).trim() } : {}),
|
|
276
|
+
...(doc.ws_url !== undefined ? { wsUrl: (doc.ws_url as string).trim() } : {}),
|
|
36
277
|
};
|
|
37
278
|
if (doc.profile !== undefined) {
|
|
38
|
-
const value = doc.profile as string;
|
|
39
|
-
|
|
279
|
+
const value = (doc.profile as string).trim();
|
|
280
|
+
const basePart = value.replace(/\\/g, "/").split("/").pop() || "";
|
|
281
|
+
const stemLower = basePart.replace(/\.json$/i, "").toLowerCase();
|
|
282
|
+
const isBareName = !value.includes("/") && !value.includes("\\");
|
|
283
|
+
if (
|
|
284
|
+
value === "." ||
|
|
285
|
+
value === ".." ||
|
|
286
|
+
(isBareName && value.includes("..")) ||
|
|
287
|
+
!stemLower ||
|
|
288
|
+
PROTOTYPE_KEYS.has(stemLower) ||
|
|
289
|
+
WINDOWS_DEVICE_STEM_RE.test(stemLower) ||
|
|
290
|
+
(isBareName && RESERVED_SIDECAR_STEMS.has(stemLower))
|
|
291
|
+
) {
|
|
292
|
+
throw new Error("Invalid project profile");
|
|
293
|
+
}
|
|
294
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
295
|
+
const homeBase = resolve(homedir());
|
|
296
|
+
const resolvedHomeTarget = resolve(homeBase, value.slice(2));
|
|
297
|
+
const relHome = relative(homeBase, resolvedHomeTarget);
|
|
298
|
+
if (!relHome || relHome.startsWith("..") || isAbsolute(relHome) || !hasSafeRawDotDotSegments(value.slice(2), homeBase) || !hasSafeDirChain(dirname(resolvedHomeTarget))) {
|
|
299
|
+
throw new Error("Invalid project profile: home-relative path traversal");
|
|
300
|
+
}
|
|
301
|
+
return { selector: value, source: "project-config", ...settings };
|
|
302
|
+
}
|
|
303
|
+
if (!isAbsolute(value) && (value.includes("/") || value.includes("\\"))) {
|
|
304
|
+
const resolvedTarget = resolve(resolvedCwd, value);
|
|
305
|
+
const rel = relative(resolvedCwd, resolvedTarget);
|
|
306
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel) || !hasSafeRawDotDotSegments(value, resolvedCwd) || !hasSafeDirChain(dirname(resolvedTarget))) {
|
|
307
|
+
throw new Error("Invalid project profile: relative path must stay within project directory");
|
|
308
|
+
}
|
|
309
|
+
return { selector: resolvedTarget, source: "project-config", ...settings };
|
|
310
|
+
}
|
|
311
|
+
if (isAbsolute(value) && (!hasSafeRawDotDotSegments(value) || !hasSafeDirChain(dirname(value)))) {
|
|
312
|
+
throw new Error("Invalid project profile: symlinked parent directory");
|
|
313
|
+
}
|
|
314
|
+
return { selector: value, source: "project-config", ...settings };
|
|
315
|
+
}
|
|
316
|
+
const profile = join(projectDir, "profile.json");
|
|
317
|
+
const profileStat = safeLstat(profile);
|
|
318
|
+
if (profileStat) {
|
|
319
|
+
if (profileStat.isSymbolicLink() || !profileStat.isFile() || profileStat.size > MAX_PROJECT_PROFILE_BYTES) {
|
|
320
|
+
throw new Error("Refusing symlinked or non-regular project .agentschat/profile.json");
|
|
321
|
+
}
|
|
322
|
+
return { selector: profile, source: "project-profile", ...settings };
|
|
40
323
|
}
|
|
41
|
-
const profile = join(cwd, ".agentschat/profile.json");
|
|
42
|
-
if (existsSync(profile)) return { selector: profile, source: "project-profile", ...settings };
|
|
43
324
|
// A declared agent/server scope must never silently disappear into a global identity.
|
|
44
325
|
if (Object.keys(settings).length) throw new Error("Project identity/server settings require a profile binding");
|
|
45
326
|
}
|