@concord-ai/concord-mcp 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/cli/agent-identity.d.ts +21 -0
- package/dist/cli/agent-identity.js +86 -0
- package/dist/cli/agent-identity.js.map +1 -0
- package/dist/cli/commands/doctor.js +0 -3
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/hook.d.ts +2 -6
- package/dist/cli/commands/hook.js +12 -17
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/inbox.d.ts +16 -0
- package/dist/cli/commands/inbox.js +172 -0
- package/dist/cli/commands/inbox.js.map +1 -0
- package/dist/cli/commands/setup.d.ts +0 -4
- package/dist/cli/commands/setup.js +17 -42
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/workspace-options.d.ts +1 -7
- package/dist/db/repositories/agent-messages.d.ts +5 -0
- package/dist/db/repositories/agent-messages.js +30 -0
- package/dist/db/repositories/agent-messages.js.map +1 -1
- package/dist/domain/delivery.d.ts +39 -0
- package/dist/domain/delivery.js +54 -0
- package/dist/domain/delivery.js.map +1 -0
- package/dist/domain/pull-inbox.d.ts +28 -0
- package/dist/domain/pull-inbox.js +59 -0
- package/dist/domain/pull-inbox.js.map +1 -0
- package/dist/domain/schemas.d.ts +51 -31
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/install/claude-hooks.js +2 -2
- package/dist/install/claude-hooks.js.map +1 -1
- package/dist/install/claude-plugin.d.ts +30 -0
- package/dist/install/claude-plugin.js +82 -0
- package/dist/install/claude-plugin.js.map +1 -0
- package/dist/install/codex-config.d.ts +14 -0
- package/dist/install/codex-config.js +80 -0
- package/dist/install/codex-config.js.map +1 -1
- package/dist/install/instructions.d.ts +1 -1
- package/dist/install/instructions.js +3 -1
- package/dist/install/instructions.js.map +1 -1
- package/dist/install/mcp-config.js +3 -1
- package/dist/install/mcp-config.js.map +1 -1
- package/dist/server.d.ts +1 -4
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/telemetry/identity.js +1 -1
- package/dist/telemetry/identity.js.map +1 -1
- package/dist/telemetry/transport.js +5 -5
- package/dist/telemetry/transport.js.map +1 -1
- package/dist/tools/agent-messages.d.ts +7 -16
- package/dist/tools/agent-messages.js +20 -52
- package/dist/tools/agent-messages.js.map +1 -1
- package/dist/tools/workflow.d.ts +3 -3
- package/dist/tools/workflow.js +11 -8
- package/dist/tools/workflow.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +21 -25
- package/plugin/concord-relay/.claude-plugin/plugin.json +13 -0
- package/plugin/concord-relay/hooks/hooks.json +35 -0
- package/plugin/concord-relay/monitors/monitors.json +7 -0
- package/plugin/concord-relay/scripts/watch-inbox.sh +30 -0
- package/dist/install/agent-communications.d.ts +0 -28
- package/dist/install/agent-communications.js +0 -61
- package/dist/install/agent-communications.js.map +0 -1
- package/dist/relay/adapters.d.ts +0 -33
- package/dist/relay/adapters.js +0 -70
- package/dist/relay/adapters.js.map +0 -1
- package/dist/relay/index.d.ts +0 -4
- package/dist/relay/index.js +0 -5
- package/dist/relay/index.js.map +0 -1
- package/dist/relay/protocol.d.ts +0 -64
- package/dist/relay/protocol.js +0 -38
- package/dist/relay/protocol.js.map +0 -1
- package/dist/relay/server.d.ts +0 -40
- package/dist/relay/server.js +0 -196
- package/dist/relay/server.js.map +0 -1
- package/dist/relay/socket-dispatcher.d.ts +0 -9
- package/dist/relay/socket-dispatcher.js +0 -74
- package/dist/relay/socket-dispatcher.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
<p align="center">
|
|
25
25
|
<a href="#quick-start">Quick start</a> ·
|
|
26
26
|
<a href="https://getconcord.ai">Website</a> ·
|
|
27
|
-
<a href="./examples/
|
|
27
|
+
<a href="./examples/whack-a-mole/">Demo</a> ·
|
|
28
28
|
<a href="./CONTRIBUTING.md">Contributing</a>
|
|
29
29
|
</p>
|
|
30
30
|
|
|
@@ -211,10 +211,12 @@ and `q` to quit.
|
|
|
211
211
|
pnpm demo
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
-
Runs the [
|
|
215
|
-
claim overlapping work,
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
Runs the [Whack-a-Mole live demo](./examples/whack-a-mole/): Claude and Codex
|
|
215
|
+
claim overlapping work, resolve it through a live prompt/reply, build a playable
|
|
216
|
+
app, transfer ownership with evidence, and hand the result to a separate Claude
|
|
217
|
+
Code reviewer. Three visible tmux panes put both builders on the left and the
|
|
218
|
+
full-height shared dashboard on the right; the reviewer runs in the background
|
|
219
|
+
while the browser hot-reloads the result.
|
|
218
220
|
|
|
219
221
|
## What this is / is not
|
|
220
222
|
|
|
@@ -227,8 +229,8 @@ See also: [Why not just use markdown?](./docs/why-not-markdown.md)
|
|
|
227
229
|
## Contributing
|
|
228
230
|
|
|
229
231
|
See [`CONTRIBUTING.md`](./CONTRIBUTING.md) and [`CLAUDE.md`](./CLAUDE.md). This
|
|
230
|
-
repo is strictly typed (no `any`, no typecasts)
|
|
231
|
-
|
|
232
|
+
repo is strictly typed (no `any`, no typecasts) and modular. Good first issues
|
|
233
|
+
are labelled [`good first issue`](https://github.com/Get-Concord-AI/concord-mcp/labels/good%20first%20issue).
|
|
232
234
|
|
|
233
235
|
## Star History
|
|
234
236
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stable per-session agent id for Claude Code. Derived from the session id so
|
|
3
|
+
* the same session always maps to the same identity (SessionStart is idempotent
|
|
4
|
+
* via upsert); falls back to a random suffix when no session id is provided.
|
|
5
|
+
*
|
|
6
|
+
* An operator-supplied `CONCORD_AGENT_ID` wins, so a human coordinating agents
|
|
7
|
+
* can name them ("alpha", "reviewer") instead of reading generated slugs.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sessionStartAgentId(sessionId: string | undefined, env?: NodeJS.ProcessEnv): string;
|
|
10
|
+
/**
|
|
11
|
+
* Work out which agent a CLI invocation is acting as, without being told.
|
|
12
|
+
*
|
|
13
|
+
* Hooks receive the session id in their stdin payload, but a plugin monitor
|
|
14
|
+
* does not — it only has its environment. Claude Code exports
|
|
15
|
+
* `CLAUDE_CODE_SESSION_ID` to both, and deriving from it here is what lets the
|
|
16
|
+
* relay work in a session started as plain `claude`, with nothing to configure.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveAgentId(explicit: string | undefined, env?: NodeJS.ProcessEnv, options?: {
|
|
19
|
+
kind?: string;
|
|
20
|
+
hookPayload?: string;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/** The one field we need from any client's hook payload. */
|
|
4
|
+
const hookSessionSchema = z.object({ session_id: z.string().optional() }).loose();
|
|
5
|
+
/**
|
|
6
|
+
* Pull the session id out of a hook payload.
|
|
7
|
+
*
|
|
8
|
+
* Codex passes its session id on stdin rather than in the environment, so a
|
|
9
|
+
* Codex hook has no other way to say which agent it is. Never throws: a hook
|
|
10
|
+
* that cannot identify itself should fall through to the other strategies
|
|
11
|
+
* rather than fail the tool call it is attached to.
|
|
12
|
+
*/
|
|
13
|
+
function hookSessionId(rawJson) {
|
|
14
|
+
let parsed;
|
|
15
|
+
try {
|
|
16
|
+
parsed = JSON.parse(rawJson);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const result = hookSessionSchema.safeParse(parsed);
|
|
22
|
+
if (!result.success)
|
|
23
|
+
return undefined;
|
|
24
|
+
const sessionId = result.data.session_id?.trim();
|
|
25
|
+
return sessionId === undefined || sessionId === '' ? undefined : sessionId;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A stable agent id for one session of one client, e.g. `codex:4f2a91c7`.
|
|
29
|
+
*
|
|
30
|
+
* Hashed rather than truncated. Codex session ids are UUIDv7, whose leading
|
|
31
|
+
* hex digits are a millisecond clock: the first eight advance only once per
|
|
32
|
+
* ~65 seconds, so truncating them gave two Codex sessions started in the same
|
|
33
|
+
* minute the same id — and therefore the same inbox.
|
|
34
|
+
*/
|
|
35
|
+
function agentIdForSession(kind, sessionId) {
|
|
36
|
+
const id = sessionId?.trim() ?? '';
|
|
37
|
+
const slug = id === ''
|
|
38
|
+
? randomBytes(4).toString('hex')
|
|
39
|
+
: createHash('sha256').update(id).digest('hex').slice(0, 8);
|
|
40
|
+
return `${kind}:${slug}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A stable per-session agent id for Claude Code. Derived from the session id so
|
|
44
|
+
* the same session always maps to the same identity (SessionStart is idempotent
|
|
45
|
+
* via upsert); falls back to a random suffix when no session id is provided.
|
|
46
|
+
*
|
|
47
|
+
* An operator-supplied `CONCORD_AGENT_ID` wins, so a human coordinating agents
|
|
48
|
+
* can name them ("alpha", "reviewer") instead of reading generated slugs.
|
|
49
|
+
*/
|
|
50
|
+
export function sessionStartAgentId(sessionId, env = process.env) {
|
|
51
|
+
const explicit = env['CONCORD_AGENT_ID']?.trim();
|
|
52
|
+
if (explicit !== undefined && explicit !== '')
|
|
53
|
+
return explicit;
|
|
54
|
+
return agentIdForSession('claude-code', sessionId);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Work out which agent a CLI invocation is acting as, without being told.
|
|
58
|
+
*
|
|
59
|
+
* Hooks receive the session id in their stdin payload, but a plugin monitor
|
|
60
|
+
* does not — it only has its environment. Claude Code exports
|
|
61
|
+
* `CLAUDE_CODE_SESSION_ID` to both, and deriving from it here is what lets the
|
|
62
|
+
* relay work in a session started as plain `claude`, with nothing to configure.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveAgentId(explicit, env = process.env, options = {}) {
|
|
65
|
+
const given = explicit?.trim();
|
|
66
|
+
if (given !== undefined && given !== '')
|
|
67
|
+
return given;
|
|
68
|
+
const configured = env['CONCORD_AGENT_ID']?.trim();
|
|
69
|
+
if (configured !== undefined && configured !== '')
|
|
70
|
+
return configured;
|
|
71
|
+
const kind = options.kind ?? 'claude-code';
|
|
72
|
+
// Codex only reveals its session id on stdin, so a payload wins over the
|
|
73
|
+
// environment: a Codex hook run from inside a Claude Code session would
|
|
74
|
+
// otherwise inherit CLAUDE_CODE_SESSION_ID and answer as the wrong agent.
|
|
75
|
+
if (options.hookPayload !== undefined) {
|
|
76
|
+
const fromHook = hookSessionId(options.hookPayload);
|
|
77
|
+
if (fromHook !== undefined)
|
|
78
|
+
return agentIdForSession(kind, fromHook);
|
|
79
|
+
}
|
|
80
|
+
const sessionId = env['CLAUDE_CODE_SESSION_ID']?.trim();
|
|
81
|
+
if (sessionId !== undefined && sessionId !== '')
|
|
82
|
+
return agentIdForSession(kind, sessionId);
|
|
83
|
+
throw new Error('Could not tell which agent this is. Run inside a Claude Code or Codex session, pass ' +
|
|
84
|
+
'--agent <id>, or set CONCORD_AGENT_ID.');
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=agent-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-identity.js","sourceRoot":"","sources":["../../src/cli/agent-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,4DAA4D;AAC5D,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;AAElF;;;;;;;GAOG;AACH,SAAS,aAAa,CAAC,OAAe;IACpC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM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;AACH,MAAM,UAAU,cAAc,CAC5B,QAA4B,EAC5B,MAAyB,OAAO,CAAC,GAAG,EACpC,UAAmD,EAAE;IAErD,MAAM,KAAK,GAAG,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAEtD,MAAM,UAAU,GAAG,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC;IACnD,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE;QAAE,OAAO,UAAU,CAAC;IAErE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,aAAa,CAAC;IAE3C,yEAAyE;IACzE,wEAAwE;IACxE,0EAA0E;IAC1E,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,wBAAwB,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,EAAE;QAAE,OAAO,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAE3F,MAAM,IAAI,KAAK,CACb,sFAAsF;QACpF,wCAAwC,CAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -5,7 +5,6 @@ import { migrations } from '../../db/schema.js';
|
|
|
5
5
|
import { buildAdoption } from '../../domain/adoption.js';
|
|
6
6
|
import { BLOCK_END, BLOCK_START } from '../../install/block.js';
|
|
7
7
|
import { CONCORD_INSTRUCTION_VERSION } from '../../install/instructions.js';
|
|
8
|
-
import { readAgentCommunicationConfig } from '../../install/agent-communications.js';
|
|
9
8
|
import { endpointPromptable } from '../../tools/agent-messages.js';
|
|
10
9
|
import { openContext } from '../context.js';
|
|
11
10
|
const instructionTargets = [
|
|
@@ -45,7 +44,6 @@ export function buildDoctorReport(ctx) {
|
|
|
45
44
|
const events = ctx.repos.events.list();
|
|
46
45
|
const adoption = buildAdoption(events);
|
|
47
46
|
const instructions = instructionStatus(ctx.repoRoot);
|
|
48
|
-
const communications = readAgentCommunicationConfig(ctx.concordPath);
|
|
49
47
|
const endpoints = ctx.repos.agentEndpoints.list();
|
|
50
48
|
const connectedEndpoints = endpoints.filter((endpoint) => endpointPromptable(endpoint));
|
|
51
49
|
const lines = [
|
|
@@ -57,7 +55,6 @@ export function buildDoctorReport(ctx) {
|
|
|
57
55
|
` concord.db ${existsSync(dbPath) ? 'ok' : 'missing'} (schema v${String(schemaVersion)}, expected v${String(migrations.length)})`,
|
|
58
56
|
` repo root ${ctx.repoRoot}`,
|
|
59
57
|
` instructions ${instructions}`,
|
|
60
|
-
` live prompts ${communications?.approved === true ? `enabled (${communications.providers.join(', ') || 'no detected clients'})` : 'not enabled'}`,
|
|
61
58
|
` endpoints ${String(connectedEndpoints.length)} reachable / ${String(endpoints.length)} registered`,
|
|
62
59
|
'',
|
|
63
60
|
'Activity',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../../src/cli/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,C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AAC,IAAI,kBAAkB,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,mBAAmB,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CACjL,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,iBAAiB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,8CAA8C,CAAC;SAC3D,MAAM,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Command } from '@commander-js/extra-typings';
|
|
2
2
|
import type { Repositories } from '../../db/index.js';
|
|
3
|
+
import { sessionStartAgentId } from '../agent-identity.js';
|
|
3
4
|
export interface HookDecision {
|
|
4
5
|
/** True → deny the tool call (exit 2). */
|
|
5
6
|
block: boolean;
|
|
@@ -16,12 +17,7 @@ export interface HookDecision {
|
|
|
16
17
|
* than the problem this guards against.
|
|
17
18
|
*/
|
|
18
19
|
export declare function decidePreToolUse(repos: Repositories, rawJson: string, selfTaskId?: string): HookDecision;
|
|
19
|
-
|
|
20
|
-
* A stable per-session agent id for Claude Code. Derived from the session id so
|
|
21
|
-
* the same session always maps to the same identity (SessionStart is idempotent
|
|
22
|
-
* via upsert); falls back to a random suffix when no session id is provided.
|
|
23
|
-
*/
|
|
24
|
-
export declare function sessionStartAgentId(sessionId: string | undefined): string;
|
|
20
|
+
export { sessionStartAgentId };
|
|
25
21
|
export interface SessionStartResult {
|
|
26
22
|
agentId: string;
|
|
27
23
|
/** Context printed to stdout, which Claude Code injects into the session. */
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
2
1
|
import { readFileSync } from 'node:fs';
|
|
3
2
|
import { z } from 'zod';
|
|
4
3
|
import { buildRoster } from '../../domain/presence.js';
|
|
4
|
+
import { sessionStartAgentId } from '../agent-identity.js';
|
|
5
5
|
import { openContext } from '../context.js';
|
|
6
6
|
import { checkFileOverlaps } from './check.js';
|
|
7
|
+
import { registerPullEndpoint } from './inbox.js';
|
|
7
8
|
/** The subset of Claude Code's PreToolUse payload we need: the edited file path.
|
|
8
9
|
* Everything else is passed through and ignored. */
|
|
9
10
|
const preToolUsePayloadSchema = z
|
|
10
11
|
.object({
|
|
11
|
-
tool_input: z.object({ file_path: z.string().optional() }).
|
|
12
|
+
tool_input: z.object({ file_path: z.string().optional() }).loose().optional(),
|
|
12
13
|
})
|
|
13
|
-
.
|
|
14
|
+
.loose();
|
|
14
15
|
/**
|
|
15
16
|
* Decide whether a Claude Code PreToolUse event (Edit/Write/MultiEdit) should be
|
|
16
17
|
* blocked because the edited file is claimed by another active task.
|
|
@@ -55,26 +56,15 @@ const sessionStartPayloadSchema = z
|
|
|
55
56
|
session_id: z.string().optional(),
|
|
56
57
|
cwd: z.string().optional(),
|
|
57
58
|
})
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
* A stable per-session agent id for Claude Code. Derived from the session id so
|
|
61
|
-
* the same session always maps to the same identity (SessionStart is idempotent
|
|
62
|
-
* via upsert); falls back to a random suffix when no session id is provided.
|
|
63
|
-
*/
|
|
64
|
-
export function sessionStartAgentId(sessionId) {
|
|
65
|
-
const slug = (sessionId ?? '')
|
|
66
|
-
.replace(/[^0-9a-z]/gi, '')
|
|
67
|
-
.slice(0, 8)
|
|
68
|
-
.toLowerCase();
|
|
69
|
-
return `claude-code:${slug === '' ? randomBytes(4).toString('hex') : slug}`;
|
|
70
|
-
}
|
|
59
|
+
.loose();
|
|
60
|
+
export { sessionStartAgentId };
|
|
71
61
|
/**
|
|
72
62
|
* Register this Claude Code session before — or even if — the model calls
|
|
73
63
|
* `start_work`, then tell it the `agent_id` and who else is active. Reads a
|
|
74
64
|
* SessionStart JSON payload.
|
|
75
65
|
*/
|
|
76
66
|
export function handleSessionStart(repos, rawJson) {
|
|
77
|
-
let parsed
|
|
67
|
+
let parsed;
|
|
78
68
|
try {
|
|
79
69
|
parsed = JSON.parse(rawJson);
|
|
80
70
|
}
|
|
@@ -95,11 +85,16 @@ export function handleSessionStart(repos, rawJson) {
|
|
|
95
85
|
summary: null,
|
|
96
86
|
status: 'active',
|
|
97
87
|
});
|
|
88
|
+
// Advertise the session as reachable before any tool call, so a peer that
|
|
89
|
+
// messages it early gets its message queued rather than rejected.
|
|
90
|
+
registerPullEndpoint(repos, agentId, 'claude-code');
|
|
98
91
|
const others = buildRoster(repos.agents.list(), Date.now()).filter((entry) => entry.agentId !== agentId);
|
|
99
92
|
const lines = [
|
|
100
93
|
`Concord: registered this session as agent \`${agentId}\`. Pass agent_id="${agentId}" to ` +
|
|
101
94
|
'Concord tools (start_work, update_work, finish_work) so your work is attributed and your ' +
|
|
102
95
|
'presence stays live.',
|
|
96
|
+
'You can receive live messages from other agents in this workspace; they arrive on their own ' +
|
|
97
|
+
'as relayed context, so you never need to poll for them.',
|
|
103
98
|
];
|
|
104
99
|
if (others.length === 0) {
|
|
105
100
|
lines.push('No other agents are currently registered.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/cli/commands/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/cli/commands/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,O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AI,QAAQ,CAAC,KAAK,EAAE,CAAC;YACnB,qEAAqE;YACrE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import type { Repositories } from '../../db/index.js';
|
|
3
|
+
import { type DeliverableMessage } from '../../domain/pull-inbox.js';
|
|
4
|
+
/**
|
|
5
|
+
* Advertise that `agentId` can receive messages by draining them from inside
|
|
6
|
+
* its own session. Re-registering refreshes the lease, so a session that dies
|
|
7
|
+
* stops looking promptable instead of silently swallowing messages.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerPullEndpoint(repos: Repositories, agentId: string, provider: string, now?: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Take every pending message for `agentId` and mark it delivered. Draining is
|
|
12
|
+
* what records delivery, so a message is only ever counted as delivered once
|
|
13
|
+
* the recipient has actually been handed it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function drainInbox(repos: Repositories, agentId: string, provider: string): DeliverableMessage[];
|
|
16
|
+
export declare function registerInboxCommand(program: Command): void;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { databasePath, resolveRepoRoot } from '../../config/paths.js';
|
|
4
|
+
import { capabilityFor, encodeCapabilities } from '../../domain/delivery.js';
|
|
5
|
+
import { renderHookPayload, renderMonitorLines, } from '../../domain/pull-inbox.js';
|
|
6
|
+
import { resolveAgentId } from '../agent-identity.js';
|
|
7
|
+
import { openContext } from '../context.js';
|
|
8
|
+
/** How long a registered pull endpoint stays promptable between drains. */
|
|
9
|
+
const PULL_ENDPOINT_TTL_MS = 90_000;
|
|
10
|
+
/**
|
|
11
|
+
* Advertise that `agentId` can receive messages by draining them from inside
|
|
12
|
+
* its own session. Re-registering refreshes the lease, so a session that dies
|
|
13
|
+
* stops looking promptable instead of silently swallowing messages.
|
|
14
|
+
*/
|
|
15
|
+
export function registerPullEndpoint(repos, agentId, provider, now = Date.now()) {
|
|
16
|
+
// The endpoint references an agent row. Hook execution order is not
|
|
17
|
+
// guaranteed, so do not assume the presence hook has already run — otherwise
|
|
18
|
+
// whether messaging works depends on which SessionStart hook fired first.
|
|
19
|
+
if (repos.agents.get(agentId) === undefined) {
|
|
20
|
+
repos.agents.upsert({
|
|
21
|
+
agentId,
|
|
22
|
+
kind: provider,
|
|
23
|
+
owner: null,
|
|
24
|
+
model: null,
|
|
25
|
+
pid: null,
|
|
26
|
+
cwd: process.cwd(),
|
|
27
|
+
worktree: null,
|
|
28
|
+
branch: null,
|
|
29
|
+
summary: null,
|
|
30
|
+
status: 'active',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const capability = capabilityFor(provider);
|
|
34
|
+
const existing = repos.agentEndpoints.getByAgent(agentId);
|
|
35
|
+
repos.agentEndpoints.upsert({
|
|
36
|
+
endpointId: existing?.endpointId ?? randomUUID(),
|
|
37
|
+
agentId,
|
|
38
|
+
provider,
|
|
39
|
+
transport: capability.transport,
|
|
40
|
+
capabilities: encodeCapabilities(capability),
|
|
41
|
+
address: `${capability.transport}:${agentId}`,
|
|
42
|
+
credentialHash: existing?.credentialHash ?? randomBytes(32).toString('hex'),
|
|
43
|
+
status: 'connected',
|
|
44
|
+
expiresAt: new Date(now + PULL_ENDPOINT_TTL_MS).toISOString(),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function toDeliverable(message) {
|
|
48
|
+
return {
|
|
49
|
+
messageId: message.messageId,
|
|
50
|
+
senderAgentId: message.senderAgentId,
|
|
51
|
+
taskId: message.taskId,
|
|
52
|
+
content: message.content,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Take every pending message for `agentId` and mark it delivered. Draining is
|
|
57
|
+
* what records delivery, so a message is only ever counted as delivered once
|
|
58
|
+
* the recipient has actually been handed it.
|
|
59
|
+
*/
|
|
60
|
+
export function drainInbox(repos, agentId, provider) {
|
|
61
|
+
registerPullEndpoint(repos, agentId, provider);
|
|
62
|
+
const claimed = repos.agentMessages.claimPendingForRecipient(agentId, provider);
|
|
63
|
+
repos.agents.touch(agentId);
|
|
64
|
+
return claimed.map(toDeliverable);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether this repository already uses Concord.
|
|
68
|
+
*
|
|
69
|
+
* The relay plugin is installed once and then loads in every session, including
|
|
70
|
+
* repositories that have nothing to do with Concord. Opening a workspace
|
|
71
|
+
* creates it, so these commands must check first and stay quiet otherwise —
|
|
72
|
+
* merely having the plugin installed should never litter unrelated projects
|
|
73
|
+
* with `.concord/` state.
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Read a hook payload piped on stdin. Only ever called behind `--from-hook`:
|
|
77
|
+
* a plugin monitor's stdin may stay open for the life of the session, and
|
|
78
|
+
* blocking on it there would silently wedge message delivery.
|
|
79
|
+
*/
|
|
80
|
+
function readHookPayload() {
|
|
81
|
+
if (process.stdin.isTTY)
|
|
82
|
+
return undefined;
|
|
83
|
+
try {
|
|
84
|
+
return readFileSync(0, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function workspaceExists(cwd) {
|
|
91
|
+
try {
|
|
92
|
+
return existsSync(databasePath(resolveRepoRoot(cwd, process.env)));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function registerInboxCommand(program) {
|
|
99
|
+
const inbox = program
|
|
100
|
+
.command('inbox')
|
|
101
|
+
.description('Receive live messages other agents addressed to this session');
|
|
102
|
+
inbox
|
|
103
|
+
.command('status')
|
|
104
|
+
.description('Exit 0 when this directory is a Concord workspace, 1 otherwise')
|
|
105
|
+
.action(() => {
|
|
106
|
+
// Lets the relay monitor bail out of a project that does not use Concord
|
|
107
|
+
// instead of polling for the life of the session.
|
|
108
|
+
if (!workspaceExists(process.cwd())) {
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
process.stdout.write('Concord workspace present.\n');
|
|
113
|
+
});
|
|
114
|
+
inbox
|
|
115
|
+
.command('register')
|
|
116
|
+
.description('Advertise this session as able to receive messages by draining them')
|
|
117
|
+
.option('--agent <id>', 'Agent id; defaults to CONCORD_AGENT_ID, then to the current session')
|
|
118
|
+
.option('--provider <name>', 'Client the agent runs in', 'claude-code')
|
|
119
|
+
.option('--from-hook', 'Read the session id from a hook payload on stdin (Codex)')
|
|
120
|
+
.action((options) => {
|
|
121
|
+
if (!workspaceExists(process.cwd()))
|
|
122
|
+
return;
|
|
123
|
+
const context = openContext(process.cwd());
|
|
124
|
+
const agentId = resolveAgentId(options.agent, process.env, {
|
|
125
|
+
kind: options.provider,
|
|
126
|
+
...(options.fromHook === true ? { hookPayload: readHookPayload() ?? '' } : {}),
|
|
127
|
+
});
|
|
128
|
+
registerPullEndpoint(context.repos, agentId, options.provider);
|
|
129
|
+
// Name the id, not just the capability. Only this id has a delivery
|
|
130
|
+
// endpoint, so an agent that lets start_work mint a fresh one becomes
|
|
131
|
+
// unreachable while still looking registered.
|
|
132
|
+
process.stdout.write(`Concord: this session is agent \`${agentId}\` and can receive live messages from other ` +
|
|
133
|
+
`agents. Pass agent_id="${agentId}" to every Concord tool call; do not invent a ` +
|
|
134
|
+
'different id.\n');
|
|
135
|
+
});
|
|
136
|
+
inbox
|
|
137
|
+
.command('drain')
|
|
138
|
+
.description('Print and acknowledge every message waiting for this agent')
|
|
139
|
+
.option('--agent <id>', 'Agent id; defaults to CONCORD_AGENT_ID, then to the current session')
|
|
140
|
+
.option('--provider <name>', 'Client the agent runs in', 'claude-code')
|
|
141
|
+
.option('--from-hook', 'Read the session id from a hook payload on stdin (Codex)')
|
|
142
|
+
.option('--format <format>', 'post-tool-use and stop emit hook JSON; monitor emits one line per message; json emits raw records', 'json')
|
|
143
|
+
.action((options) => {
|
|
144
|
+
if (!workspaceExists(process.cwd()))
|
|
145
|
+
return;
|
|
146
|
+
const context = openContext(process.cwd());
|
|
147
|
+
const agentId = resolveAgentId(options.agent, process.env, {
|
|
148
|
+
kind: options.provider,
|
|
149
|
+
...(options.fromHook === true ? { hookPayload: readHookPayload() ?? '' } : {}),
|
|
150
|
+
});
|
|
151
|
+
const messages = drainInbox(context.repos, agentId, options.provider);
|
|
152
|
+
// Silence matters: a hook that prints on an empty inbox would inject
|
|
153
|
+
// noise into the session on every single tool call.
|
|
154
|
+
if (messages.length === 0)
|
|
155
|
+
return;
|
|
156
|
+
if (options.format === 'json') {
|
|
157
|
+
process.stdout.write(`${JSON.stringify(messages)}\n`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (options.format === 'monitor') {
|
|
161
|
+
for (const line of renderMonitorLines(messages))
|
|
162
|
+
process.stdout.write(`${line}\n`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (options.format === 'post-tool-use' || options.format === 'stop') {
|
|
166
|
+
process.stdout.write(renderHookPayload(options.format, messages));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`Unknown --format: ${options.format}`);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=inbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../../src/cli/commands/inbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE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AO;QAClC,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtD,OAAO;QACT,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,KAAK,MAAM,IAAI,IAAI,kBAAkB,CAAC,QAAQ,CAAC;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;YACnF,OAAO;QACT,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,eAAe,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;YAClE,OAAO;QACT,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { Command } from '@commander-js/extra-typings';
|
|
2
|
-
import { type CommunicationProvider } from '../../install/agent-communications.js';
|
|
3
2
|
export interface SetupOptions {
|
|
4
3
|
claudeHooks?: boolean;
|
|
5
4
|
mcp?: boolean;
|
|
6
|
-
agentCommunications?: boolean;
|
|
7
|
-
communicationProviders?: readonly CommunicationProvider[];
|
|
8
5
|
env?: NodeJS.ProcessEnv;
|
|
9
6
|
}
|
|
10
7
|
export interface SetupResult {
|
|
@@ -12,7 +9,6 @@ export interface SetupResult {
|
|
|
12
9
|
workspaceId: string;
|
|
13
10
|
concordPath: string;
|
|
14
11
|
written: string[];
|
|
15
|
-
communicationProviders: CommunicationProvider[];
|
|
16
12
|
}
|
|
17
13
|
/** Ensure Concord's generated workspace is ignored without changing other rules. */
|
|
18
14
|
export declare function ensureConcordIgnored(repoRoot: string): void;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { createInterface } from 'node:readline/promises';
|
|
4
3
|
import { writeArtifacts } from '../../artifacts/index.js';
|
|
5
|
-
import { concordDir, resolveRepoRoot } from '../../config/paths.js';
|
|
6
|
-
import { detectCommunicationProviders, readAgentCommunicationConfig, writeAgentCommunicationConfig, } from '../../install/agent-communications.js';
|
|
7
4
|
import { installClaudeHook } from '../../install/claude-hooks.js';
|
|
8
|
-
import {
|
|
5
|
+
import { installClaudeRelayPlugin } from '../../install/claude-plugin.js';
|
|
6
|
+
import { installCodexHooks, installCodexMcpConfig } from '../../install/codex-config.js';
|
|
9
7
|
import { installConcord } from '../../install/index.js';
|
|
10
8
|
import { McpConfigParseError, installMcpConfigs } from '../../install/mcp-config.js';
|
|
11
9
|
import { openContext } from '../context.js';
|
|
@@ -34,58 +32,36 @@ export function runSetup(cwd, options = {}) {
|
|
|
34
32
|
if (options.mcp !== false) {
|
|
35
33
|
written.push(...installMcpConfigs(ctx.repoRoot));
|
|
36
34
|
written.push(installCodexMcpConfig(env));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
// Claude Code's half of the relay. Its background monitor is the only
|
|
36
|
+
// channel that reaches an agent idle at the prompt, and a monitor can only
|
|
37
|
+
// be declared by a plugin — settings.json cannot express one.
|
|
38
|
+
const plugin = installClaudeRelayPlugin(import.meta.url, env);
|
|
39
|
+
if (plugin !== undefined)
|
|
40
|
+
written.push(plugin);
|
|
41
|
+
// Codex has no background-monitor equivalent, so hooks are the only way it
|
|
42
|
+
// can receive a message from another agent.
|
|
43
|
+
written.push(installCodexHooks(env));
|
|
43
44
|
}
|
|
44
45
|
return {
|
|
45
46
|
repoRoot: ctx.repoRoot,
|
|
46
47
|
workspaceId: ctx.workspaceId,
|
|
47
48
|
concordPath: ctx.concordPath,
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
// A file touched by two installers is still one file to the reader.
|
|
50
|
+
written: [...new Set(written)],
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
async function askToInstallAgentCommunications(providers) {
|
|
53
|
-
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
54
|
-
try {
|
|
55
|
-
const answer = await prompt.question(`Enable live inter-agent prompting for detected clients (${providers.join(', ')})? [Y/n] `);
|
|
56
|
-
return !['n', 'no'].includes(answer.trim().toLowerCase());
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
prompt.close();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
53
|
export function registerSetupCommand(program) {
|
|
63
54
|
program
|
|
64
55
|
.command('setup')
|
|
65
56
|
.description('Set up Concord state, instructions, and MCP clients for this repository')
|
|
66
57
|
.option('--claude-hooks', 'also install an opt-in Claude Code PreToolUse overlap hook into .claude/settings.json')
|
|
67
58
|
.option('--no-mcp', 'skip MCP client registration; write local state and instructions only')
|
|
68
|
-
.
|
|
69
|
-
.action(async (options) => {
|
|
59
|
+
.action((options) => {
|
|
70
60
|
try {
|
|
71
61
|
const setupOptions = { mcp: options.mcp };
|
|
72
62
|
if (options.claudeHooks === true) {
|
|
73
63
|
setupOptions.claudeHooks = true;
|
|
74
64
|
}
|
|
75
|
-
const repoRoot = resolveRepoRoot(process.cwd(), process.env);
|
|
76
|
-
const concordPath = concordDir(repoRoot);
|
|
77
|
-
const detected = detectCommunicationProviders(repoRoot);
|
|
78
|
-
if (options.agentComms === true) {
|
|
79
|
-
setupOptions.agentCommunications = true;
|
|
80
|
-
setupOptions.communicationProviders = detected;
|
|
81
|
-
}
|
|
82
|
-
else if (process.stdin.isTTY &&
|
|
83
|
-
process.stdout.isTTY &&
|
|
84
|
-
detected.length > 0 &&
|
|
85
|
-
readAgentCommunicationConfig(concordPath) === undefined) {
|
|
86
|
-
setupOptions.agentCommunications = await askToInstallAgentCommunications(detected);
|
|
87
|
-
setupOptions.communicationProviders = detected;
|
|
88
|
-
}
|
|
89
65
|
const result = runSetup(process.cwd(), setupOptions);
|
|
90
66
|
process.stdout.write(`Concord setup complete\n` +
|
|
91
67
|
` repository: ${result.repoRoot}\n` +
|
|
@@ -99,10 +75,9 @@ export function registerSetupCommand(program) {
|
|
|
99
75
|
process.stdout.write('PreToolUse hook installed. Set CONCORD_TASK=<your task id> so it excludes your own claim.\n');
|
|
100
76
|
}
|
|
101
77
|
if (options.mcp) {
|
|
102
|
-
process.stdout.write('Restart your coding client so it reloads the project MCP server.\n'
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
process.stdout.write(`Live prompting approved for: ${result.communicationProviders.join(', ')}. Existing sessions must be restarted once.\n`);
|
|
78
|
+
process.stdout.write('Restart your coding client so it reloads the project MCP server.\n' +
|
|
79
|
+
'Codex: run /hooks once and trust the Concord hooks. Until you do, Codex skips ' +
|
|
80
|
+
'them silently and cannot receive messages from other agents.\n');
|
|
106
81
|
}
|
|
107
82
|
}
|
|
108
83
|
catch (error) {
|