svamp-cli 0.2.224 → 0.2.225

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.
@@ -1,196 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { m as resolveProjectRoot } from './run-C-9ZtEi4.mjs';
3
- import { c as workflowSteps, s as setWorkflowEnabled, i as isWorkflowEnabled, r as removeWorkflow, g as getWorkflow, l as listWorkflows, a as saveWorkflow, b as rawWorkflow } from './store-BTs0H_y0.mjs';
4
- import 'os';
5
- import 'fs/promises';
6
- import 'fs';
7
- import 'path';
8
- import 'url';
9
- import 'child_process';
10
- import 'crypto';
11
- import 'node:crypto';
12
- import 'node:fs';
13
- import 'util';
14
- import 'node:path';
15
- import 'node:events';
16
- import 'node:os';
17
- import '@agentclientprotocol/sdk';
18
- import '@modelcontextprotocol/sdk/client/index.js';
19
- import '@modelcontextprotocol/sdk/client/stdio.js';
20
- import '@modelcontextprotocol/sdk/types.js';
21
- import 'zod';
22
- import 'node:fs/promises';
23
- import 'node:util';
24
- import 'yaml';
25
-
26
- function flag(args, name) {
27
- const i = args.indexOf(name);
28
- return i !== -1 && i + 1 < args.length ? args[i + 1] : void 0;
29
- }
30
- function allFlags(args, name) {
31
- return args.filter((_a, idx) => args[idx - 1] === name);
32
- }
33
- function positional(args) {
34
- const out = [];
35
- for (let i = 0; i < args.length; i++) {
36
- const a = args[i];
37
- if (a.startsWith("--")) {
38
- if (a !== "--json") i++;
39
- continue;
40
- }
41
- out.push(a);
42
- }
43
- return out;
44
- }
45
- function describeOn(on) {
46
- if (!on) return "manual";
47
- const parts = [];
48
- if (on.schedule?.length) parts.push(`schedule(${on.schedule.map((s) => s.cron).join(", ")})`);
49
- if (on.workflow_dispatch) parts.push("workflow_dispatch");
50
- if (on.channel) parts.push(`channel(${on.channel})`);
51
- if (on.issue?.length) parts.push(`issue(${on.issue.join("/")})`);
52
- return parts.length ? parts.join(" ") : "manual";
53
- }
54
- async function workflowCommand(args) {
55
- const sub = args[0];
56
- const rest = args.slice(1);
57
- const root = resolveProjectRoot();
58
- const json = args.includes("--json");
59
- switch (sub) {
60
- case "add": {
61
- const name = positional(rest)[0];
62
- const runs = allFlags(rest, "--run");
63
- if (!name || !runs.length) {
64
- console.error('usage: svamp workflow add <name> --run "<cmd>" [--run "<cmd2>"] [--on schedule|dispatch|channel|issue] [--cron "* * * * *"] [--channel <name>] [--issue ready,closed,labeled]');
65
- process.exit(1);
66
- }
67
- const onKinds = allFlags(rest, "--on");
68
- const crons = allFlags(rest, "--cron");
69
- const on = {};
70
- if (onKinds.includes("schedule") || crons.length) on.schedule = (crons.length ? crons : ["0 * * * *"]).map((c) => ({ cron: c }));
71
- if (onKinds.includes("dispatch") || onKinds.includes("workflow_dispatch")) on.workflow_dispatch = true;
72
- if (onKinds.includes("channel") || flag(rest, "--channel")) on.channel = flag(rest, "--channel") || "default";
73
- if (onKinds.includes("issue") || flag(rest, "--issue")) on.issue = (flag(rest, "--issue") || "ready").split(",").map((s) => s.trim()).filter(Boolean);
74
- const owner = flag(rest, "--session") || process.env.SVAMP_SESSION_ID || null;
75
- const wf = { name, on: Object.keys(on).length ? on : void 0, jobs: { run: { steps: runs.map((r) => ({ run: r })) } }, session: owner };
76
- saveWorkflow(root, wf);
77
- const nSteps = workflowSteps(wf).length;
78
- if (json) console.log(JSON.stringify(wf));
79
- else console.log(`Saved workflow "${name}" (on: ${describeOn(wf.on)}, ${nSteps} step${nSteps === 1 ? "" : "s"}).`);
80
- break;
81
- }
82
- case "list":
83
- case "ls": {
84
- const all = listWorkflows(root);
85
- if (json) {
86
- console.log(JSON.stringify(all));
87
- break;
88
- }
89
- if (!all.length) {
90
- console.log("No workflows.");
91
- break;
92
- }
93
- for (const wf of all) {
94
- const n = workflowSteps(wf).length;
95
- console.log(`${wf.name} [${describeOn(wf.on)}] ${n} step${n === 1 ? "" : "s"}${isWorkflowEnabled(wf) ? "" : " (disabled)"}`);
96
- }
97
- break;
98
- }
99
- case "show": {
100
- const name = positional(rest)[0];
101
- const raw = name ? rawWorkflow(root, name) : null;
102
- if (!raw) {
103
- console.error(`Workflow not found: ${name}`);
104
- process.exit(1);
105
- }
106
- if (json) console.log(JSON.stringify(getWorkflow(root, name)));
107
- else process.stdout.write(raw);
108
- break;
109
- }
110
- case "remove":
111
- case "rm": {
112
- const name = positional(rest)[0];
113
- if (!name) {
114
- console.error("usage: svamp workflow remove <name>");
115
- process.exit(1);
116
- }
117
- console.log(removeWorkflow(root, name) ? `Removed workflow "${name}".` : `Workflow not found: ${name}`);
118
- break;
119
- }
120
- case "enable":
121
- case "disable": {
122
- const name = positional(rest)[0];
123
- if (!name) {
124
- console.error(`usage: svamp workflow ${sub} <name>`);
125
- process.exit(1);
126
- }
127
- const wf = setWorkflowEnabled(root, name, sub === "enable");
128
- if (!wf) {
129
- console.error(`Workflow not found: ${name}`);
130
- process.exit(1);
131
- }
132
- if (json) console.log(JSON.stringify(wf));
133
- else console.log(`Workflow "${name}" is now ${isWorkflowEnabled(wf) ? "active" : "disabled"}.`);
134
- break;
135
- }
136
- case "run": {
137
- const name = positional(rest)[0];
138
- const wf = name ? getWorkflow(root, name) : null;
139
- if (!wf) {
140
- console.error(`Workflow not found: ${name}`);
141
- process.exit(1);
142
- }
143
- const steps = workflowSteps(wf);
144
- console.log(`\u25B6 running workflow "${wf.name}" (${steps.length} step${steps.length === 1 ? "" : "s"})`);
145
- for (let i = 0; i < steps.length; i++) {
146
- const step = steps[i];
147
- console.log(` [${i + 1}/${steps.length}] $ ${step.run}`);
148
- const r = spawnSync("sh", ["-c", step.run], { cwd: root, stdio: "inherit" });
149
- if (r.status !== 0) {
150
- console.error(` \u2717 step ${i + 1} failed (exit ${r.status ?? "signal"}). Stopping.`);
151
- process.exit(r.status ?? 1);
152
- }
153
- }
154
- console.log(`\u2713 workflow "${wf.name}" completed.`);
155
- break;
156
- }
157
- case "guide": {
158
- console.log([
159
- "CREATE an automation WORKFLOW from a request (GitHub-Actions-style, .svamp/workflows/<name>.yaml):",
160
- " svamp workflow add <kebab-name> \\",
161
- ' [--on schedule --cron "<expr>" | --on dispatch | --on channel <name> | --on issue <labels>] \\',
162
- ' --run "<shell/svamp command>" [--run "<cmd2>"]...',
163
- " - A step is any shell or svamp command. To start a self-verifying loop on a schedule:",
164
- ` --run "svamp session loop <session-id> '<task>' --until '<done criteria>' [--max N]"`,
165
- ` - To message/prompt a session: --run "svamp session send <id> '<text>'" (use the owner id, or "." in an owned workflow).`,
166
- " - Multiple --cron flags = multiple schedules. Pick a short kebab-case name.",
167
- " Then reply with a one-line summary of the workflow you created."
168
- ].join("\n"));
169
- break;
170
- }
171
- case "help":
172
- case void 0:
173
- case "--help":
174
- case "-h":
175
- console.log([
176
- "svamp workflow \u2014 GitHub-Actions-style automation as .svamp/workflows/<name>.yaml",
177
- "",
178
- ' add <name> --run "<cmd>" [--run "<cmd2>"] [--on schedule|dispatch|channel|issue]',
179
- ' [--cron "0 9 * * 1-5"] [--channel <name>] [--issue ready,closed,labeled]',
180
- " list | show <name> | remove <name>",
181
- " enable <name> | disable <name> # toggle active/disabled (scheduler skips disabled)",
182
- " run <name> # execute the workflow's run-only steps now",
183
- ' guide # the "create a workflow from a request" procedure (so triggers can stay short)',
184
- "",
185
- "Each step is a shell command \u2014 every verb is a `svamp` CLI call, e.g.",
186
- ' svamp workflow add nightly --on schedule --cron "0 2 * * *" \\',
187
- ' --run "svamp session send . \\"Run the nightly checks and fix failures\\""'
188
- ].join("\n"));
189
- break;
190
- default:
191
- console.error(`Unknown: svamp workflow ${sub}. Try: svamp workflow help`);
192
- process.exit(1);
193
- }
194
- }
195
-
196
- export { workflowCommand };