@duct-sdk/sdk 0.5.4 → 0.5.9
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 +29 -0
- package/README.md +10 -10
- package/dist/cli/index.js +179 -36
- package/dist/core/config-roundtrip.test.d.ts +1 -0
- package/dist/core/config-roundtrip.test.js +132 -0
- package/dist/core/config.d.ts +253 -25
- package/dist/core/config.js +31 -67
- package/dist/core/endpoint-guard.d.ts +27 -0
- package/dist/core/endpoint-guard.js +71 -0
- package/dist/core/endpoint-guard.test.d.ts +1 -0
- package/dist/core/endpoint-guard.test.js +57 -0
- package/dist/core/env-diagnostics.d.ts +13 -0
- package/dist/core/env-diagnostics.js +63 -0
- package/dist/core/env-diagnostics.test.d.ts +1 -0
- package/dist/core/env-diagnostics.test.js +31 -0
- package/dist/core/profile.d.ts +44 -0
- package/dist/core/profile.js +128 -0
- package/dist/core/profile.test.d.ts +1 -0
- package/dist/core/profile.test.js +95 -0
- package/dist/core/readiness-checks.d.ts +113 -0
- package/dist/core/readiness-checks.js +110 -0
- package/dist/core/readiness-checks.test.d.ts +1 -0
- package/dist/core/readiness-checks.test.js +49 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog — @duct-sdk/sdk
|
|
2
2
|
|
|
3
|
+
## [0.5.9] — 2026-07-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **SDK-01 profile discovery** — `duct profile` commands (`show`, `list`, `use`, `init`) and auto-load from `~/.duct/profile.json`. Built-in `local` and `hosted` presets map service URLs; `DUCT_PROFILE` env still wins. Localhost guard respects `profile=local`.
|
|
7
|
+
- **Profile resolution tests** — `profile.test.ts` covers file load, env precedence, and protected shell keys.
|
|
8
|
+
- **Consumer-safe contracts packaging** — release tarballs declare the contracts semver and bundle the matching runtime schemas; publish smoke installs the packed SDK in a clean project.
|
|
9
|
+
|
|
10
|
+
## [0.5.8] — 2026-07-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **CLI diagnostics** — `duct whoami`, `duct logout`, and `duct env --redact` for account and endpoint inspection with secret redaction.
|
|
14
|
+
- **Hosted localhost guard** — `init`, `login`, `push`, and `checkup` fail in hosted mode when service URLs resolve to localhost unless `DUCT_PROFILE=local` or `DUCT_ALLOW_LOCALHOST=true`.
|
|
15
|
+
|
|
16
|
+
## [0.5.7] — 2026-07-18
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- **READINESS-01 (partial)** — shared `readiness-checks` schema (Zod) plus `duct checkup --json` machine-readable report (env signals, auth/API/shell/dashboard health, docs URL). Dashboard go-live section reuses the same check definitions.
|
|
20
|
+
|
|
21
|
+
## [0.5.6] — 2026-07-18
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- **Config schema parity** — `DuctConfigSchema` now accepts documented manifest fields that were previously stripped by Zod parse: action `inputSchema`, `dependsOn`, semantic metadata (`semanticType`, `outputSchema`, `paramMappings`, `navigatesTo`), `searchHint`/`alwaysInclude`/`interruptBehavior`, route `searchAction`, `dataModel`, and widget loop limits (`compactionTurns`, `maxToolIterations`, `maxPlanSteps`).
|
|
25
|
+
|
|
26
|
+
## [0.5.5] — 2026-07-18
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- **CLI ESM crash** — Replaced `require()` calls in the CLI entry point with ESM `import`/`readFileSync`/`existsSync` so `npx @duct-sdk/sdk --help` works from the published tarball (`"type": "module"`).
|
|
30
|
+
- **`.env` precedence** — `.env.local` now correctly overrides `.env` for the same key; shell/process environment still wins over both.
|
|
31
|
+
|
|
3
32
|
## [0.5.4] — 2026-07-17
|
|
4
33
|
|
|
5
34
|
### Added
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ The official Duct SDK and CLI. Scan your codebase, declare a manifest, push it t
|
|
|
20
20
|
| ------------- | ----------------------------------------------------------------------------------------------- |
|
|
21
21
|
| **Humans** | Embedded chat shell, structured results, signed deeplink handoff into your app |
|
|
22
22
|
| **Agents** | Permissioned API access from the same manifest — no scraping or screen automation |
|
|
23
|
-
| **Operators** | Shell credentials, action tiers, and usage from the
|
|
23
|
+
| **Operators** | Shell credentials, action tiers, and usage from the configured Duct dashboard |
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
---
|
|
@@ -28,12 +28,12 @@ The official Duct SDK and CLI. Scan your codebase, declare a manifest, push it t
|
|
|
28
28
|
## Documentation
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
| Resource
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
| [TOKEN_SPEC.md](./TOKEN_SPEC.md)
|
|
36
|
-
|
|
|
31
|
+
| Resource | Description |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Developer docs (`SITE_URL/docs`) | Quickstart, CLI, frameworks, agents, threat model |
|
|
34
|
+
| AI integration prompt (`SITE_URL/docs/integration-prompt`) | Full `DUCT_CONFIG_PROMPT.md` — copy into Cursor, Claude Code, Codex, or any agentic IDE |
|
|
35
|
+
| [TOKEN_SPEC.md](./TOKEN_SPEC.md) | Token prefixes, claims, TTLs, and cross-language verify snippets |
|
|
36
|
+
| Changelog (`SITE_URL/changelog`) | Platform release notes (includes SDK) |
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
---
|
|
@@ -42,7 +42,7 @@ The official Duct SDK and CLI. Scan your codebase, declare a manifest, push it t
|
|
|
42
42
|
|
|
43
43
|
Duct ships a single integration prompt (`DUCT_CONFIG_PROMPT.md`) for greenfield setup or auditing an existing `duct.config.ts`. Paste it into your coding assistant with the product repo open; the agent generates or reviews manifest fields, the four wiring points, env vars, and a ship checklist.
|
|
44
44
|
|
|
45
|
-
**Get the prompt:**
|
|
45
|
+
**Get the prompt:** open `SITE_URL/docs/integration-prompt` on your configured deployment. The page is expandable and copy-ready, with platform URLs resolved for that environment.
|
|
46
46
|
|
|
47
47
|
Typical flow:
|
|
48
48
|
|
|
@@ -253,12 +253,12 @@ Webhook URLs and signing secrets are configured in the **dashboard → Shell →
|
|
|
253
253
|
- Keep `DUCT_SECRET_KEY` server-side — never in `NEXT_PUBLIC_*`, `VITE_*`, or client bundles
|
|
254
254
|
- Default mutations to `agentAccessible: false` and `sideEffects: true` where appropriate
|
|
255
255
|
- Rotate keys in the dashboard if credentials are exposed
|
|
256
|
-
- Review agent-accessible actions before production — use the
|
|
256
|
+
- Review agent-accessible actions before production — use the integration prompt at `SITE_URL/docs/integration-prompt`
|
|
257
257
|
|
|
258
258
|
---
|
|
259
259
|
|
|
260
260
|
## Support
|
|
261
261
|
|
|
262
|
-
- Docs:
|
|
262
|
+
- Docs: `SITE_URL/docs` on your configured deployment
|
|
263
263
|
- npm: [@duct-sdk/sdk](https://www.npmjs.com/package/@duct-sdk/sdk)
|
|
264
264
|
|
package/dist/cli/index.js
CHANGED
|
@@ -12,25 +12,31 @@ import { detectFramework } from "./detectors/framework.js";
|
|
|
12
12
|
import { detectAuth } from "./detectors/auth.js";
|
|
13
13
|
import { getGeneratedOutputPaths } from "./output-paths.js";
|
|
14
14
|
import { integrationAuditFailed, printIntegrationAuditIssues, runIntegrationAudit, } from "./processors/integration-audit.js";
|
|
15
|
-
import { getCandidateAuthBases, getConfiguredDashboard, getManifestApiBases, getActiveApiBase, getActiveAuthBase, getAuthUrl, getShellRuntimeUrl, } from "../core/endpoints.js";
|
|
15
|
+
import { getCandidateAuthBases, getConfiguredDashboard, getManifestApiBases, getActiveApiBase, getActiveAuthBase, getAuthUrl, getShellRuntimeUrl, getDocsUrl, } from "../core/endpoints.js";
|
|
16
|
+
import { assertHostedEndpointsNotLocalhost } from "../core/endpoint-guard.js";
|
|
17
|
+
import { formatEnvDiagnostics } from "../core/env-diagnostics.js";
|
|
18
|
+
import { buildCliReadinessReport } from "../core/readiness-checks.js";
|
|
16
19
|
import * as fs from "fs/promises";
|
|
17
20
|
import * as path from "path";
|
|
18
21
|
import * as os from "os";
|
|
19
22
|
import { fileURLToPath } from "node:url";
|
|
20
|
-
import { readFileSync } from "fs";
|
|
23
|
+
import { readFileSync, existsSync } from "fs";
|
|
21
24
|
import { DuctConfigSchema, crossValidateDuctConfig } from "../core/config.js";
|
|
22
25
|
import { runAgentSafetyChecks } from "./agents/reviewer-agent.js";
|
|
23
26
|
import { ConfigRuntimeReferenceError, loadDuctConfig, } from "./config-loader.js";
|
|
24
27
|
import { computeManifestPrivilegeDiff, fetchLiveManifestConfig, formatManifestPrivilegeDiff, } from "./manifest-diff.js";
|
|
28
|
+
import { applyActiveProfileEnvSync, ensureProfileExists, getDuctProfileFilePath, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, } from "../core/profile.js";
|
|
25
29
|
// ----------------------------------------------------------------
|
|
26
30
|
// Load all standard .env files in dotenv priority order
|
|
27
|
-
// Priority
|
|
31
|
+
// Priority: shell env > later files > earlier files
|
|
28
32
|
// .env < .env.local < .env.<NODE_ENV> < .env.<NODE_ENV>.local
|
|
29
|
-
//
|
|
33
|
+
// Keys from the shell environment are never overwritten by file loads.
|
|
30
34
|
// ----------------------------------------------------------------
|
|
35
|
+
// Snapshot keys present before any .env file is read (shell/process env wins).
|
|
36
|
+
const shellEnvKeys = new Set(Object.keys(process.env));
|
|
31
37
|
function loadEnvFileSync(envPath) {
|
|
32
38
|
try {
|
|
33
|
-
const content =
|
|
39
|
+
const content = readFileSync(envPath, "utf-8");
|
|
34
40
|
for (const line of content.split("\n")) {
|
|
35
41
|
const trimmed = line.trim();
|
|
36
42
|
if (!trimmed || trimmed.startsWith("#"))
|
|
@@ -42,9 +48,9 @@ function loadEnvFileSync(envPath) {
|
|
|
42
48
|
const raw = trimmed.substring(eqIndex + 1).trim();
|
|
43
49
|
// Strip surrounding quotes if present
|
|
44
50
|
const value = /^["'].*["']$/.test(raw) ? raw.slice(1, -1) : raw;
|
|
45
|
-
// Later files override earlier ones (
|
|
46
|
-
//
|
|
47
|
-
if (key && !(key
|
|
51
|
+
// Later files override earlier ones (.env.local beats .env), but shell env
|
|
52
|
+
// keys captured at startup always win.
|
|
53
|
+
if (key && !shellEnvKeys.has(key)) {
|
|
48
54
|
process.env[key] = value;
|
|
49
55
|
}
|
|
50
56
|
}
|
|
@@ -62,13 +68,13 @@ function resolveEnvSearchDirs(startDir) {
|
|
|
62
68
|
let dir = startDir;
|
|
63
69
|
for (let i = 0; i < 10; i++) {
|
|
64
70
|
dirs.unshift(dir); // prepend so we get root→cwd order
|
|
65
|
-
const isDuctRoot =
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
const isDuctRoot = existsSync(path.join(dir, "duct.config.ts")) ||
|
|
72
|
+
existsSync(path.join(dir, "duct.config.js")) ||
|
|
73
|
+
existsSync(path.join(dir, ".git"));
|
|
68
74
|
if (isDuctRoot) {
|
|
69
75
|
break;
|
|
70
76
|
}
|
|
71
|
-
const parent =
|
|
77
|
+
const parent = path.dirname(dir);
|
|
72
78
|
if (parent === dir)
|
|
73
79
|
break; // filesystem root
|
|
74
80
|
dir = parent;
|
|
@@ -96,6 +102,9 @@ function loadAllEnvFilesSync() {
|
|
|
96
102
|
}
|
|
97
103
|
// Load all .env files synchronously at startup (before any commands run)
|
|
98
104
|
loadAllEnvFilesSync();
|
|
105
|
+
// Apply ~/.duct/profile.json (named profiles: local, hosted, custom) before commands run.
|
|
106
|
+
// Shell env keys captured at startup always win over profile defaults.
|
|
107
|
+
applyActiveProfileEnvSync({ protectedKeys: shellEnvKeys });
|
|
99
108
|
// ----------------------------------------------------------------
|
|
100
109
|
// Auth helpers — ~/.duct/auth.json
|
|
101
110
|
// ----------------------------------------------------------------
|
|
@@ -160,8 +169,9 @@ const VERSION = JSON.parse(readFileSync(pkgPath, "utf-8")).version;
|
|
|
160
169
|
// ----------------------------------------------------------------
|
|
161
170
|
const program = new Command();
|
|
162
171
|
program
|
|
163
|
-
.name("duct")
|
|
172
|
+
.name("@duct-sdk/sdk")
|
|
164
173
|
.description("SDK for the Duct shell — Shell infrastructure for humans and agents.")
|
|
174
|
+
.addHelpText("after", "\nRun via: npx @duct-sdk/sdk <command> (bin alias: duct)\n")
|
|
165
175
|
.version(VERSION);
|
|
166
176
|
// ----------------------------------------------------------------
|
|
167
177
|
// duct init
|
|
@@ -182,6 +192,7 @@ program
|
|
|
182
192
|
.option("--industry <category>", "Product industry for better modality routing (e.g., fintech, ecommerce, saas, ai)")
|
|
183
193
|
.action(async (opts) => {
|
|
184
194
|
try {
|
|
195
|
+
assertHostedEndpointsNotLocalhost();
|
|
185
196
|
await runInit({
|
|
186
197
|
cwd: process.cwd(),
|
|
187
198
|
dryRun: opts.dryRun,
|
|
@@ -282,6 +293,8 @@ program
|
|
|
282
293
|
.action(async (opts) => {
|
|
283
294
|
const spinner = ora("Reading config...").start();
|
|
284
295
|
try {
|
|
296
|
+
const authProfile = await readAuth();
|
|
297
|
+
assertHostedEndpointsNotLocalhost(authProfile);
|
|
285
298
|
const cwd = process.cwd();
|
|
286
299
|
const configPath = path.resolve(cwd, opts.config);
|
|
287
300
|
// Check config file exists
|
|
@@ -375,7 +388,6 @@ program
|
|
|
375
388
|
const shellId = validated.shellId;
|
|
376
389
|
// ── Live manifest diff (privilege deltas) ───────────────────────────────
|
|
377
390
|
let apiKey = process.env["DUCT_API_KEY"];
|
|
378
|
-
const authProfile = await readAuth();
|
|
379
391
|
if (!apiKey) {
|
|
380
392
|
apiKey = authProfile?.token;
|
|
381
393
|
}
|
|
@@ -532,6 +544,9 @@ program
|
|
|
532
544
|
const dashboardHint = getConfiguredDashboard(existingAuth);
|
|
533
545
|
const registerHint = `${dashboardHint}/register`;
|
|
534
546
|
const attemptedBases = [];
|
|
547
|
+
if (!opts.logout) {
|
|
548
|
+
assertHostedEndpointsNotLocalhost(existingAuth);
|
|
549
|
+
}
|
|
535
550
|
// duct login --logout
|
|
536
551
|
if (opts.logout) {
|
|
537
552
|
await clearAuth();
|
|
@@ -640,8 +655,22 @@ program
|
|
|
640
655
|
program
|
|
641
656
|
.command("checkup")
|
|
642
657
|
.description("Check your environment config and verify connectivity to all Duct services")
|
|
643
|
-
.
|
|
658
|
+
.option("--json", "Output machine-readable readiness report as JSON", false)
|
|
659
|
+
.action(async (opts) => {
|
|
644
660
|
const auth = await readAuth();
|
|
661
|
+
try {
|
|
662
|
+
assertHostedEndpointsNotLocalhost(auth);
|
|
663
|
+
}
|
|
664
|
+
catch (err) {
|
|
665
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
666
|
+
if (opts.json) {
|
|
667
|
+
console.log(JSON.stringify({ ok: false, error: message }, null, 2));
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
console.error(chalk.red(`\n${message}\n`));
|
|
671
|
+
}
|
|
672
|
+
process.exit(1);
|
|
673
|
+
}
|
|
645
674
|
const authUrl = getAuthUrl();
|
|
646
675
|
const apiBase = getActiveApiBase(auth);
|
|
647
676
|
const shellUrl = getShellRuntimeUrl();
|
|
@@ -649,6 +678,29 @@ program
|
|
|
649
678
|
const shellId = process.env["DUCT_SHELL_ID"];
|
|
650
679
|
const secretKey = process.env["DUCT_SECRET_KEY"];
|
|
651
680
|
const ductUrl = process.env["DUCT_URL"] ?? "";
|
|
681
|
+
const docsUrl = getDocsUrl();
|
|
682
|
+
const report = await buildCliReadinessReport({
|
|
683
|
+
env: {
|
|
684
|
+
ductUrl: ductUrl || undefined,
|
|
685
|
+
shellId,
|
|
686
|
+
secretKey,
|
|
687
|
+
authEmail: auth?.email,
|
|
688
|
+
authSlug: auth?.slug,
|
|
689
|
+
},
|
|
690
|
+
endpoints: {
|
|
691
|
+
authHealthUrl: `${authUrl}/health`,
|
|
692
|
+
apiHealthUrl: `${apiBase}/health`,
|
|
693
|
+
shellHealthUrl: `${shellUrl}/api/health`,
|
|
694
|
+
dashboardHealthUrl: `${dashUrl}/api/health`,
|
|
695
|
+
docsUrl,
|
|
696
|
+
},
|
|
697
|
+
});
|
|
698
|
+
if (opts.json) {
|
|
699
|
+
console.log(JSON.stringify(report, null, 2));
|
|
700
|
+
if (!report.ok)
|
|
701
|
+
process.exit(1);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
652
704
|
console.log(chalk.bold(`\n ◆ Duct · checkup\n`));
|
|
653
705
|
// — Env summary —
|
|
654
706
|
console.log(chalk.bold(" Environment"));
|
|
@@ -656,39 +708,30 @@ program
|
|
|
656
708
|
console.log(chalk.gray(` DUCT_SHELL_ID : ${shellId || chalk.yellow("(not set)")}`));
|
|
657
709
|
console.log(chalk.gray(` DUCT_SECRET_KEY : ${secretKey ? "sk_..." + secretKey.slice(-4) : chalk.yellow("(not set)")}`));
|
|
658
710
|
console.log(chalk.gray(` Auth profile : ${auth ? `${auth.email} (${auth.slug})` : chalk.yellow("(not logged in)")}`));
|
|
711
|
+
console.log(chalk.gray(` Docs URL : ${docsUrl}`));
|
|
659
712
|
console.log();
|
|
660
713
|
// — Service connectivity —
|
|
661
714
|
console.log(chalk.bold(" Services"));
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
];
|
|
668
|
-
for (const { label, url } of checks) {
|
|
669
|
-
try {
|
|
670
|
-
const controller = new AbortController();
|
|
671
|
-
const timer = setTimeout(() => controller.abort(), 3000);
|
|
672
|
-
const res = await fetch(url, { signal: controller.signal });
|
|
673
|
-
clearTimeout(timer);
|
|
674
|
-
if (res.ok) {
|
|
675
|
-
console.log(` ${chalk.green("✓")} ${label.padEnd(16)} ${chalk.gray(url)}`);
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
console.log(` ${chalk.red("✗")} ${label.padEnd(16)} ${chalk.red(`${res.status}`)} ${chalk.gray(url)}`);
|
|
679
|
-
}
|
|
715
|
+
const serviceChecks = report.checks.filter((c) => ["auth_reachable", "api_reachable", "shell_reachable", "dashboard_reachable"].includes(c.id));
|
|
716
|
+
for (const check of serviceChecks) {
|
|
717
|
+
const url = check.url ?? "";
|
|
718
|
+
if (check.status === "pass") {
|
|
719
|
+
console.log(` ${chalk.green("✓")} ${check.label.padEnd(16)} ${chalk.gray(url)}`);
|
|
680
720
|
}
|
|
681
|
-
|
|
682
|
-
console.log(` ${chalk.red("✗")} ${label.padEnd(16)} ${chalk.red("
|
|
721
|
+
else {
|
|
722
|
+
console.log(` ${chalk.red("✗")} ${check.label.padEnd(16)} ${chalk.red(check.message ?? "failed")} ${chalk.gray(url)}`);
|
|
683
723
|
}
|
|
684
724
|
}
|
|
685
725
|
console.log();
|
|
686
726
|
if (!auth) {
|
|
687
727
|
console.log(chalk.yellow(" ⚠ Not logged in — run: npx duct login\n"));
|
|
688
728
|
}
|
|
689
|
-
else {
|
|
729
|
+
else if (report.ok) {
|
|
690
730
|
console.log(chalk.green(" ✓ Service connectivity checks complete\n"));
|
|
691
731
|
}
|
|
732
|
+
else {
|
|
733
|
+
console.log(chalk.red(" ✗ One or more service checks failed\n"));
|
|
734
|
+
}
|
|
692
735
|
const cwd = process.cwd();
|
|
693
736
|
const configPath = path.resolve(cwd, "duct.config.ts");
|
|
694
737
|
const hasConfig = await fs.access(configPath).then(() => true).catch(() => false);
|
|
@@ -727,6 +770,106 @@ program
|
|
|
727
770
|
}
|
|
728
771
|
});
|
|
729
772
|
// ----------------------------------------------------------------
|
|
773
|
+
// duct profile — named platform URL profiles (~/.duct/profile.json)
|
|
774
|
+
// ----------------------------------------------------------------
|
|
775
|
+
const profileCmd = program
|
|
776
|
+
.command("profile")
|
|
777
|
+
.description("Manage named Duct platform profiles (local, hosted, custom)");
|
|
778
|
+
profileCmd
|
|
779
|
+
.command("show", { isDefault: true })
|
|
780
|
+
.description("Show the active profile and resolved service URLs")
|
|
781
|
+
.argument("[name]", "Profile name (default: active)")
|
|
782
|
+
.action((name) => {
|
|
783
|
+
const file = readProfileFileSync();
|
|
784
|
+
const active = resolveActiveProfileName(file);
|
|
785
|
+
const profileName = (name ?? active).trim();
|
|
786
|
+
const urls = resolveProfileUrls(profileName, file);
|
|
787
|
+
console.log(chalk.bold("\n ◆ Duct · profile\n"));
|
|
788
|
+
console.log(` active : ${active}`);
|
|
789
|
+
console.log(` showing : ${profileName}`);
|
|
790
|
+
console.log(` file : ${getDuctProfileFilePath()}`);
|
|
791
|
+
console.log();
|
|
792
|
+
console.log(chalk.bold(" URLs"));
|
|
793
|
+
for (const [key, value] of Object.entries(urls)) {
|
|
794
|
+
if (value)
|
|
795
|
+
console.log(` ${key.padEnd(14)} ${value}`);
|
|
796
|
+
}
|
|
797
|
+
if (Object.keys(urls).length === 0) {
|
|
798
|
+
console.log(chalk.gray(" (no overrides — set DUCT_URL or add profiles.local in profile.json)"));
|
|
799
|
+
}
|
|
800
|
+
console.log();
|
|
801
|
+
});
|
|
802
|
+
profileCmd
|
|
803
|
+
.command("list")
|
|
804
|
+
.description("List built-in and custom profile names")
|
|
805
|
+
.action(() => {
|
|
806
|
+
const file = readProfileFileSync();
|
|
807
|
+
const active = resolveActiveProfileName(file);
|
|
808
|
+
const names = listProfileNames(file);
|
|
809
|
+
console.log(chalk.bold("\n ◆ Duct · profile list\n"));
|
|
810
|
+
for (const name of names) {
|
|
811
|
+
const marker = name === active ? chalk.green(" (active)") : "";
|
|
812
|
+
console.log(` ${name}${marker}`);
|
|
813
|
+
}
|
|
814
|
+
console.log();
|
|
815
|
+
});
|
|
816
|
+
profileCmd
|
|
817
|
+
.command("use <name>")
|
|
818
|
+
.description("Set the active profile in ~/.duct/profile.json")
|
|
819
|
+
.action((name) => {
|
|
820
|
+
setActiveProfileSync(name.trim());
|
|
821
|
+
applyActiveProfileEnvSync({ protectedKeys: shellEnvKeys });
|
|
822
|
+
console.log(chalk.green(`\n✓ Active profile set to "${name.trim()}"\n`));
|
|
823
|
+
});
|
|
824
|
+
profileCmd
|
|
825
|
+
.command("init <name>")
|
|
826
|
+
.description("Create or update a custom profile with optional DUCT_URL")
|
|
827
|
+
.option("--duct-url <url>", "Platform base URL (DUCT_URL)")
|
|
828
|
+
.action((name, opts) => {
|
|
829
|
+
const profileName = name.trim();
|
|
830
|
+
const urls = opts.ductUrl ? { ductUrl: opts.ductUrl.trim() } : {};
|
|
831
|
+
ensureProfileExists(profileName, urls);
|
|
832
|
+
console.log(chalk.green(`\n✓ Profile "${profileName}" saved to ${getDuctProfileFilePath()}\n`));
|
|
833
|
+
});
|
|
834
|
+
// ----------------------------------------------------------------
|
|
835
|
+
// duct whoami / logout / env
|
|
836
|
+
// ----------------------------------------------------------------
|
|
837
|
+
program
|
|
838
|
+
.command("whoami")
|
|
839
|
+
.description("Show the logged-in Duct account from ~/.duct/auth.json")
|
|
840
|
+
.action(async () => {
|
|
841
|
+
const auth = await readAuth();
|
|
842
|
+
if (!auth) {
|
|
843
|
+
console.error(chalk.red("\nNot logged in. Run `npx duct login`.\n"));
|
|
844
|
+
process.exit(1);
|
|
845
|
+
}
|
|
846
|
+
console.log(chalk.bold("\n ◆ Duct · whoami\n"));
|
|
847
|
+
console.log(` email : ${auth.email}`);
|
|
848
|
+
console.log(` slug : ${auth.slug}`);
|
|
849
|
+
console.log(` company_id : ${auth.companyId || "(unknown)"}`);
|
|
850
|
+
console.log(` api_base : ${auth.apiBase ?? getActiveApiBase(auth)}`);
|
|
851
|
+
console.log(` dashboard : ${auth.dashboardUrl ?? getConfiguredDashboard(auth)}`);
|
|
852
|
+
console.log(` saved_at : ${auth.savedAt}`);
|
|
853
|
+
console.log();
|
|
854
|
+
});
|
|
855
|
+
program
|
|
856
|
+
.command("logout")
|
|
857
|
+
.description("Clear stored CLI credentials (~/.duct/auth.json)")
|
|
858
|
+
.action(async () => {
|
|
859
|
+
await clearAuth();
|
|
860
|
+
console.log(chalk.green("\n✓ Logged out — credentials cleared\n"));
|
|
861
|
+
});
|
|
862
|
+
program
|
|
863
|
+
.command("env")
|
|
864
|
+
.description("Print resolved Duct endpoints and tracked env vars")
|
|
865
|
+
.option("--redact", "Redact secret-like values", false)
|
|
866
|
+
.action(async (opts) => {
|
|
867
|
+
const auth = await readAuth();
|
|
868
|
+
console.log(chalk.bold("\n ◆ Duct · env\n"));
|
|
869
|
+
console.log(formatEnvDiagnostics(auth, { redact: Boolean(opts.redact) }));
|
|
870
|
+
console.log();
|
|
871
|
+
});
|
|
872
|
+
// ----------------------------------------------------------------
|
|
730
873
|
// duct scan (diagnostic / drift detection)
|
|
731
874
|
// ----------------------------------------------------------------
|
|
732
875
|
program
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { defineDuctConfig, validateDuctConfigStrict } from "./config.js";
|
|
4
|
+
function minimalConfig(overrides = {}) {
|
|
5
|
+
return {
|
|
6
|
+
shellId: "shell_acme_prod",
|
|
7
|
+
product: {
|
|
8
|
+
name: "Acme",
|
|
9
|
+
description: "Test",
|
|
10
|
+
baseUrl: "https://app.acme.com",
|
|
11
|
+
},
|
|
12
|
+
auth: {
|
|
13
|
+
strategy: "session-cookie",
|
|
14
|
+
sessionFields: ["id"],
|
|
15
|
+
guestAllowed: false,
|
|
16
|
+
tokenExpirySeconds: 60,
|
|
17
|
+
},
|
|
18
|
+
routes: [],
|
|
19
|
+
actions: [
|
|
20
|
+
{
|
|
21
|
+
id: "list_orders",
|
|
22
|
+
name: "List orders",
|
|
23
|
+
description: "List orders",
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: "/api/orders",
|
|
26
|
+
agentAccessible: true,
|
|
27
|
+
sideEffects: false,
|
|
28
|
+
sensitivityLevel: "low",
|
|
29
|
+
params: [],
|
|
30
|
+
requiresAuth: true,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
deeplinks: [],
|
|
34
|
+
agentPermissions: {
|
|
35
|
+
defaultLevel: "none",
|
|
36
|
+
requireUserConsent: true,
|
|
37
|
+
},
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
describe("config field round-trip", () => {
|
|
42
|
+
it("preserves action inputSchema, dependsOn, and semantic metadata", () => {
|
|
43
|
+
const inputSchema = {
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: { q: { type: "string" } },
|
|
46
|
+
};
|
|
47
|
+
const outputSchema = {
|
|
48
|
+
type: "array",
|
|
49
|
+
items: { type: "object" },
|
|
50
|
+
};
|
|
51
|
+
const config = minimalConfig({
|
|
52
|
+
actions: [
|
|
53
|
+
{
|
|
54
|
+
...minimalConfig().actions[0],
|
|
55
|
+
sensitivityLevel: "critical",
|
|
56
|
+
inputSchema,
|
|
57
|
+
dependsOn: [
|
|
58
|
+
{
|
|
59
|
+
actionId: "list_orders",
|
|
60
|
+
paramMapping: { orderId: "id" },
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
semanticType: "search_results",
|
|
64
|
+
outputSchema,
|
|
65
|
+
paramMappings: { orderId: "id" },
|
|
66
|
+
navigatesTo: "order_detail",
|
|
67
|
+
searchHint: "Search orders",
|
|
68
|
+
alwaysInclude: true,
|
|
69
|
+
interruptBehavior: "block",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
const result = validateDuctConfigStrict(config);
|
|
74
|
+
assert.equal(result.ok, true);
|
|
75
|
+
if (!result.ok)
|
|
76
|
+
return;
|
|
77
|
+
const action = result.data.actions[0];
|
|
78
|
+
assert.deepEqual(action.inputSchema, inputSchema);
|
|
79
|
+
assert.deepEqual(action.dependsOn, [
|
|
80
|
+
{ actionId: "list_orders", paramMapping: { orderId: "id" } },
|
|
81
|
+
]);
|
|
82
|
+
assert.equal(action.semanticType, "search_results");
|
|
83
|
+
assert.deepEqual(action.outputSchema, outputSchema);
|
|
84
|
+
assert.deepEqual(action.paramMappings, { orderId: "id" });
|
|
85
|
+
assert.equal(action.navigatesTo, "order_detail");
|
|
86
|
+
assert.equal(action.sensitivityLevel, "critical");
|
|
87
|
+
assert.equal(action.searchHint, "Search orders");
|
|
88
|
+
assert.equal(action.alwaysInclude, true);
|
|
89
|
+
assert.equal(action.interruptBehavior, "block");
|
|
90
|
+
});
|
|
91
|
+
it("preserves dataModel and widget loop limits", () => {
|
|
92
|
+
const dataModel = {
|
|
93
|
+
entities: [
|
|
94
|
+
{
|
|
95
|
+
id: "order",
|
|
96
|
+
label: "Order",
|
|
97
|
+
discoveryAction: "list_orders",
|
|
98
|
+
fetchAction: "get_order",
|
|
99
|
+
indexKey: "id",
|
|
100
|
+
labelKey: "name",
|
|
101
|
+
dimensions: ["status"],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
const widget = {
|
|
106
|
+
compactionTurns: 4,
|
|
107
|
+
maxToolIterations: 10,
|
|
108
|
+
maxPlanSteps: 6,
|
|
109
|
+
};
|
|
110
|
+
const config = minimalConfig({ dataModel, widget });
|
|
111
|
+
const parsed = defineDuctConfig(config);
|
|
112
|
+
assert.deepEqual(parsed.dataModel, dataModel);
|
|
113
|
+
assert.equal(parsed.widget?.compactionTurns, 4);
|
|
114
|
+
assert.equal(parsed.widget?.maxToolIterations, 10);
|
|
115
|
+
assert.equal(parsed.widget?.maxPlanSteps, 6);
|
|
116
|
+
});
|
|
117
|
+
it("accepts sensitivityLevel none on actions", () => {
|
|
118
|
+
const config = minimalConfig({
|
|
119
|
+
actions: [
|
|
120
|
+
{
|
|
121
|
+
...minimalConfig().actions[0],
|
|
122
|
+
sensitivityLevel: "none",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
const result = validateDuctConfigStrict(config);
|
|
127
|
+
assert.equal(result.ok, true);
|
|
128
|
+
if (result.ok) {
|
|
129
|
+
assert.equal(result.data.actions[0].sensitivityLevel, "none");
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|