@octen.ai/cli 0.13.1 → 0.15.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 +54 -4
- package/dist/api/errors.d.ts +4 -0
- package/dist/api/errors.js +8 -0
- package/dist/cli.js +2 -0
- package/dist/commands/completion.js +79 -24
- package/dist/commands/configureMcp.js +18 -3
- package/dist/commands/monitor/client.d.ts +6 -0
- package/dist/commands/monitor/client.js +9 -0
- package/dist/commands/monitor/confirm.d.ts +5 -0
- package/dist/commands/monitor/confirm.js +19 -0
- package/dist/commands/monitor/errors.d.ts +5 -0
- package/dist/commands/monitor/errors.js +38 -0
- package/dist/commands/monitor/index.d.ts +13 -0
- package/dist/commands/monitor/index.js +252 -0
- package/dist/commands/monitor/options.d.ts +45 -0
- package/dist/commands/monitor/options.js +187 -0
- package/dist/commands/reset.js +2 -0
- package/dist/mcp/clients.d.ts +8 -2
- package/dist/mcp/clients.js +26 -1
- package/dist/mcp/install.d.ts +10 -5
- package/dist/mcp/install.js +1 -1
- package/dist/mcp/write.js +2 -3
- package/dist/output/pretty/monitor.d.ts +7 -0
- package/dist/output/pretty/monitor.js +142 -0
- package/dist/util/detectClient.js +6 -0
- package/package.json +3 -2
- package/skills/manifest.json +1 -0
- package/skills/octen-monitor/SKILL.md +313 -0
- package/skills/octen-monitor/agents/openai.yaml +4 -0
- package/skills/octen-web-search/SKILL.md +6 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { chooseMode, emit } from "../../output/render.js";
|
|
2
|
+
import { renderDeleted, renderEvents, renderMonitor, renderMonitorList, renderRun, renderRuns, renderTriggered, } from "../../output/pretty/monitor.js";
|
|
3
|
+
import { OctenCancelledError, OctenValidationError } from "../../api/errors.js";
|
|
4
|
+
import { confirm } from "./confirm.js";
|
|
5
|
+
import { printableLine } from "../../util/terminalText.js";
|
|
6
|
+
import { parseCsvOpt, parseIntOpt } from "../utils.js";
|
|
7
|
+
import { makeMonitorClient } from "./client.js";
|
|
8
|
+
import { annotateMonitorError, incompleteReply, mayHaveApplied } from "./errors.js";
|
|
9
|
+
import { OctenAPIError as CliAPIError } from "../../api/errors.js";
|
|
10
|
+
import { buildCreateParams, buildEventsParams, buildListParams, buildRunsParams, buildUpdateParams, needsTypeLookup, parseChoiceOpt, parseField, parseMetadata, readParams, } from "./options.js";
|
|
11
|
+
const collect = (v, prev = []) => [...prev, v];
|
|
12
|
+
export function globalsOf(command) {
|
|
13
|
+
return command.optsWithGlobals();
|
|
14
|
+
}
|
|
15
|
+
export function output(g, res, render) {
|
|
16
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), render);
|
|
17
|
+
}
|
|
18
|
+
/** Run one SDK call; `write` marks calls the SDK does not retry once sent. */
|
|
19
|
+
export async function call(write, fn, advice) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
throw annotateMonitorError(e, write, advice);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Require the field a write must return (and, for an existing monitor, its own id) before reporting success. */
|
|
28
|
+
function written(res, field, advice, expectedId) {
|
|
29
|
+
const value = res?.data?.[field];
|
|
30
|
+
if (!value || (expectedId !== undefined && value !== expectedId))
|
|
31
|
+
throw incompleteReply(`${field}${expectedId ? ` ${expectedId}` : ""}`, advice);
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
// Single-quoted for POSIX shells, so a copied hint keeps characters such as & and ? intact.
|
|
35
|
+
function shellQuote(v) {
|
|
36
|
+
return `'${v.replace(/'/g, "'\\''")}'`;
|
|
37
|
+
}
|
|
38
|
+
// An empty page is a list; a reply without the list is not, and must not print "No monitors".
|
|
39
|
+
function listed(res, field) {
|
|
40
|
+
if (!Array.isArray(res?.data?.[field])) {
|
|
41
|
+
throw incompleteReply(`data.${field}`, "This was a read, so running the command again is safe.");
|
|
42
|
+
}
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
function addSettingOptions(cmd, update) {
|
|
46
|
+
return cmd
|
|
47
|
+
.option("--topic <query>", update ? "new search query (topic monitors)" : "watch new results for this search query")
|
|
48
|
+
.option("--page <url>", update ? "replace the watched URLs (page monitors), repeatable" : "watch this page for changes, repeatable (up to 10)", collect)
|
|
49
|
+
.option("--field <name:type[:description]>", "field to extract, type string|number|boolean, repeatable", (v, p) => parseField(v, p))
|
|
50
|
+
.option("--include-domains <list>", "topic monitors: comma list of domains to search", parseCsvOpt("--include-domains"))
|
|
51
|
+
.option("--exclude-domains <list>", "topic monitors: comma list of domains to leave out", parseCsvOpt("--exclude-domains"))
|
|
52
|
+
.option("--name <name>", "monitor name")
|
|
53
|
+
.option("--condition <text>", "when to notify, in plain language")
|
|
54
|
+
.option("--interval <every>", "5m-59m, 1h-100h or 1d-30d" + (update ? "" : " (default 1h)"))
|
|
55
|
+
.option("--cron <expr>", "cron schedule instead of --interval, runs at least 5 minutes apart")
|
|
56
|
+
.option("--timezone <tz>", "IANA time zone for --cron (default UTC)")
|
|
57
|
+
.option("--webhook <url>", "https URL to push events to")
|
|
58
|
+
.option("--email <address>", update ? "email address, repeatable; replaces all existing recipients" : "email address for notifications, repeatable", collect)
|
|
59
|
+
.option("--metadata <key=value>", update ? "key=value pair, repeatable; replaces all existing metadata" : "key=value pair, repeatable", (v, p) => parseMetadata(v, p))
|
|
60
|
+
.option("--params <json|@file>", "more request fields as JSON, merged with the options above", readParams);
|
|
61
|
+
}
|
|
62
|
+
export function registerMonitor(program) {
|
|
63
|
+
const monitor = program
|
|
64
|
+
.command("monitor")
|
|
65
|
+
.description("Watch a topic or pages on a schedule and get notified when something changes");
|
|
66
|
+
addSettingOptions(monitor.command("create").description("Create a monitor; its first run starts right away"), false)
|
|
67
|
+
.action(async (opts, command) => {
|
|
68
|
+
const g = globalsOf(command);
|
|
69
|
+
const params = buildCreateParams(opts);
|
|
70
|
+
const client = makeMonitorClient(g);
|
|
71
|
+
const createCheck = params.webhook?.url
|
|
72
|
+
? "The monitor may already exist: check with `octen monitor list` and do not create it again. Its one-time webhook " +
|
|
73
|
+
"secret cannot be read back, so once you find it, run `octen monitor update <id> --rotate-secret` and set the new secret on your receiver."
|
|
74
|
+
: undefined;
|
|
75
|
+
const created = written(await call(true, () => client.monitors.create(params), createCheck), "monitor_id", createCheck);
|
|
76
|
+
// The secret is returned only once; without it the new monitor's webhook cannot be verified.
|
|
77
|
+
const createdId = created.data.monitor_id;
|
|
78
|
+
if (params.webhook?.url && !created.data.webhook?.secret) {
|
|
79
|
+
throw new CliAPIError(`Monitor ${createdId} was created, but the reply has no webhook secret. Do not create it again; ` +
|
|
80
|
+
`rotate the secret with \`octen monitor update ${createdId} --rotate-secret\` and set it on your receiver.`, 200);
|
|
81
|
+
}
|
|
82
|
+
output(g, created, renderMonitor);
|
|
83
|
+
});
|
|
84
|
+
monitor
|
|
85
|
+
.command("list")
|
|
86
|
+
.description("List monitors")
|
|
87
|
+
.option("--status <status>", "active|paused", parseChoiceOpt("--status", ["active", "paused"]))
|
|
88
|
+
.option("--name <text>", "filter by name")
|
|
89
|
+
.option("--limit <n>", "1-100", parseIntOpt("--limit"))
|
|
90
|
+
.option("--cursor <cursor>", "next_cursor from the previous page")
|
|
91
|
+
.option("--page-no <n>", "page number, instead of --cursor", parseIntOpt("--page-no"))
|
|
92
|
+
.action(async (opts, command) => {
|
|
93
|
+
const g = globalsOf(command);
|
|
94
|
+
const client = makeMonitorClient(g);
|
|
95
|
+
output(g, listed(await call(false, () => client.monitors.list(buildListParams(opts))), "monitors"), renderMonitorList);
|
|
96
|
+
});
|
|
97
|
+
monitor
|
|
98
|
+
.command("get")
|
|
99
|
+
.argument("<id>", "monitor id")
|
|
100
|
+
.description("Show a monitor")
|
|
101
|
+
.action(async (id, _opts, command) => {
|
|
102
|
+
const g = globalsOf(command);
|
|
103
|
+
const client = makeMonitorClient(g);
|
|
104
|
+
output(g, await call(false, () => client.monitors.get(id)), renderMonitor);
|
|
105
|
+
});
|
|
106
|
+
addSettingOptions(monitor.command("update").argument("<id>", "monitor id").description("Change a monitor; sends only the options given"), true)
|
|
107
|
+
.option("--status <status>", "active|paused", parseChoiceOpt("--status", ["active", "paused"]))
|
|
108
|
+
.option("--clear <fields>", "remove fields: comma list of condition, webhook, email, metadata", parseCsvOpt("--clear"))
|
|
109
|
+
.option("--rotate-secret", "issue a new webhook signing secret")
|
|
110
|
+
.action(async (id, opts, command) => {
|
|
111
|
+
const g = globalsOf(command);
|
|
112
|
+
const client = makeMonitorClient(g);
|
|
113
|
+
let type;
|
|
114
|
+
let current;
|
|
115
|
+
// Only a newly added webhook returns its secret, so a URL update needs to know whether one exists.
|
|
116
|
+
if (needsTypeLookup(opts) || opts.webhook !== undefined || opts.params?.webhook !== undefined) {
|
|
117
|
+
current = await call(false, () => client.monitors.get(id));
|
|
118
|
+
type = current?.data?.type;
|
|
119
|
+
}
|
|
120
|
+
const params = buildUpdateParams(opts, type);
|
|
121
|
+
const rotating = Boolean(params.webhook?.rotate_secret);
|
|
122
|
+
const adding = Boolean(params.webhook?.url) && current !== undefined && !current?.data?.webhook?.url;
|
|
123
|
+
// A rotation cannot be read back (no endpoint returns the secret), so an unknown outcome needs its own advice.
|
|
124
|
+
const newUrl = params.webhook?.url;
|
|
125
|
+
if (newUrl !== undefined && newUrl !== null && typeof newUrl !== "string") {
|
|
126
|
+
throw new OctenValidationError("--params: webhook.url must be a string");
|
|
127
|
+
}
|
|
128
|
+
const rotationCheck = "The rotation may already have happened and the old secret may already be invalid; no endpoint returns the secret, " +
|
|
129
|
+
"so do not retry blindly: " +
|
|
130
|
+
(newUrl
|
|
131
|
+
? `check with \`octen monitor get ${id}\` whether webhook.url changed, then rotate once more on purpose ` +
|
|
132
|
+
`(add --webhook ${shellQuote(newUrl)} if it did not) and update your receiver with the new secret.`
|
|
133
|
+
: "rotate once more on purpose and update your receiver with the new secret.");
|
|
134
|
+
const urlCheck = `Check with \`octen monitor get ${id}\` whether webhook.url changed. If the webhook was newly added, its one-time secret ` +
|
|
135
|
+
"was lost with the reply and cannot be read back: rotate it on purpose with --rotate-secret and update your receiver.";
|
|
136
|
+
const advice = rotating ? rotationCheck : params.webhook?.url ? urlCheck : undefined;
|
|
137
|
+
const updated = written(await call(true, () => client.monitors.update(id, params), advice), "monitor_id", advice, id);
|
|
138
|
+
if (rotating && !updated?.data?.webhook?.secret)
|
|
139
|
+
throw incompleteReply("new webhook secret", rotationCheck);
|
|
140
|
+
if (adding && !updated?.data?.webhook?.secret) {
|
|
141
|
+
throw incompleteReply("new webhook secret", "The monitor had no webhook just before this update, so the webhook was probably added and its one-time secret is lost " +
|
|
142
|
+
`(unless another client added a webhook meanwhile). Check with \`octen monitor get ${id}\`; if your receiver has no ` +
|
|
143
|
+
"working secret, rotate it on purpose with --rotate-secret and update your receiver.");
|
|
144
|
+
}
|
|
145
|
+
output(g, updated, renderMonitor);
|
|
146
|
+
});
|
|
147
|
+
for (const [name, status] of [["pause", "paused"], ["resume", "active"]]) {
|
|
148
|
+
monitor
|
|
149
|
+
.command(name)
|
|
150
|
+
.argument("<id>", "monitor id")
|
|
151
|
+
.description(name === "pause" ? "Stop scheduled runs" : "Start scheduled runs again")
|
|
152
|
+
.action(async (id, _opts, command) => {
|
|
153
|
+
const g = globalsOf(command);
|
|
154
|
+
const client = makeMonitorClient(g);
|
|
155
|
+
const updated = written(await call(true, () => client.monitors.update(id, { status })), "monitor_id", undefined, id);
|
|
156
|
+
if (updated?.data?.status !== status)
|
|
157
|
+
throw incompleteReply(`status "${status}"`);
|
|
158
|
+
output(g, updated, renderMonitor);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
monitor
|
|
162
|
+
.command("delete")
|
|
163
|
+
.argument("<id>", "monitor id")
|
|
164
|
+
.description("Delete a monitor (cannot be undone); asks first unless --yes")
|
|
165
|
+
.option("--yes", "delete without asking (required when not run in a terminal)")
|
|
166
|
+
.action(async (id, opts, command) => {
|
|
167
|
+
const g = globalsOf(command);
|
|
168
|
+
if (!opts.yes && !(process.stdin.isTTY && process.stdout.isTTY && process.stderr.isTTY)) {
|
|
169
|
+
throw new OctenValidationError("not deleting: not running in a terminal, so pass --yes to confirm");
|
|
170
|
+
}
|
|
171
|
+
const client = makeMonitorClient(g);
|
|
172
|
+
if (!opts.yes) {
|
|
173
|
+
const describe = async () => {
|
|
174
|
+
const m = (await call(false, () => client.monitors.get(id)))?.data;
|
|
175
|
+
// The prompt must describe the monitor that will be deleted.
|
|
176
|
+
if (!m || m.monitor_id !== id) {
|
|
177
|
+
throw new OctenValidationError(`not deleting: the lookup did not return monitor ${id}`);
|
|
178
|
+
}
|
|
179
|
+
const inc = m.topic?.include_domains ?? [];
|
|
180
|
+
const exc = m.topic?.exclude_domains ?? [];
|
|
181
|
+
const what = m.topic?.query
|
|
182
|
+
? `topic "${m.topic.query}"${inc.length ? `, only ${inc.join(", ")}` : ""}${exc.length ? `, not ${exc.join(", ")}` : ""}`
|
|
183
|
+
: (m.page?.urls ?? []).join(", ");
|
|
184
|
+
const raw = JSON.stringify([m.name, m.type, m.topic?.query ?? null, inc, exc, m.page?.urls ?? null]);
|
|
185
|
+
return { shown: printableLine(`"${m.name}" (${m.monitor_id}, ${m.type}: ${what})`), raw };
|
|
186
|
+
};
|
|
187
|
+
const first = await describe();
|
|
188
|
+
if (!(await confirm(`Delete monitor ${first.shown}? This cannot be undone. [y/N] `)))
|
|
189
|
+
throw new OctenCancelledError();
|
|
190
|
+
// Someone may have changed it while the prompt was open; compare the raw values, not the display text.
|
|
191
|
+
if ((await describe()).raw !== first.raw) {
|
|
192
|
+
throw new OctenValidationError(`not deleting: monitor ${id} changed while you were confirming; run delete again`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const gone = mayHaveApplied(`\`octen monitor get ${id}\` (404101 means it is deleted)`);
|
|
196
|
+
const deleted = written(await call(true, () => client.monitors.delete(id), gone), "monitor_id", gone, id);
|
|
197
|
+
if (deleted?.data?.status !== "deleted")
|
|
198
|
+
throw incompleteReply('status "deleted"', gone);
|
|
199
|
+
output(g, deleted, renderDeleted);
|
|
200
|
+
});
|
|
201
|
+
monitor
|
|
202
|
+
.command("trigger")
|
|
203
|
+
.argument("<id>", "monitor id")
|
|
204
|
+
.description("Run a monitor now, outside its schedule")
|
|
205
|
+
.action(async (id, _opts, command) => {
|
|
206
|
+
const g = globalsOf(command);
|
|
207
|
+
const client = makeMonitorClient(g);
|
|
208
|
+
// A queued manual run shows in the run list before the monitor's last_run changes.
|
|
209
|
+
const runs = mayHaveApplied(`\`octen monitor runs ${id}\` (look for a new manual run)`);
|
|
210
|
+
output(g, written(await call(true, () => client.monitors.trigger(id), runs), "run_id", runs), renderTriggered);
|
|
211
|
+
});
|
|
212
|
+
monitor
|
|
213
|
+
.command("runs")
|
|
214
|
+
.argument("<id>", "monitor id")
|
|
215
|
+
.description("List a monitor's runs")
|
|
216
|
+
.option("--status <status>", "queued|processing|completed|skipped|failed", parseChoiceOpt("--status", ["queued", "processing", "completed", "skipped", "failed"]))
|
|
217
|
+
.option("--only-changes", "only runs that found changes")
|
|
218
|
+
.option("--order-by <order>", "time_desc|time_asc", parseChoiceOpt("--order-by", ["time_desc", "time_asc"]))
|
|
219
|
+
.option("--limit <n>", "1-100", parseIntOpt("--limit"))
|
|
220
|
+
.option("--cursor <cursor>", "next_cursor from the previous page")
|
|
221
|
+
.action(async (id, opts, command) => {
|
|
222
|
+
const g = globalsOf(command);
|
|
223
|
+
const client = makeMonitorClient(g);
|
|
224
|
+
output(g, listed(await call(false, () => client.monitors.listRuns(id, buildRunsParams(opts))), "runs"), renderRuns);
|
|
225
|
+
});
|
|
226
|
+
monitor
|
|
227
|
+
.command("run")
|
|
228
|
+
.argument("<id>", "monitor id")
|
|
229
|
+
.argument("<run_id>", "run id")
|
|
230
|
+
.description("Show one run and its items")
|
|
231
|
+
.action(async (id, runId, _opts, command) => {
|
|
232
|
+
const g = globalsOf(command);
|
|
233
|
+
const client = makeMonitorClient(g);
|
|
234
|
+
output(g, await call(false, () => client.monitors.getRun(id, runId)), renderRun);
|
|
235
|
+
});
|
|
236
|
+
monitor
|
|
237
|
+
.command("events")
|
|
238
|
+
.argument("<id>", "monitor id")
|
|
239
|
+
.description("List a monitor's events: what it found")
|
|
240
|
+
.option("--run <run_id>", "only events from this run")
|
|
241
|
+
.option("--order-by <order>", "time_desc|time_asc", parseChoiceOpt("--order-by", ["time_desc", "time_asc"]))
|
|
242
|
+
.option("--limit <n>", "1-20", parseIntOpt("--limit"))
|
|
243
|
+
.option("--cursor <cursor>", "next_cursor from the previous page")
|
|
244
|
+
.action(async (id, opts, command) => {
|
|
245
|
+
const g = globalsOf(command);
|
|
246
|
+
const client = makeMonitorClient(g);
|
|
247
|
+
output(g, listed(await call(false, () => client.monitors.listEvents(id, buildEventsParams(opts))), "events"), renderEvents);
|
|
248
|
+
});
|
|
249
|
+
// A stray extra argument (e.g. a second id) must fail rather than be ignored.
|
|
250
|
+
for (const sub of monitor.commands)
|
|
251
|
+
sub.allowExcessArguments(false);
|
|
252
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MonitorCreateParams, MonitorListEventsParams, MonitorListParams, MonitorListRunsParams, MonitorUpdateParams } from "@octen.ai/sdk";
|
|
2
|
+
export type OutputField = {
|
|
3
|
+
field_name: string;
|
|
4
|
+
field_type: "string" | "number" | "boolean";
|
|
5
|
+
field_desc?: string;
|
|
6
|
+
};
|
|
7
|
+
export type MonitorType = "topic" | "page";
|
|
8
|
+
/** Parsed options of every `octen monitor` subcommand (commander's camelCase names). */
|
|
9
|
+
export interface MonitorCliOptions {
|
|
10
|
+
topic?: string;
|
|
11
|
+
page?: string[];
|
|
12
|
+
field?: OutputField[];
|
|
13
|
+
includeDomains?: string[];
|
|
14
|
+
excludeDomains?: string[];
|
|
15
|
+
name?: string;
|
|
16
|
+
condition?: string;
|
|
17
|
+
interval?: string;
|
|
18
|
+
cron?: string;
|
|
19
|
+
timezone?: string;
|
|
20
|
+
webhook?: string;
|
|
21
|
+
email?: string[];
|
|
22
|
+
metadata?: Record<string, string>;
|
|
23
|
+
params?: Record<string, unknown>;
|
|
24
|
+
status?: string;
|
|
25
|
+
clear?: string[];
|
|
26
|
+
rotateSecret?: boolean;
|
|
27
|
+
limit?: number;
|
|
28
|
+
cursor?: string;
|
|
29
|
+
pageNo?: number;
|
|
30
|
+
onlyChanges?: boolean;
|
|
31
|
+
orderBy?: string;
|
|
32
|
+
run?: string;
|
|
33
|
+
}
|
|
34
|
+
type Obj = Record<string, unknown>;
|
|
35
|
+
export declare function parseField(v: string, prev?: OutputField[]): OutputField[];
|
|
36
|
+
export declare function parseMetadata(v: string, prev?: Record<string, string>): Record<string, string>;
|
|
37
|
+
export declare const parseChoiceOpt: (name: string, choices: readonly string[]) => (v: string) => string;
|
|
38
|
+
export declare function readParams(v: string): Obj;
|
|
39
|
+
export declare function buildCreateParams(o: MonitorCliOptions): MonitorCreateParams;
|
|
40
|
+
export declare function needsTypeLookup(o: MonitorCliOptions): boolean;
|
|
41
|
+
export declare function buildUpdateParams(o: MonitorCliOptions, type: MonitorType | undefined): MonitorUpdateParams;
|
|
42
|
+
export declare function buildListParams(o: MonitorCliOptions): MonitorListParams;
|
|
43
|
+
export declare function buildRunsParams(o: MonitorCliOptions): MonitorListRunsParams;
|
|
44
|
+
export declare function buildEventsParams(o: MonitorCliOptions): MonitorListEventsParams;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { OctenValidationError } from "../../api/errors.js";
|
|
3
|
+
const FIELD_TYPES = ["string", "number", "boolean"];
|
|
4
|
+
const CLEARABLE = ["condition", "webhook", "email", "metadata"];
|
|
5
|
+
export function parseField(v, prev = []) {
|
|
6
|
+
const first = v.indexOf(":");
|
|
7
|
+
if (first <= 0)
|
|
8
|
+
throw new OctenValidationError("--field must be name:type[:description]");
|
|
9
|
+
const second = v.indexOf(":", first + 1);
|
|
10
|
+
const name = v.slice(0, first);
|
|
11
|
+
const type = second < 0 ? v.slice(first + 1) : v.slice(first + 1, second);
|
|
12
|
+
if (!FIELD_TYPES.includes(type)) {
|
|
13
|
+
throw new OctenValidationError(`--field type must be one of ${FIELD_TYPES.join(", ")}`);
|
|
14
|
+
}
|
|
15
|
+
const field = { field_name: name, field_type: type };
|
|
16
|
+
if (second >= 0)
|
|
17
|
+
field.field_desc = v.slice(second + 1);
|
|
18
|
+
return [...prev, field];
|
|
19
|
+
}
|
|
20
|
+
export function parseMetadata(v, prev = {}) {
|
|
21
|
+
const eq = v.indexOf("=");
|
|
22
|
+
if (eq <= 0)
|
|
23
|
+
throw new OctenValidationError("--metadata must be key=value");
|
|
24
|
+
return { ...prev, [v.slice(0, eq)]: v.slice(eq + 1) };
|
|
25
|
+
}
|
|
26
|
+
export const parseChoiceOpt = (name, choices) => (v) => {
|
|
27
|
+
if (!choices.includes(v))
|
|
28
|
+
throw new OctenValidationError(`${name} must be one of ${choices.join(", ")}`);
|
|
29
|
+
return v;
|
|
30
|
+
};
|
|
31
|
+
export function readParams(v) {
|
|
32
|
+
let text = v;
|
|
33
|
+
if (v.startsWith("@")) {
|
|
34
|
+
try {
|
|
35
|
+
text = readFileSync(v.slice(1), "utf8");
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw new OctenValidationError(`--params: cannot read ${v.slice(1)}: ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
let parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = JSON.parse(text);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new OctenValidationError("--params must be a JSON object or @file");
|
|
47
|
+
}
|
|
48
|
+
if (!isObj(parsed))
|
|
49
|
+
throw new OctenValidationError("--params must be a JSON object or @file");
|
|
50
|
+
return parsed;
|
|
51
|
+
}
|
|
52
|
+
function isObj(v) {
|
|
53
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54
|
+
}
|
|
55
|
+
// Same leaf from a named option and --params is a conflict, never a silent overwrite; arrays are leaves.
|
|
56
|
+
function mergeParams(base, extra, path = "") {
|
|
57
|
+
const out = { ...base };
|
|
58
|
+
for (const [k, v] of Object.entries(extra)) {
|
|
59
|
+
const p = path ? `${path}.${k}` : k;
|
|
60
|
+
if (!Object.hasOwn(out, k))
|
|
61
|
+
Object.defineProperty(out, k, { value: v, enumerable: true, writable: true, configurable: true });
|
|
62
|
+
else if (isObj(out[k]) && isObj(v))
|
|
63
|
+
out[k] = mergeParams(out[k], v, p);
|
|
64
|
+
else
|
|
65
|
+
throw new OctenValidationError(`--params sets ${p}, which another option already sets`);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
function setIf(o, key, v) {
|
|
70
|
+
if (v !== undefined)
|
|
71
|
+
o[key] = v;
|
|
72
|
+
}
|
|
73
|
+
function schedule(o) {
|
|
74
|
+
if (o.interval === undefined && o.cron === undefined && o.timezone === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
const s = {};
|
|
77
|
+
setIf(s, "interval", o.interval);
|
|
78
|
+
setIf(s, "cron", o.cron);
|
|
79
|
+
setIf(s, "timezone", o.timezone);
|
|
80
|
+
return s;
|
|
81
|
+
}
|
|
82
|
+
// Checked on the merged request, so a cron given through --params counts.
|
|
83
|
+
function checkSchedule(body) {
|
|
84
|
+
const s = body.schedule;
|
|
85
|
+
if (s && s.timezone !== undefined && s.cron === undefined)
|
|
86
|
+
throw new OctenValidationError("--timezone needs --cron");
|
|
87
|
+
return body;
|
|
88
|
+
}
|
|
89
|
+
function typeSettings(o, type) {
|
|
90
|
+
const t = {};
|
|
91
|
+
if (type === "topic") {
|
|
92
|
+
setIf(t, "query", o.topic);
|
|
93
|
+
setIf(t, "include_domains", o.includeDomains);
|
|
94
|
+
setIf(t, "exclude_domains", o.excludeDomains);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
setIf(t, "urls", o.page);
|
|
98
|
+
}
|
|
99
|
+
setIf(t, "output_schema", o.field);
|
|
100
|
+
return Object.keys(t).length ? t : undefined;
|
|
101
|
+
}
|
|
102
|
+
function checkTypeOptions(o, type) {
|
|
103
|
+
if (type === "page" && (o.topic !== undefined || o.includeDomains || o.excludeDomains)) {
|
|
104
|
+
throw new OctenValidationError("--topic, --include-domains and --exclude-domains apply to topic monitors only");
|
|
105
|
+
}
|
|
106
|
+
if (type === "topic" && o.page !== undefined)
|
|
107
|
+
throw new OctenValidationError("--page applies to page monitors only");
|
|
108
|
+
}
|
|
109
|
+
function common(o, body) {
|
|
110
|
+
setIf(body, "name", o.name);
|
|
111
|
+
setIf(body, "condition", o.condition);
|
|
112
|
+
setIf(body, "schedule", schedule(o));
|
|
113
|
+
if (o.email !== undefined)
|
|
114
|
+
body.email = { to: o.email };
|
|
115
|
+
setIf(body, "metadata", o.metadata);
|
|
116
|
+
}
|
|
117
|
+
export function buildCreateParams(o) {
|
|
118
|
+
if ((o.topic === undefined) === (o.page === undefined)) {
|
|
119
|
+
throw new OctenValidationError("give exactly one of --topic and --page");
|
|
120
|
+
}
|
|
121
|
+
const type = o.topic !== undefined ? "topic" : "page";
|
|
122
|
+
checkTypeOptions(o, type);
|
|
123
|
+
const body = { type, [type]: typeSettings(o, type) };
|
|
124
|
+
common(o, body);
|
|
125
|
+
if (o.webhook !== undefined)
|
|
126
|
+
body.webhook = { url: o.webhook };
|
|
127
|
+
return checkSchedule(o.params ? mergeParams(body, o.params) : body);
|
|
128
|
+
}
|
|
129
|
+
export function needsTypeLookup(o) {
|
|
130
|
+
return Boolean(o.field || o.includeDomains || o.excludeDomains || o.topic !== undefined || o.page !== undefined);
|
|
131
|
+
}
|
|
132
|
+
export function buildUpdateParams(o, type) {
|
|
133
|
+
const body = {};
|
|
134
|
+
if (needsTypeLookup(o)) {
|
|
135
|
+
if (!type)
|
|
136
|
+
throw new OctenValidationError("the monitor type is needed for these options");
|
|
137
|
+
checkTypeOptions(o, type);
|
|
138
|
+
setIf(body, type, typeSettings(o, type));
|
|
139
|
+
}
|
|
140
|
+
setIf(body, "status", o.status);
|
|
141
|
+
common(o, body);
|
|
142
|
+
if (o.webhook !== undefined || o.rotateSecret) {
|
|
143
|
+
const w = {};
|
|
144
|
+
setIf(w, "url", o.webhook);
|
|
145
|
+
if (o.rotateSecret)
|
|
146
|
+
w.rotate_secret = true;
|
|
147
|
+
body.webhook = w;
|
|
148
|
+
}
|
|
149
|
+
for (const f of o.clear ?? []) {
|
|
150
|
+
if (!CLEARABLE.includes(f)) {
|
|
151
|
+
throw new OctenValidationError(`--clear accepts ${CLEARABLE.join(", ")}`);
|
|
152
|
+
}
|
|
153
|
+
if (f in body)
|
|
154
|
+
throw new OctenValidationError(`--clear ${f} conflicts with setting ${f}`);
|
|
155
|
+
body[f] = null;
|
|
156
|
+
}
|
|
157
|
+
const merged = checkSchedule(o.params ? mergeParams(body, o.params) : body);
|
|
158
|
+
if (Object.keys(merged).length === 0)
|
|
159
|
+
throw new OctenValidationError("nothing to update: give at least one option");
|
|
160
|
+
return merged;
|
|
161
|
+
}
|
|
162
|
+
export function buildListParams(o) {
|
|
163
|
+
const q = {};
|
|
164
|
+
setIf(q, "status", o.status);
|
|
165
|
+
setIf(q, "name", o.name);
|
|
166
|
+
setIf(q, "limit", o.limit);
|
|
167
|
+
setIf(q, "cursor", o.cursor);
|
|
168
|
+
setIf(q, "page_no", o.pageNo);
|
|
169
|
+
return q;
|
|
170
|
+
}
|
|
171
|
+
export function buildRunsParams(o) {
|
|
172
|
+
const q = {};
|
|
173
|
+
setIf(q, "status", o.status);
|
|
174
|
+
setIf(q, "only_changes", o.onlyChanges);
|
|
175
|
+
setIf(q, "order_by", o.orderBy);
|
|
176
|
+
setIf(q, "limit", o.limit);
|
|
177
|
+
setIf(q, "cursor", o.cursor);
|
|
178
|
+
return q;
|
|
179
|
+
}
|
|
180
|
+
export function buildEventsParams(o) {
|
|
181
|
+
const q = {};
|
|
182
|
+
setIf(q, "run_id", o.run);
|
|
183
|
+
setIf(q, "order_by", o.orderBy);
|
|
184
|
+
setIf(q, "limit", o.limit);
|
|
185
|
+
setIf(q, "cursor", o.cursor);
|
|
186
|
+
return q;
|
|
187
|
+
}
|
package/dist/commands/reset.js
CHANGED
|
@@ -15,6 +15,7 @@ const CLIENT_FLAG_MAP = {
|
|
|
15
15
|
windsurf: "windsurf",
|
|
16
16
|
vscode: "vscode",
|
|
17
17
|
codex: "codex",
|
|
18
|
+
devin: "devin",
|
|
18
19
|
openclaw: "openclaw",
|
|
19
20
|
hermes: "hermes",
|
|
20
21
|
};
|
|
@@ -32,6 +33,7 @@ export function registerReset(program, internal = {}) {
|
|
|
32
33
|
.option("--windsurf", "target Windsurf")
|
|
33
34
|
.option("--vscode", "target VS Code")
|
|
34
35
|
.option("--codex", "target Codex")
|
|
36
|
+
.option("--devin", "target Devin")
|
|
35
37
|
.option("--openclaw", "target OpenClaw")
|
|
36
38
|
.option("--hermes", "target Hermes")
|
|
37
39
|
.option("--scope <s>", "config scope: user | project (default: user)", parseScopeOpt("--scope"), "user")
|
package/dist/mcp/clients.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export type McpFormat = "json-mcpServers" | "json-servers" | "toml" | "claude-code";
|
|
2
|
+
/** Octen's hosted MCP server, for clients configured with it instead of a local npx server. */
|
|
3
|
+
export declare const HOSTED_MCP_URL = "https://mcp.octen.ai/mcp";
|
|
2
4
|
export interface McpClient {
|
|
3
|
-
id: "claude-code" | "claude-desktop" | "cursor" | "windsurf" | "vscode" | "codex";
|
|
5
|
+
id: "claude-code" | "claude-desktop" | "cursor" | "windsurf" | "vscode" | "codex" | "devin";
|
|
4
6
|
label: string;
|
|
5
7
|
format: McpFormat;
|
|
6
8
|
supportsProject: boolean;
|
|
7
|
-
|
|
9
|
+
/** Configure the hosted server (url + x-api-key header) rather than `npx octen-mcp`. */
|
|
10
|
+
hosted?: boolean;
|
|
11
|
+
pathFor(scope: "user" | "project", home: string, cwd: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string;
|
|
8
12
|
}
|
|
13
|
+
/** Devin's user config directory: %APPDATA%\devin on Windows, else $XDG_CONFIG_HOME/devin or ~/.config/devin. */
|
|
14
|
+
export declare function devinConfigDir(home: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string;
|
|
9
15
|
export declare const MCP_CLIENTS: McpClient[];
|
package/dist/mcp/clients.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
1
|
+
import { isAbsolute, join, win32 } from "node:path";
|
|
2
|
+
/** Octen's hosted MCP server, for clients configured with it instead of a local npx server. */
|
|
3
|
+
export const HOSTED_MCP_URL = "https://mcp.octen.ai/mcp";
|
|
4
|
+
/** Devin's user config directory: %APPDATA%\devin on Windows, else $XDG_CONFIG_HOME/devin or ~/.config/devin. */
|
|
5
|
+
export function devinConfigDir(home, platform = process.platform, env = process.env) {
|
|
6
|
+
if (platform === "win32")
|
|
7
|
+
return win32.join(env.APPDATA ?? win32.join(home, "AppData", "Roaming"), "devin");
|
|
8
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
9
|
+
return xdg && isAbsolute(xdg) ? join(xdg, "devin") : join(home, ".config/devin");
|
|
10
|
+
}
|
|
2
11
|
export const MCP_CLIENTS = [
|
|
3
12
|
{
|
|
4
13
|
id: "claude-code",
|
|
@@ -59,4 +68,20 @@ export const MCP_CLIENTS = [
|
|
|
59
68
|
: join(home, ".codex/config.toml");
|
|
60
69
|
},
|
|
61
70
|
},
|
|
71
|
+
{
|
|
72
|
+
id: "devin",
|
|
73
|
+
label: "Devin",
|
|
74
|
+
format: "json-mcpServers",
|
|
75
|
+
// Devin CLI and Devin Local (in Devin Desktop) read the same files:
|
|
76
|
+
// https://docs.devin.ai/cli/extensibility/mcp/configuration
|
|
77
|
+
// Project scope uses the personal local file; configure-mcp puts only an env reference there.
|
|
78
|
+
supportsProject: true,
|
|
79
|
+
hosted: true,
|
|
80
|
+
pathFor(scope, home, cwd, platform, env) {
|
|
81
|
+
if (scope === "project")
|
|
82
|
+
return join(cwd, ".devin/mcp_config.local.json");
|
|
83
|
+
const dir = devinConfigDir(home, platform, env);
|
|
84
|
+
return (platform ?? process.platform) === "win32" ? win32.join(dir, "mcp_config.json") : join(dir, "mcp_config.json");
|
|
85
|
+
},
|
|
86
|
+
},
|
|
62
87
|
];
|
package/dist/mcp/install.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { McpClient } from "./clients.js";
|
|
2
|
+
export type StdioEntry = {
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
env: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
export type HostedEntry = {
|
|
8
|
+
url: string;
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
};
|
|
2
11
|
export interface InstallOpts {
|
|
3
12
|
/** Override claude-CLI availability detection for testing */
|
|
4
13
|
hasClaudeCli?: boolean;
|
|
@@ -12,9 +21,5 @@ export interface RemoveResult {
|
|
|
12
21
|
removed: boolean;
|
|
13
22
|
method: "claude-cli" | "file";
|
|
14
23
|
}
|
|
15
|
-
export declare function installMcp(client: McpClient, scope: "user" | "project", entry:
|
|
16
|
-
command: string;
|
|
17
|
-
args: string[];
|
|
18
|
-
env: Record<string, string>;
|
|
19
|
-
}, home: string, cwd: string, opts?: InstallOpts): InstallResult;
|
|
24
|
+
export declare function installMcp(client: McpClient, scope: "user" | "project", entry: StdioEntry | HostedEntry, home: string, cwd: string, opts?: InstallOpts): InstallResult;
|
|
20
25
|
export declare function removeMcp(client: McpClient, scope: "user" | "project", home: string, cwd: string, opts?: InstallOpts): RemoveResult;
|
package/dist/mcp/install.js
CHANGED
|
@@ -12,7 +12,7 @@ function claudeAvailable(override) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export function installMcp(client, scope, entry, home, cwd, opts = {}) {
|
|
15
|
-
if (client.id === "claude-code") {
|
|
15
|
+
if (client.id === "claude-code" && "command" in entry) {
|
|
16
16
|
const apiKey = entry.env["OCTEN_API_KEY"] ?? "";
|
|
17
17
|
// A real key must never reach another process's argv: `ps -ww` and
|
|
18
18
|
// /proc/<pid>/cmdline expose it to every local user for the child's
|
package/dist/mcp/write.js
CHANGED
|
@@ -9,9 +9,8 @@ import { writeSecretFile } from "../util/secretFile.js";
|
|
|
9
9
|
* becomes a secret-bearing file.
|
|
10
10
|
*/
|
|
11
11
|
function carriesLiteralSecret(entry) {
|
|
12
|
-
const env = entry
|
|
13
|
-
|
|
14
|
-
return typeof value === "string" && value !== "" && !value.startsWith("${");
|
|
12
|
+
const { env, headers } = entry;
|
|
13
|
+
return [env?.["OCTEN_API_KEY"], headers?.["x-api-key"]].some((value) => typeof value === "string" && value !== "" && !value.startsWith("${"));
|
|
15
14
|
}
|
|
16
15
|
function assertNever(x) {
|
|
17
16
|
throw new Error(`unhandled McpFormat: ${String(x)}`);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function renderMonitor(data: any): string;
|
|
2
|
+
export declare function renderMonitorList(data: any): string;
|
|
3
|
+
export declare function renderDeleted(data: any): string;
|
|
4
|
+
export declare function renderTriggered(data: any): string;
|
|
5
|
+
export declare function renderRuns(data: any): string;
|
|
6
|
+
export declare function renderRun(data: any): string;
|
|
7
|
+
export declare function renderEvents(data: any): string;
|