@duct-sdk/sdk 0.5.13 → 0.7.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/CHANGELOG.md +61 -0
- package/README.md +418 -264
- package/TOKEN_SPEC.md +243 -243
- package/dist/cli/action-confusion-format.d.ts +17 -0
- package/dist/cli/action-confusion-format.js +24 -0
- package/dist/cli/add.d.ts +7 -0
- package/dist/cli/add.js +152 -0
- package/dist/cli/agent-prompt.d.ts +3 -0
- package/dist/cli/agent-prompt.js +39 -0
- package/dist/cli/api-sources.d.ts +26 -0
- package/dist/cli/api-sources.js +222 -0
- package/dist/cli/cloud.d.ts +162 -0
- package/dist/cli/cloud.js +306 -0
- package/dist/cli/config-loader.d.ts +14 -0
- package/dist/cli/config-loader.js +56 -7
- package/dist/cli/device-login.d.ts +17 -0
- package/dist/cli/device-login.js +75 -0
- package/dist/cli/drift.js +6 -6
- package/dist/cli/generators/any-stack.d.ts +3 -0
- package/dist/cli/generators/any-stack.js +97 -0
- package/dist/cli/generators/config.js +3 -2
- package/dist/cli/generators/receiver.js +7 -7
- package/dist/cli/generators/shell.js +12 -12
- package/dist/cli/generators/token-route.js +245 -245
- package/dist/cli/generators/wiring-snippets.d.ts +0 -14
- package/dist/cli/generators/wiring-snippets.js +188 -305
- package/dist/cli/index.js +396 -611
- package/dist/cli/mcp-core.d.ts +42 -0
- package/dist/cli/mcp-core.js +161 -0
- package/dist/cli/mcp-setup.d.ts +4 -0
- package/dist/cli/mcp-setup.js +352 -0
- package/dist/cli/mcp.d.ts +2 -0
- package/dist/cli/mcp.js +457 -0
- package/dist/cli/migrate-intershell.js +5 -5
- package/dist/cli/policy-defaults.d.ts +37 -0
- package/dist/cli/policy-defaults.js +127 -0
- package/dist/cli/policy-replay-format.d.ts +9 -0
- package/dist/cli/policy-replay-format.js +46 -0
- package/dist/cli/processors/integration-audit.js +2 -2
- package/dist/cli/processors/openapi-parser.d.ts +5 -0
- package/dist/cli/processors/openapi-parser.js +8 -3
- package/dist/cli/project-loader.d.ts +58 -0
- package/dist/cli/project-loader.js +198 -0
- package/dist/cli/project-writer.d.ts +23 -0
- package/dist/cli/project-writer.js +171 -0
- package/dist/cli/push.d.ts +43 -0
- package/dist/cli/push.js +308 -0
- package/dist/cli/safety-checks.d.ts +9 -0
- package/dist/cli/safety-checks.js +29 -0
- package/dist/cli/setup.d.ts +20 -0
- package/dist/cli/setup.js +349 -0
- package/dist/cli/shell-name.d.ts +8 -0
- package/dist/cli/shell-name.js +29 -0
- package/dist/cli/shells.d.ts +22 -0
- package/dist/cli/shells.js +122 -0
- package/dist/cli/split.d.ts +7 -0
- package/dist/cli/split.js +71 -0
- package/dist/cli/sync.d.ts +25 -0
- package/dist/cli/sync.js +120 -0
- package/dist/cli/test-runner.d.ts +21 -0
- package/dist/cli/test-runner.js +281 -0
- package/dist/core/compile.d.ts +43 -0
- package/dist/core/compile.js +512 -0
- package/dist/core/config.d.ts +538 -19
- package/dist/core/config.js +22 -14
- package/dist/core/login-handoff.d.ts +1 -1
- package/dist/core/login-handoff.js +1 -1
- package/dist/core/project.d.ts +1864 -0
- package/dist/core/project.js +291 -0
- package/dist/core/readiness-checks.js +2 -2
- package/dist/core/types.d.ts +10 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/project.d.ts +4 -0
- package/dist/project.js +8 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/package.json +94 -95
- package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
- package/dist/adapters/react/page-context-guard.test.js +0 -15
- package/dist/cli/agents/api-agent.d.ts +0 -22
- package/dist/cli/agents/api-agent.js +0 -761
- package/dist/cli/agents/auth-agent.d.ts +0 -7
- package/dist/cli/agents/auth-agent.js +0 -212
- package/dist/cli/agents/deeplink-agent.d.ts +0 -6
- package/dist/cli/agents/deeplink-agent.js +0 -285
- package/dist/cli/agents/llm.d.ts +0 -33
- package/dist/cli/agents/llm.js +0 -309
- package/dist/cli/agents/pipeline.d.ts +0 -72
- package/dist/cli/agents/pipeline.js +0 -421
- package/dist/cli/agents/reviewer-agent.d.ts +0 -13
- package/dist/cli/agents/reviewer-agent.js +0 -450
- package/dist/cli/agents/route-agent.d.ts +0 -17
- package/dist/cli/agents/route-agent.js +0 -383
- package/dist/cli/config-loader.test.d.ts +0 -1
- package/dist/cli/config-loader.test.js +0 -63
- package/dist/cli/detectors/topology.d.ts +0 -46
- package/dist/cli/detectors/topology.js +0 -417
- package/dist/cli/generators/config.test.d.ts +0 -1
- package/dist/cli/generators/config.test.js +0 -222
- package/dist/cli/generators/shell.test.d.ts +0 -1
- package/dist/cli/generators/shell.test.js +0 -73
- package/dist/cli/generators/token-route.test.d.ts +0 -1
- package/dist/cli/generators/token-route.test.js +0 -53
- package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
- package/dist/cli/generators/wiring-snippets.test.js +0 -80
- package/dist/cli/init.d.ts +0 -32
- package/dist/cli/init.js +0 -1336
- package/dist/cli/manifest-diff.test.d.ts +0 -1
- package/dist/cli/manifest-diff.test.js +0 -144
- package/dist/cli/processors/curl-parser.test.d.ts +0 -1
- package/dist/cli/processors/curl-parser.test.js +0 -24
- package/dist/cli/processors/integration-audit.test.d.ts +0 -1
- package/dist/cli/processors/integration-audit.test.js +0 -154
- package/dist/cli/processors/postprocess.d.ts +0 -22
- package/dist/cli/processors/postprocess.js +0 -107
- package/dist/cli/processors/prisma-parser.d.ts +0 -35
- package/dist/cli/processors/prisma-parser.js +0 -117
- package/dist/cli/processors/verify-discovery.d.ts +0 -33
- package/dist/cli/processors/verify-discovery.js +0 -193
- package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
- package/dist/cli/processors/verify-discovery.test.js +0 -153
- package/dist/cli/processors/zod-extractor.d.ts +0 -27
- package/dist/cli/processors/zod-extractor.js +0 -153
- package/dist/cli/prompts/review.d.ts +0 -61
- package/dist/cli/prompts/review.js +0 -410
- package/dist/cli/selectors/express.d.ts +0 -12
- package/dist/cli/selectors/express.js +0 -117
- package/dist/cli/selectors/fastapi.d.ts +0 -12
- package/dist/cli/selectors/fastapi.js +0 -122
- package/dist/cli/selectors/generic.d.ts +0 -10
- package/dist/cli/selectors/generic.js +0 -74
- package/dist/cli/selectors/index.d.ts +0 -37
- package/dist/cli/selectors/index.js +0 -315
- package/dist/cli/selectors/next.d.ts +0 -12
- package/dist/cli/selectors/next.js +0 -130
- package/dist/core/config-policy.test.d.ts +0 -1
- package/dist/core/config-policy.test.js +0 -101
- package/dist/core/config-roundtrip.test.d.ts +0 -1
- package/dist/core/config-roundtrip.test.js +0 -180
- package/dist/core/endpoint-guard.test.d.ts +0 -1
- package/dist/core/endpoint-guard.test.js +0 -57
- package/dist/core/env-diagnostics.test.d.ts +0 -1
- package/dist/core/env-diagnostics.test.js +0 -31
- package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
- package/dist/core/evidence-bundle.conformance.test.js +0 -110
- package/dist/core/evidence-bundle.test.d.ts +0 -1
- package/dist/core/evidence-bundle.test.js +0 -58
- package/dist/core/invariants.test.d.ts +0 -1
- package/dist/core/invariants.test.js +0 -217
- package/dist/core/login-handoff.test.d.ts +0 -1
- package/dist/core/login-handoff.test.js +0 -31
- package/dist/core/profile.test.d.ts +0 -1
- package/dist/core/profile.test.js +0 -95
- package/dist/core/readiness-checks.test.d.ts +0 -1
- package/dist/core/readiness-checks.test.js +0 -106
- package/dist/core/receipt.test.d.ts +0 -1
- package/dist/core/receipt.test.js +0 -75
- package/dist/core/sdk-entrypoint.test.d.ts +0 -1
- package/dist/core/sdk-entrypoint.test.js +0 -8
- package/dist/core/side-effects-review.test.d.ts +0 -1
- package/dist/core/side-effects-review.test.js +0 -28
- package/dist/core/token.conformance.test.d.ts +0 -1
- package/dist/core/token.conformance.test.js +0 -43
- package/dist/core/token.test.d.ts +0 -1
- package/dist/core/token.test.js +0 -66
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — duct setup
|
|
3
|
+
//
|
|
4
|
+
// npx @duct-sdk/sdk
|
|
5
|
+
//
|
|
6
|
+
// Sign in → pick your shell → find your API (OpenAPI in the repo, the spec
|
|
7
|
+
// your running API serves, Postman, or your coding agent) → write duct/ with
|
|
8
|
+
// safe defaults → verify with Duct cloud → push. No LLM key, no code changes.
|
|
9
|
+
// ============================================================
|
|
10
|
+
import * as fs from "fs/promises";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import { existsSync } from "fs";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import ora from "ora";
|
|
15
|
+
import inquirer from "inquirer";
|
|
16
|
+
import { PROJECT_DIR } from "../core/project.js";
|
|
17
|
+
import { getConfiguredDashboard, getDocsUrl } from "../core/endpoints.js";
|
|
18
|
+
import { classifySourceLocation, discoverLocalSources, loadApiSource, probeRemoteSpec, } from "./api-sources.js";
|
|
19
|
+
import { listAccountShells, readAuth, resolveApiKey, } from "./cloud.js";
|
|
20
|
+
import { defaultPolicy, starterTests, summarizeAgentAccess } from "./policy-defaults.js";
|
|
21
|
+
import { hasLegacyConfig, projectPaths } from "./project-loader.js";
|
|
22
|
+
import { renderProjectFiles, writeRenderedFiles } from "./project-writer.js";
|
|
23
|
+
import { loadAndValidateProject, printPushAbort, runPush } from "./push.js";
|
|
24
|
+
import { printTestReport, runTests } from "./test-runner.js";
|
|
25
|
+
import { buildAgentPrompt } from "./agent-prompt.js";
|
|
26
|
+
import { normalizeShellName } from "./shell-name.js";
|
|
27
|
+
import { openBrowser, startDeviceLogin, waitForDeviceApproval } from "./device-login.js";
|
|
28
|
+
export class SetupError extends Error {
|
|
29
|
+
hint;
|
|
30
|
+
constructor(message, hint) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.hint = hint;
|
|
33
|
+
this.name = "SetupError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const LOCAL_HOST_RE = /\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/i;
|
|
37
|
+
/** Docs link for hints — omitted when it would point a hosted user at localhost. */
|
|
38
|
+
function docsLink(dashboard) {
|
|
39
|
+
const docs = getDocsUrl();
|
|
40
|
+
if (LOCAL_HOST_RE.test(docs) && !LOCAL_HOST_RE.test(dashboard))
|
|
41
|
+
return null;
|
|
42
|
+
return docs;
|
|
43
|
+
}
|
|
44
|
+
function section(title) {
|
|
45
|
+
console.log(chalk.bold(`\n ${title}`));
|
|
46
|
+
}
|
|
47
|
+
function withScheme(value) {
|
|
48
|
+
const trimmed = value.trim().replace(/\/+$/, "");
|
|
49
|
+
return /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
50
|
+
}
|
|
51
|
+
function validUrl(value) {
|
|
52
|
+
try {
|
|
53
|
+
const url = new URL(withScheme(value));
|
|
54
|
+
return url.protocol === "http:" || url.protocol === "https:" ? true : "Use an http(s) URL";
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return "Enter a URL like https://api.example.com";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function readPackageName(root) {
|
|
61
|
+
try {
|
|
62
|
+
const pkg = JSON.parse(await fs.readFile(path.join(root, "package.json"), "utf-8"));
|
|
63
|
+
return pkg.name
|
|
64
|
+
?.replace(/^@[^/]+\//, "")
|
|
65
|
+
.replace(/[-_]+/g, " ")
|
|
66
|
+
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function ensureSignedIn(interactive) {
|
|
73
|
+
let auth = await readAuth();
|
|
74
|
+
const existingKey = resolveApiKey(auth);
|
|
75
|
+
if (existingKey) {
|
|
76
|
+
console.log(chalk.gray(` Signed in${auth?.email ? ` as ${auth.email}` : " with DUCT_API_KEY"}`));
|
|
77
|
+
return { auth, apiKey: existingKey };
|
|
78
|
+
}
|
|
79
|
+
if (!interactive) {
|
|
80
|
+
throw new SetupError("Not signed in.", "Set DUCT_API_KEY (CI) or run `npx @duct-sdk/sdk login` once, then re-run setup.");
|
|
81
|
+
}
|
|
82
|
+
// Sign in through the browser: approve this machine in the dashboard; nothing is pasted here.
|
|
83
|
+
try {
|
|
84
|
+
const { base, start } = await startDeviceLogin(auth);
|
|
85
|
+
console.log(` Confirm this code in your browser: ${chalk.bold.cyan(start.user_code)}`);
|
|
86
|
+
console.log(chalk.gray(` ${start.verification_uri_complete}`));
|
|
87
|
+
openBrowser(start.verification_uri_complete);
|
|
88
|
+
const spinner = ora("Waiting for approval…").start();
|
|
89
|
+
try {
|
|
90
|
+
auth = await waitForDeviceApproval(base, start, auth);
|
|
91
|
+
spinner.succeed(`Signed in as ${auth.email}`);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
spinner.fail("Sign-in did not complete");
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw new SetupError(err instanceof Error ? err.message : "Sign-in did not complete", "Or set DUCT_API_KEY, or run `npx @duct-sdk/sdk login --paste`.");
|
|
100
|
+
}
|
|
101
|
+
return { auth, apiKey: auth.token };
|
|
102
|
+
}
|
|
103
|
+
async function pickShell(shells, requested, interactive, dashboard) {
|
|
104
|
+
if (shells.length === 0) {
|
|
105
|
+
throw new SetupError("Your workspace has no shells yet.", `Create one at ${dashboard}/shells/new (one shell per product + environment), then re-run setup.`);
|
|
106
|
+
}
|
|
107
|
+
if (requested) {
|
|
108
|
+
// Accept the shell ID or its name (prod, checkout-prod), normalized the same way everywhere.
|
|
109
|
+
const name = normalizeShellName(requested);
|
|
110
|
+
const match = shells.find((shell) => shell.id === requested || (name && shell.environment === name));
|
|
111
|
+
if (!match) {
|
|
112
|
+
throw new SetupError(`Shell ${requested} is not in your workspace.`, `Your shells: ${shells.map((s) => `${s.environment ?? s.id} (${s.id})`).join(", ")}. Create one: npx @duct-sdk/sdk shells create ${name || "<name>"} --domain <url>`);
|
|
113
|
+
}
|
|
114
|
+
return match;
|
|
115
|
+
}
|
|
116
|
+
if (shells.length === 1 || !interactive)
|
|
117
|
+
return shells[0];
|
|
118
|
+
const { shellId } = await inquirer.prompt([
|
|
119
|
+
{
|
|
120
|
+
type: "list",
|
|
121
|
+
name: "shellId",
|
|
122
|
+
message: "Which shell is this project?",
|
|
123
|
+
choices: shells.map((shell) => ({
|
|
124
|
+
name: `${shell.id}${shell.environment ? chalk.gray(` ${shell.environment}`) : ""}${shell.registered_domain ? chalk.gray(` ${shell.registered_domain}`) : ""}`,
|
|
125
|
+
value: shell.id,
|
|
126
|
+
})),
|
|
127
|
+
},
|
|
128
|
+
]);
|
|
129
|
+
return shells.find((shell) => shell.id === shellId);
|
|
130
|
+
}
|
|
131
|
+
async function chooseSource(root, opts, interactive, apiBase) {
|
|
132
|
+
if (opts.source === "none")
|
|
133
|
+
return { kind: "none" };
|
|
134
|
+
if (opts.source) {
|
|
135
|
+
const source = classifySourceLocation(opts.source);
|
|
136
|
+
if (!source.remote) {
|
|
137
|
+
const absolute = path.resolve(opts.cwd, opts.source);
|
|
138
|
+
if (!existsSync(absolute))
|
|
139
|
+
throw new SetupError(`${opts.source} does not exist.`);
|
|
140
|
+
source.location = path.relative(root, absolute).split(path.sep).join("/");
|
|
141
|
+
}
|
|
142
|
+
return { kind: "source", source };
|
|
143
|
+
}
|
|
144
|
+
const spinner = ora("Looking for an OpenAPI spec or Postman collection in this repo…").start();
|
|
145
|
+
const local = await discoverLocalSources(root);
|
|
146
|
+
if (local.length > 0) {
|
|
147
|
+
spinner.succeed(`Found ${local.length === 1 ? local[0].location : `${local.length} API descriptions`}`);
|
|
148
|
+
if (local.length === 1 || !interactive)
|
|
149
|
+
return { kind: "source", source: local[0] };
|
|
150
|
+
const { location } = await inquirer.prompt([
|
|
151
|
+
{
|
|
152
|
+
type: "list",
|
|
153
|
+
name: "location",
|
|
154
|
+
message: "Which one describes the API agents should use?",
|
|
155
|
+
choices: local.map((source) => ({ name: `${source.location} ${chalk.gray(source.kind)}`, value: source.location })),
|
|
156
|
+
},
|
|
157
|
+
]);
|
|
158
|
+
return { kind: "source", source: local.find((source) => source.location === location) };
|
|
159
|
+
}
|
|
160
|
+
if (apiBase && validUrl(apiBase) === true) {
|
|
161
|
+
spinner.text = `Asking ${new URL(withScheme(apiBase)).origin} for its OpenAPI spec…`;
|
|
162
|
+
const remote = await probeRemoteSpec(apiBase);
|
|
163
|
+
if (remote) {
|
|
164
|
+
spinner.succeed(`Your API serves its spec at ${remote}`);
|
|
165
|
+
return { kind: "source", source: { kind: "openapi", location: remote, remote: true } };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
spinner.info("No OpenAPI spec found");
|
|
169
|
+
if (!interactive)
|
|
170
|
+
return { kind: "none" };
|
|
171
|
+
const { next } = await inquirer.prompt([
|
|
172
|
+
{
|
|
173
|
+
type: "list",
|
|
174
|
+
name: "next",
|
|
175
|
+
message: "How should Duct learn your API?",
|
|
176
|
+
choices: [
|
|
177
|
+
{ name: "Use my coding agent (Claude Code, Cursor, Codex) to read the code", value: "agent" },
|
|
178
|
+
{ name: "Point to a spec file or URL", value: "path" },
|
|
179
|
+
{ name: "Start empty — I'll add actions myself", value: "none" },
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
]);
|
|
183
|
+
if (next === "agent")
|
|
184
|
+
return { kind: "agent" };
|
|
185
|
+
if (next === "none")
|
|
186
|
+
return { kind: "none" };
|
|
187
|
+
const { location } = await inquirer.prompt([
|
|
188
|
+
{ type: "input", name: "location", message: "Path or URL to an OpenAPI spec / Postman collection:" },
|
|
189
|
+
]);
|
|
190
|
+
return chooseSource(root, { ...opts, source: String(location).trim() }, interactive, apiBase);
|
|
191
|
+
}
|
|
192
|
+
export async function runSetup(opts) {
|
|
193
|
+
const interactive = Boolean(process.stdin.isTTY) && !opts.yes && process.env.CI !== "true";
|
|
194
|
+
const root = path.resolve(opts.cwd);
|
|
195
|
+
const paths = projectPaths(root);
|
|
196
|
+
console.log(chalk.bold("\n Duct setup"));
|
|
197
|
+
console.log(chalk.gray(" Connects your API to Duct from its OpenAPI spec. No code changes required.\n"));
|
|
198
|
+
if (hasLegacyConfig(root) && !existsSync(paths.project)) {
|
|
199
|
+
throw new SetupError("This project already has duct.config.ts.", "Run `npx @duct-sdk/sdk split` to move it into the duct/ folder layout — nothing about enforcement changes.");
|
|
200
|
+
}
|
|
201
|
+
if (existsSync(paths.project) && !opts.force) {
|
|
202
|
+
if (!interactive) {
|
|
203
|
+
throw new SetupError("duct/ already exists.", "Use `duct sync` to refresh actions, or `duct setup --force` to start over.");
|
|
204
|
+
}
|
|
205
|
+
const { overwrite } = await inquirer.prompt([
|
|
206
|
+
{ type: "confirm", name: "overwrite", default: false, message: "duct/ already exists. Start over and overwrite it?" },
|
|
207
|
+
]);
|
|
208
|
+
if (!overwrite) {
|
|
209
|
+
console.log(chalk.gray("\n Kept your files. Try `npx @duct-sdk/sdk test` or `npx @duct-sdk/sdk sync`.\n"));
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
section("Sign in");
|
|
214
|
+
const { auth, apiKey } = await ensureSignedIn(interactive);
|
|
215
|
+
const dashboard = getConfiguredDashboard(auth);
|
|
216
|
+
section("Shell");
|
|
217
|
+
const shells = await listAccountShells(auth, apiKey);
|
|
218
|
+
const shell = await pickShell(shells, opts.shell, interactive, dashboard);
|
|
219
|
+
console.log(chalk.gray(` ${shell.id}${shell.environment ? ` · ${shell.environment}` : ""}`));
|
|
220
|
+
section("Your API");
|
|
221
|
+
const registered = shell.registered_domain ? withScheme(shell.registered_domain) : undefined;
|
|
222
|
+
let apiBase = opts.apiUrl ? withScheme(opts.apiUrl) : registered;
|
|
223
|
+
if (interactive && !opts.apiUrl) {
|
|
224
|
+
const { entered } = await inquirer.prompt([
|
|
225
|
+
{
|
|
226
|
+
type: "input",
|
|
227
|
+
name: "entered",
|
|
228
|
+
message: "Where is your API served? (public URL Duct will call)",
|
|
229
|
+
default: apiBase,
|
|
230
|
+
validate: validUrl,
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
apiBase = withScheme(String(entered));
|
|
234
|
+
}
|
|
235
|
+
const choice = await chooseSource(root, opts, interactive, apiBase);
|
|
236
|
+
let loaded = null;
|
|
237
|
+
if (choice.kind === "source") {
|
|
238
|
+
const spinner = ora(`Reading ${choice.source.location}…`).start();
|
|
239
|
+
try {
|
|
240
|
+
loaded = await loadApiSource(root, choice.source);
|
|
241
|
+
spinner.succeed(`${loaded.actions.length} action${loaded.actions.length === 1 ? "" : "s"} from ${choice.source.location}` +
|
|
242
|
+
(loaded.skipped > 0 ? chalk.gray(` (${loaded.skipped} HEAD/unsupported skipped)`) : ""));
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
spinner.fail(`Could not read ${choice.source.location}`);
|
|
246
|
+
throw new SetupError(err instanceof Error ? err.message : String(err));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const defaultName = loaded?.title ?? (await readPackageName(root)) ?? shell.id.replace(/^shell_/, "");
|
|
250
|
+
let productName = defaultName;
|
|
251
|
+
if (interactive) {
|
|
252
|
+
const { name } = await inquirer.prompt([
|
|
253
|
+
{ type: "input", name: "name", message: "Product name:", default: defaultName },
|
|
254
|
+
]);
|
|
255
|
+
productName = String(name).trim() || defaultName;
|
|
256
|
+
}
|
|
257
|
+
const baseUrl = registered ?? apiBase;
|
|
258
|
+
if (!baseUrl) {
|
|
259
|
+
throw new SetupError("Duct needs your product URL.", "Re-run with --api-url https://api.your-product.com");
|
|
260
|
+
}
|
|
261
|
+
const actions = loaded?.actions ?? [];
|
|
262
|
+
const project = {
|
|
263
|
+
shellId: shell.id,
|
|
264
|
+
product: {
|
|
265
|
+
name: productName,
|
|
266
|
+
description: `${productName} — connected to Duct`,
|
|
267
|
+
baseUrl,
|
|
268
|
+
...(apiBase && apiBase !== baseUrl ? { apiBaseUrl: apiBase } : {}),
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
const capabilities = {
|
|
272
|
+
version: 1,
|
|
273
|
+
source: loaded
|
|
274
|
+
? { kind: loaded.source.kind, location: loaded.source.location, syncedAt: new Date().toISOString() }
|
|
275
|
+
: { kind: "manual" },
|
|
276
|
+
actions,
|
|
277
|
+
};
|
|
278
|
+
section("Policy");
|
|
279
|
+
const rendered = renderProjectFiles({
|
|
280
|
+
project,
|
|
281
|
+
capabilities,
|
|
282
|
+
policy: defaultPolicy(actions),
|
|
283
|
+
tests: starterTests(actions),
|
|
284
|
+
annotatePolicy: true,
|
|
285
|
+
});
|
|
286
|
+
await writeRenderedFiles(root, rendered);
|
|
287
|
+
for (const file of Object.keys(rendered))
|
|
288
|
+
console.log(chalk.gray(` wrote ${file}`));
|
|
289
|
+
if (choice.kind === "agent" || actions.length === 0) {
|
|
290
|
+
const promptPath = path.join(root, PROJECT_DIR, "AGENT_PROMPT.md");
|
|
291
|
+
await fs.writeFile(promptPath, `${buildAgentPrompt({ hasProject: true })}\n`, "utf-8");
|
|
292
|
+
console.log(chalk.bold("\n Next: let your coding agent list your endpoints."));
|
|
293
|
+
console.log(` Open Claude Code, Cursor, or Codex in this repo and paste:`);
|
|
294
|
+
console.log(chalk.cyan(` Follow ${PROJECT_DIR}/AGENT_PROMPT.md to fill duct/capabilities.json, then run npx @duct-sdk/sdk test.`));
|
|
295
|
+
const docs = docsLink(dashboard);
|
|
296
|
+
console.log(chalk.gray(` Then run \`npx @duct-sdk/sdk push\`.${docs ? ` Docs: ${docs}/quickstart` : ""}\n`));
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
const project_ = await loadAndValidateProject(root).catch((err) => {
|
|
300
|
+
printPushAbort(err);
|
|
301
|
+
throw new SetupError("The generated project did not validate.", "Fix the items above, then run `npx @duct-sdk/sdk test`.");
|
|
302
|
+
});
|
|
303
|
+
const summary = summarizeAgentAccess(project_.validated);
|
|
304
|
+
const preview = (ids) => (ids.length === 0 ? "" : chalk.gray(` ${ids.slice(0, 4).join(", ")}${ids.length > 4 ? ", …" : ""}`));
|
|
305
|
+
console.log(`\n Agents can call ${String(summary.agentsCanCall.length).padStart(3)}${preview(summary.agentsCanCall)}`);
|
|
306
|
+
console.log(` Need a human ${String(summary.needsHuman.length).padStart(3)}${preview(summary.needsHuman)}`);
|
|
307
|
+
console.log(` Blocked ${String(summary.blocked.length).padStart(3)}${preview(summary.blocked)}`);
|
|
308
|
+
console.log(chalk.gray("\n Agents need the user's consent for every call. Edit duct/policy.ts to change any of this."));
|
|
309
|
+
section("Check with Duct");
|
|
310
|
+
const report = await runTests({ cwd: root });
|
|
311
|
+
printTestReport(report);
|
|
312
|
+
if (opts.push === false) {
|
|
313
|
+
console.log(chalk.gray(" Skipped push (--no-push). Run `npx @duct-sdk/sdk push` when ready.\n"));
|
|
314
|
+
return report.ok;
|
|
315
|
+
}
|
|
316
|
+
if (!report.ok) {
|
|
317
|
+
console.log(chalk.yellow(" Not pushing until the checks pass.\n"));
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
let confirmed = Boolean(opts.yes);
|
|
321
|
+
if (interactive) {
|
|
322
|
+
const { go } = await inquirer.prompt([
|
|
323
|
+
{ type: "confirm", name: "go", default: true, message: "Everything checks out. Push this policy live?" },
|
|
324
|
+
]);
|
|
325
|
+
confirmed = Boolean(go);
|
|
326
|
+
}
|
|
327
|
+
if (!confirmed) {
|
|
328
|
+
console.log(chalk.gray("\n Not pushed. Run `npx @duct-sdk/sdk push` when ready.\n"));
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
section("Push");
|
|
332
|
+
try {
|
|
333
|
+
await runPush({ cwd: root, yes: true });
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
printPushAbort(err);
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
console.log(chalk.bold.green("\n Setup complete. Your shell is live.\n"));
|
|
340
|
+
console.log(` Try it ${chalk.cyan(`${dashboard}/shells/${shell.id}/playground`)}`);
|
|
341
|
+
console.log(` Connect agents ${chalk.cyan(`${dashboard}/shells/${shell.id}/agent-setup`)}`);
|
|
342
|
+
console.log(` Change rules edit duct/policy.ts → npx @duct-sdk/sdk test → npx @duct-sdk/sdk push`);
|
|
343
|
+
console.log(` Users & chat npx @duct-sdk/sdk add identity · npx @duct-sdk/sdk add shell`);
|
|
344
|
+
const docs = docsLink(dashboard);
|
|
345
|
+
if (docs)
|
|
346
|
+
console.log(chalk.gray(` Docs ${docs}/quickstart`));
|
|
347
|
+
console.log();
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SHELL_NAME_MAX = 40;
|
|
2
|
+
export declare const SHELL_NAME_RE: RegExp;
|
|
3
|
+
/** Turn what a person typed ("EU Prod") into a valid name ("eu-prod"), or "" if nothing is left. */
|
|
4
|
+
export declare function normalizeShellName(input: string): string;
|
|
5
|
+
/** Why a name is not valid, or null when it is. */
|
|
6
|
+
export declare function shellNameError(name: string): string | null;
|
|
7
|
+
/** shell_<company slug>_<name>, with only [a-z0-9_]. */
|
|
8
|
+
export declare function shellIdFor(slug: string, name: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Shell name rule, identical to services/auth/src/lib/shell-name.ts and the dashboard's copy. All
|
|
2
|
+
// three run the shared cases in packages/contracts/src/fixtures/shell-names.json, so the CLI, MCP,
|
|
3
|
+
// dashboard, and server never disagree about a name or the shell ID it produces.
|
|
4
|
+
export const SHELL_NAME_MAX = 40;
|
|
5
|
+
export const SHELL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
6
|
+
/** Turn what a person typed ("EU Prod") into a valid name ("eu-prod"), or "" if nothing is left. */
|
|
7
|
+
export function normalizeShellName(input) {
|
|
8
|
+
return input
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
11
|
+
.replace(/^-+|-+$/g, '')
|
|
12
|
+
.slice(0, SHELL_NAME_MAX)
|
|
13
|
+
.replace(/-+$/, '');
|
|
14
|
+
}
|
|
15
|
+
/** Why a name is not valid, or null when it is. */
|
|
16
|
+
export function shellNameError(name) {
|
|
17
|
+
if (!name)
|
|
18
|
+
return 'Enter a name.';
|
|
19
|
+
if (name.length > SHELL_NAME_MAX)
|
|
20
|
+
return `Use ${SHELL_NAME_MAX} characters or fewer.`;
|
|
21
|
+
if (!SHELL_NAME_RE.test(name)) {
|
|
22
|
+
return 'Use lowercase letters, digits, and single hyphens, starting and ending with a letter or digit.';
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/** shell_<company slug>_<name>, with only [a-z0-9_]. */
|
|
27
|
+
export function shellIdFor(slug, name) {
|
|
28
|
+
return `shell_${slug}_${name}`.toLowerCase().replace(/[^a-z0-9_]/g, '_');
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AccountShell } from "./cloud.js";
|
|
2
|
+
export declare class ShellsError extends Error {
|
|
3
|
+
readonly hint?: string | undefined;
|
|
4
|
+
readonly existingShellId?: string | undefined;
|
|
5
|
+
constructor(message: string, hint?: string | undefined, existingShellId?: string | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare function listShells(): Promise<AccountShell[]>;
|
|
8
|
+
export declare function printShells(shells: AccountShell[]): void;
|
|
9
|
+
/** Make sure .env.duct* files are git-ignored in the repository that contains `dir`. */
|
|
10
|
+
export declare function ensureGitIgnored(dir: string): Promise<void>;
|
|
11
|
+
/** A path that does not exist yet: never overwrite a file that may hold the only copy of a secret. */
|
|
12
|
+
export declare function freshPath(dir: string, name: string): string;
|
|
13
|
+
export interface CreateShellOutcome {
|
|
14
|
+
shellId: string;
|
|
15
|
+
name: string;
|
|
16
|
+
envFile: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function createShell(opts: {
|
|
19
|
+
cwd: string;
|
|
20
|
+
name: string;
|
|
21
|
+
domains: string[];
|
|
22
|
+
}): Promise<CreateShellOutcome>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — duct shells
|
|
3
|
+
//
|
|
4
|
+
// npx @duct-sdk/sdk shells list the workspace's shells
|
|
5
|
+
// npx @duct-sdk/sdk shells create <name> --domain https://app.example.com
|
|
6
|
+
//
|
|
7
|
+
// A shell name is prod, staging, dev, or any custom name (checkout-prod, us-east); the rule is
|
|
8
|
+
// shared with the dashboard and the server (shell-name.ts). The new shell's secret is shown
|
|
9
|
+
// once by Duct, so it is written to a git-ignored .env.duct.<name> file and never printed.
|
|
10
|
+
// ============================================================
|
|
11
|
+
import { existsSync } from "fs";
|
|
12
|
+
import * as fs from "fs/promises";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import { CloudError, listAccountShells, provisionShell, readAuth, resolveApiKey } from "./cloud.js";
|
|
16
|
+
import { normalizeShellName, shellNameError } from "./shell-name.js";
|
|
17
|
+
export class ShellsError extends Error {
|
|
18
|
+
hint;
|
|
19
|
+
existingShellId;
|
|
20
|
+
constructor(message, hint, existingShellId) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.hint = hint;
|
|
23
|
+
this.existingShellId = existingShellId;
|
|
24
|
+
this.name = "ShellsError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function signedIn() {
|
|
28
|
+
const auth = await readAuth();
|
|
29
|
+
const apiKey = resolveApiKey(auth);
|
|
30
|
+
if (!apiKey) {
|
|
31
|
+
throw new ShellsError("Not signed in.", "Run `npx @duct-sdk/sdk login` (or set DUCT_API_KEY in CI), then try again.");
|
|
32
|
+
}
|
|
33
|
+
return { auth, apiKey };
|
|
34
|
+
}
|
|
35
|
+
export async function listShells() {
|
|
36
|
+
const { auth, apiKey } = await signedIn();
|
|
37
|
+
return listAccountShells(auth, apiKey);
|
|
38
|
+
}
|
|
39
|
+
export function printShells(shells) {
|
|
40
|
+
if (shells.length === 0) {
|
|
41
|
+
console.log("\n No shells yet. Create one: npx @duct-sdk/sdk shells create prod --domain https://app.example.com\n");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log();
|
|
45
|
+
const width = Math.max(...shells.map((s) => s.id.length), 8);
|
|
46
|
+
for (const shell of shells) {
|
|
47
|
+
console.log(` ${shell.id.padEnd(width)} ${chalk.gray((shell.environment ?? "").padEnd(16))} ${shell.status ?? ""}`);
|
|
48
|
+
}
|
|
49
|
+
console.log();
|
|
50
|
+
}
|
|
51
|
+
function gitRoot(start) {
|
|
52
|
+
let dir = path.resolve(start);
|
|
53
|
+
for (let i = 0; i < 25; i++) {
|
|
54
|
+
if (existsSync(path.join(dir, ".git")))
|
|
55
|
+
return dir;
|
|
56
|
+
const parent = path.dirname(dir);
|
|
57
|
+
if (parent === dir)
|
|
58
|
+
return null;
|
|
59
|
+
dir = parent;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/** Make sure .env.duct* files are git-ignored in the repository that contains `dir`. */
|
|
64
|
+
export async function ensureGitIgnored(dir) {
|
|
65
|
+
const root = gitRoot(dir);
|
|
66
|
+
if (!root)
|
|
67
|
+
return;
|
|
68
|
+
const file = path.join(root, ".gitignore");
|
|
69
|
+
const current = existsSync(file) ? await fs.readFile(file, "utf-8") : "";
|
|
70
|
+
if (current.split(/\r?\n/).some((line) => line.trim() === ".env.duct*"))
|
|
71
|
+
return;
|
|
72
|
+
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
73
|
+
await fs.writeFile(file, `${current}${prefix}# Duct shell credentials (secret, shown once)\n.env.duct*\n`, "utf-8");
|
|
74
|
+
}
|
|
75
|
+
/** A path that does not exist yet: never overwrite a file that may hold the only copy of a secret. */
|
|
76
|
+
export function freshPath(dir, name) {
|
|
77
|
+
let candidate = path.join(dir, `.env.duct.${name}`);
|
|
78
|
+
for (let n = 2; existsSync(candidate); n++)
|
|
79
|
+
candidate = path.join(dir, `.env.duct.${name}.${n}`);
|
|
80
|
+
return candidate;
|
|
81
|
+
}
|
|
82
|
+
export async function createShell(opts) {
|
|
83
|
+
const name = normalizeShellName(opts.name);
|
|
84
|
+
const problem = shellNameError(name);
|
|
85
|
+
if (problem)
|
|
86
|
+
throw new ShellsError(`"${opts.name}" is not a valid shell name. ${problem}`);
|
|
87
|
+
const domains = opts.domains.map((d) => d.trim()).filter(Boolean);
|
|
88
|
+
if (domains.length === 0) {
|
|
89
|
+
throw new ShellsError("Add at least one domain where your product runs.", "For example: --domain https://app.example.com");
|
|
90
|
+
}
|
|
91
|
+
for (const domain of domains) {
|
|
92
|
+
try {
|
|
93
|
+
new URL(domain);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new ShellsError(`${domain} is not a URL.`, "Use the full origin, for example https://app.example.com");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const { auth, apiKey } = await signedIn();
|
|
100
|
+
const existing = (await listAccountShells(auth, apiKey)).find((s) => s.environment === name);
|
|
101
|
+
if (existing) {
|
|
102
|
+
throw new ShellsError(`You already have a shell named "${name}" (${existing.id}).`, `Use it: npx @duct-sdk/sdk setup --shell ${name}`, existing.id);
|
|
103
|
+
}
|
|
104
|
+
let shell;
|
|
105
|
+
try {
|
|
106
|
+
shell = await provisionShell(auth, apiKey, name, domains);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
if (err instanceof CloudError && err.code === "shell_exists") {
|
|
110
|
+
const id = err.body?.shell_id;
|
|
111
|
+
throw new ShellsError(err.message, `Use it: npx @duct-sdk/sdk setup --shell ${name}`, id);
|
|
112
|
+
}
|
|
113
|
+
if (err instanceof CloudError)
|
|
114
|
+
throw new ShellsError(err.message);
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
const envFile = freshPath(opts.cwd, name);
|
|
118
|
+
await ensureGitIgnored(opts.cwd);
|
|
119
|
+
await fs.writeFile(envFile, `# Duct shell ${shell.shell_id}. Keep this file out of version control; the secret cannot be shown again.\n` +
|
|
120
|
+
`DUCT_SHELL_ID=${shell.shell_id}\nDUCT_SECRET_KEY=${shell.secret_key}\n`, { encoding: "utf-8", mode: 0o600 });
|
|
121
|
+
return { shellId: shell.shell_id, name, envFile };
|
|
122
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — duct split: duct.config.ts → duct/ folder
|
|
3
|
+
//
|
|
4
|
+
// Writes project.ts, capabilities.json, policy.ts (and shell.ts when the
|
|
5
|
+
// config has chat settings), then recompiles them and proves the gateway
|
|
6
|
+
// would make the same decision for every action before reporting success.
|
|
7
|
+
// ============================================================
|
|
8
|
+
import * as fs from "fs/promises";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { existsSync } from "fs";
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
import { DuctConfigSchema } from "../core/config.js";
|
|
14
|
+
import { compileProject, enforcementDiff, splitDuctConfig } from "../core/compile.js";
|
|
15
|
+
import { loadProjectFiles, projectPaths, resolveProjectConfig } from "./project-loader.js";
|
|
16
|
+
import { renderProjectFiles, writeRenderedFiles } from "./project-writer.js";
|
|
17
|
+
export async function runSplit(opts) {
|
|
18
|
+
const resolved = await resolveProjectConfig(opts.cwd, opts.config ?? (existsSync(path.join(opts.cwd, "duct.config.ts")) ? "duct.config.ts" : undefined));
|
|
19
|
+
if (resolved.layout !== "legacy") {
|
|
20
|
+
console.log(chalk.green("\n ✓ This project already uses the duct/ folder layout.\n"));
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const paths = projectPaths(resolved.root);
|
|
24
|
+
if (existsSync(paths.project) && !opts.force) {
|
|
25
|
+
throw new Error("duct/project.ts already exists. Re-run with --force to overwrite it.");
|
|
26
|
+
}
|
|
27
|
+
const parsed = DuctConfigSchema.safeParse(resolved.config);
|
|
28
|
+
if (!parsed.success) {
|
|
29
|
+
throw new Error(`duct.config.ts is invalid, fix it first:\n${parsed.error.errors
|
|
30
|
+
.map((err) => ` • [${err.path.join(".")}] ${err.message}`)
|
|
31
|
+
.join("\n")}`);
|
|
32
|
+
}
|
|
33
|
+
const original = parsed.data;
|
|
34
|
+
const split = splitDuctConfig(original);
|
|
35
|
+
const rendered = renderProjectFiles({ ...split });
|
|
36
|
+
console.log(chalk.bold("\n duct split\n"));
|
|
37
|
+
if (opts.dryRun) {
|
|
38
|
+
for (const [file, content] of Object.entries(rendered)) {
|
|
39
|
+
console.log(chalk.cyan(` ── ${file}`));
|
|
40
|
+
console.log(content);
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// Prove equivalence before touching the project: write to a scratch folder, recompile, diff.
|
|
45
|
+
const scratch = await fs.mkdtemp(path.join(os.tmpdir(), "duct-split-"));
|
|
46
|
+
try {
|
|
47
|
+
await writeRenderedFiles(scratch, rendered);
|
|
48
|
+
const { files } = await loadProjectFiles(scratch);
|
|
49
|
+
const compiled = DuctConfigSchema.parse(compileProject(files).config);
|
|
50
|
+
const diffs = enforcementDiff(original, compiled);
|
|
51
|
+
if (diffs.length > 0) {
|
|
52
|
+
console.log(chalk.red(" ✗ The split project would enforce differently, so nothing was written:"));
|
|
53
|
+
for (const diff of diffs)
|
|
54
|
+
console.log(chalk.red(` • ${diff}`));
|
|
55
|
+
console.log(chalk.yellow("\n duct.config.ts is unchanged and still used for push. Please report this.\n"));
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
await fs.rm(scratch, { recursive: true, force: true });
|
|
61
|
+
}
|
|
62
|
+
const written = await writeRenderedFiles(resolved.root, rendered);
|
|
63
|
+
for (const file of written)
|
|
64
|
+
console.log(chalk.green(` wrote ${file}`));
|
|
65
|
+
for (const warning of split.warnings)
|
|
66
|
+
console.log(chalk.yellow(` ! ${warning}`));
|
|
67
|
+
console.log(chalk.green(`\n ✓ Verified: every action (${original.actions.length}) gets the same decision as before.`));
|
|
68
|
+
console.log(chalk.gray(" duct/ now takes precedence over duct.config.ts. Delete duct.config.ts when you're happy."));
|
|
69
|
+
console.log(chalk.gray(" Next: npx @duct-sdk/sdk test\n"));
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CapabilitiesFile } from "../core/project.js";
|
|
2
|
+
type Action = CapabilitiesFile["actions"][number];
|
|
3
|
+
export interface SyncOptions {
|
|
4
|
+
cwd: string;
|
|
5
|
+
/** Override the recorded source (path or URL). */
|
|
6
|
+
source?: string;
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
/** Keep actions that disappeared from the source instead of removing them. */
|
|
9
|
+
keepRemoved?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface SyncDiff {
|
|
12
|
+
added: string[];
|
|
13
|
+
removed: string[];
|
|
14
|
+
changed: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
fields: string[];
|
|
17
|
+
}>;
|
|
18
|
+
next: CapabilitiesFile;
|
|
19
|
+
}
|
|
20
|
+
/** Merge fresh actions from the source into the current file. Pure — exported for tests. */
|
|
21
|
+
export declare function mergeCapabilities(current: CapabilitiesFile, fresh: Action[], source: CapabilitiesFile["source"], opts?: {
|
|
22
|
+
keepRemoved?: boolean;
|
|
23
|
+
}): SyncDiff;
|
|
24
|
+
export declare function runSync(opts: SyncOptions): Promise<SyncDiff>;
|
|
25
|
+
export {};
|