@duct-sdk/sdk 0.5.11 → 0.5.12

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog — @duct-sdk/sdk
2
2
 
3
+ ## [0.5.12] — 2026-07-25
4
+
5
+ ### Added
6
+ - **`sideEffectsReviewAck`** — manifest action field (reason string) when declared `sideEffects` intentionally disagrees with HTTP-method-derived expectation. `duct push` blocks CI/non-TTY pushes until set; interactive push prompts and writes acks into `duct.config.ts`. No `--force` skip.
7
+
3
8
  ## [0.5.11] — 2026-07-22
4
9
 
5
10
  ### Added
package/dist/cli/index.js CHANGED
@@ -23,6 +23,8 @@ import { fileURLToPath } from "node:url";
23
23
  import { readFileSync, existsSync } from "fs";
24
24
  import { DuctConfigSchema, crossValidateDuctConfig } from "../core/config.js";
25
25
  import { runAgentSafetyChecks } from "./agents/reviewer-agent.js";
26
+ import { formatSideEffectMismatchLines, findSideEffectReviewMismatches, resolveSideEffectReviewAcks, } from "./side-effects-review-push.js";
27
+ import { generateConfigFile } from "./generators/config.js";
26
28
  import { ConfigRuntimeReferenceError, loadDuctConfig, } from "./config-loader.js";
27
29
  import { computeManifestPrivilegeDiff, fetchLiveManifestConfig, formatManifestPrivilegeDiff, detectDashboardNetworkReverts, } from "./manifest-diff.js";
28
30
  import { applyActiveProfileEnvSync, ensureProfileExists, getDuctProfileFilePath, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, } from "../core/profile.js";
@@ -333,7 +335,7 @@ program
333
335
  process.exit(1);
334
336
  }
335
337
  config = validation.data;
336
- const validated = validation.data;
338
+ let validated = validation.data;
337
339
  const crossIssues = crossValidateDuctConfig(validated);
338
340
  const crossErrors = crossIssues.filter((i) => i.severity === "error");
339
341
  if (crossErrors.length > 0) {
@@ -378,6 +380,33 @@ program
378
380
  }
379
381
  console.log(chalk.gray("\n Continuing with --yes.\n"));
380
382
  }
383
+ const interactiveReview = Boolean(process.stdin.isTTY) && process.env.CI !== "true";
384
+ const reviewMismatchesBefore = findSideEffectReviewMismatches(validated.actions);
385
+ if (reviewMismatchesBefore.length > 0) {
386
+ try {
387
+ const reviewedActions = await resolveSideEffectReviewAcks(validated.actions, {
388
+ interactive: interactiveReview,
389
+ });
390
+ if (reviewedActions !== validated.actions) {
391
+ validated = { ...validated, actions: reviewedActions };
392
+ config = { ...config, actions: reviewedActions };
393
+ const configPath = path.resolve(cwd, opts.config ?? "duct.config.ts");
394
+ await fs.writeFile(configPath, generateConfigFile(validated), "utf-8");
395
+ console.log(chalk.green("\n ✓ Wrote sideEffectsReviewAck reasons to duct.config.ts\n"));
396
+ }
397
+ }
398
+ catch (err) {
399
+ if (err instanceof Error && err.message === "side_effects_review_required") {
400
+ console.log(chalk.red("\n Push blocked — side-effect classification review required.\n"));
401
+ for (const line of formatSideEffectMismatchLines(reviewMismatchesBefore)) {
402
+ console.log(chalk.red(line));
403
+ }
404
+ console.log(chalk.gray("\n Add sideEffectsReviewAck with a reason on each listed action in duct.config.ts (no --force skip).\n"));
405
+ process.exit(1);
406
+ }
407
+ throw err;
408
+ }
409
+ }
381
410
  // Warn on weak DUCT_SECRET_KEY — must be ≥ 32 chars for adequate HMAC entropy
382
411
  const secretKey = process.env["DUCT_SECRET_KEY"];
383
412
  if (secretKey && secretKey.length < 32) {
@@ -0,0 +1,11 @@
1
+ import { type SideEffectReviewMismatch } from '@duct-sdk/contracts';
2
+ import type { ActionManifest } from '../core/types.js';
3
+ export declare function findSideEffectReviewMismatches(actions: ActionManifest[]): SideEffectReviewMismatch[];
4
+ export declare function formatSideEffectMismatchLines(mismatches: SideEffectReviewMismatch[]): string[];
5
+ /**
6
+ * Interactive: prompt for acknowledgment reasons and merge into actions.
7
+ * Non-interactive: throws with mismatch list (no --force escape hatch).
8
+ */
9
+ export declare function resolveSideEffectReviewAcks(actions: ActionManifest[], opts: {
10
+ interactive: boolean;
11
+ }): Promise<ActionManifest[]>;
@@ -0,0 +1,48 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import { collectSideEffectReviewMismatches, } from '@duct-sdk/contracts';
4
+ export function findSideEffectReviewMismatches(actions) {
5
+ return collectSideEffectReviewMismatches(actions.map((a) => ({
6
+ id: a.id,
7
+ method: a.method,
8
+ sideEffects: a.sideEffects,
9
+ sideEffectsReviewAck: a.sideEffectsReviewAck,
10
+ })));
11
+ }
12
+ export function formatSideEffectMismatchLines(mismatches) {
13
+ return mismatches.map((m) => ` • ${m.actionId} (${m.method}): declared sideEffects=${m.declared}, derived=${m.derived}`);
14
+ }
15
+ /**
16
+ * Interactive: prompt for acknowledgment reasons and merge into actions.
17
+ * Non-interactive: throws with mismatch list (no --force escape hatch).
18
+ */
19
+ export async function resolveSideEffectReviewAcks(actions, opts) {
20
+ let working = actions.map((a) => ({ ...a }));
21
+ let mismatches = findSideEffectReviewMismatches(working);
22
+ if (mismatches.length === 0)
23
+ return working;
24
+ console.log(chalk.yellow('\n Side-effect classification review:\n'));
25
+ for (const line of formatSideEffectMismatchLines(mismatches)) {
26
+ console.log(chalk.yellow(line));
27
+ }
28
+ console.log(chalk.gray('\n Declared sideEffects disagrees with the HTTP method expectation. Add sideEffectsReviewAck with a reason in duct.config.ts (reviewed in git).\n'));
29
+ if (!opts.interactive) {
30
+ throw new Error('side_effects_review_required');
31
+ }
32
+ for (const mismatch of mismatches) {
33
+ const { reason } = await inquirer.prompt([
34
+ {
35
+ type: 'input',
36
+ name: 'reason',
37
+ message: `Acknowledge ${mismatch.actionId} (declared=${mismatch.declared}, derived=${mismatch.derived}) — reason:`,
38
+ validate: (v) => (v?.trim().length >= 8 ? true : 'Enter at least 8 characters'),
39
+ },
40
+ ]);
41
+ working = working.map((a) => a.id === mismatch.actionId ? { ...a, sideEffectsReviewAck: reason.trim() } : a);
42
+ }
43
+ mismatches = findSideEffectReviewMismatches(working);
44
+ if (mismatches.length > 0) {
45
+ throw new Error('side_effects_review_incomplete');
46
+ }
47
+ return working;
48
+ }
@@ -184,6 +184,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
184
184
  path: z.ZodString;
185
185
  agentAccessible: z.ZodBoolean;
186
186
  sideEffects: z.ZodBoolean;
187
+ sideEffectsReviewAck: z.ZodOptional<z.ZodString>;
187
188
  sensitivityLevel: z.ZodEnum<["none", "low", "medium", "high", "critical"]>;
188
189
  params: z.ZodDefault<z.ZodArray<z.ZodObject<{
189
190
  name: z.ZodString;
@@ -270,6 +271,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
270
271
  sideEffects: boolean;
271
272
  sensitivityLevel: "none" | "low" | "medium" | "high" | "critical";
272
273
  requiresAuth: boolean;
274
+ sideEffectsReviewAck?: string | undefined;
273
275
  responseSchema?: Record<string, unknown> | undefined;
274
276
  inputSchema?: Record<string, unknown> | undefined;
275
277
  rateLimit?: number | undefined;
@@ -315,6 +317,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
315
317
  description?: string | undefined;
316
318
  schema?: Record<string, unknown> | undefined;
317
319
  }[] | undefined;
320
+ sideEffectsReviewAck?: string | undefined;
318
321
  responseSchema?: Record<string, unknown> | undefined;
319
322
  inputSchema?: Record<string, unknown> | undefined;
320
323
  rateLimit?: number | undefined;
@@ -648,6 +651,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
648
651
  sideEffects: boolean;
649
652
  sensitivityLevel: "none" | "low" | "medium" | "high" | "critical";
650
653
  requiresAuth: boolean;
654
+ sideEffectsReviewAck?: string | undefined;
651
655
  responseSchema?: Record<string, unknown> | undefined;
652
656
  inputSchema?: Record<string, unknown> | undefined;
653
657
  rateLimit?: number | undefined;
@@ -828,6 +832,7 @@ export declare const DuctConfigSchema: z.ZodObject<{
828
832
  description?: string | undefined;
829
833
  schema?: Record<string, unknown> | undefined;
830
834
  }[] | undefined;
835
+ sideEffectsReviewAck?: string | undefined;
831
836
  responseSchema?: Record<string, unknown> | undefined;
832
837
  inputSchema?: Record<string, unknown> | undefined;
833
838
  rateLimit?: number | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { collectSideEffectReviewMismatches, deriveExpectedSideEffects, } from '@duct-sdk/contracts';
4
+ describe('side-effects-review', () => {
5
+ it('derives sideEffects from HTTP method', () => {
6
+ assert.equal(deriveExpectedSideEffects('GET'), false);
7
+ assert.equal(deriveExpectedSideEffects('post'), true);
8
+ assert.equal(deriveExpectedSideEffects(''), null);
9
+ });
10
+ it('flags mismatches without acknowledgment', () => {
11
+ const mismatches = collectSideEffectReviewMismatches([
12
+ { id: 'search', method: 'POST', sideEffects: false },
13
+ ]);
14
+ assert.equal(mismatches.length, 1);
15
+ assert.equal(mismatches[0]?.actionId, 'search');
16
+ });
17
+ it('accepts acknowledged mismatches', () => {
18
+ const mismatches = collectSideEffectReviewMismatches([
19
+ {
20
+ id: 'search',
21
+ method: 'POST',
22
+ sideEffects: false,
23
+ sideEffectsReviewAck: 'Body-heavy search only; no mutations',
24
+ },
25
+ ]);
26
+ assert.equal(mismatches.length, 0);
27
+ });
28
+ });
@@ -101,6 +101,11 @@ export interface ActionManifest {
101
101
  agentAccessible: boolean;
102
102
  /** Whether this action mutates state (POST/PUT/PATCH/DELETE) */
103
103
  sideEffects: boolean;
104
+ /**
105
+ * Free-text reason when `sideEffects` intentionally disagrees with the HTTP-method-derived expectation.
106
+ * Required for push when declared ≠ derived (stored in git / manifest hash).
107
+ */
108
+ sideEffectsReviewAck?: string;
104
109
  /** Data sensitivity classification */
105
110
  sensitivityLevel: SensitivityLevel;
106
111
  /** Input parameters */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — manifest, CLI, and embed components for permissioned human and agent access to your product APIs.",
6
6
  "main": "dist/index.js",