ctxpipe 0.1.0-alpha.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/bin/ctxpipe.js +6 -42
- package/dist/auth.d.ts +52 -0
- package/dist/auth.js +416 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +56 -0
- package/dist/commands.js +264 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +19 -0
- package/dist/constants.js.map +1 -0
- package/dist/fs-operations.d.ts +16 -0
- package/dist/fs-operations.js +62 -0
- package/dist/fs-operations.js.map +1 -0
- package/dist/mcp/json.d.ts +3 -0
- package/dist/mcp/json.js +15 -0
- package/dist/mcp/json.js.map +1 -0
- package/dist/mcp/mcp-operations.d.ts +103 -0
- package/dist/mcp/mcp-operations.js +464 -0
- package/dist/mcp/mcp-operations.js.map +1 -0
- package/dist/mcp/paths.d.ts +7 -0
- package/dist/mcp/paths.js +17 -0
- package/dist/mcp/paths.js.map +1 -0
- package/dist/memory/agentmemory-client.d.ts +24 -0
- package/dist/memory/agentmemory-client.js +47 -0
- package/dist/memory/agentmemory-client.js.map +1 -0
- package/dist/memory/hydration.d.ts +141 -0
- package/dist/memory/hydration.js +390 -0
- package/dist/memory/hydration.js.map +1 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/markdown.d.ts +29 -0
- package/dist/memory/markdown.js +193 -0
- package/dist/memory/markdown.js.map +1 -0
- package/dist/memory/mcp-server.d.ts +48 -0
- package/dist/memory/mcp-server.js +322 -0
- package/dist/memory/mcp-server.js.map +1 -0
- package/dist/memory/paths.d.ts +12 -0
- package/dist/memory/paths.js +71 -0
- package/dist/memory/paths.js.map +1 -0
- package/dist/memory/policy.d.ts +16 -0
- package/dist/memory/policy.js +81 -0
- package/dist/memory/policy.js.map +1 -0
- package/dist/memory/run-hook.d.ts +13 -0
- package/dist/memory/run-hook.js +44 -0
- package/dist/memory/run-hook.js.map +1 -0
- package/dist/memory/run-init.d.ts +11 -0
- package/dist/memory/run-init.js +92 -0
- package/dist/memory/run-init.js.map +1 -0
- package/dist/memory/run-mcp.d.ts +3 -0
- package/dist/memory/run-mcp.js +7 -0
- package/dist/memory/run-mcp.js.map +1 -0
- package/dist/memory/run-meta.d.ts +11 -0
- package/dist/memory/run-meta.js +124 -0
- package/dist/memory/run-meta.js.map +1 -0
- package/dist/memory/supervisor.d.ts +49 -0
- package/dist/memory/supervisor.js +217 -0
- package/dist/memory/supervisor.js.map +1 -0
- package/dist/program.d.ts +1 -0
- package/dist/program.js +209 -0
- package/dist/program.js.map +1 -0
- package/dist/prompts.d.ts +42 -0
- package/dist/prompts.js +336 -0
- package/dist/prompts.js.map +1 -0
- package/dist/system.d.ts +3 -0
- package/dist/system.js +27 -0
- package/dist/system.js.map +1 -0
- package/dist/ui.d.ts +20 -0
- package/dist/ui.js +115 -0
- package/dist/ui.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +26 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Operation } from "./mcp/mcp-operations.js";
|
|
2
|
+
export declare function isInteractive(opts: {
|
|
3
|
+
nonInteractive?: boolean;
|
|
4
|
+
json?: boolean;
|
|
5
|
+
}): boolean;
|
|
6
|
+
export type InitRunOpts = {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
org?: string;
|
|
9
|
+
scope?: string;
|
|
10
|
+
agents: string[];
|
|
11
|
+
dryRun: boolean;
|
|
12
|
+
json: boolean;
|
|
13
|
+
nonInteractive: boolean;
|
|
14
|
+
mcp: boolean;
|
|
15
|
+
/** Tri-state: true = always enable, false = always skip, undefined = ask in interactive mode. */
|
|
16
|
+
memory?: boolean;
|
|
17
|
+
/** Install Claude Code SessionStart/Stop hooks for memory automation. */
|
|
18
|
+
claudeHooks?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type McpAddRunOpts = {
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
org?: string;
|
|
23
|
+
scope?: string;
|
|
24
|
+
clients: string[];
|
|
25
|
+
dryRun: boolean;
|
|
26
|
+
json: boolean;
|
|
27
|
+
nonInteractive: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare function runInit(opts: InitRunOpts): Promise<void>;
|
|
30
|
+
export declare function runAuthLogin(opts: {
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
export declare function runAuthWhoami(opts: {
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
json: boolean;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
export declare function runAuthLogout(opts: {
|
|
38
|
+
baseUrl: string;
|
|
39
|
+
json: boolean;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
export declare function runMcpAdd(opts: McpAddRunOpts): Promise<void>;
|
|
42
|
+
export declare function runDoctor(opts: {
|
|
43
|
+
json: boolean;
|
|
44
|
+
}): void;
|
|
45
|
+
export type ConfirmAndApplyOpts = {
|
|
46
|
+
operations: Operation[];
|
|
47
|
+
json: boolean;
|
|
48
|
+
nonInteractive: boolean;
|
|
49
|
+
interactive: boolean;
|
|
50
|
+
dryRun: boolean;
|
|
51
|
+
introShown: boolean;
|
|
52
|
+
setupSummary?: string[];
|
|
53
|
+
successMessage?: string;
|
|
54
|
+
outroMessage?: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function confirmAndApply({ operations, json, nonInteractive, interactive, dryRun, introShown, setupSummary, successMessage, outroMessage, }: ConfirmAndApplyOpts): Promise<void>;
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import { intro, log, note, outro, tasks } from "@clack/prompts";
|
|
3
|
+
import { CLIENTS, CLIENT_COMMANDS, CLIENT_LABELS } from "./constants.js";
|
|
4
|
+
import { packageVersion } from "./version.js";
|
|
5
|
+
import { fetchSession, loginWithDeviceFlow, readStoredAuth, removeStoredAuth, resolveCtxpipeBaseUrl, sessionUser, userLabel, } from "./auth.js";
|
|
6
|
+
import { applyOperation, applyOperations } from "./fs-operations.js";
|
|
7
|
+
import { buildClaudeHooksOperation, buildCtxpipeConfigOperation, buildMcpOperations, buildMemoryArtifactOperations, createOperationContext, validateClients, validateScope, } from "./mcp/mcp-operations.js";
|
|
8
|
+
import { normalizeBaseUrl } from "./mcp/paths.js";
|
|
9
|
+
import { promptConfirm, promptInitWizard, promptMcpWizard } from "./prompts.js";
|
|
10
|
+
import { commandExists } from "./system.js";
|
|
11
|
+
import { describeAppliedItem, describeOperation, brandName, printDoctorTable, writeResult } from "./ui.js";
|
|
12
|
+
export function isInteractive(opts) {
|
|
13
|
+
return !opts.nonInteractive && !opts.json && input.isTTY && output.isTTY;
|
|
14
|
+
}
|
|
15
|
+
export async function runInit(opts) {
|
|
16
|
+
const interactive = isInteractive(opts);
|
|
17
|
+
const answers = {
|
|
18
|
+
org: opts.org ?? null,
|
|
19
|
+
baseUrl: opts.baseUrl,
|
|
20
|
+
agents: [...opts.agents],
|
|
21
|
+
scope: opts.scope ?? null,
|
|
22
|
+
nonInteractive: opts.nonInteractive,
|
|
23
|
+
dryRun: opts.dryRun,
|
|
24
|
+
json: opts.json,
|
|
25
|
+
mcp: opts.mcp,
|
|
26
|
+
memory: opts.memory,
|
|
27
|
+
};
|
|
28
|
+
if (interactive) {
|
|
29
|
+
Object.assign(answers, await promptInitWizard(answers));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (!answers.org)
|
|
33
|
+
throw new Error("Missing --org for non-interactive init");
|
|
34
|
+
if (!answers.scope)
|
|
35
|
+
throw new Error("Missing --scope for non-interactive init");
|
|
36
|
+
if (answers.agents.length === 0 && answers.mcp) {
|
|
37
|
+
throw new Error("Missing --agents for non-interactive init");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const org = answers.org;
|
|
41
|
+
const scope = answers.scope;
|
|
42
|
+
const agents = answers.agents;
|
|
43
|
+
if (!org)
|
|
44
|
+
throw new Error("Missing --org");
|
|
45
|
+
if (!scope)
|
|
46
|
+
throw new Error("Missing --scope");
|
|
47
|
+
validateScope(scope);
|
|
48
|
+
validateClients(agents);
|
|
49
|
+
// In non-interactive mode an unspecified --memory means "do not enable".
|
|
50
|
+
const memoryEnabled = answers.memory === true;
|
|
51
|
+
const context = createOperationContext({ commandExists });
|
|
52
|
+
const ctxpipeConfig = buildCtxpipeConfigOperation({
|
|
53
|
+
baseUrl: answers.baseUrl,
|
|
54
|
+
org,
|
|
55
|
+
context,
|
|
56
|
+
});
|
|
57
|
+
const mcpOps = answers.mcp
|
|
58
|
+
? buildMcpOperations({
|
|
59
|
+
clients: agents,
|
|
60
|
+
baseUrl: answers.baseUrl,
|
|
61
|
+
org,
|
|
62
|
+
scope,
|
|
63
|
+
memory: memoryEnabled,
|
|
64
|
+
context,
|
|
65
|
+
})
|
|
66
|
+
: [];
|
|
67
|
+
const memoryOps = memoryEnabled ? buildMemoryArtifactOperations({ context }) : [];
|
|
68
|
+
const claudeHookOps = memoryEnabled && opts.claudeHooks && agents.includes("claude")
|
|
69
|
+
? [buildClaudeHooksOperation({ context })]
|
|
70
|
+
: [];
|
|
71
|
+
const operations = [ctxpipeConfig, ...mcpOps, ...memoryOps, ...claudeHookOps];
|
|
72
|
+
await confirmAndApply({
|
|
73
|
+
operations,
|
|
74
|
+
json: opts.json,
|
|
75
|
+
nonInteractive: opts.nonInteractive,
|
|
76
|
+
interactive,
|
|
77
|
+
dryRun: answers.dryRun,
|
|
78
|
+
introShown: interactive,
|
|
79
|
+
setupSummary: [
|
|
80
|
+
`Organization ${org}`,
|
|
81
|
+
`Scope ${scopeLabel(scope)}`,
|
|
82
|
+
`Agents ${agentsLabel(agents, answers.mcp)}`,
|
|
83
|
+
`Memory ${memoryEnabled ? "enabled (local AgentMemory + .ai/memory)" : "disabled"}`,
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export async function runAuthLogin(opts) {
|
|
88
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
89
|
+
const auth = await loginWithDeviceFlow({ baseUrl });
|
|
90
|
+
const session = await fetchSession({ baseUrl, accessToken: auth.accessToken }).catch(() => null);
|
|
91
|
+
log.success(`Signed in as ${userLabel(session) ?? "ctx|"}.`);
|
|
92
|
+
}
|
|
93
|
+
export async function runAuthWhoami(opts) {
|
|
94
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
95
|
+
const auth = await readStoredAuth(baseUrl);
|
|
96
|
+
if (!auth) {
|
|
97
|
+
const result = { status: "signed-out", baseUrl: normalizeBaseUrl(baseUrl) };
|
|
98
|
+
if (opts.json) {
|
|
99
|
+
console.log(JSON.stringify(result, null, 2));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
log.warn("Not signed in.");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const session = await fetchSession({ baseUrl, accessToken: auth.accessToken });
|
|
106
|
+
const result = {
|
|
107
|
+
status: "ok",
|
|
108
|
+
baseUrl: normalizeBaseUrl(baseUrl),
|
|
109
|
+
user: sessionUser(session),
|
|
110
|
+
};
|
|
111
|
+
if (opts.json) {
|
|
112
|
+
console.log(JSON.stringify(result, null, 2));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
log.success(`Signed in as ${userLabel(session) ?? "ctx|"}.`);
|
|
116
|
+
}
|
|
117
|
+
export async function runAuthLogout(opts) {
|
|
118
|
+
const baseUrl = resolveCtxpipeBaseUrl(process.cwd(), opts.baseUrl);
|
|
119
|
+
await removeStoredAuth(baseUrl);
|
|
120
|
+
const result = { status: "ok", baseUrl: normalizeBaseUrl(baseUrl) };
|
|
121
|
+
if (opts.json) {
|
|
122
|
+
console.log(JSON.stringify(result, null, 2));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
log.success("Signed out.");
|
|
126
|
+
}
|
|
127
|
+
export async function runMcpAdd(opts) {
|
|
128
|
+
const interactive = isInteractive(opts);
|
|
129
|
+
const values = {
|
|
130
|
+
org: opts.org ?? null,
|
|
131
|
+
baseUrl: opts.baseUrl,
|
|
132
|
+
clients: [...opts.clients],
|
|
133
|
+
scope: opts.scope ?? null,
|
|
134
|
+
dryRun: opts.dryRun,
|
|
135
|
+
};
|
|
136
|
+
if (interactive) {
|
|
137
|
+
Object.assign(values, await promptMcpWizard(values));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (!values.org)
|
|
141
|
+
throw new Error("Missing --org for non-interactive mcp add");
|
|
142
|
+
if (!values.scope)
|
|
143
|
+
throw new Error("Missing --scope for non-interactive mcp add");
|
|
144
|
+
if (values.clients.length === 0) {
|
|
145
|
+
throw new Error("Missing --client for non-interactive mcp add");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const org = values.org;
|
|
149
|
+
const scope = values.scope;
|
|
150
|
+
const clients = values.clients;
|
|
151
|
+
if (!org)
|
|
152
|
+
throw new Error("Missing --org");
|
|
153
|
+
if (!scope)
|
|
154
|
+
throw new Error("Missing --scope");
|
|
155
|
+
validateScope(scope);
|
|
156
|
+
validateClients(clients);
|
|
157
|
+
const operations = buildMcpOperations({
|
|
158
|
+
clients,
|
|
159
|
+
baseUrl: values.baseUrl,
|
|
160
|
+
org,
|
|
161
|
+
scope,
|
|
162
|
+
context: createOperationContext({ commandExists }),
|
|
163
|
+
});
|
|
164
|
+
// mcp add does not toggle memory; users opt-in through `ctxpipe memory init`.
|
|
165
|
+
await confirmAndApply({
|
|
166
|
+
operations,
|
|
167
|
+
json: opts.json,
|
|
168
|
+
nonInteractive: opts.nonInteractive,
|
|
169
|
+
interactive,
|
|
170
|
+
dryRun: values.dryRun,
|
|
171
|
+
introShown: interactive,
|
|
172
|
+
setupSummary: [
|
|
173
|
+
`Organization ${org}`,
|
|
174
|
+
`Scope ${scopeLabel(scope)}`,
|
|
175
|
+
`Agents ${agentsLabel(clients, true)}`,
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
export function runDoctor(opts) {
|
|
180
|
+
const data = {
|
|
181
|
+
version: packageVersion,
|
|
182
|
+
node: process.version,
|
|
183
|
+
cwd: process.cwd(),
|
|
184
|
+
package: "ctxpipe",
|
|
185
|
+
detectedClients: Object.fromEntries(CLIENTS.map((client) => [client, commandExists(CLIENT_COMMANDS[client])])),
|
|
186
|
+
};
|
|
187
|
+
if (opts.json) {
|
|
188
|
+
console.log(JSON.stringify(data, null, 2));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
printDoctorTable(data);
|
|
192
|
+
}
|
|
193
|
+
export async function confirmAndApply({ operations, json, nonInteractive, interactive, dryRun, introShown, setupSummary, successMessage = "ctxpipe is connected", outroMessage = "Setup complete.", }) {
|
|
194
|
+
if (operations.length === 0) {
|
|
195
|
+
writeResult(json, { status: "noop", operations: [] });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const summary = operations.map(describeOperation);
|
|
199
|
+
if (json) {
|
|
200
|
+
if (!dryRun && !nonInteractive) {
|
|
201
|
+
throw new Error("Refusing to apply changes without --non-interactive in JSON mode");
|
|
202
|
+
}
|
|
203
|
+
const result = dryRun
|
|
204
|
+
? { status: "dry-run", operations: summary }
|
|
205
|
+
: applyOperations(operations);
|
|
206
|
+
writeResult(json, result);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!introShown) {
|
|
210
|
+
intro(`${brandName()} setup`);
|
|
211
|
+
}
|
|
212
|
+
if (setupSummary && setupSummary.length > 0) {
|
|
213
|
+
note(setupSummary.join("\n"), "Setup choices");
|
|
214
|
+
}
|
|
215
|
+
note(operations.map((op) => `+ ${describeOperation(op)}`).join("\n"), dryRun ? "Planned changes" : "Ready to apply");
|
|
216
|
+
if (dryRun) {
|
|
217
|
+
outro("Dry run complete. No files or client configs were changed.");
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (!nonInteractive) {
|
|
221
|
+
if (!interactive) {
|
|
222
|
+
throw new Error("Refusing to apply changes without --non-interactive in non-interactive mode");
|
|
223
|
+
}
|
|
224
|
+
const ok = await promptConfirm("Apply these changes?", true);
|
|
225
|
+
if (!ok) {
|
|
226
|
+
outro("No changes made.");
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const applied = [];
|
|
231
|
+
await tasks(operations.map((op) => ({
|
|
232
|
+
title: describeOperation(op),
|
|
233
|
+
task: () => {
|
|
234
|
+
const result = applyOperation(op);
|
|
235
|
+
applied.push(result);
|
|
236
|
+
return describeAppliedItem(result);
|
|
237
|
+
},
|
|
238
|
+
})));
|
|
239
|
+
if (applied.some((item) => item.status === "manual")) {
|
|
240
|
+
note(applied.map(describeAppliedItem).join("\n"), "Manual follow-up");
|
|
241
|
+
}
|
|
242
|
+
log.success(successMessage);
|
|
243
|
+
log.info("Your agents may ask you to approve ctx| the first time they use MCP.");
|
|
244
|
+
outro(outroMessage);
|
|
245
|
+
}
|
|
246
|
+
function scopeLabel(scope) {
|
|
247
|
+
if (scope === "repo")
|
|
248
|
+
return "This repo";
|
|
249
|
+
if (scope === "user")
|
|
250
|
+
return "Globally";
|
|
251
|
+
if (scope === "both")
|
|
252
|
+
return "This repo and globally";
|
|
253
|
+
return scope;
|
|
254
|
+
}
|
|
255
|
+
function agentsLabel(clients, mcpEnabled) {
|
|
256
|
+
if (!mcpEnabled)
|
|
257
|
+
return "MCP disabled";
|
|
258
|
+
if (clients.length === 0)
|
|
259
|
+
return "None selected";
|
|
260
|
+
return clients
|
|
261
|
+
.map((client) => CLIENT_LABELS[client] ?? client)
|
|
262
|
+
.join(", ");
|
|
263
|
+
}
|
|
264
|
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;QAAE,OAAO,cAAc,CAAA;IACtC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,eAAe,CAAA;IAChD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAgB,CAAC,IAAI,MAAM,CAAC;SAC1D,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DEFAULT_BASE_URL = "https://app.ctxpipe.ai";
|
|
2
|
+
export declare const AUTH_CLIENT_ID = "ctxpipe-cli";
|
|
3
|
+
export declare const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
4
|
+
export declare const CLIENTS: readonly ["codex", "claude", "cursor", "opencode", "vscode"];
|
|
5
|
+
export type Client = (typeof CLIENTS)[number];
|
|
6
|
+
export type Scope = "repo" | "user" | "both";
|
|
7
|
+
export declare const CLIENT_LABELS: Record<Client, string>;
|
|
8
|
+
export declare const CLIENT_COMMANDS: Record<Client, string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const DEFAULT_BASE_URL = "https://app.ctxpipe.ai";
|
|
2
|
+
export const AUTH_CLIENT_ID = "ctxpipe-cli";
|
|
3
|
+
export const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
4
|
+
export const CLIENTS = ["codex", "claude", "cursor", "opencode", "vscode"];
|
|
5
|
+
export const CLIENT_LABELS = {
|
|
6
|
+
codex: "Codex",
|
|
7
|
+
claude: "Claude Code",
|
|
8
|
+
cursor: "Cursor",
|
|
9
|
+
opencode: "OpenCode",
|
|
10
|
+
vscode: "VS Code / Copilot",
|
|
11
|
+
};
|
|
12
|
+
export const CLIENT_COMMANDS = {
|
|
13
|
+
codex: "codex",
|
|
14
|
+
claude: "claude",
|
|
15
|
+
cursor: "cursor",
|
|
16
|
+
opencode: "opencode",
|
|
17
|
+
vscode: "code",
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAA;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAA;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAA;AAE/E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAA;AAKnF,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,mBAAmB;CAC5B,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,MAAM;CACf,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonObject } from "./mcp/json.js";
|
|
2
|
+
import type { Operation } from "./mcp/mcp-operations.js";
|
|
3
|
+
export type ApplyOperationResult = {
|
|
4
|
+
status: "written" | "unchanged" | "created" | "skipped";
|
|
5
|
+
path: string;
|
|
6
|
+
} | {
|
|
7
|
+
status: "ran" | "manual";
|
|
8
|
+
detail: string;
|
|
9
|
+
};
|
|
10
|
+
export type ApplyResult = {
|
|
11
|
+
status: "ok";
|
|
12
|
+
operations: ApplyOperationResult[];
|
|
13
|
+
};
|
|
14
|
+
export declare function readJsonObject(path: string): JsonObject;
|
|
15
|
+
export declare function applyOperations(operations: Operation[]): ApplyResult;
|
|
16
|
+
export declare function applyOperation(op: Operation): ApplyOperationResult;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { parseJsonObject } from "./mcp/json.js";
|
|
5
|
+
export function readJsonObject(path) {
|
|
6
|
+
return parseJsonObject(existsSync(path) ? readFileSync(path, "utf8") : null);
|
|
7
|
+
}
|
|
8
|
+
export function applyOperations(operations) {
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const op of operations) {
|
|
11
|
+
results.push(applyOperation(op));
|
|
12
|
+
}
|
|
13
|
+
return { status: "ok", operations: results };
|
|
14
|
+
}
|
|
15
|
+
export function applyOperation(op) {
|
|
16
|
+
if (op.type === "write-json") {
|
|
17
|
+
const existing = readJsonObject(op.path);
|
|
18
|
+
const next = `${JSON.stringify(op.content(existing), null, 2)}\n`;
|
|
19
|
+
const previous = existsSync(op.path) ? readFileSync(op.path, "utf8") : null;
|
|
20
|
+
if (previous === next) {
|
|
21
|
+
return { status: "unchanged", path: op.path };
|
|
22
|
+
}
|
|
23
|
+
mkdirSync(dirname(op.path), { recursive: true });
|
|
24
|
+
writeFileSync(op.path, next, "utf8");
|
|
25
|
+
return { status: "written", path: op.path };
|
|
26
|
+
}
|
|
27
|
+
if (op.type === "write-text") {
|
|
28
|
+
if (op.skipIfExists && existsSync(op.path)) {
|
|
29
|
+
return { status: "skipped", path: op.path };
|
|
30
|
+
}
|
|
31
|
+
const previous = existsSync(op.path) ? readFileSync(op.path, "utf8") : null;
|
|
32
|
+
const next = op.content(previous);
|
|
33
|
+
if (previous === next) {
|
|
34
|
+
return { status: "unchanged", path: op.path };
|
|
35
|
+
}
|
|
36
|
+
mkdirSync(dirname(op.path), { recursive: true });
|
|
37
|
+
writeFileSync(op.path, next, "utf8");
|
|
38
|
+
return { status: "written", path: op.path };
|
|
39
|
+
}
|
|
40
|
+
if (op.type === "mkdir") {
|
|
41
|
+
if (existsSync(op.path)) {
|
|
42
|
+
return { status: "unchanged", path: op.path };
|
|
43
|
+
}
|
|
44
|
+
mkdirSync(op.path, { recursive: true });
|
|
45
|
+
return { status: "created", path: op.path };
|
|
46
|
+
}
|
|
47
|
+
if (op.type === "run") {
|
|
48
|
+
const command = op.command[0];
|
|
49
|
+
if (!command)
|
|
50
|
+
throw new Error("Cannot run an empty command");
|
|
51
|
+
const result = spawnSync(command, op.command.slice(1), {
|
|
52
|
+
encoding: "utf8",
|
|
53
|
+
stdio: "pipe",
|
|
54
|
+
});
|
|
55
|
+
if (result.status !== 0) {
|
|
56
|
+
throw new Error(`${op.command.join(" ")} failed: ${result.stderr || result.stdout}`);
|
|
57
|
+
}
|
|
58
|
+
return { status: "ran", detail: op.command.join(" ") };
|
|
59
|
+
}
|
|
60
|
+
return { status: "manual", detail: op.detail };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=fs-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-operations.js","sourceRoot":"","sources":["../src/fs-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAY/C,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC9E,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,UAAuB;IACrD,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC5B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6B,CAAC,CAAA;QAC5D,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACrD,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,MAAM;SACd,CAAC,CAAA;QACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACtF,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACxD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAA;AAChD,CAAC"}
|
package/dist/mcp/json.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function isObject(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function parseJsonObject(value) {
|
|
5
|
+
if (value == null)
|
|
6
|
+
return {};
|
|
7
|
+
try {
|
|
8
|
+
const parsed = JSON.parse(value);
|
|
9
|
+
return isObject(parsed) ? parsed : {};
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/mcp/json.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAE5B,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACzC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Client, Scope } from "../constants.js";
|
|
2
|
+
import type { JsonObject } from "./json.js";
|
|
3
|
+
export type WriteJsonOperation = {
|
|
4
|
+
type: "write-json";
|
|
5
|
+
path: string;
|
|
6
|
+
description: string;
|
|
7
|
+
content: (existing?: JsonObject) => JsonObject;
|
|
8
|
+
};
|
|
9
|
+
export type RunOperation = {
|
|
10
|
+
type: "run";
|
|
11
|
+
command: string[];
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
export type ManualOperation = {
|
|
15
|
+
type: "manual";
|
|
16
|
+
description: string;
|
|
17
|
+
detail: string;
|
|
18
|
+
};
|
|
19
|
+
export type WriteTextOperation = {
|
|
20
|
+
type: "write-text";
|
|
21
|
+
path: string;
|
|
22
|
+
description: string;
|
|
23
|
+
/** If true, never overwrite an existing file. */
|
|
24
|
+
skipIfExists?: boolean;
|
|
25
|
+
content: (existing?: string | null) => string;
|
|
26
|
+
};
|
|
27
|
+
export type MkdirOperation = {
|
|
28
|
+
type: "mkdir";
|
|
29
|
+
path: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
export type Operation = WriteJsonOperation | RunOperation | ManualOperation | WriteTextOperation | MkdirOperation;
|
|
33
|
+
export type OperationContext = {
|
|
34
|
+
cwd: string;
|
|
35
|
+
homeDir: string;
|
|
36
|
+
commandExists: (command: string) => boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare function createOperationContext(overrides?: Partial<OperationContext>): OperationContext;
|
|
39
|
+
export declare function buildCtxpipeConfigOperation({ baseUrl, org, context, }: {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
org: string;
|
|
42
|
+
context?: OperationContext;
|
|
43
|
+
}): WriteJsonOperation;
|
|
44
|
+
/** Memory-only init: records org/baseUrl when org is known; preserves existing org on re-run. */
|
|
45
|
+
export declare function buildMemoryConfigOperation({ org, baseUrl, context, }: {
|
|
46
|
+
org?: string | null;
|
|
47
|
+
baseUrl: string;
|
|
48
|
+
context?: OperationContext;
|
|
49
|
+
}): WriteJsonOperation;
|
|
50
|
+
export declare function buildMemoryArtifactOperations({ context, }?: {
|
|
51
|
+
context?: OperationContext;
|
|
52
|
+
}): Operation[];
|
|
53
|
+
export declare function buildClaudeHooksOperation({ context, }?: {
|
|
54
|
+
context?: OperationContext;
|
|
55
|
+
}): WriteJsonOperation;
|
|
56
|
+
export declare function buildMemoryMcpOperations({ clients, baseUrl, org, scope, context, }: {
|
|
57
|
+
clients: Client[];
|
|
58
|
+
baseUrl: string;
|
|
59
|
+
org?: string | null;
|
|
60
|
+
scope: Scope;
|
|
61
|
+
context?: OperationContext;
|
|
62
|
+
}): Operation[];
|
|
63
|
+
export declare function buildMcpOperations({ clients, baseUrl, org, scope, memory, context, }: {
|
|
64
|
+
clients: Client[];
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
org: string;
|
|
67
|
+
scope: Scope;
|
|
68
|
+
memory?: boolean;
|
|
69
|
+
context?: OperationContext;
|
|
70
|
+
}): Operation[];
|
|
71
|
+
export declare function buildClientOperations({ client, baseUrl, org, scope, memory, memoryOnly, context, }: {
|
|
72
|
+
client: Client;
|
|
73
|
+
baseUrl: string;
|
|
74
|
+
org: string;
|
|
75
|
+
scope: "repo" | "user";
|
|
76
|
+
memory?: boolean;
|
|
77
|
+
memoryOnly?: boolean;
|
|
78
|
+
context?: OperationContext;
|
|
79
|
+
}): Operation[];
|
|
80
|
+
export declare function writeMcpServersOperation({ path, url, label, cwd, memory, memoryOnly, }: {
|
|
81
|
+
path: string;
|
|
82
|
+
url: string;
|
|
83
|
+
label: string;
|
|
84
|
+
cwd: string;
|
|
85
|
+
memory?: boolean;
|
|
86
|
+
memoryOnly?: boolean;
|
|
87
|
+
}): WriteJsonOperation;
|
|
88
|
+
export declare function writeOpenCodeOperation({ path, url, cwd, memory, memoryOnly, }: {
|
|
89
|
+
path: string;
|
|
90
|
+
url: string;
|
|
91
|
+
cwd: string;
|
|
92
|
+
memory?: boolean;
|
|
93
|
+
memoryOnly?: boolean;
|
|
94
|
+
}): WriteJsonOperation;
|
|
95
|
+
export declare function writeVsCodeOperation({ path, url, cwd, memory, memoryOnly, }: {
|
|
96
|
+
path: string;
|
|
97
|
+
url: string;
|
|
98
|
+
cwd: string;
|
|
99
|
+
memory?: boolean;
|
|
100
|
+
memoryOnly?: boolean;
|
|
101
|
+
}): WriteJsonOperation;
|
|
102
|
+
export declare function validateScope(scope: string): asserts scope is Scope;
|
|
103
|
+
export declare function validateClients(clients: string[]): asserts clients is Client[];
|