@edspencer/paddock 0.61.1 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -14
- package/package.json +1 -1
- package/packages/server/dist/app.js +35 -8
- package/packages/server/dist/claude-credentials.d.ts +116 -0
- package/packages/server/dist/claude-credentials.js +103 -0
- package/packages/server/dist/claude-home.d.ts +102 -30
- package/packages/server/dist/claude-home.js +437 -97
- package/packages/server/dist/claude-instructions.d.ts +121 -0
- package/packages/server/dist/claude-instructions.js +114 -0
- package/packages/server/dist/claude-mcp.d.ts +146 -0
- package/packages/server/dist/claude-mcp.js +367 -0
- package/packages/server/dist/claude-settings.d.ts +159 -0
- package/packages/server/dist/claude-settings.js +159 -0
- package/packages/server/dist/cli/args.d.ts +1 -9
- package/packages/server/dist/cli/args.js +36 -18
- package/packages/server/dist/cli/paddock.js +20 -39
- package/packages/server/dist/config.d.ts +166 -30
- package/packages/server/dist/config.js +106 -26
- package/packages/server/dist/herdctl-agent-config.d.ts +11 -1
- package/packages/server/dist/herdctl-agent-config.js +53 -7
- package/packages/server/dist/herdctl-agent-names.d.ts +11 -0
- package/packages/server/dist/herdctl-agent-names.js +31 -0
- package/packages/server/dist/herdctl.d.ts +69 -13
- package/packages/server/dist/herdctl.js +70 -18
- package/packages/server/dist/instance-config.js +36 -0
- package/packages/server/dist/mcp-servers.d.ts +168 -0
- package/packages/server/dist/mcp-servers.js +305 -0
- package/packages/server/dist/routes/chats.js +10 -4
- package/packages/server/dist/transcripts.d.ts +61 -30
- package/packages/server/dist/transcripts.js +141 -46
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/{InstanceConfigPage-BgNXqAox.js → InstanceConfigPage-Ca905oey.js} +1 -1
- package/packages/web/dist/assets/{MarkdownRenderer-DfD_UtqU.js → MarkdownRenderer-ChlC1ezH.js} +1 -1
- package/packages/web/dist/assets/{ProjectRedirect-1EXdHXmO.js → ProjectRedirect-CslqbhUb.js} +1 -1
- package/packages/web/dist/assets/{ProjectView-DHb5vNUp.js → ProjectView-DkNdilGo.js} +3 -3
- package/packages/web/dist/assets/{ProjectsGrid-Br-EhLZE.js → ProjectsGrid-BrlvLc-Y.js} +1 -1
- package/packages/web/dist/assets/{arc-C2Jekujs.js → arc-CGqCI5nQ.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-CflCA-em.js → architectureDiagram-3BPJPVTR-Cp4KTxE2.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-Ds7GLNnC.js → blockDiagram-GPEHLZMM-yFxaTv04.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-D4WyGO6I.js → c4Diagram-AAUBKEIU-59lhWjRt.js} +1 -1
- package/packages/web/dist/assets/channel-CZs6Z1i5.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-tQunO_M5.js → chunk-2J33WTMH-BrpXGnJg.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-DT5dOWd2.js → chunk-4BX2VUAB-UxBDb5pi.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-CfTUqUEF.js → chunk-55IACEB6-D4ZJyUHW.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-sK5bOAA0.js → chunk-727SXJPM-DWdPj_8E.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-DcMgVe-P.js → chunk-AQP2D5EJ-BIpNbflY.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-In3h_-7v.js → chunk-FMBD7UC4-f6iJDfdI.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-DuaIeRaC.js → chunk-ND2GUHAM-Bz3TKIJk.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-DeT5mR5T.js → chunk-QZHKN3VN-buQmkafK.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-CrbEUUCd.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-CrbEUUCd.js +2 -0
- package/packages/web/dist/assets/{core-DgOgLvnM.js → core-TyFI6p0n.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-CyO-rznJ.js → cose-bilkent-S5V4N54A-CIkdi0XF.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG-B_9Ihzgn.js → dagre-BM42HDAG-BnLJCfNs.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-z5mvZ5YT.js → diagram-2AECGRRQ-D0OqfDB9.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-Bsz0cgfn.js → diagram-5GNKFQAL-DQ2spGrK.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-B29k5f4q.js → diagram-KO2AKTUF-RDIVQ_S3.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-CFrwsHoI.js → diagram-LMA3HP47-DKoTfh2C.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-D9Sjc2HR.js → diagram-OG6HWLK6-6k0OuSAL.js} +1 -1
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-C3vbkD7M.js → erDiagram-TEJ5UH35-B-oQaYAC.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-DkMIgntd.js → flowDiagram-I6XJVG4X-B7qpYe9C.js} +1 -1
- package/packages/web/dist/assets/{format-BFDqyFuw.js → format-PHdEBNOi.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-nvHanjpW.js → ganttDiagram-6RSMTGT7-SfBsqMmx.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-DbCNfOu7.js → gitGraphDiagram-PVQCEYII-CuM4Rl_i.js} +1 -1
- package/packages/web/dist/assets/{index-DGCs1YIO.js → index-D_1ogxg1.js} +2 -2
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-aJjH9x3D.js → infoDiagram-5YYISTIA-Dq-32Oj4.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-DoifwNnZ.js → ishikawaDiagram-YF4QCWOH-BLFHCj_o.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-Cz9kG9HN.js → journeyDiagram-JHISSGLW-CHP-Yu63.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-BoXnfr7A.js → kanban-definition-UN3LZRKU-DRuehSqn.js} +1 -1
- package/packages/web/dist/assets/{linear-BlTTO9yR.js → linear-Bwz2vnH7.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-YAG8eSPQ.js → mermaid.core-CeMMnCip.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-DtUBKfkr.js → mindmap-definition-RKZ34NQL-CEdqeoRW.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-B3Rwpmy0.js → pieDiagram-4H26LBE5-BdDXBx87.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-B8eJtTyk.js → quadrantDiagram-W4KKPZXB-Bovd1Zhx.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-CpAluiY9.js → requirementDiagram-4Y6WPE33-DiyrKnJ2.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-Cl_Rd1tN.js → sankeyDiagram-5OEKKPKP-BuX7TRVw.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-CRpqKSGm.js → sequenceDiagram-3UESZ5HK-BjetZWJo.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-h3h8gXv_.js → stateDiagram-AJRCARHV-4AUBV6dF.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-Cq84MOtb.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-PVr5V_pG.js → timeline-definition-PNZ67QCA-BpQ8g8Bm.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-De-4NPAX.js → vennDiagram-CIIHVFJN-Cj99BWER.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-Dtv10D2d.js → wardley-L42UT6IY-S7AGTOWw.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-p2fJuQ6C.js → wardleyDiagram-YWT4CUSO-LNXkUA7S.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6-DyYF-k92.js → xychartDiagram-2RQKCTM6-DGdTh4Xk.js} +1 -1
- package/packages/web/dist/index.html +1 -1
- package/packages/web/dist/sw.js +1 -1
- package/packages/server/dist/cli/claude-home-choice.d.ts +0 -44
- package/packages/server/dist/cli/claude-home-choice.js +0 -108
- package/packages/web/dist/assets/channel-B1K_gwAH.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-DYQQOKrW.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-DYQQOKrW.js +0 -2
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-BKRI9TnH.js +0 -2
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prefix that makes a string an environment reference rather than a literal.
|
|
3
|
+
* Same spelling as `managementApi.clients.<id>.auth.ref`, deliberately: an
|
|
4
|
+
* operator should have to learn it once.
|
|
5
|
+
*/
|
|
6
|
+
export const ENV_REF_PREFIX = "env:";
|
|
7
|
+
/**
|
|
8
|
+
* Server names paddock materialises itself, which a declaration may not take.
|
|
9
|
+
*
|
|
10
|
+
* Kept as literals rather than imported from `send-file-mcp.ts`/`self-mcp.ts` so
|
|
11
|
+
* config resolution stays free of the runtime modules — `mcp-servers-reserved`
|
|
12
|
+
* in the unit tests asserts the two spellings still agree.
|
|
13
|
+
*/
|
|
14
|
+
export const RESERVED_MCP_SERVER_NAMES = ["paddock", "paddock_manage"];
|
|
15
|
+
/**
|
|
16
|
+
* `mcp__<server>__<tool>` is the tool name both runtimes match against, and the
|
|
17
|
+
* allowlist pattern is built from it by string concatenation, so a name with a
|
|
18
|
+
* separator or whitespace in it produces a pattern that matches nothing. Claude
|
|
19
|
+
* Code uses the same character class for a server name.
|
|
20
|
+
*/
|
|
21
|
+
const NAME_RE = /^[A-Za-z0-9_-]+$/;
|
|
22
|
+
/** Keys of a declaration this module understands. Anything else is a typo. */
|
|
23
|
+
const KNOWN_KEYS = new Set(["command", "args", "env", "url", "type", "headers"]);
|
|
24
|
+
/**
|
|
25
|
+
* Env keys whose INLINE value is probably a credential. Deliberately a name
|
|
26
|
+
* heuristic and never a value one: matching on the value would mean reading it
|
|
27
|
+
* closely enough to describe it, and this module's whole posture is that it
|
|
28
|
+
* never looks at a value it is not about to hand to a server process.
|
|
29
|
+
*/
|
|
30
|
+
const SECRET_ISH_KEY_RE = /(TOKEN|SECRET|KEY|PASSWORD|PASSWD|CREDENTIAL|AUTH|PAT|COOKIE)/i;
|
|
31
|
+
function isRecord(v) {
|
|
32
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A URL with everything credential-shaped removed — no query string, no
|
|
36
|
+
* fragment, no `user:pass@`. Used for every log line that mentions a `url`,
|
|
37
|
+
* because a remote MCP endpoint's API key is conventionally a query parameter.
|
|
38
|
+
* An unparseable URL is reported as its scheme only rather than echoed.
|
|
39
|
+
*/
|
|
40
|
+
export function redactUrl(raw) {
|
|
41
|
+
try {
|
|
42
|
+
const u = new URL(raw);
|
|
43
|
+
const auth = u.username || u.password ? "<redacted>@" : "";
|
|
44
|
+
return `${u.protocol}//${auth}${u.host}${u.pathname}${u.search ? "?<redacted>" : ""}`;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return "<unparseable url>";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A server rendered for a human, carrying no secret. THE chokepoint: every
|
|
52
|
+
* notice, warning and error about a declared server goes through here, so
|
|
53
|
+
* auditing "can a token reach a log line?" is auditing one function.
|
|
54
|
+
*
|
|
55
|
+
* Args and env values are counted, never printed — an API key is as likely to be
|
|
56
|
+
* `--token=…` in `args` as it is to be an `env` value. The command is reduced to
|
|
57
|
+
* its basename for the same reason, which the leak test in
|
|
58
|
+
* `test/unit/mcp-servers.test.ts` is what forced: a full path is more useful in a
|
|
59
|
+
* log, but the rule "nothing from the block is echoed" is only worth having if it
|
|
60
|
+
* has no exceptions to remember. The server's own name is printed alongside and
|
|
61
|
+
* is what actually identifies it.
|
|
62
|
+
*/
|
|
63
|
+
export function describeServer(name, def) {
|
|
64
|
+
const parts = [];
|
|
65
|
+
if (def.command)
|
|
66
|
+
parts.push(`stdio: ${def.command.split(/[\\/]/).pop()}`);
|
|
67
|
+
if (def.url)
|
|
68
|
+
parts.push(`http: ${redactUrl(def.url)}`);
|
|
69
|
+
if (def.args?.length)
|
|
70
|
+
parts.push(`${def.args.length} args`);
|
|
71
|
+
const envCount = Object.keys(def.env ?? {}).length;
|
|
72
|
+
if (envCount > 0)
|
|
73
|
+
parts.push(`${envCount} env ${envCount === 1 ? "entry" : "entries"}`);
|
|
74
|
+
return `${name} (${parts.join(", ")})`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolve a string leaf: `env:VAR_NAME` reads `VAR_NAME`, anything else is a
|
|
78
|
+
* literal.
|
|
79
|
+
*
|
|
80
|
+
* An unset or blank variable FAILS the leaf, which drops the whole server. That
|
|
81
|
+
* is the fail-closed direction here for the same reason it is in
|
|
82
|
+
* `management-config.ts`: a server started without the credential it was
|
|
83
|
+
* declared with either fails every call confusingly or — worse for something
|
|
84
|
+
* that talks to a third party — connects unauthenticated.
|
|
85
|
+
*/
|
|
86
|
+
function resolveLeaf(raw, env, where) {
|
|
87
|
+
if (!raw.startsWith(ENV_REF_PREFIX))
|
|
88
|
+
return { ok: true, value: raw };
|
|
89
|
+
const varName = raw.slice(ENV_REF_PREFIX.length).trim();
|
|
90
|
+
if (varName.length === 0)
|
|
91
|
+
return { ok: false, error: `${where}: \`env:\` names no variable` };
|
|
92
|
+
const value = env[varName];
|
|
93
|
+
if (value === undefined || value.trim().length === 0) {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
error: `${where}: environment variable ${varName} is unset or empty`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return { ok: true, value };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Validate + resolve one declaration into the shape herdctl's `McpServerSchema`
|
|
103
|
+
* carries, or explain why it cannot be.
|
|
104
|
+
*
|
|
105
|
+
* The rejections are the interesting part, and each is a thing step 5 discovered
|
|
106
|
+
* the engine strips silently:
|
|
107
|
+
*
|
|
108
|
+
* - **`headers`** — there is no field for them, so a bearer-authenticated server
|
|
109
|
+
* would arrive unauthenticated AND miss its stored OAuth token, which is keyed
|
|
110
|
+
* on a hash that includes the headers. Step 5 passes such a host server with a
|
|
111
|
+
* warning; a hand-written declaration gets an error instead, because the user
|
|
112
|
+
* typed the header and can act on being told it does nothing.
|
|
113
|
+
* - **`type: sse`** — every `url` is mapped to `type: "http"` downstream, so an
|
|
114
|
+
* sse server is silently downgraded, with the same OAuth-key consequence.
|
|
115
|
+
* - **an unknown key** — the only defence against `arg:`/`envs:`/`commands:`,
|
|
116
|
+
* which would otherwise yield a server that starts with the wrong argv.
|
|
117
|
+
*/
|
|
118
|
+
function narrowDeclaration(name, raw, env) {
|
|
119
|
+
const where = `mcpServers.${name}`;
|
|
120
|
+
const errors = [];
|
|
121
|
+
const warnings = [];
|
|
122
|
+
const fail = (msg) => ({
|
|
123
|
+
errors: [...errors, `${msg} — not attached`],
|
|
124
|
+
warnings,
|
|
125
|
+
});
|
|
126
|
+
if (!NAME_RE.test(name)) {
|
|
127
|
+
return fail(`${where}: a server name may contain only letters, digits, \`_\` and \`-\` (its tools are ` +
|
|
128
|
+
`named mcp__${name}__<tool>, and the allowlist pattern is built from that)`);
|
|
129
|
+
}
|
|
130
|
+
if (RESERVED_MCP_SERVER_NAMES.includes(name)) {
|
|
131
|
+
return fail(`${where}: "${name}" is reserved for a server paddock injects itself, and two servers ` +
|
|
132
|
+
`cannot share the mcp__${name}__* namespace`);
|
|
133
|
+
}
|
|
134
|
+
if (!isRecord(raw))
|
|
135
|
+
return fail(`${where}: is not a mapping`);
|
|
136
|
+
const unknown = Object.keys(raw).filter((k) => !KNOWN_KEYS.has(k));
|
|
137
|
+
if (unknown.length > 0) {
|
|
138
|
+
return fail(`${where}: unrecognised key(s) ${unknown.join(", ")} (supported: command, args, env, url) ` +
|
|
139
|
+
`— a mistyped key would otherwise be dropped without a trace`);
|
|
140
|
+
}
|
|
141
|
+
if (raw.headers !== undefined) {
|
|
142
|
+
const keys = isRecord(raw.headers) ? Object.keys(raw.headers) : [];
|
|
143
|
+
return fail(`${where}: \`headers\`${keys.length > 0 ? ` (${keys.join(", ")})` : ""} cannot be ` +
|
|
144
|
+
`carried — the engine's MCP schema has no field for them, so the server would arrive ` +
|
|
145
|
+
`unauthenticated and its stored OAuth token (keyed on a hash that includes the headers) ` +
|
|
146
|
+
`would not be found either`);
|
|
147
|
+
}
|
|
148
|
+
const hasCommand = typeof raw.command === "string" && raw.command.trim().length > 0;
|
|
149
|
+
const hasUrl = typeof raw.url === "string" && raw.url.trim().length > 0;
|
|
150
|
+
if (hasCommand && hasUrl) {
|
|
151
|
+
return fail(`${where}: declares both a \`command\` and a \`url\`; a server is one or the other`);
|
|
152
|
+
}
|
|
153
|
+
if (!hasCommand && !hasUrl) {
|
|
154
|
+
return fail(`${where}: declares neither a \`command\` nor a \`url\`, so there is nothing to start`);
|
|
155
|
+
}
|
|
156
|
+
if (raw.type !== undefined) {
|
|
157
|
+
const type = String(raw.type).trim().toLowerCase();
|
|
158
|
+
if (type === "sse") {
|
|
159
|
+
return fail(`${where}: \`type: sse\` cannot be carried — every \`url\` server is connected to as ` +
|
|
160
|
+
`streamable HTTP downstream, so an sse server would be silently downgraded (and its ` +
|
|
161
|
+
`stored OAuth token, keyed on a hash that includes the type, not found). Declare it ` +
|
|
162
|
+
`as \`http\` if the server supports it`);
|
|
163
|
+
}
|
|
164
|
+
const expected = hasUrl ? "http" : "stdio";
|
|
165
|
+
if (type !== expected) {
|
|
166
|
+
return fail(`${where}: \`type: ${type}\` disagrees with the declaration (expected ${expected})`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const server = {};
|
|
170
|
+
if (hasCommand) {
|
|
171
|
+
const res = resolveLeaf(raw.command.trim(), env, `${where}.command`);
|
|
172
|
+
if (!res.ok)
|
|
173
|
+
return { errors, warnings: [...warnings, `${res.error} — server not attached`] };
|
|
174
|
+
server.command = res.value;
|
|
175
|
+
}
|
|
176
|
+
if (hasUrl) {
|
|
177
|
+
const res = resolveLeaf(raw.url.trim(), env, `${where}.url`);
|
|
178
|
+
if (!res.ok)
|
|
179
|
+
return { errors, warnings: [...warnings, `${res.error} — server not attached`] };
|
|
180
|
+
server.url = res.value;
|
|
181
|
+
// A key in the query string is the usual way a remote MCP endpoint is
|
|
182
|
+
// authenticated now that `headers` cannot be carried, and this file is
|
|
183
|
+
// git-tracked. Say so once; never echo the query itself.
|
|
184
|
+
if (!raw.url.startsWith(ENV_REF_PREFIX)) {
|
|
185
|
+
let parsed;
|
|
186
|
+
try {
|
|
187
|
+
parsed = new URL(server.url);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
/* an unparseable url is the engine's problem, not a secrets one */
|
|
191
|
+
}
|
|
192
|
+
if (parsed && (parsed.search || parsed.username || parsed.password)) {
|
|
193
|
+
warnings.push(`${where}.url: carries a query string or userinfo, which is where an API key usually ` +
|
|
194
|
+
`rides. This file is git-tracked — prefer \`url: ${ENV_REF_PREFIX}VAR_NAME\` and ` +
|
|
195
|
+
`keep the value in the environment`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (raw.args !== undefined) {
|
|
200
|
+
if (!Array.isArray(raw.args) || !raw.args.every((a) => typeof a === "string")) {
|
|
201
|
+
return fail(`${where}.args: must be a list of strings`);
|
|
202
|
+
}
|
|
203
|
+
const args = [];
|
|
204
|
+
for (const [i, arg] of raw.args.entries()) {
|
|
205
|
+
const res = resolveLeaf(arg, env, `${where}.args[${i}]`);
|
|
206
|
+
if (!res.ok)
|
|
207
|
+
return { errors, warnings: [...warnings, `${res.error} — server not attached`] };
|
|
208
|
+
args.push(res.value);
|
|
209
|
+
}
|
|
210
|
+
if (args.length > 0)
|
|
211
|
+
server.args = args;
|
|
212
|
+
}
|
|
213
|
+
if (raw.env !== undefined) {
|
|
214
|
+
if (!isRecord(raw.env))
|
|
215
|
+
return fail(`${where}.env: must be a mapping of NAME to value`);
|
|
216
|
+
const resolved = {};
|
|
217
|
+
for (const [key, value] of Object.entries(raw.env)) {
|
|
218
|
+
if (typeof value !== "string") {
|
|
219
|
+
return fail(`${where}.env.${key}: must be a string (values are passed to a process verbatim)`);
|
|
220
|
+
}
|
|
221
|
+
const res = resolveLeaf(value, env, `${where}.env.${key}`);
|
|
222
|
+
if (!res.ok)
|
|
223
|
+
return { errors, warnings: [...warnings, `${res.error} — server not attached`] };
|
|
224
|
+
resolved[key] = res.value;
|
|
225
|
+
if (!value.startsWith(ENV_REF_PREFIX) && SECRET_ISH_KEY_RE.test(key)) {
|
|
226
|
+
warnings.push(`${where}.env.${key}: looks like a credential and is written into the config file ` +
|
|
227
|
+
`itself, which is git-tracked — prefer \`${key}: ${ENV_REF_PREFIX}VAR_NAME\` and set ` +
|
|
228
|
+
`the value in the environment`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (Object.keys(resolved).length > 0)
|
|
232
|
+
server.env = resolved;
|
|
233
|
+
}
|
|
234
|
+
return { server, errors, warnings };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Resolve the whole `mcpServers:` block against `env`.
|
|
238
|
+
*
|
|
239
|
+
* Never throws. A declaration paddock cannot carry is reported and dropped so one
|
|
240
|
+
* typo cannot take an instance down — the same posture as
|
|
241
|
+
* `resolveManagementApiConfig`, and for the same reason: this is a capability,
|
|
242
|
+
* and losing a capability is better than losing the instance.
|
|
243
|
+
*/
|
|
244
|
+
export function resolveDeclaredMcpServers(file, env) {
|
|
245
|
+
const servers = {};
|
|
246
|
+
const errors = [];
|
|
247
|
+
const warnings = [];
|
|
248
|
+
if (file === undefined || file === null)
|
|
249
|
+
return { servers, errors, warnings };
|
|
250
|
+
if (!isRecord(file)) {
|
|
251
|
+
errors.push("mcpServers: must be a mapping of server name to declaration — ignored");
|
|
252
|
+
return { servers, errors, warnings };
|
|
253
|
+
}
|
|
254
|
+
for (const [rawName, decl] of Object.entries(file)) {
|
|
255
|
+
const name = rawName.trim();
|
|
256
|
+
if (name.length === 0) {
|
|
257
|
+
errors.push("mcpServers: a server name is empty — not attached");
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const res = narrowDeclaration(name, decl, env);
|
|
261
|
+
errors.push(...res.errors);
|
|
262
|
+
warnings.push(...res.warnings);
|
|
263
|
+
if (res.server)
|
|
264
|
+
servers[name] = res.server;
|
|
265
|
+
}
|
|
266
|
+
return { servers, errors, warnings };
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* What to say at boot about the declared servers — the answer to "what does this
|
|
270
|
+
* instance actually have?", which should be readable off the log rather than
|
|
271
|
+
* inferred from a YAML file plus an environment.
|
|
272
|
+
*
|
|
273
|
+
* Takes the already-resolved servers, so it cannot see a raw declaration and
|
|
274
|
+
* therefore cannot leak one; every line it produces goes through
|
|
275
|
+
* {@link describeServer}.
|
|
276
|
+
*/
|
|
277
|
+
export function declaredMcpNotices(opts) {
|
|
278
|
+
const names = Object.keys(opts.servers);
|
|
279
|
+
if (names.length === 0)
|
|
280
|
+
return [];
|
|
281
|
+
const notices = [
|
|
282
|
+
{
|
|
283
|
+
level: "info",
|
|
284
|
+
message: `MCP servers declared by this instance (\`mcpServers:\`): ` +
|
|
285
|
+
`${names.map((n) => describeServer(n, opts.servers[n])).join("; ")}. ` +
|
|
286
|
+
`Every project's keeper gets all of them.`,
|
|
287
|
+
},
|
|
288
|
+
];
|
|
289
|
+
const shadowed = names.filter((n) => opts.hostNames?.includes(n));
|
|
290
|
+
if (shadowed.length > 0) {
|
|
291
|
+
notices.push({
|
|
292
|
+
level: "info",
|
|
293
|
+
message: `${shadowed.join(", ")} ${shadowed.length === 1 ? "is" : "are"} also declared in your ` +
|
|
294
|
+
`~/.claude.json (\`claude.mcpServers: host\`); this instance's own declaration wins.`,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (opts.browserMcp && names.includes("playwright")) {
|
|
298
|
+
notices.push({
|
|
299
|
+
level: "warn",
|
|
300
|
+
message: `mcpServers.playwright collides with paddock's own browser server, which WINS — your ` +
|
|
301
|
+
`declaration is not attached. Set \`browserMcp: false\` to use yours instead.`,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return notices;
|
|
305
|
+
}
|
|
@@ -584,7 +584,7 @@ export function registerChatWorkspaceRoutes(app, ctx) {
|
|
|
584
584
|
schema: {
|
|
585
585
|
tags: ["Chats"],
|
|
586
586
|
summary: "Delete a project chat",
|
|
587
|
-
description: "Deletes a project chat (session)
|
|
587
|
+
description: "Deletes a project chat (session) and clears any archived/starred flag so a future session id can't inherit it. Responds 200 with `{ ok, removed, retained }`. In a Claude home Paddock owns, the transcript JSONL is unlinked (`removed: true`). In a home it does NOT own the transcript is the user's own terminal `claude` history — Paddock plants no symlink there (#682), so there is no copy to delete — and the session is RELEASED instead: it leaves the chat list, the file stays on disk, and `retained` is true (#689).",
|
|
588
588
|
params: {
|
|
589
589
|
type: "object",
|
|
590
590
|
properties: {
|
|
@@ -605,7 +605,7 @@ export function registerChatWorkspaceRoutes(app, ctx) {
|
|
|
605
605
|
try {
|
|
606
606
|
const agent = await agentForSlug(req.params.slug);
|
|
607
607
|
await cleanupAttachments(agent, req.params.sessionId);
|
|
608
|
-
const removed = await herdctl.deleteSession(agent, req.params.sessionId);
|
|
608
|
+
const { removed, retained } = await herdctl.deleteSession(agent, req.params.sessionId);
|
|
609
609
|
// Drop any archived/starred/unread/detached flag so a future session id
|
|
610
610
|
// can't inherit it. (Read-state watermarks, other users' unread overrides,
|
|
611
611
|
// provenance and any queued message are deliberately NOT swept here — that
|
|
@@ -619,7 +619,7 @@ export function registerChatWorkspaceRoutes(app, ctx) {
|
|
|
619
619
|
// has to be cleared on the same path — otherwise a recycled session id
|
|
620
620
|
// silently starts life detached from a parent it never had.
|
|
621
621
|
await parentDetach.setDetached(agent, req.params.sessionId, false).catch(() => undefined);
|
|
622
|
-
return reply.code(200).send({ ok: true, removed });
|
|
622
|
+
return reply.code(200).send({ ok: true, removed, retained });
|
|
623
623
|
}
|
|
624
624
|
catch (err) {
|
|
625
625
|
return sendProjectError(reply, err);
|
|
@@ -1208,7 +1208,13 @@ export function registerChatWorkspaceRoutes(app, ctx) {
|
|
|
1208
1208
|
try {
|
|
1209
1209
|
await cleanupAttachments(agent, sessionId);
|
|
1210
1210
|
const gone = await herdctl.deleteSession(agent, sessionId);
|
|
1211
|
-
|
|
1211
|
+
// `retained` counts as success here, and the distinction matters for
|
|
1212
|
+
// the flag-clearing below. These two buckets are "no longer in the
|
|
1213
|
+
// chat list" vs "still in it": a RELEASED chat (#689) left the list
|
|
1214
|
+
// even though its transcript survives on disk, so its flags must be
|
|
1215
|
+
// cleared like any other departure. Only a genuine failure — nothing
|
|
1216
|
+
// on disk to act on — belongs in `failed`.
|
|
1217
|
+
if (gone.removed || gone.retained)
|
|
1212
1218
|
removed.push(sessionId);
|
|
1213
1219
|
else
|
|
1214
1220
|
failed.push(sessionId);
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whose transcripts this instance uses — the `claude.transcripts` config key.
|
|
3
|
+
*
|
|
4
|
+
* `own` = paddock's, inside the data dir / project. `host` = this machine's
|
|
5
|
+
* Claude Code, shared live. See the module doc for the mechanism.
|
|
6
|
+
*/
|
|
7
|
+
export type TranscriptsMode = "own" | "host";
|
|
8
|
+
/** Isolation is the default: nothing outside the data dir is written (#691). */
|
|
9
|
+
export declare const DEFAULT_TRANSCRIPTS_MODE: TranscriptsMode;
|
|
10
|
+
/** Type guard, so an unknown config value falls back instead of failing a boot. */
|
|
11
|
+
export declare function isKnownTranscriptsMode(value: string): value is TranscriptsMode;
|
|
1
12
|
/**
|
|
2
13
|
* Encode a working directory the way Claude Code names its transcript dir.
|
|
3
14
|
* For paths under 200 chars this is just the non-alphanumeric→'-' replacement
|
|
@@ -8,7 +19,44 @@ export declare function encodeProjectDir(dir: string): string;
|
|
|
8
19
|
/** Absolute path to the project's local transcript directory. */
|
|
9
20
|
export declare function projectChatsDir(projectDir: string): string;
|
|
10
21
|
/**
|
|
11
|
-
*
|
|
22
|
+
* The transcript folder a Claude home holds for `workingDir` —
|
|
23
|
+
* `<home>/projects/<encoded-cwd>`.
|
|
24
|
+
*
|
|
25
|
+
* The LITERAL path, before any symlink is followed, which is what makes it worth
|
|
26
|
+
* naming: it is the string Claude Code builds its session file AND its agent
|
|
27
|
+
* memory dir (`<here>/memory`) out of, and the agent harness refuses to write to
|
|
28
|
+
* any path with a `.claude` component in it (#690). Under paddock's own home it
|
|
29
|
+
* never has one, in either {@link TranscriptsMode}.
|
|
30
|
+
*/
|
|
31
|
+
export declare function encodedTranscriptDir(claudeHome: string, workingDir: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Where a project's transcripts are planted, and where they point.
|
|
34
|
+
*
|
|
35
|
+
* `path` is the Claude home to plant the redirect symlink in, and it is REQUIRED
|
|
36
|
+
* — no default (#620). Callers must pass `cfg.claudeHome`: the engine is
|
|
37
|
+
* constructed with that same resolved value, and a symlink planted in a
|
|
38
|
+
* different home than the one the engine reads is exactly the "chats list but
|
|
39
|
+
* open empty" failure (#588). It used to default to the env-derived home for
|
|
40
|
+
* callers with no config, and `ensureSweeperHome` silently took that default —
|
|
41
|
+
* so the sweeper's symlink landed in a different home than every other agent's.
|
|
42
|
+
* Making the parameter required is what stops that class of bug at the type
|
|
43
|
+
* level.
|
|
44
|
+
*
|
|
45
|
+
* Since #691 paddock ALWAYS owns `path`, so the old `owned` flag is gone: the
|
|
46
|
+
* question it used to answer ("may we write here?") now has one answer, and the
|
|
47
|
+
* question that actually varies — whose transcripts these are — is
|
|
48
|
+
* {@link transcripts}.
|
|
49
|
+
*/
|
|
50
|
+
export interface ClaudeHomeTarget {
|
|
51
|
+
/** Absolute path to paddock's own Claude home (`cfg.claudeHome`). */
|
|
52
|
+
path: string;
|
|
53
|
+
/** Whose transcripts this instance uses (`cfg.claude.transcripts`). */
|
|
54
|
+
transcripts: TranscriptsMode;
|
|
55
|
+
/** The user's own `~/.claude` — the store under `transcripts: "host"`. */
|
|
56
|
+
userHome: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Ensure the project's transcript store exists and that Claude Code's encoded
|
|
12
60
|
* transcript path for `workingDir` is a symlink pointing at it (migrating an
|
|
13
61
|
* existing real transcript dir in the process). Safe to call on every agent
|
|
14
62
|
* registration. Never throws — a failure here must not block agent registration
|
|
@@ -21,38 +69,21 @@ export declare function projectChatsDir(projectDir: string): string;
|
|
|
21
69
|
* store stays in the project's metadata dir (the data repo) — so transcripts
|
|
22
70
|
* never pollute the external repo's working tree — hence the two are split.
|
|
23
71
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* different home than the one the engine reads is exactly the "chats list but
|
|
28
|
-
* open empty" failure (#588). It used to default to the env-derived home for
|
|
29
|
-
* callers with no config, and `ensureSweeperHome` silently took that default —
|
|
30
|
-
* so the sweeper's symlink landed in a different home than every other agent's.
|
|
31
|
-
* Making the parameter required is what stops that class of bug at the type
|
|
32
|
-
* level.
|
|
33
|
-
*
|
|
34
|
-
* `home.owned` gates EVERY write into the home (#620, #682). Two of them:
|
|
72
|
+
* The store is `<chatsHostDir>/.chats/` under `transcripts: "own"` and the user's
|
|
73
|
+
* own `~/.claude/projects/<encoded-cwd>/` under `transcripts: "host"`; everything
|
|
74
|
+
* below is the same code either way.
|
|
35
75
|
*
|
|
36
|
-
*
|
|
37
|
-
* files and then REMOVES the originals. That is correct self-healing inside a
|
|
38
|
-
* home paddock owns, where such a directory can only be paddock's own doing.
|
|
39
|
-
* Inside the user's `~/.claude` it is somebody else's data — a `claude` CLI
|
|
40
|
-
* session run in a directory paddock happens to also manage — so we leave it
|
|
41
|
-
* strictly alone and let the SDK keep writing there.
|
|
42
|
-
* - Planting the redirect symlink at a path that does not exist yet. Not
|
|
43
|
-
* destructive on the day it happens, which is why it was missed, but it
|
|
44
|
-
* silently claims where the user's FUTURE sessions for that directory get
|
|
45
|
-
* written (#682). See the branch itself for the full argument.
|
|
76
|
+
* ## The one write into `~/.claude`, and why it is not the #682 mistake
|
|
46
77
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
78
|
+
* Under `host` this creates `~/.claude/projects/<encoded-cwd>/` if it is missing,
|
|
79
|
+
* because a symlink to a non-existent directory is not something Claude Code can
|
|
80
|
+
* `mkdir -p` through. That is a directory Claude Code itself would create the
|
|
81
|
+
* first time the user ran `claude` there, made under a config key whose entire
|
|
82
|
+
* meaning is "share the host's transcripts". #682 was the opposite: planting a
|
|
83
|
+
* link that silently REDIRECTED the user's future sessions into paddock's store
|
|
84
|
+
* on an instance that had asked for no such thing. Under `own` — the default —
|
|
85
|
+
* nothing under `~/.claude` is created, read or written at all.
|
|
49
86
|
*/
|
|
50
|
-
export interface ClaudeHomeTarget {
|
|
51
|
-
/** Absolute path to the Claude home to plant the redirect symlink in. */
|
|
52
|
-
path: string;
|
|
53
|
-
/** Whether paddock owns this home — see `PaddockConfig.ownsClaudeHome`. */
|
|
54
|
-
owned: boolean;
|
|
55
|
-
}
|
|
56
87
|
export declare function ensureProjectChats(workingDir: string, chatsHostDir: string, home: ClaudeHomeTarget): Promise<void>;
|
|
57
88
|
/**
|
|
58
89
|
* Read a session's FIRST user message text, untruncated, straight from its
|