@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
package/dist/cli/index.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// ============================================================
|
|
3
|
-
// @duct/sdk — CLI
|
|
3
|
+
// @duct-sdk/sdk — CLI entry point (`npx @duct-sdk/sdk`, bin: duct)
|
|
4
4
|
// ============================================================
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import chalk from "chalk";
|
|
7
7
|
import ora from "ora";
|
|
8
8
|
import inquirer from "inquirer";
|
|
9
|
-
import { runInit } from "./init.js";
|
|
10
9
|
import { SandboxFS } from "./fs/sandbox.js";
|
|
11
10
|
import { detectFramework } from "./detectors/framework.js";
|
|
12
11
|
import { detectAuth } from "./detectors/auth.js";
|
|
13
12
|
import { getGeneratedOutputPaths } from "./output-paths.js";
|
|
14
13
|
import { integrationAuditFailed, printIntegrationAuditIssues, runIntegrationAudit, } from "./processors/integration-audit.js";
|
|
15
|
-
import {
|
|
14
|
+
import { getConfiguredDashboard, getManifestApiBases, getActiveApiBase, getAuthUrl, getShellRuntimeUrl, getDocsUrl, } from "../core/endpoints.js";
|
|
16
15
|
import { assertHostedEndpointsNotLocalhost } from "../core/endpoint-guard.js";
|
|
17
16
|
import { formatEnvDiagnostics } from "../core/env-diagnostics.js";
|
|
18
17
|
import { buildCliReadinessReport } from "../core/readiness-checks.js";
|
|
19
18
|
import * as fs from "fs/promises";
|
|
20
19
|
import * as path from "path";
|
|
21
|
-
import * as os from "os";
|
|
22
20
|
import { fileURLToPath } from "node:url";
|
|
23
21
|
import { readFileSync, existsSync } from "fs";
|
|
24
|
-
import { DuctConfigSchema
|
|
25
|
-
import {
|
|
26
|
-
import { formatSideEffectMismatchLines, findSideEffectReviewMismatches, resolveSideEffectReviewAcks, } from "./side-effects-review-push.js";
|
|
27
|
-
import { generateConfigFile } from "./generators/config.js";
|
|
28
|
-
import { ConfigRuntimeReferenceError, loadDuctConfig, } from "./config-loader.js";
|
|
29
|
-
import { computeManifestPrivilegeDiff, fetchLiveManifestConfig, formatManifestPrivilegeDiff, detectDashboardNetworkReverts, } from "./manifest-diff.js";
|
|
22
|
+
import { DuctConfigSchema } from "../core/config.js";
|
|
23
|
+
import { splitDuctConfig } from "../core/compile.js";
|
|
30
24
|
import { applyActiveProfileEnvSync, ensureProfileExists, getDuctProfileFilePath, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, } from "../core/profile.js";
|
|
25
|
+
import { DUCT_AUTH_FILE, clearAuth, listAccountShells, loginWithKey, readAuth } from "./cloud.js";
|
|
26
|
+
import { findProjectRoot, ProjectLoadError, resolveProjectConfig } from "./project-loader.js";
|
|
27
|
+
import { renderProjectFiles, writeRenderedFiles } from "./project-writer.js";
|
|
28
|
+
import { PushAbortedError, printPushAbort, runPush } from "./push.js";
|
|
29
|
+
import { printTestReport, runTests } from "./test-runner.js";
|
|
30
|
+
import { runSetup, SetupError } from "./setup.js";
|
|
31
|
+
import { createShell, listShells, printShells, ShellsError } from "./shells.js";
|
|
32
|
+
import { openBrowser, startDeviceLogin, waitForDeviceApproval } from "./device-login.js";
|
|
33
|
+
import { runSync } from "./sync.js";
|
|
34
|
+
import { runSplit } from "./split.js";
|
|
35
|
+
import { runAdd } from "./add.js";
|
|
36
|
+
import { buildAgentPrompt } from "./agent-prompt.js";
|
|
31
37
|
// ----------------------------------------------------------------
|
|
32
38
|
// Load all standard .env files in dotenv priority order
|
|
33
39
|
// Priority: shell env > later files > earlier files
|
|
@@ -70,7 +76,8 @@ function resolveEnvSearchDirs(startDir) {
|
|
|
70
76
|
let dir = startDir;
|
|
71
77
|
for (let i = 0; i < 10; i++) {
|
|
72
78
|
dirs.unshift(dir); // prepend so we get root→cwd order
|
|
73
|
-
const isDuctRoot = existsSync(path.join(dir, "duct.
|
|
79
|
+
const isDuctRoot = existsSync(path.join(dir, "duct", "project.ts")) ||
|
|
80
|
+
existsSync(path.join(dir, "duct.config.ts")) ||
|
|
74
81
|
existsSync(path.join(dir, "duct.config.js")) ||
|
|
75
82
|
existsSync(path.join(dir, ".git"));
|
|
76
83
|
if (isDuctRoot) {
|
|
@@ -108,60 +115,6 @@ loadAllEnvFilesSync();
|
|
|
108
115
|
// Shell env keys captured at startup always win over profile defaults.
|
|
109
116
|
applyActiveProfileEnvSync({ protectedKeys: shellEnvKeys });
|
|
110
117
|
// ----------------------------------------------------------------
|
|
111
|
-
// Auth helpers — ~/.duct/auth.json
|
|
112
|
-
// ----------------------------------------------------------------
|
|
113
|
-
const DUCT_AUTH_FILE = path.join(os.homedir(), ".duct", "auth.json");
|
|
114
|
-
async function readAuth() {
|
|
115
|
-
try {
|
|
116
|
-
const raw = await fs.readFile(DUCT_AUTH_FILE, "utf-8");
|
|
117
|
-
return JSON.parse(raw);
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function saveAuth(auth) {
|
|
124
|
-
const dir = path.dirname(DUCT_AUTH_FILE);
|
|
125
|
-
await fs.mkdir(dir, { recursive: true });
|
|
126
|
-
await fs.writeFile(DUCT_AUTH_FILE, JSON.stringify(auth, null, 2), "utf-8");
|
|
127
|
-
// Restrict to owner-only on Unix/macOS (mode 600).
|
|
128
|
-
// On Windows, chmod is typically ignored; access is governed by NTFS ACLs for
|
|
129
|
-
// the user's profile directory (~/.duct/). Keep the credentials file private.
|
|
130
|
-
try {
|
|
131
|
-
await fs.chmod(DUCT_AUTH_FILE, 0o600);
|
|
132
|
-
}
|
|
133
|
-
catch { /* non-fatal on Windows or restricted filesystems */ }
|
|
134
|
-
}
|
|
135
|
-
async function clearAuth() {
|
|
136
|
-
try {
|
|
137
|
-
await fs.unlink(DUCT_AUTH_FILE);
|
|
138
|
-
}
|
|
139
|
-
catch { /* already gone */ }
|
|
140
|
-
}
|
|
141
|
-
async function validateAndSaveToken(rawKey, ductApiBase, dashboardUrl) {
|
|
142
|
-
const response = await fetch(`${ductApiBase}/v1/auth/validate`, {
|
|
143
|
-
headers: { Authorization: `Bearer ${rawKey}` },
|
|
144
|
-
});
|
|
145
|
-
if (!response.ok)
|
|
146
|
-
throw new Error("Invalid API key");
|
|
147
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
148
|
-
if (!contentType.includes("application/json")) {
|
|
149
|
-
throw new Error(`Unexpected response from ${ductApiBase} (expected JSON)`);
|
|
150
|
-
}
|
|
151
|
-
const data = await response.json();
|
|
152
|
-
const auth = {
|
|
153
|
-
token: rawKey,
|
|
154
|
-
email: data.email ?? "unknown",
|
|
155
|
-
companyId: data.company_id ?? "",
|
|
156
|
-
slug: data.slug ?? "",
|
|
157
|
-
apiBase: ductApiBase,
|
|
158
|
-
dashboardUrl,
|
|
159
|
-
savedAt: new Date().toISOString(),
|
|
160
|
-
};
|
|
161
|
-
await saveAuth(auth);
|
|
162
|
-
return auth;
|
|
163
|
-
}
|
|
164
|
-
// ----------------------------------------------------------------
|
|
165
118
|
// Version from package.json
|
|
166
119
|
// ----------------------------------------------------------------
|
|
167
120
|
const pkgPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../package.json");
|
|
@@ -171,535 +124,377 @@ const VERSION = JSON.parse(readFileSync(pkgPath, "utf-8")).version;
|
|
|
171
124
|
// ----------------------------------------------------------------
|
|
172
125
|
const program = new Command();
|
|
173
126
|
program
|
|
174
|
-
.name("
|
|
175
|
-
.description("
|
|
127
|
+
.name("duct")
|
|
128
|
+
.description("Connect your API to Duct and control what AI agents may do with it.\n" +
|
|
129
|
+
"Run with npx @duct-sdk/sdk <command>. With no command, runs setup.")
|
|
176
130
|
.addHelpText("after", "\nRun via: npx @duct-sdk/sdk <command> (bin alias: duct)\n")
|
|
177
131
|
.version(VERSION);
|
|
178
132
|
// ----------------------------------------------------------------
|
|
179
|
-
// duct
|
|
133
|
+
// duct setup (default command) — the 2-minute path
|
|
180
134
|
// ----------------------------------------------------------------
|
|
135
|
+
function exitWithError(err) {
|
|
136
|
+
if (err instanceof SetupError) {
|
|
137
|
+
console.error(chalk.red(`\n ✗ ${err.message}`));
|
|
138
|
+
if (err.hint)
|
|
139
|
+
console.error(chalk.gray(` ${err.hint}`));
|
|
140
|
+
console.error();
|
|
141
|
+
}
|
|
142
|
+
else if (err instanceof ShellsError) {
|
|
143
|
+
console.error(chalk.red(`\n ✗ ${err.message}`));
|
|
144
|
+
if (err.hint)
|
|
145
|
+
console.error(chalk.gray(` ${err.hint}`));
|
|
146
|
+
console.error();
|
|
147
|
+
}
|
|
148
|
+
else if (err instanceof PushAbortedError) {
|
|
149
|
+
printPushAbort(err);
|
|
150
|
+
}
|
|
151
|
+
else if (err instanceof ProjectLoadError) {
|
|
152
|
+
console.error(chalk.red(`\n ✗ ${err.message}\n`));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
156
|
+
console.error(chalk.red(`\n ✗ ${message}\n`));
|
|
157
|
+
}
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
181
160
|
program
|
|
182
|
-
.command("
|
|
183
|
-
.description("
|
|
184
|
-
.option("--
|
|
185
|
-
.option("--
|
|
186
|
-
.option("--
|
|
187
|
-
.option("--
|
|
188
|
-
.option("-y, --yes", "
|
|
189
|
-
.option("--no-
|
|
190
|
-
.option("--
|
|
191
|
-
.option("--api-spec <path>", "Path to an OpenAPI/Swagger spec file — skips Route + API agents for instant, high-accuracy init")
|
|
192
|
-
.option("--curl-collection <path>", "Path to a cURL script or Postman collection JSON — skips Route + API agents")
|
|
193
|
-
.option("--api-url <url>", "Separate API base URL when your API runs on a different domain (e.g., https://api.example.com)")
|
|
194
|
-
.option("--industry <category>", "Product industry for better modality routing (e.g., fintech, ecommerce, saas, ai)")
|
|
161
|
+
.command("setup", { isDefault: true })
|
|
162
|
+
.description("Connect your API to Duct: find your API, write duct/ with safe defaults, verify, push")
|
|
163
|
+
.option("--source <pathOrUrl>", "OpenAPI spec, Postman collection, or curl script (path or URL); 'none' to start empty")
|
|
164
|
+
.option("--openapi <pathOrUrl>", "Alias for --source")
|
|
165
|
+
.option("--api-url <url>", "Public URL where your API is served (default: the shell's registered domain)")
|
|
166
|
+
.option("--shell <shellId>", "Shell to use when your workspace has several")
|
|
167
|
+
.option("-y, --yes", "Accept defaults without prompting (CI)", false)
|
|
168
|
+
.option("--no-push", "Write and verify, but do not push")
|
|
169
|
+
.option("--force", "Overwrite an existing duct/ folder", false)
|
|
195
170
|
.action(async (opts) => {
|
|
196
171
|
try {
|
|
197
|
-
assertHostedEndpointsNotLocalhost();
|
|
198
|
-
await
|
|
172
|
+
assertHostedEndpointsNotLocalhost(await readAuth());
|
|
173
|
+
const ok = await runSetup({
|
|
199
174
|
cwd: process.cwd(),
|
|
200
|
-
|
|
201
|
-
framework: opts.framework,
|
|
202
|
-
noAgents: Boolean(opts.noAgents) || Boolean(opts.manual),
|
|
203
|
-
manual: Boolean(opts.manual),
|
|
204
|
-
update: opts.update,
|
|
205
|
-
yes: opts.yes,
|
|
206
|
-
noInteractive: Boolean(opts.noInteractive),
|
|
207
|
-
apiSpec: opts.apiSpec,
|
|
208
|
-
curlCollection: opts.curlCollection,
|
|
175
|
+
source: opts.source ?? opts.openapi,
|
|
209
176
|
apiUrl: opts.apiUrl,
|
|
210
|
-
|
|
177
|
+
shell: opts.shell,
|
|
178
|
+
yes: opts.yes,
|
|
179
|
+
push: opts.push,
|
|
180
|
+
force: opts.force,
|
|
211
181
|
});
|
|
182
|
+
if (!ok)
|
|
183
|
+
process.exit(1);
|
|
212
184
|
}
|
|
213
185
|
catch (err) {
|
|
214
|
-
|
|
215
|
-
console.error(chalk.red(`\nError: ${message}\n`));
|
|
216
|
-
process.exit(1);
|
|
186
|
+
exitWithError(err);
|
|
217
187
|
}
|
|
218
188
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const actions = (Array.isArray(config.actions) ? config.actions : []);
|
|
237
|
-
const dataModel = config.dataModel;
|
|
238
|
-
const dataModelEntities = dataModel?.entities ?? [];
|
|
239
|
-
const seen = new Set();
|
|
240
|
-
// 1. dataModel entity chains: discoveryAction → fetchAction
|
|
241
|
-
for (const entity of dataModelEntities) {
|
|
242
|
-
if (entity.discoveryAction === entity.fetchAction)
|
|
243
|
-
continue;
|
|
244
|
-
const hasDiscovery = actions.some((a) => a.id === entity.discoveryAction);
|
|
245
|
-
const hasFetch = actions.some((a) => a.id === entity.fetchAction);
|
|
246
|
-
if (!hasDiscovery || !hasFetch)
|
|
247
|
-
continue;
|
|
248
|
-
const wfId = `wf_list_fetch_${entity.id}`;
|
|
249
|
-
if (seen.has(wfId))
|
|
250
|
-
continue;
|
|
251
|
-
seen.add(wfId);
|
|
252
|
-
const entityLabel = entity.label ?? entity.id;
|
|
253
|
-
workflows.push({
|
|
254
|
-
id: wfId,
|
|
255
|
-
name: `List and fetch ${entityLabel}`,
|
|
256
|
-
steps: [{ action_id: entity.discoveryAction }, { action_id: entity.fetchAction }],
|
|
257
|
-
intent_patterns: [
|
|
258
|
-
`show me ${entityLabel}`,
|
|
259
|
-
`find ${entityLabel}`,
|
|
260
|
-
`get ${entityLabel}`,
|
|
261
|
-
`list ${entityLabel}`,
|
|
262
|
-
],
|
|
189
|
+
program
|
|
190
|
+
.command("init")
|
|
191
|
+
.description("Deprecated — use `setup` (deterministic, no LLM key)")
|
|
192
|
+
.option("--api-spec <path>", "Same as setup --source")
|
|
193
|
+
.option("--curl-collection <path>", "Same as setup --source")
|
|
194
|
+
.option("--api-url <url>", "Same as setup --api-url")
|
|
195
|
+
.option("-y, --yes", "Same as setup --yes", false)
|
|
196
|
+
.allowUnknownOption(true)
|
|
197
|
+
.action(async (opts) => {
|
|
198
|
+
console.log(chalk.yellow("\n `duct init` is now `duct setup`: it reads your OpenAPI spec (or lets your coding agent\n" +
|
|
199
|
+
" read your code) and writes a duct/ folder. No LLM key needed. Running setup…"));
|
|
200
|
+
try {
|
|
201
|
+
const ok = await runSetup({
|
|
202
|
+
cwd: process.cwd(),
|
|
203
|
+
source: opts.apiSpec ?? opts.curlCollection,
|
|
204
|
+
apiUrl: opts.apiUrl,
|
|
205
|
+
yes: opts.yes,
|
|
263
206
|
});
|
|
207
|
+
if (!ok)
|
|
208
|
+
process.exit(1);
|
|
264
209
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (!action.dependsOn || action.dependsOn.length === 0)
|
|
268
|
-
continue;
|
|
269
|
-
const wfId = `wf_dep_${action.id}`;
|
|
270
|
-
if (seen.has(wfId))
|
|
271
|
-
continue;
|
|
272
|
-
seen.add(wfId);
|
|
273
|
-
const order = buildDependsOnOrder(action.id, actions, new Set());
|
|
274
|
-
if (order.length <= 1)
|
|
275
|
-
continue;
|
|
276
|
-
const actionLabel = action.name ?? action.id;
|
|
277
|
-
workflows.push({
|
|
278
|
-
id: wfId,
|
|
279
|
-
name: `Execute ${actionLabel}`,
|
|
280
|
-
steps: order.slice(0, 8).map((id) => ({ action_id: id })),
|
|
281
|
-
intent_patterns: action.description ? [action.description] : [actionLabel],
|
|
282
|
-
});
|
|
210
|
+
catch (err) {
|
|
211
|
+
exitWithError(err);
|
|
283
212
|
}
|
|
284
|
-
|
|
285
|
-
}
|
|
213
|
+
});
|
|
286
214
|
// ----------------------------------------------------------------
|
|
287
215
|
// duct push
|
|
288
216
|
// ----------------------------------------------------------------
|
|
289
217
|
program
|
|
290
218
|
.command("push")
|
|
291
|
-
.description("
|
|
292
|
-
.option("--config <path>", "
|
|
293
|
-
.option("--dry-run", "
|
|
294
|
-
.option("--yes", "
|
|
219
|
+
.description("Validate your project and publish it to Duct (duct/ folder or duct.config.ts)")
|
|
220
|
+
.option("--config <path>", "Use a specific duct.config.ts or duct/ folder instead of auto-detecting")
|
|
221
|
+
.option("--dry-run", "Run every gate and print the privilege diff without pushing", false)
|
|
222
|
+
.option("--yes", "Acknowledge warnings and privilege increases (CI override)", false)
|
|
295
223
|
.action(async (opts) => {
|
|
296
|
-
const spinner = ora("Reading config...").start();
|
|
297
224
|
try {
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// Check config file exists
|
|
303
|
-
try {
|
|
304
|
-
await fs.access(configPath);
|
|
225
|
+
const outcome = await runPush({ cwd: process.cwd(), config: opts.config, dryRun: opts.dryRun, yes: opts.yes });
|
|
226
|
+
if (outcome.pushed) {
|
|
227
|
+
console.log(chalk.green(`\n Live — ${outcome.actionCount} actions enforced for ${outcome.shellId}`));
|
|
228
|
+
console.log(chalk.gray(" Verify end to end: npx @duct-sdk/sdk test\n"));
|
|
305
229
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
console.log(chalk.red(` • [${err.path.join(".")}] ${err.message}`));
|
|
333
|
-
}
|
|
334
|
-
console.log(chalk.gray("\nSee /docs/configuration for the required manifest shape.\n"));
|
|
335
|
-
process.exit(1);
|
|
336
|
-
}
|
|
337
|
-
config = validation.data;
|
|
338
|
-
let validated = validation.data;
|
|
339
|
-
const crossIssues = crossValidateDuctConfig(validated);
|
|
340
|
-
const crossErrors = crossIssues.filter((i) => i.severity === "error");
|
|
341
|
-
if (crossErrors.length > 0) {
|
|
342
|
-
spinner.fail("Config cross-validation failed");
|
|
343
|
-
console.log(chalk.red("\nCross-field errors:\n"));
|
|
344
|
-
for (const issue of crossErrors) {
|
|
345
|
-
console.log(chalk.red(` • [${issue.area}] ${issue.issue}`));
|
|
346
|
-
console.log(chalk.gray(` Fix: ${issue.fix}`));
|
|
347
|
-
}
|
|
348
|
-
console.log();
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
exitWithError(err);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
// ----------------------------------------------------------------
|
|
236
|
+
// duct test / validate — will Duct work for my API?
|
|
237
|
+
// ----------------------------------------------------------------
|
|
238
|
+
program
|
|
239
|
+
.command("test")
|
|
240
|
+
.description("Check your project with Duct cloud: reachability, guardrails, and your policy tests")
|
|
241
|
+
.option("--config <path>", "Use a specific duct.config.ts or duct/ folder")
|
|
242
|
+
.option("--offline", "Only run local checks (no network)", false)
|
|
243
|
+
.option("--json", "Machine-readable output", false)
|
|
244
|
+
.action(async (opts) => {
|
|
245
|
+
try {
|
|
246
|
+
if (!opts.offline)
|
|
247
|
+
assertHostedEndpointsNotLocalhost(await readAuth());
|
|
248
|
+
if (!opts.json)
|
|
249
|
+
console.log(chalk.bold("\n Duct · test\n"));
|
|
250
|
+
const report = await runTests({ cwd: process.cwd(), config: opts.config, offline: opts.offline });
|
|
251
|
+
if (opts.json)
|
|
252
|
+
console.log(JSON.stringify(report, null, 2));
|
|
253
|
+
else
|
|
254
|
+
printTestReport(report);
|
|
255
|
+
if (!report.ok)
|
|
349
256
|
process.exit(1);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
exitWithError(err);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
program
|
|
263
|
+
.command("validate")
|
|
264
|
+
.description("Check project files locally (no network) — fast, CI-safe")
|
|
265
|
+
.option("--config <path>", "Use a specific duct.config.ts or duct/ folder")
|
|
266
|
+
.option("--json", "Machine-readable output", false)
|
|
267
|
+
.action(async (opts) => {
|
|
268
|
+
const report = await runTests({ cwd: process.cwd(), config: opts.config, offline: true });
|
|
269
|
+
const checks = report.checks.filter((check) => check.id !== "cloud");
|
|
270
|
+
if (opts.json) {
|
|
271
|
+
console.log(JSON.stringify({ ok: report.ok, checks }, null, 2));
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
console.log(chalk.bold("\n Duct · validate\n"));
|
|
275
|
+
printTestReport({ ...report, checks });
|
|
276
|
+
}
|
|
277
|
+
if (!report.ok)
|
|
278
|
+
process.exit(1);
|
|
279
|
+
});
|
|
280
|
+
// ----------------------------------------------------------------
|
|
281
|
+
// duct sync / split / add / prompt
|
|
282
|
+
// ----------------------------------------------------------------
|
|
283
|
+
program
|
|
284
|
+
.command("sync")
|
|
285
|
+
.description("Refresh duct/capabilities.json from your OpenAPI spec (keeps your reviewed fields)")
|
|
286
|
+
.option("--source <pathOrUrl>", "Sync from a different spec than the one recorded")
|
|
287
|
+
.option("--dry-run", "Show what would change without writing", false)
|
|
288
|
+
.option("--keep-removed", "Keep actions that disappeared from the source", false)
|
|
289
|
+
.action(async (opts) => {
|
|
290
|
+
try {
|
|
291
|
+
console.log(chalk.bold("\n Duct · sync\n"));
|
|
292
|
+
await runSync({ cwd: process.cwd(), source: opts.source, dryRun: opts.dryRun, keepRemoved: opts.keepRemoved });
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
exitWithError(err);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
program
|
|
299
|
+
.command("split")
|
|
300
|
+
.description("Move a legacy duct.config.ts into the duct/ folder layout (verified identical enforcement)")
|
|
301
|
+
.option("--config <path>", "Path to duct.config.ts", undefined)
|
|
302
|
+
.option("--dry-run", "Print the files without writing them", false)
|
|
303
|
+
.option("--force", "Overwrite an existing duct/ folder", false)
|
|
304
|
+
.action(async (opts) => {
|
|
305
|
+
try {
|
|
306
|
+
const ok = await runSplit({ cwd: process.cwd(), config: opts.config, dryRun: opts.dryRun, force: opts.force });
|
|
307
|
+
if (!ok)
|
|
368
308
|
process.exit(1);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
exitWithError(err);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
program
|
|
315
|
+
.command("add <layer>")
|
|
316
|
+
.description("Add an optional layer: identity (act for signed-in users) or shell (embed the chat UI)")
|
|
317
|
+
.option("--force", "Overwrite generated files that already exist", false)
|
|
318
|
+
.action(async (layer, opts) => {
|
|
319
|
+
if (layer !== "identity" && layer !== "shell") {
|
|
320
|
+
console.error(chalk.red(`\n Unknown layer "${layer}". Use: duct add identity | duct add shell\n`));
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
await runAdd({ cwd: process.cwd(), layer, force: opts.force });
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
exitWithError(err);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
program
|
|
331
|
+
.command("prompt")
|
|
332
|
+
.description("Print instructions for your coding agent to describe your API in duct/capabilities.json")
|
|
333
|
+
.option("--write", "Also save them to duct/AGENT_PROMPT.md", false)
|
|
334
|
+
.action(async (opts) => {
|
|
335
|
+
const found = findProjectRoot(process.cwd());
|
|
336
|
+
const text = buildAgentPrompt({ hasProject: found?.layout === "split" });
|
|
337
|
+
console.log(`\n${text}\n`);
|
|
338
|
+
if (opts.write) {
|
|
339
|
+
const root = found?.root ?? process.cwd();
|
|
340
|
+
await fs.mkdir(path.join(root, "duct"), { recursive: true });
|
|
341
|
+
await fs.writeFile(path.join(root, "duct", "AGENT_PROMPT.md"), `${text}\n`, "utf-8");
|
|
342
|
+
console.log(chalk.green(" ✓ Saved duct/AGENT_PROMPT.md\n"));
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
// ----------------------------------------------------------------
|
|
346
|
+
// duct shells — list or create shells
|
|
347
|
+
// ----------------------------------------------------------------
|
|
348
|
+
const shellsCommand = program
|
|
349
|
+
.command("shells")
|
|
350
|
+
.description("List your shells, or create one (prod, staging, dev, or a custom name such as checkout-prod)");
|
|
351
|
+
shellsCommand
|
|
352
|
+
.command("list", { isDefault: true })
|
|
353
|
+
.description("List the shells in your workspace")
|
|
354
|
+
.option("--json", "Machine-readable output", false)
|
|
355
|
+
.action(async (opts) => {
|
|
356
|
+
try {
|
|
357
|
+
const shells = await listShells();
|
|
358
|
+
if (opts.json)
|
|
359
|
+
console.log(JSON.stringify({ shells }, null, 2));
|
|
360
|
+
else
|
|
361
|
+
printShells(shells);
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
exitWithError(err);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
shellsCommand
|
|
368
|
+
.command("create <name>")
|
|
369
|
+
.description("Create a shell; its credentials are saved to a git-ignored .env.duct.<name> file")
|
|
370
|
+
.option("--domain <url...>", "Where your product and API run (repeatable)")
|
|
371
|
+
.option("--json", "Machine-readable output (never includes the secret)", false)
|
|
372
|
+
.action(async (name, opts) => {
|
|
373
|
+
try {
|
|
374
|
+
const outcome = await createShell({ cwd: process.cwd(), name, domains: opts.domain ?? [] });
|
|
375
|
+
const relative = path.relative(process.cwd(), outcome.envFile) || outcome.envFile;
|
|
376
|
+
if (opts.json) {
|
|
377
|
+
console.log(JSON.stringify({ shell_id: outcome.shellId, name: outcome.name, env_file: relative }));
|
|
428
378
|
}
|
|
429
379
|
else {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
liveConfig = JSON.parse(snapshotRaw);
|
|
434
|
-
console.log(chalk.gray("\n Using .duct-manifest.json as diff baseline (not logged in).\n"));
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
console.log(chalk.gray("\n No live manifest baseline (first push or run `npx duct login`).\n"));
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
const privilegeDiff = computeManifestPrivilegeDiff(validated, liveConfig);
|
|
441
|
-
const diffLines = formatManifestPrivilegeDiff(privilegeDiff);
|
|
442
|
-
console.log(chalk.bold("\n Manifest privilege diff:\n"));
|
|
443
|
-
for (const line of diffLines) {
|
|
444
|
-
const color = privilegeDiff.hasPrivilegeIncrease ? chalk.red : chalk.green;
|
|
445
|
-
console.log(color(` ${line}`));
|
|
446
|
-
}
|
|
447
|
-
console.log();
|
|
448
|
-
if (privilegeDiff.hasPrivilegeIncrease && !opts.yes) {
|
|
449
|
-
console.log(chalk.red("\n Push blocked — privilege-increasing changes require explicit confirmation.\n" +
|
|
450
|
-
" Re-run with --yes to acknowledge (CI override).\n"));
|
|
451
|
-
process.exit(1);
|
|
452
|
-
}
|
|
453
|
-
// Dashboard-managed network settings (intershell_enabled, registry_visibility) are toggled
|
|
454
|
-
// live in the dashboard. A push whose config would turn OFF what the dashboard has ON is the
|
|
455
|
-
// silent-revert footgun — flag it and block unless --yes so a stale/CI config can't quietly
|
|
456
|
-
// disable cross-shell reachability. The dashboard stays the default winner.
|
|
457
|
-
const networkReverts = detectDashboardNetworkReverts(liveConfig, validated);
|
|
458
|
-
const forceDashboardNetworkOverride = networkReverts.length > 0 && opts.yes;
|
|
459
|
-
if (networkReverts.length > 0) {
|
|
460
|
-
console.log(chalk.yellow("\n ⚠ Network settings you changed in the dashboard would be reverted by this push:\n"));
|
|
461
|
-
for (const r of networkReverts)
|
|
462
|
-
console.log(chalk.yellow(` • ${r}`));
|
|
463
|
-
console.log(chalk.gray("\n The dashboard is the live control for these settings. To keep them, set the\n" +
|
|
464
|
-
" matching values in duct.config.ts (e.g. `intershell_enabled: true`).\n"));
|
|
465
|
-
if (!opts.yes) {
|
|
466
|
-
console.log(chalk.yellow(" Push blocked. Re-run with --yes to apply this push and override the dashboard.\n"));
|
|
467
|
-
process.exit(1);
|
|
468
|
-
}
|
|
469
|
-
console.log(chalk.gray(" Continuing with --yes — the dashboard settings will be overwritten.\n"));
|
|
470
|
-
}
|
|
471
|
-
if (opts.dryRun) {
|
|
472
|
-
console.log(chalk.green("✓ Dry-run complete — manifest not pushed.\n"));
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
if (!apiKey) {
|
|
476
|
-
console.error(chalk.red("\nNot logged in.\n"));
|
|
477
|
-
console.log("Run `npx duct login` first.\n");
|
|
478
|
-
process.exit(1);
|
|
380
|
+
console.log(chalk.green(`\n Created ${outcome.shellId}`));
|
|
381
|
+
console.log(` Credentials saved to ${chalk.cyan(relative)} (git-ignored). Put them in your server's environment.`);
|
|
382
|
+
console.log(chalk.gray(` Next: npx @duct-sdk/sdk setup --shell ${outcome.name}\n`));
|
|
479
383
|
}
|
|
480
|
-
// ── Pre-compute workflows from dataModel + dependsOn graph ───────────────
|
|
481
|
-
// Walk the entity DAG to generate named workflow stubs that the shell can
|
|
482
|
-
// execute without a per-step LLM routing call.
|
|
483
|
-
const precomputedWorkflows = computePrecomputedWorkflows(config);
|
|
484
|
-
if (precomputedWorkflows.length > 0) {
|
|
485
|
-
console.log(chalk.gray(`\n ◆ ${precomputedWorkflows.length} workflow(s) pre-computed from dataModel + dependsOn graph`));
|
|
486
|
-
for (const wf of precomputedWorkflows) {
|
|
487
|
-
const stepNames = wf.steps.map((s) => s.action_id).join(" → ");
|
|
488
|
-
console.log(chalk.gray(` • ${wf.name} (${stepNames})`));
|
|
489
|
-
}
|
|
490
|
-
console.log();
|
|
491
|
-
// Embed into the manifest so Duct stores them alongside actions
|
|
492
|
-
config = { ...config, precomputedWorkflows };
|
|
493
|
-
}
|
|
494
|
-
const pushSpinner = ora("Pushing to Duct cloud...").start();
|
|
495
|
-
const auth = authProfile;
|
|
496
|
-
const manifestBases = getManifestApiBases(auth);
|
|
497
|
-
let success = false;
|
|
498
|
-
let lastError = "";
|
|
499
|
-
const attemptedBases = [];
|
|
500
|
-
for (const base of manifestBases) {
|
|
501
|
-
attemptedBases.push(base);
|
|
502
|
-
const response = await fetch(`${base}/v1/shells/${shellId}/manifest`, {
|
|
503
|
-
method: "PUT",
|
|
504
|
-
headers: {
|
|
505
|
-
"Content-Type": "application/json",
|
|
506
|
-
Authorization: `Bearer ${apiKey}`,
|
|
507
|
-
},
|
|
508
|
-
body: JSON.stringify({
|
|
509
|
-
config,
|
|
510
|
-
...(forceDashboardNetworkOverride
|
|
511
|
-
? { force_dashboard_network_override: true }
|
|
512
|
-
: {}),
|
|
513
|
-
}),
|
|
514
|
-
});
|
|
515
|
-
if (response.ok) {
|
|
516
|
-
success = true;
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
const body = await response.text();
|
|
520
|
-
lastError = `API error (${response.status}) at ${base}: ${body}`;
|
|
521
|
-
// Keep probing in case this host doesn't expose manifest endpoints.
|
|
522
|
-
if (response.status === 404) {
|
|
523
|
-
continue;
|
|
524
|
-
}
|
|
525
|
-
pushSpinner.fail("Push failed");
|
|
526
|
-
// Parse the error body and surface the real cause clearly.
|
|
527
|
-
// The proxy may wrap inner service errors as a JSON string inside `message`.
|
|
528
|
-
let outerErr = {};
|
|
529
|
-
let innerErr = {};
|
|
530
|
-
try {
|
|
531
|
-
outerErr = JSON.parse(body);
|
|
532
|
-
}
|
|
533
|
-
catch { /* raw string error */ }
|
|
534
|
-
if (typeof outerErr["message"] === "string") {
|
|
535
|
-
try {
|
|
536
|
-
innerErr = JSON.parse(outerErr["message"]);
|
|
537
|
-
}
|
|
538
|
-
catch { /* not JSON */ }
|
|
539
|
-
}
|
|
540
|
-
const innerCode = (innerErr["error"] ?? outerErr["error"] ?? "");
|
|
541
|
-
const retryAfter = innerErr["retry_after"];
|
|
542
|
-
if (innerCode === "too_many_requests") {
|
|
543
|
-
const wait = retryAfter ? ` Try again in ${retryAfter}s.` : " Try again shortly.";
|
|
544
|
-
console.error(chalk.red("\n Auth service rate-limited: too many failed token validation attempts."));
|
|
545
|
-
console.log(chalk.yellow(` This usually means DUCT_SECRET_KEY was missing or invalid on previous runs.${wait}`));
|
|
546
|
-
console.log(chalk.gray(" 1. Confirm DUCT_SECRET_KEY is set in your .env (at the same level as duct.config.ts)"));
|
|
547
|
-
console.log(chalk.gray(" 2. Run `npx duct login` if your session token is stale"));
|
|
548
|
-
console.log(chalk.gray(" 3. Run `npx duct checkup` to verify env vars are loaded\n"));
|
|
549
|
-
}
|
|
550
|
-
else if (response.status === 401) {
|
|
551
|
-
const hint = outerErr["message"] ?? body;
|
|
552
|
-
console.error(chalk.red(`\n Authentication failed: ${hint}`));
|
|
553
|
-
console.log(chalk.gray(" Run `npx duct login` to refresh your credentials, then retry.\n"));
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
console.error(chalk.red(`\n${lastError}`));
|
|
557
|
-
console.log(chalk.gray(" Tip: Check DUCT_URL is set and services are running."));
|
|
558
|
-
console.log(chalk.gray(" Run npx duct checkup to diagnose connectivity.\n"));
|
|
559
|
-
}
|
|
560
|
-
process.exit(1);
|
|
561
|
-
}
|
|
562
|
-
if (!success) {
|
|
563
|
-
pushSpinner.fail("Push failed");
|
|
564
|
-
console.error(chalk.red(`\n${lastError || "No manifest API endpoint responded"}`));
|
|
565
|
-
console.log(chalk.gray(" Tip: Check that DUCT_URL is set and services are reachable."));
|
|
566
|
-
console.log(chalk.gray(" Run npx duct checkup to diagnose connectivity.\n"));
|
|
567
|
-
process.exit(1);
|
|
568
|
-
}
|
|
569
|
-
pushSpinner.succeed(`Manifest synced for shell: ${chalk.cyan(shellId)}`);
|
|
570
|
-
// Keep .duct-manifest.json in sync so `duct scan --manifest-diff` always
|
|
571
|
-
// diffs against what was actually last pushed, not just what `duct init` wrote.
|
|
572
|
-
try {
|
|
573
|
-
const snapshotPath = path.resolve(cwd, ".duct-manifest.json");
|
|
574
|
-
await fs.writeFile(snapshotPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
575
|
-
}
|
|
576
|
-
catch { /* non-fatal — snapshot is a local convenience file */ }
|
|
577
|
-
console.log(chalk.green("\n ◆ Manifest synced\n"));
|
|
578
384
|
}
|
|
579
385
|
catch (err) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
386
|
+
if (opts.json && err instanceof ShellsError) {
|
|
387
|
+
console.log(JSON.stringify({ error: err.message, hint: err.hint, existing_shell_id: err.existingShellId }));
|
|
388
|
+
process.exit(1);
|
|
389
|
+
}
|
|
390
|
+
exitWithError(err);
|
|
584
391
|
}
|
|
585
392
|
});
|
|
586
393
|
// ----------------------------------------------------------------
|
|
394
|
+
// duct mcp — onboarding server for coding assistants
|
|
395
|
+
// ----------------------------------------------------------------
|
|
396
|
+
program
|
|
397
|
+
.command("mcp")
|
|
398
|
+
.description("Start the duct-onboarding MCP server so your coding assistant can connect this codebase (stdio)")
|
|
399
|
+
.addHelpText("after", "\nClaude Code: claude mcp add duct-onboarding -- npx -y @duct-sdk/sdk mcp\n" +
|
|
400
|
+
'Cursor, VS Code, others: command "npx", args ["-y", "@duct-sdk/sdk", "mcp"]\n')
|
|
401
|
+
.action(async () => {
|
|
402
|
+
const { runMcpServer } = await import("./mcp.js");
|
|
403
|
+
await runMcpServer();
|
|
404
|
+
});
|
|
405
|
+
// ----------------------------------------------------------------
|
|
406
|
+
// duct mcp-setup — dashboard setup server for coding assistants
|
|
407
|
+
// ----------------------------------------------------------------
|
|
408
|
+
program
|
|
409
|
+
.command("mcp-setup")
|
|
410
|
+
.description("Start the duct-setup MCP server: webhooks, sign-in links, partner profiles, and connection checks (stdio)")
|
|
411
|
+
.addHelpText("after", "\nSeparate from `duct mcp` so an assistant only loads these four tools when you need them.\n" +
|
|
412
|
+
"Claude Code: claude mcp add duct-setup -- npx -y @duct-sdk/sdk mcp-setup\n" +
|
|
413
|
+
'Cursor, VS Code, others: command "npx", args ["-y", "@duct-sdk/sdk", "mcp-setup"]\n')
|
|
414
|
+
.action(async () => {
|
|
415
|
+
const { runSetupMcpServer } = await import("./mcp-setup.js");
|
|
416
|
+
await runSetupMcpServer();
|
|
417
|
+
});
|
|
418
|
+
// ----------------------------------------------------------------
|
|
587
419
|
// duct login
|
|
588
420
|
// ----------------------------------------------------------------
|
|
589
421
|
program
|
|
590
422
|
.command("login")
|
|
591
|
-
.description("
|
|
592
|
-
.option("--token <token>", "
|
|
423
|
+
.description("Sign in: opens your browser to approve this machine (or use --token / DUCT_API_KEY in CI)")
|
|
424
|
+
.option("--token <token>", "Sign in with an existing API key (dk_live_...) instead of the browser")
|
|
425
|
+
.option("--paste", "Paste an API key at a masked prompt instead of using the browser", false)
|
|
593
426
|
.option("--logout", "Clear stored credentials")
|
|
594
427
|
.action(async (opts) => {
|
|
595
428
|
const existingAuth = await readAuth();
|
|
596
429
|
const dashboardHint = getConfiguredDashboard(existingAuth);
|
|
597
|
-
const registerHint = `${dashboardHint}/register`;
|
|
598
|
-
const attemptedBases = [];
|
|
599
|
-
if (!opts.logout) {
|
|
600
|
-
assertHostedEndpointsNotLocalhost(existingAuth);
|
|
601
|
-
}
|
|
602
|
-
// duct login --logout
|
|
603
430
|
if (opts.logout) {
|
|
604
431
|
await clearAuth();
|
|
605
|
-
console.log(chalk.green("\n
|
|
432
|
+
console.log(chalk.green("\n Signed out. Credentials removed.\n"));
|
|
606
433
|
return;
|
|
607
434
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
console.log(chalk.yellow("\n ⚠ Passing --token on the command line stores the key in your shell history.\n" +
|
|
611
|
-
" Prefer interactive login (masked prompt) or set DUCT_API_KEY in the environment.\n"));
|
|
612
|
-
rawKey = opts.token;
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
console.log(chalk.bold("\n ◆ Duct Login\n"));
|
|
616
|
-
console.log(" Get your API key from " +
|
|
617
|
-
chalk.cyan(registerHint) +
|
|
618
|
-
" → after signup it is shown once.\n");
|
|
619
|
-
const { apiKey } = await inquirer.prompt([
|
|
620
|
-
{
|
|
621
|
-
type: "password",
|
|
622
|
-
name: "apiKey",
|
|
623
|
-
message: "Paste your Duct API key (dk_live_...):",
|
|
624
|
-
mask: "*",
|
|
625
|
-
validate: (v) => v.startsWith("dk_live_") || "Key must start with dk_live_",
|
|
626
|
-
},
|
|
627
|
-
]);
|
|
628
|
-
rawKey = apiKey;
|
|
629
|
-
}
|
|
630
|
-
const spinner = ora("Validating key…").start();
|
|
435
|
+
assertHostedEndpointsNotLocalhost(existingAuth);
|
|
436
|
+
let auth;
|
|
631
437
|
try {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
attemptedBases.push(base);
|
|
637
|
-
try {
|
|
638
|
-
const dashboardUrl = getConfiguredDashboard(existingAuth);
|
|
639
|
-
auth = await validateAndSaveToken(rawKey, base, dashboardUrl);
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
catch (err) {
|
|
643
|
-
lastError = err;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
if (!auth) {
|
|
647
|
-
const message = lastError instanceof Error ? lastError.message : "Invalid API key";
|
|
648
|
-
throw new Error(message);
|
|
649
|
-
}
|
|
650
|
-
spinner.succeed(`Logged in as ${chalk.bold(auth.email)} (${auth.slug})`);
|
|
651
|
-
console.log(chalk.gray(` API base: ${auth.apiBase}`));
|
|
652
|
-
console.log(chalk.gray(` Credentials saved to ${DUCT_AUTH_FILE}\n` +
|
|
653
|
-
" Storage: JSON file with your API key (dk_live_…). Unix/macOS: file mode 600.\n" +
|
|
654
|
-
" Windows: NTFS ACLs on your user profile govern access — keep ~/.duct private.\n"));
|
|
655
|
-
console.log(chalk.yellow(` ⚠ Keep this file private — it contains your API key.\n Add ${DUCT_AUTH_FILE} to your global .gitignore.\n`));
|
|
656
|
-
// Best-effort: fetch and display provisioned shells for this account.
|
|
657
|
-
// Account/identity endpoints use the auth base URL, not the API base URL.
|
|
658
|
-
try {
|
|
659
|
-
const authBase = getActiveAuthBase(auth);
|
|
660
|
-
const shellsRes = await fetch(`${authBase}/v1/account/shells`, {
|
|
661
|
-
headers: { Authorization: `Bearer ${rawKey}` },
|
|
662
|
-
signal: AbortSignal.timeout(4000),
|
|
663
|
-
});
|
|
664
|
-
if (shellsRes.ok) {
|
|
665
|
-
const shellsData = await shellsRes.json();
|
|
666
|
-
const shells = shellsData.shells ?? [];
|
|
667
|
-
if (shells.length > 0) {
|
|
668
|
-
console.log(chalk.bold(` Provisioned shells (${shells.length}):`));
|
|
669
|
-
for (const s of shells) {
|
|
670
|
-
const status = s.status === "active"
|
|
671
|
-
? chalk.green("active")
|
|
672
|
-
: chalk.yellow(s.status ?? "unknown");
|
|
673
|
-
const env = s.environment ? chalk.gray(` — ${s.environment}`) : "";
|
|
674
|
-
console.log(` ${chalk.cyan(s.id)}${env} ${status}`);
|
|
675
|
-
}
|
|
676
|
-
console.log();
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
console.log(chalk.gray(" No shells provisioned yet — visit the dashboard to create one.\n"));
|
|
680
|
-
}
|
|
438
|
+
if (opts.token || opts.paste) {
|
|
439
|
+
let rawKey = opts.token ?? "";
|
|
440
|
+
if (opts.token) {
|
|
441
|
+
console.log(chalk.yellow("\n ! --token puts the key in your shell history. Prefer `login` (browser) or DUCT_API_KEY.\n"));
|
|
681
442
|
}
|
|
682
443
|
else {
|
|
683
|
-
|
|
444
|
+
const { apiKey } = await inquirer.prompt([
|
|
445
|
+
{
|
|
446
|
+
type: "password",
|
|
447
|
+
name: "apiKey",
|
|
448
|
+
message: "Duct API key (dk_live_...):",
|
|
449
|
+
mask: "*",
|
|
450
|
+
validate: (v) => v.startsWith("dk_live_") || "Keys start with dk_live_",
|
|
451
|
+
},
|
|
452
|
+
]);
|
|
453
|
+
rawKey = apiKey;
|
|
684
454
|
}
|
|
455
|
+
const spinner = ora("Checking key…").start();
|
|
456
|
+
auth = await loginWithKey(rawKey, existingAuth).catch((err) => {
|
|
457
|
+
spinner.fail("Key rejected");
|
|
458
|
+
throw err;
|
|
459
|
+
});
|
|
460
|
+
spinner.stop();
|
|
685
461
|
}
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
console.log(chalk.
|
|
462
|
+
else {
|
|
463
|
+
const { base, start } = await startDeviceLogin(existingAuth);
|
|
464
|
+
console.log(chalk.bold("\n Sign in to Duct\n"));
|
|
465
|
+
console.log(` Confirm this code in your browser: ${chalk.bold.cyan(start.user_code)}`);
|
|
466
|
+
console.log(chalk.gray(` ${start.verification_uri_complete}`));
|
|
467
|
+
console.log(chalk.gray(` No browser here? Open ${start.verification_uri} on any device and enter the code.\n`));
|
|
468
|
+
openBrowser(start.verification_uri_complete);
|
|
469
|
+
const spinner = ora("Waiting for approval…").start();
|
|
470
|
+
auth = await waitForDeviceApproval(base, start, existingAuth).catch((err) => {
|
|
471
|
+
spinner.fail("Sign-in did not complete");
|
|
472
|
+
throw err;
|
|
473
|
+
});
|
|
474
|
+
spinner.stop();
|
|
689
475
|
}
|
|
690
476
|
}
|
|
691
477
|
catch (err) {
|
|
692
|
-
spinner.fail("Login failed");
|
|
693
478
|
const message = err instanceof Error ? err.message : String(err);
|
|
694
|
-
console.error(chalk.red(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
console.log(chalk.gray(" Tip: Set DUCT_URL and make sure your Duct stack is running."));
|
|
699
|
-
console.log(chalk.gray(" Run npx duct checkup to diagnose connectivity."));
|
|
700
|
-
console.log(chalk.gray(` Get your API key from ${dashboardHint}\n`));
|
|
479
|
+
console.error(chalk.red(`\n ✗ ${message}`));
|
|
480
|
+
console.log(chalk.gray(" Check connectivity with: npx @duct-sdk/sdk checkup"));
|
|
481
|
+
console.log(chalk.gray(` Dashboard: ${dashboardHint}\n`));
|
|
701
482
|
process.exit(1);
|
|
702
483
|
}
|
|
484
|
+
console.log(chalk.green(`\n Signed in as ${auth.email} (${auth.slug})`));
|
|
485
|
+
console.log(chalk.gray(` Credentials saved to ${DUCT_AUTH_FILE}. Keep it private; revoke this machine any time in Settings → API keys.`));
|
|
486
|
+
try {
|
|
487
|
+
const shells = await listAccountShells(auth, auth.token);
|
|
488
|
+
if (shells.length === 0) {
|
|
489
|
+
console.log(chalk.gray(" No shells yet. Create one: npx @duct-sdk/sdk shells create prod --domain https://app.example.com\n"));
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
printShells(shells);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
console.log();
|
|
497
|
+
}
|
|
703
498
|
});
|
|
704
499
|
// ----------------------------------------------------------------
|
|
705
500
|
// duct checkup — validate env + service connectivity
|
|
@@ -753,7 +548,7 @@ program
|
|
|
753
548
|
process.exit(1);
|
|
754
549
|
return;
|
|
755
550
|
}
|
|
756
|
-
console.log(chalk.bold(`\n
|
|
551
|
+
console.log(chalk.bold(`\n Duct · checkup\n`));
|
|
757
552
|
// — Env summary —
|
|
758
553
|
console.log(chalk.bold(" Environment"));
|
|
759
554
|
console.log(chalk.gray(` DUCT_URL : ${ductUrl || chalk.yellow("(not set — using localhost defaults)")}`));
|
|
@@ -776,7 +571,7 @@ program
|
|
|
776
571
|
}
|
|
777
572
|
console.log();
|
|
778
573
|
if (!auth) {
|
|
779
|
-
console.log(chalk.yellow("
|
|
574
|
+
console.log(chalk.yellow(" ! Not logged in — run: npx @duct-sdk/sdk login\n"));
|
|
780
575
|
}
|
|
781
576
|
else if (report.ok) {
|
|
782
577
|
console.log(chalk.green(" ✓ Service connectivity checks complete\n"));
|
|
@@ -784,15 +579,14 @@ program
|
|
|
784
579
|
else {
|
|
785
580
|
console.log(chalk.red(" ✗ One or more service checks failed\n"));
|
|
786
581
|
}
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
const hasConfig = await fs.access(configPath).then(() => true).catch(() => false);
|
|
790
|
-
if (hasConfig) {
|
|
582
|
+
const found = findProjectRoot(process.cwd());
|
|
583
|
+
if (found) {
|
|
791
584
|
console.log(chalk.bold(" Project integration"));
|
|
792
585
|
try {
|
|
586
|
+
const cwd = found.root;
|
|
793
587
|
const sandboxFs = new SandboxFS(cwd);
|
|
794
|
-
const
|
|
795
|
-
const config =
|
|
588
|
+
const resolved = await resolveProjectConfig(cwd);
|
|
589
|
+
const config = resolved.config;
|
|
796
590
|
const framework = await detectFramework(cwd);
|
|
797
591
|
const authDetection = await detectAuth(sandboxFs);
|
|
798
592
|
const outputPaths = getGeneratedOutputPaths(cwd, framework);
|
|
@@ -818,12 +612,12 @@ program
|
|
|
818
612
|
console.log(chalk.green(" ✓ Integration audit passed\n"));
|
|
819
613
|
}
|
|
820
614
|
else {
|
|
821
|
-
console.log(chalk.yellow("
|
|
615
|
+
console.log(chalk.yellow(" ! Integration audit found warnings — review fixes above\n"));
|
|
822
616
|
}
|
|
823
617
|
}
|
|
824
618
|
catch (err) {
|
|
825
619
|
const message = err instanceof Error ? err.message : String(err);
|
|
826
|
-
console.log(chalk.yellow(`
|
|
620
|
+
console.log(chalk.yellow(` ! Could not run integration audit: ${message}\n`));
|
|
827
621
|
}
|
|
828
622
|
}
|
|
829
623
|
});
|
|
@@ -842,7 +636,7 @@ profileCmd
|
|
|
842
636
|
const active = resolveActiveProfileName(file);
|
|
843
637
|
const profileName = (name ?? active).trim();
|
|
844
638
|
const urls = resolveProfileUrls(profileName, file);
|
|
845
|
-
console.log(chalk.bold("\n
|
|
639
|
+
console.log(chalk.bold("\n Duct · profile\n"));
|
|
846
640
|
console.log(` active : ${active}`);
|
|
847
641
|
console.log(` showing : ${profileName}`);
|
|
848
642
|
console.log(` file : ${getDuctProfileFilePath()}`);
|
|
@@ -864,7 +658,7 @@ profileCmd
|
|
|
864
658
|
const file = readProfileFileSync();
|
|
865
659
|
const active = resolveActiveProfileName(file);
|
|
866
660
|
const names = listProfileNames(file);
|
|
867
|
-
console.log(chalk.bold("\n
|
|
661
|
+
console.log(chalk.bold("\n Duct · profile list\n"));
|
|
868
662
|
for (const name of names) {
|
|
869
663
|
const marker = name === active ? chalk.green(" (active)") : "";
|
|
870
664
|
console.log(` ${name}${marker}`);
|
|
@@ -898,10 +692,10 @@ program
|
|
|
898
692
|
.action(async () => {
|
|
899
693
|
const auth = await readAuth();
|
|
900
694
|
if (!auth) {
|
|
901
|
-
console.error(chalk.red("\nNot logged in. Run `npx duct login`.\n"));
|
|
695
|
+
console.error(chalk.red("\nNot logged in. Run `npx @duct-sdk/sdk login`.\n"));
|
|
902
696
|
process.exit(1);
|
|
903
697
|
}
|
|
904
|
-
console.log(chalk.bold("\n
|
|
698
|
+
console.log(chalk.bold("\n Duct · whoami\n"));
|
|
905
699
|
console.log(` email : ${auth.email}`);
|
|
906
700
|
console.log(` slug : ${auth.slug}`);
|
|
907
701
|
console.log(` company_id : ${auth.companyId || "(unknown)"}`);
|
|
@@ -923,7 +717,7 @@ program
|
|
|
923
717
|
.option("--redact", "Redact secret-like values", false)
|
|
924
718
|
.action(async (opts) => {
|
|
925
719
|
const auth = await readAuth();
|
|
926
|
-
console.log(chalk.bold("\n
|
|
720
|
+
console.log(chalk.bold("\n Duct · env\n"));
|
|
927
721
|
console.log(formatEnvDiagnostics(auth, { redact: Boolean(opts.redact) }));
|
|
928
722
|
console.log();
|
|
929
723
|
});
|
|
@@ -932,29 +726,21 @@ program
|
|
|
932
726
|
// ----------------------------------------------------------------
|
|
933
727
|
program
|
|
934
728
|
.command("scan")
|
|
935
|
-
.description("Probe live API endpoints against
|
|
936
|
-
.option("--config <path>", "
|
|
729
|
+
.description("Probe live API endpoints against your project and report drift")
|
|
730
|
+
.option("--config <path>", "Use a specific duct.config.ts or duct/ folder")
|
|
937
731
|
.option("--json", "Output results as JSON", false)
|
|
938
|
-
.option("--manifest-diff", "Diff
|
|
732
|
+
.option("--manifest-diff", "Diff your project against the last pushed snapshot (.duct-manifest.json) — no HTTP probing, CI-safe", false)
|
|
939
733
|
.action(async (opts) => {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
console.log(chalk.bold("\n ◆ Duct · scan\n"));
|
|
943
|
-
// Check config exists
|
|
944
|
-
const configExists = await sandboxFs.exists(opts.config);
|
|
945
|
-
if (!configExists) {
|
|
946
|
-
console.log(chalk.yellow(`No ${opts.config} found. Run \`npx duct init\` first.\n`));
|
|
947
|
-
process.exit(1);
|
|
948
|
-
}
|
|
949
|
-
// Load config from compiled JS if available, otherwise parse TypeScript source.
|
|
734
|
+
console.log(chalk.bold("\n Duct · scan\n"));
|
|
735
|
+
let cwd = process.cwd();
|
|
950
736
|
let config;
|
|
951
737
|
try {
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
config =
|
|
738
|
+
const resolved = await resolveProjectConfig(cwd, opts.config);
|
|
739
|
+
cwd = resolved.root;
|
|
740
|
+
config = resolved.config;
|
|
955
741
|
}
|
|
956
|
-
catch {
|
|
957
|
-
console.log(chalk.yellow(
|
|
742
|
+
catch (err) {
|
|
743
|
+
console.log(chalk.yellow(`${err instanceof Error ? err.message : String(err)}\n`));
|
|
958
744
|
process.exit(1);
|
|
959
745
|
}
|
|
960
746
|
// --manifest-diff: compare current duct.config.ts with last pushed snapshot
|
|
@@ -966,7 +752,7 @@ program
|
|
|
966
752
|
snapshot = JSON.parse(raw);
|
|
967
753
|
}
|
|
968
754
|
catch {
|
|
969
|
-
console.log(chalk.yellow(" No .duct-manifest.json snapshot found. Run `npx duct
|
|
755
|
+
console.log(chalk.yellow(" No .duct-manifest.json snapshot found. Run `npx @duct-sdk/sdk push` first.\n"));
|
|
970
756
|
process.exit(1);
|
|
971
757
|
}
|
|
972
758
|
const snapshotActions = new Map((snapshot.actions ?? []).map((a) => [`${a.method}:${a.path}`, a]));
|
|
@@ -1045,7 +831,7 @@ program
|
|
|
1045
831
|
console.log(` ${chalk.red("-")} ${r}`);
|
|
1046
832
|
console.log();
|
|
1047
833
|
}
|
|
1048
|
-
console.log(chalk.gray(" Run `npx duct push` to sync changes with Duct cloud.\n"));
|
|
834
|
+
console.log(chalk.gray(" Run `npx @duct-sdk/sdk push` to sync changes with Duct cloud.\n"));
|
|
1049
835
|
}
|
|
1050
836
|
}
|
|
1051
837
|
// Write drift.json report
|
|
@@ -1083,8 +869,8 @@ program
|
|
|
1083
869
|
program
|
|
1084
870
|
.command("pull <hash>")
|
|
1085
871
|
.description("Restore a manifest version from push history (e.g. duct pull a3f9b12)")
|
|
1086
|
-
.option("--config <path>", "
|
|
1087
|
-
.option("--shell-id <shellId>", "Override shell ID (
|
|
872
|
+
.option("--config <path>", "Write a legacy duct.config.ts at this path instead of the duct/ folder")
|
|
873
|
+
.option("--shell-id <shellId>", "Override shell ID (read from your project by default)")
|
|
1088
874
|
.action(async (hash, opts) => {
|
|
1089
875
|
const spinner = ora("Fetching push record…").start();
|
|
1090
876
|
try {
|
|
@@ -1096,20 +882,20 @@ program
|
|
|
1096
882
|
}
|
|
1097
883
|
if (!apiKey) {
|
|
1098
884
|
spinner.fail("Not logged in");
|
|
1099
|
-
console.log(chalk.yellow("\nRun `npx duct login` first.\n"));
|
|
885
|
+
console.log(chalk.yellow("\nRun `npx @duct-sdk/sdk login` first.\n"));
|
|
1100
886
|
process.exit(1);
|
|
1101
887
|
}
|
|
888
|
+
const found = findProjectRoot(process.cwd());
|
|
889
|
+
const writeSplit = !opts.config && found?.layout === "split";
|
|
1102
890
|
// Resolve shell ID
|
|
1103
891
|
let shellId = opts.shellId;
|
|
1104
892
|
if (!shellId) {
|
|
1105
|
-
const cwd = process.cwd();
|
|
1106
|
-
const configPath = path.resolve(cwd, opts.config);
|
|
1107
893
|
try {
|
|
1108
|
-
const
|
|
1109
|
-
shellId = config["shellId"];
|
|
894
|
+
const resolved = await resolveProjectConfig(process.cwd(), opts.config);
|
|
895
|
+
shellId = resolved.config["shellId"];
|
|
1110
896
|
}
|
|
1111
897
|
catch {
|
|
1112
|
-
//
|
|
898
|
+
// project may not exist yet — will ask
|
|
1113
899
|
}
|
|
1114
900
|
}
|
|
1115
901
|
if (!shellId) {
|
|
@@ -1145,39 +931,40 @@ program
|
|
|
1145
931
|
console.error(chalk.red("\nNo manifest data in record.\n"));
|
|
1146
932
|
process.exit(1);
|
|
1147
933
|
}
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
await fs.access(configPath);
|
|
934
|
+
const target = writeSplit ? "duct/" : (opts.config ?? "duct.config.ts");
|
|
935
|
+
const targetExists = writeSplit
|
|
936
|
+
? true
|
|
937
|
+
: await fs.access(path.resolve(process.cwd(), target)).then(() => true).catch(() => false);
|
|
938
|
+
if (targetExists) {
|
|
1154
939
|
const { confirm } = await inquirer.prompt([
|
|
1155
940
|
{
|
|
1156
941
|
type: "confirm",
|
|
1157
942
|
name: "confirm",
|
|
1158
|
-
message:
|
|
943
|
+
message: `Overwrite ${target} with push ${hash}?`,
|
|
1159
944
|
default: false,
|
|
1160
945
|
},
|
|
1161
946
|
]);
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
947
|
+
if (!confirm) {
|
|
948
|
+
console.log(chalk.yellow("\nAborted — nothing overwritten.\n"));
|
|
949
|
+
process.exit(0);
|
|
950
|
+
}
|
|
1166
951
|
}
|
|
1167
|
-
if (
|
|
1168
|
-
|
|
1169
|
-
|
|
952
|
+
if (writeSplit && found) {
|
|
953
|
+
const parsedManifest = DuctConfigSchema.parse(manifest);
|
|
954
|
+
await writeRenderedFiles(found.root, renderProjectFiles(splitDuctConfig(parsedManifest)));
|
|
1170
955
|
}
|
|
1171
|
-
|
|
956
|
+
else {
|
|
957
|
+
const configContent = `// Restored from push history — hash: ${hash}
|
|
1172
958
|
// Pushed at: ${record.pushed_at ?? "unknown"}
|
|
1173
|
-
// Run \`npx duct push\` to re-sync this version to Duct cloud.
|
|
959
|
+
// Run \`npx @duct-sdk/sdk push\` to re-sync this version to Duct cloud.
|
|
1174
960
|
import { defineDuctConfig } from '@duct-sdk/sdk';
|
|
1175
961
|
|
|
1176
962
|
export default defineDuctConfig(${JSON.stringify(manifest, null, 2)});
|
|
1177
963
|
`;
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
console.log(chalk.
|
|
964
|
+
await fs.writeFile(path.resolve(process.cwd(), target), configContent, "utf-8");
|
|
965
|
+
}
|
|
966
|
+
console.log(chalk.green(`\n ${target} restored from ${hash}\n`));
|
|
967
|
+
console.log(chalk.gray(` Run \`npx @duct-sdk/sdk test\` then \`push\` to re-sync this version.\n`));
|
|
1181
968
|
}
|
|
1182
969
|
catch (err) {
|
|
1183
970
|
spinner.fail("Pull failed");
|
|
@@ -1196,8 +983,8 @@ export default defineDuctConfig(${JSON.stringify(manifest, null, 2)});
|
|
|
1196
983
|
program
|
|
1197
984
|
.command("rollback <hash>")
|
|
1198
985
|
.description("Set a historical push as the active manifest on Duct cloud (no local file changes)")
|
|
1199
|
-
.option("--shell-id <shellId>", "Override shell ID (
|
|
1200
|
-
.option("--config <path>", "
|
|
986
|
+
.option("--shell-id <shellId>", "Override shell ID (read from your project by default)")
|
|
987
|
+
.option("--config <path>", "duct.config.ts or duct/ folder to read shellId from (auto-detected by default)")
|
|
1201
988
|
.option("--yes", "Skip confirmation prompt", false)
|
|
1202
989
|
.action(async (hash, opts) => {
|
|
1203
990
|
const spinner = ora("Resolving shell…").start();
|
|
@@ -1210,19 +997,17 @@ program
|
|
|
1210
997
|
}
|
|
1211
998
|
if (!apiKey) {
|
|
1212
999
|
spinner.fail("Not logged in");
|
|
1213
|
-
console.log(chalk.yellow("\nRun `npx duct login` first.\n"));
|
|
1000
|
+
console.log(chalk.yellow("\nRun `npx @duct-sdk/sdk login` first.\n"));
|
|
1214
1001
|
process.exit(1);
|
|
1215
1002
|
}
|
|
1216
1003
|
// Resolve shell ID
|
|
1217
1004
|
let shellId = opts.shellId;
|
|
1218
1005
|
if (!shellId) {
|
|
1219
|
-
const cwd = process.cwd();
|
|
1220
|
-
const configPath = path.resolve(cwd, opts.config);
|
|
1221
1006
|
try {
|
|
1222
|
-
const
|
|
1223
|
-
shellId = config["shellId"];
|
|
1007
|
+
const resolved = await resolveProjectConfig(process.cwd(), opts.config);
|
|
1008
|
+
shellId = resolved.config["shellId"];
|
|
1224
1009
|
}
|
|
1225
|
-
catch { /*
|
|
1010
|
+
catch { /* project may not exist */ }
|
|
1226
1011
|
}
|
|
1227
1012
|
if (!shellId) {
|
|
1228
1013
|
spinner.stop();
|
|
@@ -1277,8 +1062,8 @@ program
|
|
|
1277
1062
|
process.exit(1);
|
|
1278
1063
|
}
|
|
1279
1064
|
activateSpinner.succeed(`Hash ${chalk.cyan(hash)} is now the live manifest for ${chalk.cyan(shellId)}`);
|
|
1280
|
-
console.log(chalk.green("\n
|
|
1281
|
-
console.log(chalk.gray(` Tip: Run \`npx duct pull ${hash}\` to also restore duct.config.ts locally.\n`));
|
|
1065
|
+
console.log(chalk.green("\n Rollback complete\n"));
|
|
1066
|
+
console.log(chalk.gray(` Tip: Run \`npx @duct-sdk/sdk pull ${hash}\` to also restore duct.config.ts locally.\n`));
|
|
1282
1067
|
}
|
|
1283
1068
|
catch (err) {
|
|
1284
1069
|
spinner.fail("Rollback failed");
|
|
@@ -1309,7 +1094,7 @@ program
|
|
|
1309
1094
|
}
|
|
1310
1095
|
if (!apiKey) {
|
|
1311
1096
|
spinner.fail("Not logged in");
|
|
1312
|
-
console.log(chalk.yellow("\nRun `npx duct login` first.\n"));
|
|
1097
|
+
console.log(chalk.yellow("\nRun `npx @duct-sdk/sdk login` first.\n"));
|
|
1313
1098
|
process.exit(1);
|
|
1314
1099
|
}
|
|
1315
1100
|
const auth = await readAuth();
|
|
@@ -1398,12 +1183,12 @@ program
|
|
|
1398
1183
|
process.exit(1);
|
|
1399
1184
|
}
|
|
1400
1185
|
pushSpinner.succeed(`Manifest pushed to ${chalk.cyan(opts.to)}`);
|
|
1401
|
-
console.log(chalk.green("\n
|
|
1186
|
+
console.log(chalk.green("\n Promotion complete\n"));
|
|
1402
1187
|
if (pushHash)
|
|
1403
1188
|
console.log(chalk.dim(` Hash: ${chalk.cyan(pushHash)}`));
|
|
1404
1189
|
if (pushChecksum)
|
|
1405
1190
|
console.log(chalk.dim(` Checksum: ${pushChecksum}`));
|
|
1406
|
-
console.log(chalk.dim(`\n Tip: Run \`npx duct scan --shell-id ${opts.to}\` to verify the promoted shell.\n`));
|
|
1191
|
+
console.log(chalk.dim(`\n Tip: Run \`npx @duct-sdk/sdk scan --shell-id ${opts.to}\` to verify the promoted shell.\n`));
|
|
1407
1192
|
// Persist promoted manifest locally as snapshot so --update diffs correctly
|
|
1408
1193
|
try {
|
|
1409
1194
|
const snapshotPath = path.resolve(process.cwd(), ".duct-manifest.json");
|