@concord-ai/concord-mcp 0.11.0 → 0.12.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/dist/cli/commands/adapters.js +12 -1
- package/dist/cli/commands/adapters.js.map +1 -1
- package/dist/cli/commands/cloud-codex.d.ts +14 -0
- package/dist/cli/commands/cloud-codex.js +148 -0
- package/dist/cli/commands/cloud-codex.js.map +1 -0
- package/dist/cli/commands/cloud-hooks.d.ts +11 -0
- package/dist/cli/commands/cloud-hooks.js +121 -0
- package/dist/cli/commands/cloud-hooks.js.map +1 -0
- package/dist/cli/commands/cloud-inbox.d.ts +49 -0
- package/dist/cli/commands/cloud-inbox.js +167 -0
- package/dist/cli/commands/cloud-inbox.js.map +1 -0
- package/dist/cli/commands/cloud-views.d.ts +11 -0
- package/dist/cli/commands/cloud-views.js +92 -0
- package/dist/cli/commands/cloud-views.js.map +1 -0
- package/dist/cli/commands/cloud.d.ts +41 -0
- package/dist/cli/commands/cloud.js +226 -0
- package/dist/cli/commands/cloud.js.map +1 -0
- package/dist/cli/commands/export.js +7 -0
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/hook.js +39 -19
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/inbox.js +129 -57
- package/dist/cli/commands/inbox.js.map +1 -1
- package/dist/cli/commands/session-start-message.d.ts +8 -0
- package/dist/cli/commands/session-start-message.js +21 -0
- package/dist/cli/commands/session-start-message.js.map +1 -0
- package/dist/cli/commands/status.js +4 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/tasks.js +4 -2
- package/dist/cli/commands/tasks.js.map +1 -1
- package/dist/cli/commands/who.js +4 -2
- package/dist/cli/commands/who.js.map +1 -1
- package/dist/cli/index.js +16 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cloud/browser-login.d.ts +27 -0
- package/dist/cloud/browser-login.js +115 -0
- package/dist/cloud/browser-login.js.map +1 -0
- package/dist/cloud/client.d.ts +68 -0
- package/dist/cloud/client.js +114 -0
- package/dist/cloud/client.js.map +1 -0
- package/dist/cloud/http-transport.d.ts +18 -0
- package/dist/cloud/http-transport.js +40 -0
- package/dist/cloud/http-transport.js.map +1 -0
- package/dist/cloud/proxy.d.ts +56 -0
- package/dist/cloud/proxy.js +162 -0
- package/dist/cloud/proxy.js.map +1 -0
- package/dist/cloud/runtime.d.ts +152 -0
- package/dist/cloud/runtime.js +332 -0
- package/dist/cloud/runtime.js.map +1 -0
- package/dist/cloud/settings.d.ts +62 -0
- package/dist/cloud/settings.js +162 -0
- package/dist/cloud/settings.js.map +1 -0
- package/dist/cloud/tokens.d.ts +20 -0
- package/dist/cloud/tokens.js +87 -0
- package/dist/cloud/tokens.js.map +1 -0
- package/dist/config/paths.d.ts +13 -0
- package/dist/config/paths.js +40 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/domain/project-key.d.ts +23 -0
- package/dist/domain/project-key.js +109 -0
- package/dist/domain/project-key.js.map +1 -0
- package/dist/domain/pull-inbox.d.ts +12 -0
- package/dist/domain/pull-inbox.js +14 -1
- package/dist/domain/pull-inbox.js.map +1 -1
- package/dist/domain/schemas.d.ts +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/install/adapters/index.js +6 -13
- package/dist/install/adapters/index.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/plugin/concord-relay/scripts/watch-inbox.sh +11 -0
- package/plugin/cursor/concord-relay/cursor-hook.mjs +16 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { existsSync, linkSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { concordDir, userHome } from '../config/paths.js';
|
|
5
|
+
/**
|
|
6
|
+
* Where Concord Cloud mode is configured. Two files, deliberately separate:
|
|
7
|
+
*
|
|
8
|
+
* - **Credentials** (`~/.concord/credentials.json`, mode 0600) — the API URL and
|
|
9
|
+
* key. Per user, never in a repository: `.mcp.json` and friends are usually
|
|
10
|
+
* committed, and a key must not ride along.
|
|
11
|
+
* - **Link** (`<repo>/.concord/cloud.json`) — that this repository works through
|
|
12
|
+
* the cloud, and as which project. Its presence is the switch for cloud mode;
|
|
13
|
+
* without it everything stays local, exactly as before.
|
|
14
|
+
*/
|
|
15
|
+
const oauthTokensSchema = z.object({
|
|
16
|
+
accessToken: z.string().min(1),
|
|
17
|
+
refreshToken: z.string().min(1),
|
|
18
|
+
/** Epoch milliseconds. */
|
|
19
|
+
expiresAt: z.number().int(),
|
|
20
|
+
clientId: z.string().min(1),
|
|
21
|
+
tokenEndpoint: z.url(),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* An API key (CI, headless machines), or the tokens a browser login obtained.
|
|
25
|
+
* Either way the file is private to this user; see `cloud/tokens.ts` for how
|
|
26
|
+
* a request gets its bearer token from it.
|
|
27
|
+
*/
|
|
28
|
+
const credentialsSchema = z.union([
|
|
29
|
+
z.object({ apiUrl: z.url(), apiKey: z.string().min(1) }),
|
|
30
|
+
z.object({ apiUrl: z.url(), oauth: oauthTokensSchema }),
|
|
31
|
+
]);
|
|
32
|
+
const linkSchema = z.object({
|
|
33
|
+
apiUrl: z.url(),
|
|
34
|
+
/** The repository's normalised git remote; see `normalizeProjectKey`. */
|
|
35
|
+
projectKey: z.string().min(1),
|
|
36
|
+
});
|
|
37
|
+
export function credentialsPath(env) {
|
|
38
|
+
return join(userHome(env), '.concord', 'credentials.json');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This machine, as Concord Cloud knows it: registered at login and sent with
|
|
42
|
+
* every call, so agents resolve per machine as they do locally. Kept apart from
|
|
43
|
+
* the credentials so logging out forgets the key but not the machine.
|
|
44
|
+
*/
|
|
45
|
+
const machineSchema = z.object({ machineKey: z.string().min(1) });
|
|
46
|
+
export function machinePath(env) {
|
|
47
|
+
return join(userHome(env), '.concord', 'machine.json');
|
|
48
|
+
}
|
|
49
|
+
export function readMachineKey(env) {
|
|
50
|
+
return readJson(machinePath(env), machineSchema)?.machineKey;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* This machine's key, minted and saved the first time one is needed. Created
|
|
54
|
+
* exclusively, by linking a complete file into place, so two first logins at
|
|
55
|
+
* once agree on one key: the loser reads the winner's.
|
|
56
|
+
*/
|
|
57
|
+
export function ensureMachineKey(env, mint, link = linkSync) {
|
|
58
|
+
const saved = readMachineKey(env);
|
|
59
|
+
if (saved !== undefined)
|
|
60
|
+
return saved;
|
|
61
|
+
const path = machinePath(env);
|
|
62
|
+
const machineKey = mint();
|
|
63
|
+
const content = `${JSON.stringify({ machineKey }, null, 2)}\n`;
|
|
64
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
65
|
+
const temporary = `${path}.${String(process.pid)}.tmp`;
|
|
66
|
+
writeFileSync(temporary, content, { mode: 0o644 });
|
|
67
|
+
try {
|
|
68
|
+
link(temporary, path);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
const winner = readMachineKey(env);
|
|
72
|
+
if (winner !== undefined)
|
|
73
|
+
return winner;
|
|
74
|
+
// A damaged file is replaced, but one that cannot be read may hold this
|
|
75
|
+
// machine's real key, so it is left alone rather than overwritten.
|
|
76
|
+
if (existsSync(path)) {
|
|
77
|
+
try {
|
|
78
|
+
readFileSync(path);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
82
|
+
throw new Error(`Cannot read ${path}, this machine's identity: ${reason}`, {
|
|
83
|
+
cause: error,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// No hard links here (exFAT, some network shares), or a damaged file in
|
|
88
|
+
// the way: a rename still publishes a complete file, replacing a damaged
|
|
89
|
+
// one. Two first logins at the very same moment on such a filesystem may
|
|
90
|
+
// register one machine twice, which is harmless; whichever key is saved
|
|
91
|
+
// is the one every later login uses.
|
|
92
|
+
renameSync(temporary, path);
|
|
93
|
+
return readMachineKey(env) ?? machineKey;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
rmSync(temporary, { force: true });
|
|
97
|
+
}
|
|
98
|
+
return machineKey;
|
|
99
|
+
}
|
|
100
|
+
export function linkPath(repoRoot) {
|
|
101
|
+
return join(concordDir(repoRoot), 'cloud.json');
|
|
102
|
+
}
|
|
103
|
+
/** Reads a JSON file through a schema; a missing or unreadable file is absent. */
|
|
104
|
+
function readJson(path, schema) {
|
|
105
|
+
if (!existsSync(path))
|
|
106
|
+
return undefined;
|
|
107
|
+
try {
|
|
108
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
109
|
+
const parsed = schema.safeParse(raw);
|
|
110
|
+
return parsed.success ? parsed.data : undefined;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Writes through a new file renamed into place: an interrupted write leaves the
|
|
118
|
+
* old file whole, and a secret is never in a file anyone else can read, since
|
|
119
|
+
* the new file is created with its mode rather than changed to it afterwards.
|
|
120
|
+
*/
|
|
121
|
+
function writeJson(path, value, mode = 0o644) {
|
|
122
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
123
|
+
const temporary = `${path}.${String(process.pid)}.tmp`;
|
|
124
|
+
rmSync(temporary, { force: true });
|
|
125
|
+
try {
|
|
126
|
+
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode, flag: 'wx' });
|
|
127
|
+
renameSync(temporary, path);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
rmSync(temporary, { force: true });
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function readCredentials(env) {
|
|
135
|
+
return readJson(credentialsPath(env), credentialsSchema);
|
|
136
|
+
}
|
|
137
|
+
export function writeCredentials(env, credentials) {
|
|
138
|
+
writeJson(credentialsPath(env), credentialsSchema.parse(credentials), 0o600);
|
|
139
|
+
}
|
|
140
|
+
export function readLink(repoRoot) {
|
|
141
|
+
return readJson(linkPath(repoRoot), linkSchema);
|
|
142
|
+
}
|
|
143
|
+
export function writeLink(repoRoot, link) {
|
|
144
|
+
writeJson(linkPath(repoRoot), linkSchema.parse(link));
|
|
145
|
+
}
|
|
146
|
+
/** Returns whether a link was there to remove. */
|
|
147
|
+
export function removeLink(repoRoot) {
|
|
148
|
+
const path = linkPath(repoRoot);
|
|
149
|
+
if (!existsSync(path))
|
|
150
|
+
return false;
|
|
151
|
+
rmSync(path);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
/** Returns whether there were credentials to remove. */
|
|
155
|
+
export function removeCredentials(env) {
|
|
156
|
+
const path = credentialsPath(env);
|
|
157
|
+
if (!existsSync(path))
|
|
158
|
+
return false;
|
|
159
|
+
rmSync(path);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/cloud/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;GASG;AAEH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,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C;AACxD,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,IAAI,CAAC;AACd,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,iBAAiB,CAAC,GAAsB;IACtD,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Fetch } from './client.js';
|
|
2
|
+
import { type OAuthTokens } from './settings.js';
|
|
3
|
+
/**
|
|
4
|
+
* The bearer token for Concord Cloud, whichever way this machine logged in.
|
|
5
|
+
*
|
|
6
|
+
* An API key is used as it is. A browser login holds a short-lived access
|
|
7
|
+
* token and a refresh token; the access token is refreshed shortly before it
|
|
8
|
+
* expires and the rotated pair saved, so a session that runs for days never
|
|
9
|
+
* presents an expired token. Read from the credentials file on every call, so
|
|
10
|
+
* a refresh by another process on this machine is picked up rather than
|
|
11
|
+
* repeated.
|
|
12
|
+
*/
|
|
13
|
+
export type Bearer = (signal?: AbortSignal) => Promise<string>;
|
|
14
|
+
/** Exchanges a grant at a token endpoint for a fresh pair. */
|
|
15
|
+
export declare function requestTokens(oauth: Pick<OAuthTokens, 'clientId' | 'tokenEndpoint'>, grant: Record<string, string>, fetchImpl: Fetch, now?: () => number,
|
|
16
|
+
/** A caller with its own deadline (a hook): the request ends with it, not later. */
|
|
17
|
+
signal?: AbortSignal): Promise<OAuthTokens>;
|
|
18
|
+
export declare function bearerFor(env: NodeJS.ProcessEnv,
|
|
19
|
+
/** The API the token is for. A login to another API is never sent here. */
|
|
20
|
+
apiUrl: string, fetchImpl: Fetch, now?: () => number): Bearer;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { assertKeySafeUrl, sameApi } from './client.js';
|
|
3
|
+
import { readCredentials, writeCredentials } from './settings.js';
|
|
4
|
+
/** Refreshed this long before expiry, so a token never expires in flight. */
|
|
5
|
+
const EARLY_MS = 60_000;
|
|
6
|
+
const TIMEOUT_MS = 15_000;
|
|
7
|
+
const tokenResponse = z.object({
|
|
8
|
+
access_token: z.string().min(1),
|
|
9
|
+
refresh_token: z.string().min(1),
|
|
10
|
+
expires_in: z.number().positive(),
|
|
11
|
+
});
|
|
12
|
+
/** Exchanges a grant at a token endpoint for a fresh pair. */
|
|
13
|
+
export async function requestTokens(oauth, grant, fetchImpl, now = Date.now,
|
|
14
|
+
/** A caller with its own deadline (a hook): the request ends with it, not later. */
|
|
15
|
+
signal) {
|
|
16
|
+
assertKeySafeUrl(oauth.tokenEndpoint);
|
|
17
|
+
const timeout = AbortSignal.timeout(TIMEOUT_MS);
|
|
18
|
+
const response = await fetchImpl(oauth.tokenEndpoint, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
21
|
+
body: new URLSearchParams({ ...grant, client_id: oauth.clientId }).toString(),
|
|
22
|
+
signal: signal === undefined ? timeout : AbortSignal.any([timeout, signal]),
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`Concord Cloud sign-in answered ${String(response.status)}; run \`concord cloud login\` again.`);
|
|
26
|
+
}
|
|
27
|
+
const raw = await response.json();
|
|
28
|
+
const parsed = tokenResponse.safeParse(raw);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
throw new Error('Concord Cloud sign-in returned no usable tokens.');
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
accessToken: parsed.data.access_token,
|
|
34
|
+
refreshToken: parsed.data.refresh_token,
|
|
35
|
+
expiresAt: now() + parsed.data.expires_in * 1000,
|
|
36
|
+
clientId: oauth.clientId,
|
|
37
|
+
tokenEndpoint: oauth.tokenEndpoint,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function bearerFor(env,
|
|
41
|
+
/** The API the token is for. A login to another API is never sent here. */
|
|
42
|
+
apiUrl, fetchImpl, now = Date.now) {
|
|
43
|
+
const current = () => {
|
|
44
|
+
const credentials = readCredentials(env);
|
|
45
|
+
if (credentials === undefined) {
|
|
46
|
+
throw new Error('Not logged in to Concord Cloud; run `concord cloud login`.');
|
|
47
|
+
}
|
|
48
|
+
if (!sameApi(credentials.apiUrl, apiUrl)) {
|
|
49
|
+
throw new Error(`This machine is now logged in to ${credentials.apiUrl}, not ${apiUrl}; ` +
|
|
50
|
+
'restart the session to use the new login.');
|
|
51
|
+
}
|
|
52
|
+
return credentials;
|
|
53
|
+
};
|
|
54
|
+
// One refresh at a time in this process: concurrent calls share it.
|
|
55
|
+
let refreshing;
|
|
56
|
+
return async (signal) => {
|
|
57
|
+
const credentials = current();
|
|
58
|
+
if ('apiKey' in credentials)
|
|
59
|
+
return credentials.apiKey;
|
|
60
|
+
if (credentials.oauth.expiresAt - now() > EARLY_MS)
|
|
61
|
+
return credentials.oauth.accessToken;
|
|
62
|
+
if (refreshing === undefined) {
|
|
63
|
+
const { oauth } = credentials;
|
|
64
|
+
const attempt = requestTokens(oauth, { grant_type: 'refresh_token', refresh_token: oauth.refreshToken }, fetchImpl, now, signal).then((fresh) => {
|
|
65
|
+
// Saved only over the login it refreshed. Had someone logged out, or
|
|
66
|
+
// in again, meanwhile, this result is theirs to discard, not to undo.
|
|
67
|
+
const latest = current();
|
|
68
|
+
if (!('oauth' in latest) || latest.oauth.refreshToken !== oauth.refreshToken) {
|
|
69
|
+
if ('oauth' in latest && latest.oauth.expiresAt - now() > EARLY_MS) {
|
|
70
|
+
return latest.oauth.accessToken;
|
|
71
|
+
}
|
|
72
|
+
throw new Error('The Concord Cloud login changed; run `concord cloud login`.');
|
|
73
|
+
}
|
|
74
|
+
writeCredentials(env, { apiUrl: credentials.apiUrl, oauth: fresh });
|
|
75
|
+
return fresh.accessToken;
|
|
76
|
+
});
|
|
77
|
+
refreshing = attempt;
|
|
78
|
+
attempt.then(() => {
|
|
79
|
+
refreshing = undefined;
|
|
80
|
+
}, () => {
|
|
81
|
+
refreshing = undefined;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return refreshing;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/cloud/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAc,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAoB,MAAM,eAAe,CAAC;AAcpF,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEH,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAsD,EACtD,KAA6B,EAC7B,SAAgB,EAChB,MAAoB,IAAI,CAAC,GAAG;AAC5B,oFAAoF;AACpF,MAAoB;IAEpB,gBAAgB,CAAC,KAAK,CAAC,aAAa,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,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY,EAAE,CAAC;oBAC7E,IAAI,OAAO,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;wBACnE,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC;oBAClC,CAAC;oBACD,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;gBACjF,CAAC;gBACD,gBAAgB,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpE,OAAO,KAAK,CAAC,WAAW,CAAC;YAC3B,CAAC,CAAC,CAAC;YACH,UAAU,GAAG,OAAO,CAAC;YACrB,OAAO,CAAC,IAAI,CACV,GAAG,EAAE;gBACH,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC,EACD,GAAG,EAAE;gBACH,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/config/paths.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export declare const WORKSPACE_ID_PREFIX = "ws_";
|
|
|
12
12
|
* Concord still works outside a git repo.
|
|
13
13
|
*/
|
|
14
14
|
export declare function findRepoRoot(startDir: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The checkout `startDir` is in: a linked worktree's own root, where
|
|
17
|
+
* `findRepoRoot` would follow it to the primary checkout. File paths an agent
|
|
18
|
+
* passes are inside the checkout it works in.
|
|
19
|
+
*/
|
|
20
|
+
export declare function findCheckoutRoot(startDir: string): string;
|
|
21
|
+
/** The checkout the MCP server works in, chosen as `resolveRepoRoot` chooses. */
|
|
22
|
+
export declare function resolveCheckoutRoot(cwd: string, env: NodeJS.ProcessEnv): string;
|
|
15
23
|
/**
|
|
16
24
|
* Resolve the repo root for the MCP server, whose own `process.cwd()` is
|
|
17
25
|
* unreliable: when the server is registered at user scope it is launched from
|
|
@@ -37,3 +45,8 @@ export declare function workspaceRootFromId(workspaceId: string): string;
|
|
|
37
45
|
export declare function concordDir(repoRoot: string): string;
|
|
38
46
|
/** Absolute path to the SQLite database for a given repo root. */
|
|
39
47
|
export declare function databasePath(repoRoot: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* The user's home directory, honouring `HOME` and then `USERPROFILE` before
|
|
50
|
+
* the OS default, so tests and unusual shells can point it elsewhere.
|
|
51
|
+
*/
|
|
52
|
+
export declare function userHome(env: NodeJS.ProcessEnv): string;
|
package/dist/config/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
1
2
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
3
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
4
|
/** Directory name that holds all Concord state within a repo. */
|
|
@@ -56,6 +57,34 @@ export function findRepoRoot(startDir) {
|
|
|
56
57
|
dir = parent;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The checkout `startDir` is in: a linked worktree's own root, where
|
|
62
|
+
* `findRepoRoot` would follow it to the primary checkout. File paths an agent
|
|
63
|
+
* passes are inside the checkout it works in.
|
|
64
|
+
*/
|
|
65
|
+
export function findCheckoutRoot(startDir) {
|
|
66
|
+
const start = canonicalPath(startDir);
|
|
67
|
+
let dir = start;
|
|
68
|
+
for (;;) {
|
|
69
|
+
if (existsSync(join(dir, '.git'))) {
|
|
70
|
+
return dir;
|
|
71
|
+
}
|
|
72
|
+
const parent = dirname(dir);
|
|
73
|
+
if (parent === dir) {
|
|
74
|
+
return start;
|
|
75
|
+
}
|
|
76
|
+
dir = parent;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The checkout the MCP server works in, chosen as `resolveRepoRoot` chooses. */
|
|
80
|
+
export function resolveCheckoutRoot(cwd, env) {
|
|
81
|
+
for (const name of ['CONCORD_REPO_ROOT', 'CLAUDE_PROJECT_DIR']) {
|
|
82
|
+
const configured = env[name]?.trim();
|
|
83
|
+
if (configured !== undefined && configured !== '')
|
|
84
|
+
return findCheckoutRoot(configured);
|
|
85
|
+
}
|
|
86
|
+
return findCheckoutRoot(cwd);
|
|
87
|
+
}
|
|
59
88
|
/**
|
|
60
89
|
* Resolve the repo root for the MCP server, whose own `process.cwd()` is
|
|
61
90
|
* unreliable: when the server is registered at user scope it is launched from
|
|
@@ -121,4 +150,15 @@ export function concordDir(repoRoot) {
|
|
|
121
150
|
export function databasePath(repoRoot) {
|
|
122
151
|
return join(concordDir(repoRoot), DB_FILENAME);
|
|
123
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The user's home directory, honouring `HOME` and then `USERPROFILE` before
|
|
155
|
+
* the OS default, so tests and unusual shells can point it elsewhere.
|
|
156
|
+
*/
|
|
157
|
+
export function userHome(env) {
|
|
158
|
+
const configured = env['HOME']?.trim();
|
|
159
|
+
if (configured !== undefined && configured !== '')
|
|
160
|
+
return configured;
|
|
161
|
+
const profile = env['USERPROFILE']?.trim();
|
|
162
|
+
return profile === undefined || profile === '' ? homedir() : profile;
|
|
163
|
+
}
|
|
124
164
|
//# sourceMappingURL=paths.js.map
|
package/dist/config/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/config/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzE,iEAAiE;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC,uDAAuD;AACvD,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,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S,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repository's identity in the cloud: its git remote, reduced to the part
|
|
3
|
+
* every clone agrees on.
|
|
4
|
+
*
|
|
5
|
+
* The same repository is cloned as `git@github.com:Org/Repo.git` on one machine
|
|
6
|
+
* and `https://github.com/org/repo` on another. Both must name one project, or
|
|
7
|
+
* two agents in the same repository would never see each other's claims. So
|
|
8
|
+
* scheme, credentials, port, a trailing `.git` and slashes are dropped, the scp
|
|
9
|
+
* form (`host:path`) becomes `host/path`, and the whole key is lowercased —
|
|
10
|
+
* the major hosts treat owner and repository names case-insensitively.
|
|
11
|
+
*
|
|
12
|
+
* Returns null for anything that does not reduce to a host and a path, so a
|
|
13
|
+
* caller refuses it rather than storing a key that collides by accident (`""`,
|
|
14
|
+
* or a bare word every repository without a remote would share).
|
|
15
|
+
*
|
|
16
|
+
* A mirror of Concord Cloud's `normalizeProjectKey` (concord-cloud
|
|
17
|
+
* `packages/domain/src/project-key.ts`): the cloud names a repository by this
|
|
18
|
+
* key, and the local runtime must compute the same one from `git remote` so an
|
|
19
|
+
* agent's repository and the cloud's agree. The server normalises again, so a
|
|
20
|
+
* mismatch here would only mean asking about a repository nobody uses — keep
|
|
21
|
+
* the two in step, with the same tests.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeProjectKey(remote: string): string | null;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host as the WHATWG URL parser spells it for `https`: lowercased, IPv6
|
|
3
|
+
* compressed, shortened IPv4 expanded. One parser for every form of remote, so
|
|
4
|
+
* a key normalised twice is unchanged.
|
|
5
|
+
*/
|
|
6
|
+
function normalizeHost(host) {
|
|
7
|
+
try {
|
|
8
|
+
return new URL(`https://${host}/`).hostname;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A URL path as the URL parser spells it, with every `%` that begins no escape
|
|
16
|
+
* written `%25`: one spelling of each path, however it arrived, and unchanged
|
|
17
|
+
* by a second pass.
|
|
18
|
+
*/
|
|
19
|
+
function urlPath(escaped) {
|
|
20
|
+
try {
|
|
21
|
+
const path = new URL(`https://host/${escaped}`).pathname;
|
|
22
|
+
return path.replace(/%(?![0-9a-f]{2})/gi, '%25');
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The host and path a remote names, in whichever of git's forms it is written. */
|
|
29
|
+
function splitRemote(value) {
|
|
30
|
+
if (value.includes('://')) {
|
|
31
|
+
try {
|
|
32
|
+
const url = new URL(value);
|
|
33
|
+
// Kept escaped: decoding would let a key change on a second pass. A
|
|
34
|
+
// backslash survives in a non-https path, so it is escaped, not reread
|
|
35
|
+
// as the separator https would make it.
|
|
36
|
+
return {
|
|
37
|
+
host: url.hostname,
|
|
38
|
+
path: urlPath(url.pathname.slice(1).replace(/\\/g, encodeURIComponent)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// scp-like syntax: [user@]host:path — no scheme, and a colon before any slash.
|
|
46
|
+
// A bracketed IPv6 host is matched whole, or its own colons would be taken
|
|
47
|
+
// for the separator. Its path is literal, so every character a URL path
|
|
48
|
+
// would read specially is escaped first: `repo#one`, `repo%23one` and
|
|
49
|
+
// `repo\one` are three repositories, and `repo#one` is the URL's `repo%23one`.
|
|
50
|
+
const scp = /^(?:[^@/[]+@)?(\[[^\]]+\]|[^:/[]+):(?!\/)(.+)$/.exec(value);
|
|
51
|
+
if (scp !== null) {
|
|
52
|
+
return {
|
|
53
|
+
host: scp[1] ?? '',
|
|
54
|
+
path: urlPath((scp[2] ?? '').replace(/[%\\#?]/g, encodeURIComponent)),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// host/path, as a key itself is written: already escaped.
|
|
58
|
+
const slash = value.indexOf('/');
|
|
59
|
+
return slash === -1
|
|
60
|
+
? null
|
|
61
|
+
: { host: value.slice(0, slash), path: urlPath(value.slice(slash + 1)) };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A repository's identity in the cloud: its git remote, reduced to the part
|
|
65
|
+
* every clone agrees on.
|
|
66
|
+
*
|
|
67
|
+
* The same repository is cloned as `git@github.com:Org/Repo.git` on one machine
|
|
68
|
+
* and `https://github.com/org/repo` on another. Both must name one project, or
|
|
69
|
+
* two agents in the same repository would never see each other's claims. So
|
|
70
|
+
* scheme, credentials, port, a trailing `.git` and slashes are dropped, the scp
|
|
71
|
+
* form (`host:path`) becomes `host/path`, and the whole key is lowercased —
|
|
72
|
+
* the major hosts treat owner and repository names case-insensitively.
|
|
73
|
+
*
|
|
74
|
+
* Returns null for anything that does not reduce to a host and a path, so a
|
|
75
|
+
* caller refuses it rather than storing a key that collides by accident (`""`,
|
|
76
|
+
* or a bare word every repository without a remote would share).
|
|
77
|
+
*
|
|
78
|
+
* A mirror of Concord Cloud's `normalizeProjectKey` (concord-cloud
|
|
79
|
+
* `packages/domain/src/project-key.ts`): the cloud names a repository by this
|
|
80
|
+
* key, and the local runtime must compute the same one from `git remote` so an
|
|
81
|
+
* agent's repository and the cloud's agree. The server normalises again, so a
|
|
82
|
+
* mismatch here would only mean asking about a repository nobody uses — keep
|
|
83
|
+
* the two in step, with the same tests.
|
|
84
|
+
*/
|
|
85
|
+
export function normalizeProjectKey(remote) {
|
|
86
|
+
const value = remote.trim();
|
|
87
|
+
// A filesystem path is a remote too (`git clone /srv/repo`, or `C:repo` on
|
|
88
|
+
// Windows), but not one that names the same repository on every machine.
|
|
89
|
+
if (value === '' || /^(?:[/\\~.]|[a-z]:)/i.test(value)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const remoteParts = splitRemote(value);
|
|
93
|
+
const remotePath = remoteParts?.path ?? null;
|
|
94
|
+
const remoteHost = remoteParts === null ? null : normalizeHost(remoteParts.host);
|
|
95
|
+
if (remotePath === null || remoteHost === null || remoteHost === '') {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
// Trailing slashes and `.git` are stripped together, however they repeat.
|
|
99
|
+
const key = `${remoteHost}/${remotePath}`
|
|
100
|
+
.toLowerCase()
|
|
101
|
+
.replace(/\/+/g, '/')
|
|
102
|
+
.replace(/(?:\/|\.git)+$/, '');
|
|
103
|
+
const [host, ...path] = key.split('/');
|
|
104
|
+
if (host === undefined || host === '' || path.length === 0 || path.some((part) => part === '')) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return key;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=project-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-key.js","sourceRoot":"","sources":["../../src/domain/project-key.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,OAAO,CAAC,OAAe;IAC9B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,KAAK,C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17
|
}
|
|
18
|
+
/** A drained message as every channel renders it; the same for a local and a cloud drain. */
|
|
19
|
+
export declare function toDeliverable(message: {
|
|
20
|
+
messageId: string;
|
|
21
|
+
senderAgentId: string;
|
|
22
|
+
taskId: string | null;
|
|
23
|
+
content: string;
|
|
24
|
+
replyToMessageId: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
deliveredAt: string | null;
|
|
27
|
+
}): DeliverableMessage;
|
|
28
|
+
/** The human-readable block shared by every channel. */
|
|
29
|
+
export declare function renderInboxBody(messages: readonly DeliverableMessage[]): string;
|
|
18
30
|
/** One line per message, for a plugin monitor's stdout. */
|
|
19
31
|
export declare function renderMonitorLines(messages: readonly DeliverableMessage[]): string[];
|
|
20
32
|
/** Gemini AfterTool can append context to the current model turn. */
|
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
* Stop decision "block" + reason (re-opens a finished turn)
|
|
8
8
|
* monitor one stdout line per message (arrives even when idle)
|
|
9
9
|
*/
|
|
10
|
+
/** A drained message as every channel renders it; the same for a local and a cloud drain. */
|
|
11
|
+
export function toDeliverable(message) {
|
|
12
|
+
return {
|
|
13
|
+
messageId: message.messageId,
|
|
14
|
+
senderAgentId: message.senderAgentId,
|
|
15
|
+
taskId: message.taskId,
|
|
16
|
+
content: message.content,
|
|
17
|
+
messageKind: message.replyToMessageId === null ? 'prompt' : 'reply',
|
|
18
|
+
deliveryLatencyMs: message.deliveredAt === null
|
|
19
|
+
? null
|
|
20
|
+
: Math.max(0, Date.parse(message.deliveredAt) - Date.parse(message.createdAt)),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* Framing is deliberately terse. Every delivery pays for it, and the standing
|
|
12
25
|
* explanation — that a relayed message is peer information rather than an
|
|
@@ -19,7 +32,7 @@ function renderMessage(message) {
|
|
|
19
32
|
return `[concord from ${message.senderAgentId} id=${message.messageId}${task}]\n${message.content}`;
|
|
20
33
|
}
|
|
21
34
|
/** The human-readable block shared by every channel. */
|
|
22
|
-
function renderInboxBody(messages) {
|
|
35
|
+
export function renderInboxBody(messages) {
|
|
23
36
|
return messages.map(renderMessage).join('\n\n');
|
|
24
37
|
}
|
|
25
38
|
/** One line per message, for a plugin monitor's stdout. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-inbox.js","sourceRoot":"","sources":["../../src/domain/pull-inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,OAA2B;IAChD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,EAAE,CAAC;IACtE,OAAO,iBAAiB,OAAO,CAAC,aAAa,OAAO,OAAO,CAAC,SAAS,GAAG,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;AACtG,CAAC;AAED,wDAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"pull-inbox.js","sourceRoot":"","sources":["../../src/domain/pull-inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAAC,OAQ7B;IACC,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO;QACnE,iBAAiB,EACf,OAAO,CAAC,WAAW,KAAK,IAAI;YAC1B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAA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,OAAiC,EACjC,QAAuC;IAEvC,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,6DAA6D,IAAI,EAAE;SAC5E,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,kBAAkB,EAAE;YAClB,aAAa,EAAE,aAAa;YAC5B,iBAAiB,EAAE,IAAI;SACxB;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GACnC,0FAA0F;IAC1F,6FAA6F;IAC7F,sFAAsF;IACtF,6FAA6F;IAC7F,kBAAkB,CAAC"}
|
package/dist/domain/schemas.d.ts
CHANGED
|
@@ -78,9 +78,9 @@ export declare const transferWorkInputShape: {
|
|
|
78
78
|
readonly task_id: z.ZodString;
|
|
79
79
|
readonly action: z.ZodEnum<{
|
|
80
80
|
accept: "accept";
|
|
81
|
+
decline: "decline";
|
|
81
82
|
reopen: "reopen";
|
|
82
83
|
assign: "assign";
|
|
83
|
-
decline: "decline";
|
|
84
84
|
release: "release";
|
|
85
85
|
reassign: "reassign";
|
|
86
86
|
offer: "offer";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
3
|
import { writeArtifacts } from './artifacts/index.js';
|
|
4
|
+
import { cloudSessionFor, connectCloud, createCloudProxyServer } from './cloud/proxy.js';
|
|
4
5
|
import { startBackgroundUpdateCheck } from './update-notifier.js';
|
|
5
|
-
import { resolveRepoRoot } from './config/paths.js';
|
|
6
|
+
import { resolveCheckoutRoot, resolveRepoRoot } from './config/paths.js';
|
|
6
7
|
import { resolveIdentity } from './domain/identity.js';
|
|
7
8
|
import { createServer } from './server.js';
|
|
8
9
|
import { ensureAgentRegistered } from './tools/register-agent.js';
|
|
@@ -12,11 +13,19 @@ import { VERSION } from './version.js';
|
|
|
12
13
|
import { WorkspaceManager } from './workspaces/manager.js';
|
|
13
14
|
async function main() {
|
|
14
15
|
const repoRoot = resolveRepoRoot(process.cwd(), process.env);
|
|
15
|
-
const workspaceManager = WorkspaceManager.fromEnvironment(repoRoot, process.env);
|
|
16
16
|
// One server process per session, with the session id in its environment, so
|
|
17
17
|
// this agent's identity is known before the transport connects — and it is the
|
|
18
18
|
// same id the relay CLI derives for the same session.
|
|
19
19
|
const identity = resolveIdentity(process.env);
|
|
20
|
+
// A repository linked to Concord Cloud works through it: no local database,
|
|
21
|
+
// and no telemetry from this package for operations that are not local.
|
|
22
|
+
const cloud = cloudSessionFor(repoRoot, process.env, identity, resolveCheckoutRoot(process.cwd(), process.env));
|
|
23
|
+
if (cloud !== undefined) {
|
|
24
|
+
const proxy = createCloudProxyServer(cloud, () => connectCloud(cloud));
|
|
25
|
+
await proxy.connect(new StdioServerTransport());
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const workspaceManager = WorkspaceManager.fromEnvironment(repoRoot, process.env);
|
|
20
29
|
if (identity !== undefined) {
|
|
21
30
|
ensureAgentRegistered(workspaceManager.current().repos, identity, repoRoot);
|
|
22
31
|
}
|