@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/push.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — duct push pipeline
|
|
3
|
+
//
|
|
4
|
+
// Same gates for both layouts (duct/ folder or legacy duct.config.ts):
|
|
5
|
+
// schema → cross-field → agent-safety → side-effect review → privilege
|
|
6
|
+
// diff → dashboard network-revert guard → push → local snapshot.
|
|
7
|
+
// ============================================================
|
|
8
|
+
import * as fs from "fs/promises";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import ora from "ora";
|
|
12
|
+
import { DuctConfigSchema, crossValidateDuctConfig } from "../core/config.js";
|
|
13
|
+
import { assertHostedEndpointsNotLocalhost } from "../core/endpoint-guard.js";
|
|
14
|
+
import { runAgentSafetyChecks } from "./safety-checks.js";
|
|
15
|
+
import { formatSideEffectMismatchLines, findSideEffectReviewMismatches, resolveSideEffectReviewAcks, } from "./side-effects-review-push.js";
|
|
16
|
+
import { generateConfigFile } from "./generators/config.js";
|
|
17
|
+
import { computeManifestPrivilegeDiff, detectDashboardNetworkReverts, fetchLiveManifestConfig, formatManifestPrivilegeDiff, } from "./manifest-diff.js";
|
|
18
|
+
import { resolveProjectConfig } from "./project-loader.js";
|
|
19
|
+
import { CloudError, checkActionConfusion, checkPolicyReplay, pushManifest, readAuth, resolveApiKey } from "./cloud.js";
|
|
20
|
+
import { formatActionConfusion } from "./action-confusion-format.js";
|
|
21
|
+
import { formatPolicyReplay } from "./policy-replay-format.js";
|
|
22
|
+
export class PushAbortedError extends Error {
|
|
23
|
+
details;
|
|
24
|
+
constructor(message, details = []) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.details = details;
|
|
27
|
+
this.name = "PushAbortedError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Load + validate without network calls. Throws PushAbortedError with every problem found. */
|
|
31
|
+
export async function loadAndValidateProject(cwd, explicitConfig) {
|
|
32
|
+
const resolved = await resolveProjectConfig(cwd, explicitConfig);
|
|
33
|
+
const validation = DuctConfigSchema.safeParse(resolved.config);
|
|
34
|
+
if (!validation.success) {
|
|
35
|
+
throw new PushAbortedError(resolved.layout === "split" ? "Compiled manifest is invalid" : "duct.config.ts is invalid", validation.error.errors.map((err) => `[${err.path.join(".")}] ${err.message}`));
|
|
36
|
+
}
|
|
37
|
+
const validated = validation.data;
|
|
38
|
+
const crossErrors = crossValidateDuctConfig(validated).filter((issue) => issue.severity === "error");
|
|
39
|
+
if (crossErrors.length > 0) {
|
|
40
|
+
throw new PushAbortedError("Cross-field validation failed", crossErrors.map((issue) => `[${issue.area}] ${issue.issue} — ${issue.fix}`));
|
|
41
|
+
}
|
|
42
|
+
const safetyIssues = runAgentSafetyChecks({
|
|
43
|
+
routes: validated.routes,
|
|
44
|
+
actions: validated.actions,
|
|
45
|
+
auth: validated.auth,
|
|
46
|
+
deeplinks: validated.deeplinks,
|
|
47
|
+
});
|
|
48
|
+
const safetyErrors = safetyIssues.filter((issue) => issue.severity === "error");
|
|
49
|
+
if (safetyErrors.length > 0) {
|
|
50
|
+
throw new PushAbortedError("Agent-safety review failed", safetyErrors.map((issue) => `${issue.message}${issue.suggestion ? ` — ${issue.suggestion}` : ""}`));
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
resolved,
|
|
54
|
+
validated,
|
|
55
|
+
config: validated,
|
|
56
|
+
safetyWarnings: safetyIssues
|
|
57
|
+
.filter((issue) => issue.severity === "warning")
|
|
58
|
+
.map((issue) => `${issue.message}${issue.suggestion ? ` — ${issue.suggestion}` : ""}`),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function buildDependsOnOrder(targetId, actions, visited = new Set()) {
|
|
62
|
+
if (visited.has(targetId) || visited.size > 8)
|
|
63
|
+
return [];
|
|
64
|
+
visited.add(targetId);
|
|
65
|
+
const action = actions.find((a) => a.id === targetId);
|
|
66
|
+
const order = [];
|
|
67
|
+
for (const dep of action?.dependsOn ?? [])
|
|
68
|
+
order.push(...buildDependsOnOrder(dep.actionId, actions, visited));
|
|
69
|
+
order.push(targetId);
|
|
70
|
+
return order;
|
|
71
|
+
}
|
|
72
|
+
export function computePrecomputedWorkflows(config) {
|
|
73
|
+
const workflows = [];
|
|
74
|
+
const actions = (Array.isArray(config.actions) ? config.actions : []);
|
|
75
|
+
const dataModel = config.dataModel;
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
for (const entity of dataModel?.entities ?? []) {
|
|
78
|
+
if (entity.discoveryAction === entity.fetchAction)
|
|
79
|
+
continue;
|
|
80
|
+
if (!actions.some((a) => a.id === entity.discoveryAction) || !actions.some((a) => a.id === entity.fetchAction)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const id = `wf_list_fetch_${entity.id}`;
|
|
84
|
+
if (seen.has(id))
|
|
85
|
+
continue;
|
|
86
|
+
seen.add(id);
|
|
87
|
+
const label = entity.label ?? entity.id;
|
|
88
|
+
workflows.push({
|
|
89
|
+
id,
|
|
90
|
+
name: `List and fetch ${label}`,
|
|
91
|
+
steps: [{ action_id: entity.discoveryAction }, { action_id: entity.fetchAction }],
|
|
92
|
+
intent_patterns: [`show me ${label}`, `find ${label}`, `get ${label}`, `list ${label}`],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
for (const action of actions) {
|
|
96
|
+
if (!action.dependsOn || action.dependsOn.length === 0)
|
|
97
|
+
continue;
|
|
98
|
+
const id = `wf_dep_${action.id}`;
|
|
99
|
+
if (seen.has(id))
|
|
100
|
+
continue;
|
|
101
|
+
seen.add(id);
|
|
102
|
+
const order = buildDependsOnOrder(action.id, actions, new Set());
|
|
103
|
+
if (order.length <= 1)
|
|
104
|
+
continue;
|
|
105
|
+
const label = action.name ?? action.id;
|
|
106
|
+
workflows.push({
|
|
107
|
+
id,
|
|
108
|
+
name: `Execute ${label}`,
|
|
109
|
+
steps: order.slice(0, 8).map((stepId) => ({ action_id: stepId })),
|
|
110
|
+
intent_patterns: action.description ? [action.description] : [label],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return workflows;
|
|
114
|
+
}
|
|
115
|
+
// ----------------------------------------------------------------
|
|
116
|
+
// Side-effect review acks — written back to the file the developer owns
|
|
117
|
+
// ----------------------------------------------------------------
|
|
118
|
+
async function persistReviewAcks(resolved, validated) {
|
|
119
|
+
if (resolved.layout === "legacy" && resolved.configPath) {
|
|
120
|
+
await fs.writeFile(resolved.configPath, generateConfigFile(validated), "utf-8");
|
|
121
|
+
return path.basename(resolved.configPath);
|
|
122
|
+
}
|
|
123
|
+
const capabilitiesPath = resolved.paths.capabilities;
|
|
124
|
+
const raw = JSON.parse(await fs.readFile(capabilitiesPath, "utf-8"));
|
|
125
|
+
const acks = new Map(validated.actions
|
|
126
|
+
.filter((action) => action.sideEffectsReviewAck)
|
|
127
|
+
.map((action) => [action.id, action.sideEffectsReviewAck]));
|
|
128
|
+
for (const action of raw.actions ?? []) {
|
|
129
|
+
const ack = acks.get(String(action.id));
|
|
130
|
+
if (ack)
|
|
131
|
+
action.sideEffectsReviewAck = ack;
|
|
132
|
+
}
|
|
133
|
+
await fs.writeFile(capabilitiesPath, `${JSON.stringify(raw, null, 2)}\n`, "utf-8");
|
|
134
|
+
return "duct/capabilities.json";
|
|
135
|
+
}
|
|
136
|
+
// ----------------------------------------------------------------
|
|
137
|
+
// runPush
|
|
138
|
+
// ----------------------------------------------------------------
|
|
139
|
+
export async function runPush(opts) {
|
|
140
|
+
const authProfile = await readAuth();
|
|
141
|
+
assertHostedEndpointsNotLocalhost(authProfile);
|
|
142
|
+
const spinner = ora("Reading project…").start();
|
|
143
|
+
let project;
|
|
144
|
+
try {
|
|
145
|
+
project = await loadAndValidateProject(opts.cwd, opts.config);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
spinner.fail("Project check failed");
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
151
|
+
const { resolved } = project;
|
|
152
|
+
let { validated, config } = project;
|
|
153
|
+
spinner.succeed(resolved.layout === "split"
|
|
154
|
+
? `Compiled duct/ (${validated.actions.length} action${validated.actions.length === 1 ? "" : "s"})`
|
|
155
|
+
: `Loaded duct.config.ts (${validated.actions.length} action${validated.actions.length === 1 ? "" : "s"})`);
|
|
156
|
+
for (const warning of resolved.warnings)
|
|
157
|
+
console.log(chalk.yellow(` ! ${warning}`));
|
|
158
|
+
if (project.safetyWarnings.length > 0) {
|
|
159
|
+
console.log(chalk.yellow("\n Agent-safety warnings:\n"));
|
|
160
|
+
for (const warning of project.safetyWarnings)
|
|
161
|
+
console.log(chalk.yellow(` ! ${warning}`));
|
|
162
|
+
if (!opts.yes) {
|
|
163
|
+
throw new PushAbortedError("Push blocked by agent-safety warnings. Re-run with --yes to acknowledge (CI override).");
|
|
164
|
+
}
|
|
165
|
+
console.log(chalk.gray("\n Continuing with --yes.\n"));
|
|
166
|
+
}
|
|
167
|
+
const mismatches = findSideEffectReviewMismatches(validated.actions);
|
|
168
|
+
if (mismatches.length > 0) {
|
|
169
|
+
const interactive = Boolean(process.stdin.isTTY) && process.env.CI !== "true";
|
|
170
|
+
try {
|
|
171
|
+
const reviewed = await resolveSideEffectReviewAcks(validated.actions, { interactive });
|
|
172
|
+
if (reviewed !== validated.actions) {
|
|
173
|
+
validated = { ...validated, actions: reviewed };
|
|
174
|
+
config = { ...config, actions: reviewed };
|
|
175
|
+
const target = await persistReviewAcks(resolved, validated);
|
|
176
|
+
console.log(chalk.green(`\n ✓ Wrote sideEffectsReviewAck reasons to ${target}\n`));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
if (err instanceof Error && err.message === "side_effects_review_required") {
|
|
181
|
+
throw new PushAbortedError("Push blocked — side-effect classification review required. Add sideEffectsReviewAck with a reason on each listed action.", formatSideEffectMismatchLines(mismatches));
|
|
182
|
+
}
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const secretKey = process.env["DUCT_SECRET_KEY"];
|
|
187
|
+
if (secretKey && secretKey.length < 32) {
|
|
188
|
+
console.log(chalk.yellow(`\n ! DUCT_SECRET_KEY is only ${secretKey.length} characters — use at least 32 random characters (openssl rand -hex 32).\n`));
|
|
189
|
+
}
|
|
190
|
+
const shellId = validated.shellId;
|
|
191
|
+
const apiKey = resolveApiKey(authProfile);
|
|
192
|
+
let liveConfig = null;
|
|
193
|
+
if (apiKey) {
|
|
194
|
+
const liveSpinner = ora("Fetching live manifest for diff…").start();
|
|
195
|
+
liveConfig = await fetchLiveManifestConfig(shellId, apiKey, authProfile).catch(() => null);
|
|
196
|
+
liveSpinner.stop();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
try {
|
|
200
|
+
liveConfig = JSON.parse(await fs.readFile(path.join(resolved.root, ".duct-manifest.json"), "utf-8"));
|
|
201
|
+
console.log(chalk.gray("\n Using .duct-manifest.json as diff baseline (not signed in).\n"));
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
console.log(chalk.gray("\n No live manifest baseline (first push, or not signed in).\n"));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const privilegeDiff = computeManifestPrivilegeDiff(validated, liveConfig);
|
|
208
|
+
console.log(chalk.bold("\n Privilege diff:\n"));
|
|
209
|
+
const color = privilegeDiff.hasPrivilegeIncrease ? chalk.red : chalk.green;
|
|
210
|
+
for (const line of formatManifestPrivilegeDiff(privilegeDiff))
|
|
211
|
+
console.log(color(` ${line}`));
|
|
212
|
+
console.log();
|
|
213
|
+
if (privilegeDiff.hasPrivilegeIncrease && !opts.yes) {
|
|
214
|
+
throw new PushAbortedError("Push blocked — this push gives agents more power. Review the diff above, then re-run with --yes.");
|
|
215
|
+
}
|
|
216
|
+
// What this version would have done to the shell's recent real calls (needs a live shell).
|
|
217
|
+
if (apiKey && liveConfig) {
|
|
218
|
+
const replaySpinner = ora("Replaying recent calls against this version…").start();
|
|
219
|
+
const replay = await checkPolicyReplay(authProfile, apiKey, shellId, config).catch(() => null);
|
|
220
|
+
replaySpinner.stop();
|
|
221
|
+
if (replay) {
|
|
222
|
+
const { lines, breaksCalls } = formatPolicyReplay(replay);
|
|
223
|
+
console.log(chalk.bold(" Effect on recent calls:\n"));
|
|
224
|
+
for (const line of lines)
|
|
225
|
+
console.log((breaksCalls ? chalk.red : chalk.gray)(` ${line}`));
|
|
226
|
+
console.log();
|
|
227
|
+
if (breaksCalls && !opts.yes) {
|
|
228
|
+
throw new PushAbortedError("Push blocked — this version would stop calls that work today. Review the list above, then re-run with --yes.");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
console.log(chalk.gray(" Could not replay recent calls; continuing.\n"));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Actions that read alike get routed to each other; say so before they go live (never blocks).
|
|
236
|
+
if (apiKey) {
|
|
237
|
+
const confusion = await checkActionConfusion(authProfile, apiKey, shellId, config).catch(() => null);
|
|
238
|
+
const lines = confusion ? formatActionConfusion(confusion) : [];
|
|
239
|
+
if (lines.length > 0) {
|
|
240
|
+
console.log(chalk.yellow(" Actions that may be confused:\n"));
|
|
241
|
+
for (const line of lines)
|
|
242
|
+
console.log(chalk.yellow(` ${line}`));
|
|
243
|
+
console.log();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const networkReverts = detectDashboardNetworkReverts(liveConfig, validated);
|
|
247
|
+
if (networkReverts.length > 0) {
|
|
248
|
+
console.log(chalk.yellow("\n ! Network settings you changed in the dashboard would be reverted by this push:\n"));
|
|
249
|
+
for (const revert of networkReverts)
|
|
250
|
+
console.log(chalk.yellow(` • ${revert}`));
|
|
251
|
+
if (!opts.yes) {
|
|
252
|
+
throw new PushAbortedError("Push blocked — set the matching values in your project (network) or re-run with --yes to override the dashboard.");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (opts.dryRun) {
|
|
256
|
+
console.log(chalk.green("✓ Dry run complete — nothing pushed.\n"));
|
|
257
|
+
return { pushed: false, shellId, layout: resolved.layout, actionCount: validated.actions.length };
|
|
258
|
+
}
|
|
259
|
+
if (!apiKey) {
|
|
260
|
+
throw new PushAbortedError("Not signed in. Run `npx @duct-sdk/sdk login` (or set DUCT_API_KEY in CI).");
|
|
261
|
+
}
|
|
262
|
+
const workflows = computePrecomputedWorkflows(config);
|
|
263
|
+
if (workflows.length > 0) {
|
|
264
|
+
console.log(chalk.gray(` ${workflows.length} workflow(s) precomputed from dataModel + dependsOn`));
|
|
265
|
+
config = { ...config, precomputedWorkflows: workflows };
|
|
266
|
+
}
|
|
267
|
+
const pushSpinner = ora("Pushing to Duct…").start();
|
|
268
|
+
let result;
|
|
269
|
+
try {
|
|
270
|
+
result = await pushManifest(authProfile, apiKey, shellId, config, {
|
|
271
|
+
forceDashboardNetworkOverride: networkReverts.length > 0 && Boolean(opts.yes),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
pushSpinner.fail("Push failed");
|
|
276
|
+
if (err instanceof CloudError) {
|
|
277
|
+
const details = [];
|
|
278
|
+
if (err.status === 401)
|
|
279
|
+
details.push("Run `npx @duct-sdk/sdk login` to refresh your credentials.");
|
|
280
|
+
if (err.code === "unverified_upstream_origin") {
|
|
281
|
+
details.push("Your API origin must be one of the shell's registered domains (Dashboard → Shell → Settings).");
|
|
282
|
+
}
|
|
283
|
+
if (err.code === "too_many_requests")
|
|
284
|
+
details.push("Rate limited — wait a minute and retry.");
|
|
285
|
+
throw new PushAbortedError(err.message, details);
|
|
286
|
+
}
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
pushSpinner.succeed(`Pushed to ${chalk.cyan(shellId)}${result.push_hash ? chalk.gray(` (${result.push_hash})`) : ""}`);
|
|
290
|
+
try {
|
|
291
|
+
await fs.writeFile(path.join(resolved.root, ".duct-manifest.json"), `${JSON.stringify(config, null, 2)}\n`, "utf-8");
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
/* snapshot is a local convenience */
|
|
295
|
+
}
|
|
296
|
+
return { pushed: true, shellId, layout: resolved.layout, result, actionCount: validated.actions.length };
|
|
297
|
+
}
|
|
298
|
+
export function printPushAbort(err) {
|
|
299
|
+
if (err instanceof PushAbortedError) {
|
|
300
|
+
console.log(chalk.red(`\n ✗ ${err.message}`));
|
|
301
|
+
for (const detail of err.details)
|
|
302
|
+
console.log(chalk.red(` • ${detail}`));
|
|
303
|
+
console.log();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
307
|
+
console.log(chalk.red(`\n ✗ ${message}\n`));
|
|
308
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ActionManifest, AuthSchema, DeeplinkDefinition, ReviewIssue, RouteManifest } from "../core/types.js";
|
|
2
|
+
export interface SafetyCheckInput {
|
|
3
|
+
routes: RouteManifest[];
|
|
4
|
+
actions: ActionManifest[];
|
|
5
|
+
auth: AuthSchema;
|
|
6
|
+
deeplinks: DeeplinkDefinition[];
|
|
7
|
+
}
|
|
8
|
+
/** Blocks exposing high/critical actions to agents; warns on unthrottled agent writes. */
|
|
9
|
+
export declare function runAgentSafetyChecks(input: SafetyCheckInput): ReviewIssue[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — Agent-safety checks run by `duct push` and `duct test` (no LLM)
|
|
3
|
+
// ============================================================
|
|
4
|
+
/** Blocks exposing high/critical actions to agents; warns on unthrottled agent writes. */
|
|
5
|
+
export function runAgentSafetyChecks(input) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
input.actions.forEach((action, index) => {
|
|
8
|
+
if (action.agentAccessible &&
|
|
9
|
+
(action.sensitivityLevel === "high" || action.sensitivityLevel === "critical")) {
|
|
10
|
+
issues.push({
|
|
11
|
+
code: "HIGH_SENSITIVITY_AGENT_ACCESSIBLE",
|
|
12
|
+
severity: "error",
|
|
13
|
+
message: `Action "${action.id}" is agent-accessible but has sensitivity level "${action.sensitivityLevel}"`,
|
|
14
|
+
path: `actions[${index}].agentAccessible`,
|
|
15
|
+
suggestion: "Remove it from policy.agents.allow (or add it to agents.deny), or lower its sensitivity if that is accurate",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (action.agentAccessible && action.sideEffects && !action.rateLimit) {
|
|
19
|
+
issues.push({
|
|
20
|
+
code: "AGENT_SIDE_EFFECT_NO_RATE_LIMIT",
|
|
21
|
+
severity: "warning",
|
|
22
|
+
message: `Agent-accessible action "${action.id}" has side effects but no rate limit`,
|
|
23
|
+
path: `actions[${index}].rateLimit`,
|
|
24
|
+
suggestion: 'Add a limit in policy.limits, e.g. { "*": { perMinute: 60 } }',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return issues;
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface SetupOptions {
|
|
2
|
+
cwd: string;
|
|
3
|
+
/** Path or URL to an OpenAPI spec / Postman collection / curl script, or "none". */
|
|
4
|
+
source?: string;
|
|
5
|
+
/** Where your API is served, if different from the shell's registered domain. */
|
|
6
|
+
apiUrl?: string;
|
|
7
|
+
/** Shell id to use when the workspace has several. */
|
|
8
|
+
shell?: string;
|
|
9
|
+
/** Accept every default without prompting. */
|
|
10
|
+
yes?: boolean;
|
|
11
|
+
/** Push after a green check (default true). */
|
|
12
|
+
push?: boolean;
|
|
13
|
+
/** Overwrite an existing duct/ folder. */
|
|
14
|
+
force?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class SetupError extends Error {
|
|
17
|
+
readonly hint?: string | undefined;
|
|
18
|
+
constructor(message: string, hint?: string | undefined);
|
|
19
|
+
}
|
|
20
|
+
export declare function runSetup(opts: SetupOptions): Promise<boolean>;
|