opensddrag 0.1.1 → 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/README.md +87 -0
- package/package.json +1 -1
- package/src/commands/init.js +61 -46
- package/src/commands/status.js +7 -10
- package/src/config.js +53 -0
- package/src/templates/commands/index.js +82 -689
- package/src/templates/commands/opencode.js +59 -653
- package/src/templates/skill-md.js +180 -0
- package/src/templates/skills/_shared.js +35 -0
- package/src/templates/skills/apply.js +64 -0
- package/src/templates/skills/archive.js +52 -0
- package/src/templates/skills/continue.js +63 -0
- package/src/templates/skills/design.js +82 -0
- package/src/templates/skills/explore.js +62 -0
- package/src/templates/skills/flow.js +65 -0
- package/src/templates/skills/index.js +66 -186
- package/src/templates/skills/propose.js +74 -0
- package/src/templates/skills/search.js +60 -0
- package/src/templates/skills/spec.js +94 -0
- package/src/templates/skills/status.js +66 -0
- package/src/templates/skills/sync.js +65 -0
- package/src/templates/skills/tasks.js +70 -0
- package/src/templates/skills/verify.js +74 -0
package/README.md
CHANGED
|
@@ -63,6 +63,9 @@ npx opensddrag init --server http://localhost:8000 --project my-app --yes
|
|
|
63
63
|
# Remote server with an API key
|
|
64
64
|
npx opensddrag init --server https://sdd.example.com --api-key sk-... --yes
|
|
65
65
|
|
|
66
|
+
# CI — configure via env vars, no flags needed
|
|
67
|
+
OPENSDDRAG_SERVER_URL=http://mcp.internal:8000 OPENSDDRAG_API_KEY=sk-... npx opensddrag init --project my-app --yes
|
|
68
|
+
|
|
66
69
|
# Configure only OpenCode (skip Claude Code)
|
|
67
70
|
npx opensddrag init --tools opencode
|
|
68
71
|
```
|
|
@@ -74,8 +77,11 @@ npx opensddrag init --tools opencode
|
|
|
74
77
|
| `.mcp.json` | Claude Code MCP server entry (`type: http`) |
|
|
75
78
|
| `opencode.json` | OpenCode MCP server entry (only with `--tools opencode`) |
|
|
76
79
|
| `.claude/skills/opensddrag-*/SKILL.md` | One skill file per SDD command |
|
|
80
|
+
| `.claude/skills/opensddrag-harness/SKILL.md` | Harness rule management skill |
|
|
77
81
|
| `.agents/skills/opensddrag-*/SKILL.md` | Same skills for agent-native tooling |
|
|
82
|
+
| `.agents/skills/opensddrag-harness/SKILL.md` | Same harness skill for agent-native tooling |
|
|
78
83
|
| `.opencode/skills/opensddrag-*/SKILL.md` | OpenCode-native skills (when selected) |
|
|
84
|
+
| `.opencode/skills/opensddrag-harness/SKILL.md` | OpenCode-native harness skill (when selected) |
|
|
79
85
|
| `.claude/commands/opsr/*.md` | Claude Code slash commands |
|
|
80
86
|
| `.opencode/commands/opsr/*.md` | OpenCode slash commands (when selected) |
|
|
81
87
|
| `CLAUDE.md` | OpenSddRag section appended (or file created) |
|
|
@@ -87,8 +93,14 @@ npx opensddrag init --tools opencode
|
|
|
87
93
|
|
|
88
94
|
Check whether the current project is correctly wired to the server.
|
|
89
95
|
|
|
96
|
+
```
|
|
97
|
+
Options:
|
|
98
|
+
--server <url> Override the server URL for this check
|
|
99
|
+
```
|
|
100
|
+
|
|
90
101
|
```bash
|
|
91
102
|
npx opensddrag status
|
|
103
|
+
npx opensddrag status --server http://mcp.internal:8000
|
|
92
104
|
```
|
|
93
105
|
|
|
94
106
|
Reports:
|
|
@@ -99,6 +111,32 @@ Reports:
|
|
|
99
111
|
- `CLAUDE.md` — whether the OpenSddRag section exists
|
|
100
112
|
- Server — live health check + project registration confirmation
|
|
101
113
|
|
|
114
|
+
## Environment Variables
|
|
115
|
+
|
|
116
|
+
Both `init` and `status` support configuration via environment variables. Precedence order (first match wins):
|
|
117
|
+
|
|
118
|
+
1. `--server` / `--api-key` CLI flags
|
|
119
|
+
2. Environment variables
|
|
120
|
+
3. `opensddrag.yaml` (`server_url` or `server` field)
|
|
121
|
+
4. Built-in default (`http://localhost:8000`)
|
|
122
|
+
|
|
123
|
+
| Variable | Purpose |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `OPENSDDRAG_SERVER_URL` | MCP server URL — used when no `--server` flag is passed |
|
|
126
|
+
| `OPENSDDRAG_API_KEY` | API key for authenticated servers — used when no `--api-key` flag is passed |
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Connect to a remote server without flags
|
|
130
|
+
export OPENSDDRAG_SERVER_URL=http://mcp.internal:8000
|
|
131
|
+
export OPENSDDRAG_API_KEY=sk-abc123
|
|
132
|
+
npx opensddrag init --project my-app --yes
|
|
133
|
+
npx opensddrag status
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`OPENSDDRAG_API_KEY` is honored for any server URL — including `localhost` — so local servers with `AUTH_ENABLED=true` work correctly.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
102
140
|
## SDD Slash Commands
|
|
103
141
|
|
|
104
142
|
After `init`, the following slash commands are available inside Claude Code (prefix `/opsr:`):
|
|
@@ -118,6 +156,55 @@ After `init`, the following slash commands are available inside Claude Code (pre
|
|
|
118
156
|
| `/opsr:status` | Show what is in progress and what is done |
|
|
119
157
|
| `/opsr:flow` | Run the full SDD flow end-to-end for a feature |
|
|
120
158
|
| `/opsr:search` | Semantic search over specs and past work |
|
|
159
|
+
| `/opsr:harness` | Add, list, or disable project rules enforced at SDD phase gates |
|
|
160
|
+
|
|
161
|
+
## Harness
|
|
162
|
+
|
|
163
|
+
The Harness is a rule-gate layer built on top of the SDD workflow. It lets you define persistent, per-project behavioral rules that are automatically injected into every agent session and enforced at specific SDD phase gates.
|
|
164
|
+
|
|
165
|
+
**How it works:**
|
|
166
|
+
- Rules are stored in the MCP server's database, scoped to your project.
|
|
167
|
+
- `always` rules are returned automatically by `get_working_context` at the start of every session.
|
|
168
|
+
- Phase-gate rules (`on_spec`, `on_apply`, `on_verify`, `on_archive`) are surfaced by `get_harness_checklist` when the corresponding SDD command runs its gate step.
|
|
169
|
+
- Agents check the checklist before completing each gate action and must satisfy all `error`-severity rules.
|
|
170
|
+
|
|
171
|
+
### Triggers
|
|
172
|
+
|
|
173
|
+
| Trigger | When it fires |
|
|
174
|
+
|---|---|
|
|
175
|
+
| `always` | Every agent session — injected via `get_working_context` |
|
|
176
|
+
| `on_spec` | Before saving a spec artifact (`/opsr:spec`) |
|
|
177
|
+
| `on_apply` | Before marking a task complete (`/opsr:apply`) |
|
|
178
|
+
| `on_verify` | Before declaring verification done (`/opsr:verify`) |
|
|
179
|
+
| `on_archive` | Before archiving change artifacts (`/opsr:archive`) |
|
|
180
|
+
|
|
181
|
+
### MCP Tools
|
|
182
|
+
|
|
183
|
+
| Tool | Description |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `add_rule` | Create or update a project rule (name, trigger, category, severity, instruction) |
|
|
186
|
+
| `list_rules` | List all rules for the project, grouped by trigger |
|
|
187
|
+
| `get_harness_checklist` | Return enabled rules for a specific trigger — called by SDD commands at phase gates |
|
|
188
|
+
|
|
189
|
+
### Managing rules
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Inside Claude Code, after opensddrag init:
|
|
193
|
+
|
|
194
|
+
# Add a rule interactively
|
|
195
|
+
/opsr:harness add
|
|
196
|
+
|
|
197
|
+
# Add a rule directly
|
|
198
|
+
/opsr:harness add name=no-raw-sql trigger=on_apply category=forbidden severity=error instruction="Never write raw SQL strings — use the repository layer"
|
|
199
|
+
|
|
200
|
+
# List all rules
|
|
201
|
+
/opsr:harness list
|
|
202
|
+
|
|
203
|
+
# Disable a rule
|
|
204
|
+
/opsr:harness disable no-raw-sql
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
121
208
|
|
|
122
209
|
## Server Setup
|
|
123
210
|
|
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -5,10 +5,12 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
|
5
5
|
import { join, basename } from "path";
|
|
6
6
|
|
|
7
7
|
import { checkHealth, createProject } from "../api.js";
|
|
8
|
+
import { DEFAULT_SERVER_URL, resolveServerUrl, resolveApiKey } from "../config.js";
|
|
8
9
|
import { renderClaudeMdBlock, renderClaudeMdStandalone } from "../templates/claude-md.js";
|
|
9
10
|
import { getCommands } from "../templates/commands/index.js";
|
|
10
11
|
import { getOpenCodeCommands } from "../templates/commands/opencode.js";
|
|
11
|
-
import { getSkills } from "../templates/skills/index.js";
|
|
12
|
+
import { getSkills, getOpenCodeSkills } from "../templates/skills/index.js";
|
|
13
|
+
import { getHarnessSkill, getOpenCodeHarnessSkill } from "../templates/skill-md.js";
|
|
12
14
|
|
|
13
15
|
// ── Config writers ─────────────────────────────────────────────────────────────
|
|
14
16
|
|
|
@@ -40,6 +42,9 @@ function writeOpenCode(cwd, serverUrl, _apiKey) {
|
|
|
40
42
|
url: `${serverUrl}/mcp`,
|
|
41
43
|
enabled: true,
|
|
42
44
|
};
|
|
45
|
+
if (_apiKey) {
|
|
46
|
+
config.mcp.opensddrag.headers = { Authorization: `Bearer ${_apiKey}` };
|
|
47
|
+
}
|
|
43
48
|
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
44
49
|
return "opencode.json";
|
|
45
50
|
}
|
|
@@ -55,7 +60,7 @@ export const initCommand = new Command("init")
|
|
|
55
60
|
.description("Connect the current project to an OpenSddRag MCP server")
|
|
56
61
|
.option("--project <slug>", "Project slug (default: current directory name)")
|
|
57
62
|
.option("--name <name>", "Project display name")
|
|
58
|
-
.option("--server <url>", "OpenSddRag server URL"
|
|
63
|
+
.option("--server <url>", "OpenSddRag server URL")
|
|
59
64
|
.option("--api-key <key>", "API key for authenticated servers")
|
|
60
65
|
.option("--tools <list>", "Comma-separated tools to configure: claude,opencode (default: ask)")
|
|
61
66
|
.option("--yes", "Skip confirmation prompts")
|
|
@@ -65,13 +70,16 @@ export const initCommand = new Command("init")
|
|
|
65
70
|
console.log(chalk.bold("\n OpenSddRag — Project Init\n"));
|
|
66
71
|
|
|
67
72
|
// ── Inputs ────────────────────────────────────────────────────────────────
|
|
68
|
-
const
|
|
69
|
-
|
|
73
|
+
const resolvedUrl = resolveServerUrl(opts, cwd);
|
|
74
|
+
let serverUrl;
|
|
75
|
+
if (opts.yes || resolvedUrl !== DEFAULT_SERVER_URL) {
|
|
76
|
+
serverUrl = resolvedUrl;
|
|
77
|
+
} else {
|
|
78
|
+
serverUrl = await input({ message: "OpenSddRag server URL:", default: DEFAULT_SERVER_URL });
|
|
79
|
+
}
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let apiKey = opts.apiKey || null;
|
|
74
|
-
if (!apiKey && isRemote && !opts.yes) {
|
|
81
|
+
let apiKey = resolveApiKey(opts);
|
|
82
|
+
if (!apiKey && !opts.yes) {
|
|
75
83
|
apiKey = await password({
|
|
76
84
|
message: "API key (leave blank to skip — server must have AUTH_ENABLED=false):",
|
|
77
85
|
mask: "*",
|
|
@@ -114,15 +122,15 @@ export const initCommand = new Command("init")
|
|
|
114
122
|
console.log("\n" + chalk.dim(" Will create/update:"));
|
|
115
123
|
if (selectedTools.includes("Claude Code")) {
|
|
116
124
|
console.log(chalk.dim(" .mcp.json — MCP server (type: http)"));
|
|
125
|
+
console.log(chalk.dim(" .claude/skills/opensddrag-*/SKILL.md — individual skill per command"));
|
|
126
|
+
console.log(chalk.dim(" .agents/skills/opensddrag-*/SKILL.md — individual skill per command"));
|
|
127
|
+
console.log(chalk.dim(" .claude/commands/opsr/ — slash commands (/opsr:propose, /opsr:apply, /opsr:harness...)"));
|
|
117
128
|
}
|
|
118
|
-
console.log(chalk.dim(" .claude/skills/opensddrag-*/SKILL.md — individual skill per command"));
|
|
119
|
-
console.log(chalk.dim(" .agents/skills/opensddrag-*/SKILL.md — individual skill per command"));
|
|
120
129
|
if (selectedTools.includes("OpenCode")) {
|
|
121
|
-
console.log(chalk.dim(" opencode.json
|
|
130
|
+
console.log(chalk.dim(" opencode.json — MCP server"));
|
|
122
131
|
console.log(chalk.dim(" .opencode/skills/opensddrag-*/SKILL.md — OpenCode-native skills"));
|
|
123
|
-
console.log(chalk.dim(" .opencode/commands/opsr/
|
|
132
|
+
console.log(chalk.dim(" .opencode/commands/opsr/ — slash commands (/opsr:propose, /opsr:apply...)"));
|
|
124
133
|
}
|
|
125
|
-
console.log(chalk.dim(" .claude/commands/opsr/ — slash commands (/opsr:propose, /opsr:apply...)"));
|
|
126
134
|
console.log(chalk.dim(" CLAUDE.md — OpenSddRag section"));
|
|
127
135
|
console.log(chalk.dim(` Remote: register '${slug}' in central database\n`));
|
|
128
136
|
|
|
@@ -138,9 +146,13 @@ export const initCommand = new Command("init")
|
|
|
138
146
|
console.log(chalk.green("✓"));
|
|
139
147
|
} catch {
|
|
140
148
|
console.log(chalk.red("✗"));
|
|
149
|
+
const isLocal = serverUrl.includes("localhost") || serverUrl.includes("127.0.0.1");
|
|
141
150
|
console.error(chalk.red(`\n Cannot reach ${serverUrl}`));
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
if (isLocal) {
|
|
152
|
+
console.error(chalk.dim(" Make sure the OpenSddRag server is running:"));
|
|
153
|
+
console.error(chalk.dim(" docker compose up -d"));
|
|
154
|
+
}
|
|
155
|
+
console.error(chalk.dim(" Pass --server <url> or set OPENSDDRAG_SERVER_URL."));
|
|
144
156
|
process.exit(1);
|
|
145
157
|
}
|
|
146
158
|
|
|
@@ -165,57 +177,60 @@ export const initCommand = new Command("init")
|
|
|
165
177
|
const file = TOOL_WRITERS[tool](cwd, serverUrl, apiKey);
|
|
166
178
|
configured.push(`${tool} → ${file}`);
|
|
167
179
|
}
|
|
168
|
-
// Individual skill files per command
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
for (const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
// Individual skill files per command — each tool gets its own generator
|
|
181
|
+
if (selectedTools.includes("Claude Code")) {
|
|
182
|
+
const ccSkills = [
|
|
183
|
+
...getSkills(slug, serverUrl),
|
|
184
|
+
{ name: "opensddrag-harness", content: getHarnessSkill({ slug, serverUrl }) },
|
|
185
|
+
];
|
|
186
|
+
const ccRoots = [join(cwd, ".claude", "skills"), join(cwd, ".agents", "skills")];
|
|
187
|
+
for (const skill of ccSkills) {
|
|
188
|
+
for (const root of ccRoots) {
|
|
189
|
+
const skillDir = join(root, skill.name);
|
|
190
|
+
mkdirSync(skillDir, { recursive: true });
|
|
191
|
+
writeFileSync(join(skillDir, "SKILL.md"), skill.content);
|
|
192
|
+
}
|
|
193
|
+
configured.push(`skill → ${skill.name}/SKILL.md (${ccRoots.length} root(s))`);
|
|
179
194
|
}
|
|
180
|
-
configured.push(`skill → .claude/skills/${skill.name}/SKILL.md`);
|
|
181
195
|
}
|
|
182
|
-
|
|
183
|
-
// Install OpenCode-native skills if OpenCode is selected
|
|
184
196
|
if (selectedTools.includes("OpenCode")) {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
const ocSkills = [
|
|
198
|
+
...getOpenCodeSkills(slug, serverUrl),
|
|
199
|
+
{ name: "opensddrag-harness", content: getOpenCodeHarnessSkill({ slug, serverUrl }) },
|
|
200
|
+
];
|
|
201
|
+
const ocRoot = join(cwd, ".opencode", "skills");
|
|
202
|
+
for (const skill of ocSkills) {
|
|
203
|
+
const skillDir = join(ocRoot, skill.name);
|
|
188
204
|
mkdirSync(skillDir, { recursive: true });
|
|
189
205
|
writeFileSync(join(skillDir, "SKILL.md"), skill.content);
|
|
190
|
-
configured.push(`skill →
|
|
206
|
+
configured.push(`skill → ${skill.name}/SKILL.md (1 root(s))`);
|
|
191
207
|
}
|
|
192
208
|
}
|
|
193
209
|
console.log(chalk.green("✓"));
|
|
194
210
|
for (const c of configured) console.log(chalk.dim(` ${c}`));
|
|
195
211
|
|
|
196
|
-
// ── 4. Slash commands
|
|
212
|
+
// ── 4. Slash commands ────────────────────────────────────────────────────
|
|
197
213
|
process.stdout.write(chalk.bold(" 4/5 ") + "Writing slash commands... ");
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
214
|
+
let totalCommands = 0;
|
|
215
|
+
if (selectedTools.includes("Claude Code")) {
|
|
216
|
+
const commands = getCommands(slug, serverUrl);
|
|
217
|
+
for (const cmd of commands) {
|
|
218
|
+
const cmdDir = join(cwd, ".claude", "commands", cmd.folder);
|
|
219
|
+
mkdirSync(cmdDir, { recursive: true });
|
|
220
|
+
writeFileSync(join(cmdDir, `${cmd.name}.md`), cmd.content);
|
|
221
|
+
}
|
|
222
|
+
totalCommands += commands.length;
|
|
207
223
|
}
|
|
208
|
-
|
|
209
|
-
// Install OpenCode-native commands if OpenCode is selected
|
|
210
224
|
if (selectedTools.includes("OpenCode")) {
|
|
211
225
|
const opencodeCommands = getOpenCodeCommands(slug, serverUrl);
|
|
212
226
|
for (const cmd of opencodeCommands) {
|
|
213
227
|
const cmdDir = join(cwd, ".opencode", "commands", cmd.folder);
|
|
214
228
|
mkdirSync(cmdDir, { recursive: true });
|
|
215
229
|
writeFileSync(join(cmdDir, `${cmd.name}.md`), cmd.content);
|
|
216
|
-
configured.push(`command → .opencode/commands/${cmd.folder}/${cmd.name}.md`);
|
|
217
230
|
}
|
|
231
|
+
totalCommands += opencodeCommands.length;
|
|
218
232
|
}
|
|
233
|
+
console.log(chalk.green(`✓ (${totalCommands} commands)`));
|
|
219
234
|
|
|
220
235
|
// ── 5. CLAUDE.md ──────────────────────────────────────────────────────────
|
|
221
236
|
process.stdout.write(chalk.bold(" 5/5 ") + "Updating CLAUDE.md... ");
|
package/src/commands/status.js
CHANGED
|
@@ -4,25 +4,22 @@ import { existsSync, readFileSync } from "fs";
|
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
|
|
6
6
|
import { checkHealth, listProjects } from "../api.js";
|
|
7
|
+
import { resolveServerUrl, loadOpensddragYaml } from "../config.js";
|
|
7
8
|
|
|
8
9
|
export const statusCommand = new Command("status")
|
|
9
10
|
.description("Check OpenSddRag connection status for the current project")
|
|
10
|
-
.
|
|
11
|
+
.option("--server <url>", "OpenSddRag server URL")
|
|
12
|
+
.action(async (opts) => {
|
|
11
13
|
const cwd = process.cwd();
|
|
12
14
|
|
|
13
15
|
console.log(chalk.bold("\n OpenSddRag — Status\n"));
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const serverUrl = resolveServerUrl(opts, cwd);
|
|
18
|
+
const yaml = loadOpensddragYaml(cwd);
|
|
19
|
+
const slug = yaml?.project ?? null;
|
|
17
20
|
|
|
18
21
|
// ── Local config ──────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
if (existsSync(yamlPath)) {
|
|
21
|
-
const yaml = readFileSync(yamlPath, "utf8");
|
|
22
|
-
const slugMatch = yaml.match(/^project:\s*(.+)$/m);
|
|
23
|
-
const serverMatch = yaml.match(/^server:\s*(.+)$/m);
|
|
24
|
-
if (slugMatch) slug = slugMatch[1].trim();
|
|
25
|
-
if (serverMatch) serverUrl = serverMatch[1].trim();
|
|
22
|
+
if (yaml) {
|
|
26
23
|
console.log(chalk.green(" ✓") + ` opensddrag.yaml → project: ${chalk.cyan(slug)}`);
|
|
27
24
|
} else {
|
|
28
25
|
console.log(chalk.red(" ✗") + " opensddrag.yaml not found — run: " + chalk.dim("opensddrag init"));
|
package/src/config.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_SERVER_URL = "http://localhost:8000";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parse opensddrag.yaml from cwd.
|
|
8
|
+
* Reads both `server:` and `server_url:` keys for backward compatibility.
|
|
9
|
+
* Returns { project, server_url } or null on missing/malformed file.
|
|
10
|
+
*/
|
|
11
|
+
export function loadOpensddragYaml(cwd) {
|
|
12
|
+
const yamlPath = join(cwd, "opensddrag.yaml");
|
|
13
|
+
if (!existsSync(yamlPath)) return null;
|
|
14
|
+
try {
|
|
15
|
+
const text = readFileSync(yamlPath, "utf8");
|
|
16
|
+
const projectMatch = text.match(/^project:\s*["']?(.+?)["']?\s*$/m);
|
|
17
|
+
const serverMatch = text.match(/^(?:server_url|server):\s*["']?(.+?)["']?\s*$/m);
|
|
18
|
+
return {
|
|
19
|
+
project: projectMatch?.[1]?.trim() ?? null,
|
|
20
|
+
server_url: serverMatch?.[1]?.trim() ?? null,
|
|
21
|
+
};
|
|
22
|
+
} catch {
|
|
23
|
+
process.stderr.write("Warning: Ignoring malformed opensddrag.yaml\n");
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the MCP server URL with precedence:
|
|
30
|
+
* 1. opts.server (--server CLI flag)
|
|
31
|
+
* 2. OPENSDDRAG_SERVER_URL env var
|
|
32
|
+
* 3. opensddrag.yaml server_url / server field
|
|
33
|
+
* 4. DEFAULT_SERVER_URL
|
|
34
|
+
*/
|
|
35
|
+
export function resolveServerUrl(opts, cwd) {
|
|
36
|
+
if (opts?.server) return opts.server;
|
|
37
|
+
if (process.env.OPENSDDRAG_SERVER_URL) return process.env.OPENSDDRAG_SERVER_URL;
|
|
38
|
+
const yaml = loadOpensddragYaml(cwd ?? process.cwd());
|
|
39
|
+
if (yaml?.server_url) return yaml.server_url;
|
|
40
|
+
return DEFAULT_SERVER_URL;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the API key with precedence:
|
|
45
|
+
* 1. opts.apiKey (--api-key CLI flag)
|
|
46
|
+
* 2. OPENSDDRAG_API_KEY env var
|
|
47
|
+
* 3. null
|
|
48
|
+
*/
|
|
49
|
+
export function resolveApiKey(opts) {
|
|
50
|
+
if (opts?.apiKey) return opts.apiKey;
|
|
51
|
+
if (process.env.OPENSDDRAG_API_KEY) return process.env.OPENSDDRAG_API_KEY;
|
|
52
|
+
return null;
|
|
53
|
+
}
|