ctxpipe 0.0.0-beta-20260528143132

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/bin/ctxpipe.js +9 -0
  4. package/dist/auth.d.ts +52 -0
  5. package/dist/auth.js +412 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/cli.d.ts +1 -0
  8. package/dist/cli.js +12 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/commands.d.ts +56 -0
  11. package/dist/commands.js +263 -0
  12. package/dist/commands.js.map +1 -0
  13. package/dist/constants.d.ts +8 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/fs-operations.d.ts +16 -0
  17. package/dist/fs-operations.js +62 -0
  18. package/dist/fs-operations.js.map +1 -0
  19. package/dist/mcp/json.d.ts +3 -0
  20. package/dist/mcp/json.js +15 -0
  21. package/dist/mcp/json.js.map +1 -0
  22. package/dist/mcp/mcp-operations.d.ts +106 -0
  23. package/dist/mcp/mcp-operations.js +492 -0
  24. package/dist/mcp/mcp-operations.js.map +1 -0
  25. package/dist/mcp/paths.d.ts +7 -0
  26. package/dist/mcp/paths.js +17 -0
  27. package/dist/mcp/paths.js.map +1 -0
  28. package/dist/memory/agentmemory-client.d.ts +24 -0
  29. package/dist/memory/agentmemory-client.js +47 -0
  30. package/dist/memory/agentmemory-client.js.map +1 -0
  31. package/dist/memory/hydration.d.ts +141 -0
  32. package/dist/memory/hydration.js +390 -0
  33. package/dist/memory/hydration.js.map +1 -0
  34. package/dist/memory/index.d.ts +4 -0
  35. package/dist/memory/index.js +5 -0
  36. package/dist/memory/index.js.map +1 -0
  37. package/dist/memory/markdown.d.ts +29 -0
  38. package/dist/memory/markdown.js +193 -0
  39. package/dist/memory/markdown.js.map +1 -0
  40. package/dist/memory/mcp-server.d.ts +48 -0
  41. package/dist/memory/mcp-server.js +322 -0
  42. package/dist/memory/mcp-server.js.map +1 -0
  43. package/dist/memory/paths.d.ts +13 -0
  44. package/dist/memory/paths.js +74 -0
  45. package/dist/memory/paths.js.map +1 -0
  46. package/dist/memory/policy.d.ts +16 -0
  47. package/dist/memory/policy.js +81 -0
  48. package/dist/memory/policy.js.map +1 -0
  49. package/dist/memory/run-hook.d.ts +13 -0
  50. package/dist/memory/run-hook.js +42 -0
  51. package/dist/memory/run-hook.js.map +1 -0
  52. package/dist/memory/run-init.d.ts +11 -0
  53. package/dist/memory/run-init.js +93 -0
  54. package/dist/memory/run-init.js.map +1 -0
  55. package/dist/memory/run-mcp.d.ts +3 -0
  56. package/dist/memory/run-mcp.js +5 -0
  57. package/dist/memory/run-mcp.js.map +1 -0
  58. package/dist/memory/run-meta.d.ts +11 -0
  59. package/dist/memory/run-meta.js +122 -0
  60. package/dist/memory/run-meta.js.map +1 -0
  61. package/dist/memory/supervisor.d.ts +49 -0
  62. package/dist/memory/supervisor.js +213 -0
  63. package/dist/memory/supervisor.js.map +1 -0
  64. package/dist/program.d.ts +1 -0
  65. package/dist/program.js +209 -0
  66. package/dist/program.js.map +1 -0
  67. package/dist/prompts.d.ts +42 -0
  68. package/dist/prompts.js +336 -0
  69. package/dist/prompts.js.map +1 -0
  70. package/dist/system.d.ts +3 -0
  71. package/dist/system.js +27 -0
  72. package/dist/system.js.map +1 -0
  73. package/dist/ui.d.ts +20 -0
  74. package/dist/ui.js +115 -0
  75. package/dist/ui.js.map +1 -0
  76. package/dist/version.d.ts +1 -0
  77. package/dist/version.js +4 -0
  78. package/dist/version.js.map +1 -0
  79. package/package.json +45 -0
@@ -0,0 +1,263 @@
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, 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
+ clients: agents,
56
+ memory: memoryEnabled,
57
+ context,
58
+ });
59
+ const mcpOps = answers.mcp
60
+ ? buildMcpOperations({
61
+ clients: agents,
62
+ baseUrl: answers.baseUrl,
63
+ org,
64
+ scope,
65
+ memory: memoryEnabled,
66
+ context,
67
+ })
68
+ : [];
69
+ const memoryOps = memoryEnabled ? buildMemoryArtifactOperations({ context }) : [];
70
+ const claudeHookOps = memoryEnabled && opts.claudeHooks && agents.includes("claude")
71
+ ? [buildClaudeHooksOperation({ context })]
72
+ : [];
73
+ const operations = [ctxpipeConfig, ...mcpOps, ...memoryOps, ...claudeHookOps];
74
+ await confirmAndApply({
75
+ operations,
76
+ json: opts.json,
77
+ nonInteractive: opts.nonInteractive,
78
+ interactive,
79
+ dryRun: answers.dryRun,
80
+ introShown: interactive,
81
+ setupSummary: [
82
+ `Organization ${org}`,
83
+ `Scope ${scopeLabel(scope)}`,
84
+ `Agents ${agentsLabel(agents, answers.mcp)}`,
85
+ `Memory ${memoryEnabled ? "enabled (local AgentMemory + .ai/memory)" : "disabled"}`,
86
+ ],
87
+ });
88
+ }
89
+ export async function runAuthLogin(opts) {
90
+ const auth = await loginWithDeviceFlow({ baseUrl: opts.baseUrl });
91
+ const session = await fetchSession({ baseUrl: opts.baseUrl, accessToken: auth.accessToken }).catch(() => null);
92
+ log.success(`Signed in as ${userLabel(session) ?? "ctx|"}.`);
93
+ }
94
+ export async function runAuthWhoami(opts) {
95
+ const auth = await readStoredAuth(opts.baseUrl);
96
+ if (!auth) {
97
+ const result = { status: "signed-out", baseUrl: normalizeBaseUrl(opts.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: opts.baseUrl, accessToken: auth.accessToken });
106
+ const result = {
107
+ status: "ok",
108
+ baseUrl: normalizeBaseUrl(opts.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
+ await removeStoredAuth(opts.baseUrl);
119
+ const result = { status: "ok", baseUrl: normalizeBaseUrl(opts.baseUrl) };
120
+ if (opts.json) {
121
+ console.log(JSON.stringify(result, null, 2));
122
+ return;
123
+ }
124
+ log.success("Signed out.");
125
+ }
126
+ export async function runMcpAdd(opts) {
127
+ const interactive = isInteractive(opts);
128
+ const values = {
129
+ org: opts.org ?? null,
130
+ baseUrl: opts.baseUrl,
131
+ clients: [...opts.clients],
132
+ scope: opts.scope ?? null,
133
+ dryRun: opts.dryRun,
134
+ };
135
+ if (interactive) {
136
+ Object.assign(values, await promptMcpWizard(values));
137
+ }
138
+ else {
139
+ if (!values.org)
140
+ throw new Error("Missing --org for non-interactive mcp add");
141
+ if (!values.scope)
142
+ throw new Error("Missing --scope for non-interactive mcp add");
143
+ if (values.clients.length === 0) {
144
+ throw new Error("Missing --client for non-interactive mcp add");
145
+ }
146
+ }
147
+ const org = values.org;
148
+ const scope = values.scope;
149
+ const clients = values.clients;
150
+ if (!org)
151
+ throw new Error("Missing --org");
152
+ if (!scope)
153
+ throw new Error("Missing --scope");
154
+ validateScope(scope);
155
+ validateClients(clients);
156
+ const operations = buildMcpOperations({
157
+ clients,
158
+ baseUrl: values.baseUrl,
159
+ org,
160
+ scope,
161
+ context: createOperationContext({ commandExists }),
162
+ });
163
+ // mcp add does not toggle memory; users opt-in through `ctxpipe memory init`.
164
+ await confirmAndApply({
165
+ operations,
166
+ json: opts.json,
167
+ nonInteractive: opts.nonInteractive,
168
+ interactive,
169
+ dryRun: values.dryRun,
170
+ introShown: interactive,
171
+ setupSummary: [
172
+ `Organization ${org}`,
173
+ `Scope ${scopeLabel(scope)}`,
174
+ `Agents ${agentsLabel(clients, true)}`,
175
+ ],
176
+ });
177
+ }
178
+ export function runDoctor(opts) {
179
+ const data = {
180
+ version: packageVersion,
181
+ node: process.version,
182
+ cwd: process.cwd(),
183
+ package: "ctxpipe",
184
+ detectedClients: Object.fromEntries(CLIENTS.map((client) => [client, commandExists(CLIENT_COMMANDS[client])])),
185
+ };
186
+ if (opts.json) {
187
+ console.log(JSON.stringify(data, null, 2));
188
+ return;
189
+ }
190
+ printDoctorTable(data);
191
+ }
192
+ export async function confirmAndApply({ operations, json, nonInteractive, interactive, dryRun, introShown, setupSummary, successMessage = "ctxpipe is connected", outroMessage = "Setup complete.", }) {
193
+ if (operations.length === 0) {
194
+ writeResult(json, { status: "noop", operations: [] });
195
+ return;
196
+ }
197
+ const summary = operations.map(describeOperation);
198
+ if (json) {
199
+ if (!dryRun && !nonInteractive) {
200
+ throw new Error("Refusing to apply changes without --non-interactive in JSON mode");
201
+ }
202
+ const result = dryRun
203
+ ? { status: "dry-run", operations: summary }
204
+ : applyOperations(operations);
205
+ writeResult(json, result);
206
+ return;
207
+ }
208
+ if (!introShown) {
209
+ intro(`${brandName()} setup`);
210
+ }
211
+ if (setupSummary && setupSummary.length > 0) {
212
+ note(setupSummary.join("\n"), "Setup choices");
213
+ }
214
+ note(operations.map((op) => `+ ${describeOperation(op)}`).join("\n"), dryRun ? "Planned changes" : "Ready to apply");
215
+ if (dryRun) {
216
+ outro("Dry run complete. No files or client configs were changed.");
217
+ return;
218
+ }
219
+ if (!nonInteractive) {
220
+ if (!interactive) {
221
+ throw new Error("Refusing to apply changes without --non-interactive in non-interactive mode");
222
+ }
223
+ const ok = await promptConfirm("Apply these changes?", true);
224
+ if (!ok) {
225
+ outro("No changes made.");
226
+ return;
227
+ }
228
+ }
229
+ const applied = [];
230
+ await tasks(operations.map((op) => ({
231
+ title: describeOperation(op),
232
+ task: () => {
233
+ const result = applyOperation(op);
234
+ applied.push(result);
235
+ return describeAppliedItem(result);
236
+ },
237
+ })));
238
+ if (applied.some((item) => item.status === "manual")) {
239
+ note(applied.map(describeAppliedItem).join("\n"), "Manual follow-up");
240
+ }
241
+ log.success(successMessage);
242
+ log.info("Your agents may ask you to approve ctx| the first time they use MCP.");
243
+ outro(outroMessage);
244
+ }
245
+ function scopeLabel(scope) {
246
+ if (scope === "repo")
247
+ return "This repo";
248
+ if (scope === "user")
249
+ return "Globally";
250
+ if (scope === "both")
251
+ return "This repo and globally";
252
+ return scope;
253
+ }
254
+ function agentsLabel(clients, mcpEnabled) {
255
+ if (!mcpEnabled)
256
+ return "MCP disabled";
257
+ if (clients.length === 0)
258
+ return "None selected";
259
+ return clients
260
+ .map((client) => CLIENT_LABELS[client] ?? client)
261
+ .join(", ");
262
+ }
263
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,SAAS,GACV,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpE,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,eAAe,EACf,aAAa,GAEd,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3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QAAE,OAAO,UAAU,CAAA;IACvC,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,wBAAwB,CAAA;IACrD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,WAAW,CAAC,OAAiB,EAAE,UAAmB;IACzD,IAAI,CAAC,UAAU;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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+1,3 @@
1
+ export type JsonObject = Record<string, unknown>;
2
+ export declare function isObject(value: unknown): value is JsonObject;
3
+ export declare function parseJsonObject(value: string | null): JsonObject;
@@ -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,106 @@
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, clients, memory, context, }: {
40
+ baseUrl: string;
41
+ org: string;
42
+ clients: Client[];
43
+ memory?: boolean;
44
+ context?: OperationContext;
45
+ }): WriteJsonOperation;
46
+ /** Memory-only init: sets memory stanza and client list; org/url only when org is known. */
47
+ export declare function buildMemoryConfigOperation({ org, baseUrl, clients, context, }: {
48
+ org?: string | null;
49
+ baseUrl: string;
50
+ clients: Client[];
51
+ context?: OperationContext;
52
+ }): WriteJsonOperation;
53
+ export declare function buildMemoryArtifactOperations({ context, }?: {
54
+ context?: OperationContext;
55
+ }): Operation[];
56
+ export declare function buildClaudeHooksOperation({ context, }?: {
57
+ context?: OperationContext;
58
+ }): WriteJsonOperation;
59
+ export declare function buildMemoryMcpOperations({ clients, baseUrl, org, scope, context, }: {
60
+ clients: Client[];
61
+ baseUrl: string;
62
+ org?: string | null;
63
+ scope: Scope;
64
+ context?: OperationContext;
65
+ }): Operation[];
66
+ export declare function buildMcpOperations({ clients, baseUrl, org, scope, memory, context, }: {
67
+ clients: Client[];
68
+ baseUrl: string;
69
+ org: string;
70
+ scope: Scope;
71
+ memory?: boolean;
72
+ context?: OperationContext;
73
+ }): Operation[];
74
+ export declare function buildClientOperations({ client, baseUrl, org, scope, memory, memoryOnly, context, }: {
75
+ client: Client;
76
+ baseUrl: string;
77
+ org: string;
78
+ scope: "repo" | "user";
79
+ memory?: boolean;
80
+ memoryOnly?: boolean;
81
+ context?: OperationContext;
82
+ }): Operation[];
83
+ export declare function writeMcpServersOperation({ path, url, label, cwd, memory, memoryOnly, }: {
84
+ path: string;
85
+ url: string;
86
+ label: string;
87
+ cwd: string;
88
+ memory?: boolean;
89
+ memoryOnly?: boolean;
90
+ }): WriteJsonOperation;
91
+ export declare function writeOpenCodeOperation({ path, url, cwd, memory, memoryOnly, }: {
92
+ path: string;
93
+ url: string;
94
+ cwd: string;
95
+ memory?: boolean;
96
+ memoryOnly?: boolean;
97
+ }): WriteJsonOperation;
98
+ export declare function writeVsCodeOperation({ path, url, cwd, memory, memoryOnly, }: {
99
+ path: string;
100
+ url: string;
101
+ cwd: string;
102
+ memory?: boolean;
103
+ memoryOnly?: boolean;
104
+ }): WriteJsonOperation;
105
+ export declare function validateScope(scope: string): asserts scope is Scope;
106
+ export declare function validateClients(clients: string[]): asserts clients is Client[];