@duct-sdk/sdk 0.3.6 → 0.3.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 CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.3.9] — 2026-06-14
6
+
7
+ ### Added
8
+ - **`duct init --curl-collection`** — import actions from curl scripts or Postman Collection v2.1 JSON (deterministic, no LLM)
9
+ - **`core/auth-boundaries.ts`** — shared helpers for action-definition fingerprints and risk-tiered scope checks (aligned with Duct platform auth validation)
10
+
11
+ ### Improved
12
+ - **OpenAPI import** — `$ref` resolution for requestBody schemas; tag-based action ID derivation; collision suffixes; lower confidence when `operationId` is absent
13
+
14
+ ## [0.3.8] — 2026-06-11
15
+
16
+ ### Fixed
17
+ - **Smoother shell drag** — bubble and panel drags batch position updates to one React commit per animation frame, attach move listeners synchronously on pointer down, use pointer capture, and disable panel `transform` while dragging.
18
+
19
+ ## [0.3.7] — 2026-06-11
20
+
21
+ ### Added
22
+ - `@duct-sdk/sdk/server` exports `sendIntershellAction` and `sendIntershellQuery` — thin cross-shell client with consent retry (IS-29)
23
+
5
24
  ## [0.3.6] — 2026-06-10
6
25
 
7
26
  ### Fixed
@@ -5,7 +5,7 @@
5
5
  "use client";
6
6
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
7
7
  import React, { useEffect, useRef, useCallback, useMemo, useState, } from "react";
8
- import { resolveShellDimensions, } from "../../core/types.js";
8
+ import { resolveShellDimensions, SHELL_PANEL_VIEWPORT_INSETS, } from "../../core/types.js";
9
9
  /**
10
10
  * Hook that polls the shell status endpoint once on mount.
11
11
  * Use when you need to conditionally render UI based on shell liveness.
@@ -121,6 +121,29 @@ function clampPanel(x, y, width, height) {
121
121
  y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
122
122
  };
123
123
  }
124
+ /** Coalesce high-frequency pointer moves to one React update per animation frame. */
125
+ function scheduleRafUpdate(rafRef, pendingRef, pos, commit) {
126
+ pendingRef.current = pos;
127
+ if (rafRef.current)
128
+ return;
129
+ rafRef.current = requestAnimationFrame(() => {
130
+ rafRef.current = 0;
131
+ const next = pendingRef.current;
132
+ if (next)
133
+ commit(next);
134
+ });
135
+ }
136
+ function cancelRafUpdate(rafRef, pendingRef, commit) {
137
+ if (rafRef.current) {
138
+ cancelAnimationFrame(rafRef.current);
139
+ rafRef.current = 0;
140
+ }
141
+ const next = pendingRef.current;
142
+ pendingRef.current = null;
143
+ if (next)
144
+ commit(next);
145
+ return next;
146
+ }
124
147
  /**
125
148
  * DuctShell — a self-contained floating launcher button + chat panel.
126
149
  *
@@ -162,6 +185,10 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
162
185
  const [panelPos, setPanelPos] = useState(null);
163
186
  const [isPanelDragging, setIsPanelDragging] = useState(false);
164
187
  const panelDragState = useRef(null);
188
+ const bubbleDragRaf = useRef(0);
189
+ const bubbleDragPending = useRef(null);
190
+ const panelDragRaf = useRef(0);
191
+ const panelDragPending = useRef(null);
165
192
  // Resolve theme for the launcher chrome (light/dark surface).
166
193
  const [isDarkChrome, setIsDarkChrome] = useState(theme === "dark");
167
194
  // Shell liveness — only checked when readyCheck=true
@@ -388,34 +415,16 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
388
415
  }
389
416
  catch { /* ignore corrupt storage */ }
390
417
  }, [shellId, draggable]);
391
- // Free-drag the open panel using a top handle. The handle sits outside the
392
- // iframe so dragging works without relying on iframe internals.
393
- useEffect(() => {
394
- if (!isPanelDragging)
395
- return;
396
- const onMove = (e) => {
397
- const st = panelDragState.current;
398
- if (!st)
399
- return;
400
- setPanelPos(clampPanel(e.clientX - st.dx, e.clientY - st.dy, st.width, st.height));
401
- };
402
- const onUp = () => {
403
- setIsPanelDragging(false);
404
- panelDragState.current = null;
405
- };
406
- window.addEventListener("pointermove", onMove);
407
- window.addEventListener("pointerup", onUp);
408
- return () => {
409
- window.removeEventListener("pointermove", onMove);
410
- window.removeEventListener("pointerup", onUp);
411
- };
412
- }, [isPanelDragging]);
413
418
  // Launcher bubble: pointer stays default until the user actually drags (4px threshold).
414
419
  // A tap opens; a drag repositions — no separate handle or grab cursor on hover.
415
420
  const onBubblePointerDown = useCallback((e) => {
416
421
  if (!draggable)
417
422
  return;
418
- const rect = e.currentTarget.getBoundingClientRect();
423
+ e.preventDefault();
424
+ const btn = e.currentTarget;
425
+ btn.setPointerCapture(e.pointerId);
426
+ btn.style.transform = "scale(1)";
427
+ const rect = btn.getBoundingClientRect();
419
428
  const st = {
420
429
  dx: e.clientX - rect.left,
421
430
  dy: e.clientY - rect.top,
@@ -424,7 +433,10 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
424
433
  moved: false,
425
434
  };
426
435
  dragState.current = st;
427
- setBubblePos((prev) => prev ?? clampBubble(rect.left, rect.top));
436
+ const initial = clampBubble(rect.left, rect.top);
437
+ setBubblePos((prev) => prev ?? initial);
438
+ bubbleDragPending.current = initial;
439
+ const commitBubblePos = (pos) => setBubblePos(pos);
428
440
  const onMove = (ev) => {
429
441
  if (!dragState.current)
430
442
  return;
@@ -433,25 +445,30 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
433
445
  && Math.abs(ev.clientY - st.startY) <= 4) {
434
446
  return;
435
447
  }
436
- st.moved = true;
437
- setIsDragging(true);
438
- setBubblePos(clampBubble(ev.clientX - st.dx, ev.clientY - st.dy));
448
+ if (!st.moved) {
449
+ st.moved = true;
450
+ setIsDragging(true);
451
+ }
452
+ scheduleRafUpdate(bubbleDragRaf, bubbleDragPending, clampBubble(ev.clientX - st.dx, ev.clientY - st.dy), commitBubblePos);
439
453
  };
440
- const onUp = () => {
454
+ const onUp = (ev) => {
455
+ if (btn.hasPointerCapture(ev.pointerId)) {
456
+ btn.releasePointerCapture(ev.pointerId);
457
+ }
441
458
  window.removeEventListener("pointermove", onMove);
442
459
  window.removeEventListener("pointerup", onUp);
443
460
  dragState.current = null;
444
461
  setIsDragging(false);
462
+ const finalPos = cancelRafUpdate(bubbleDragRaf, bubbleDragPending, commitBubblePos);
445
463
  if (st.moved) {
446
- setBubblePos((pos) => {
447
- if (pos) {
448
- try {
449
- window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(pos));
450
- }
451
- catch { /* ignore */ }
464
+ const pos = finalPos ?? bubbleDragPending.current;
465
+ if (pos) {
466
+ setBubblePos(pos);
467
+ try {
468
+ window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(pos));
452
469
  }
453
- return pos;
454
- });
470
+ catch { /* ignore */ }
471
+ }
455
472
  setPanelPos(null);
456
473
  }
457
474
  else {
@@ -461,18 +478,44 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
461
478
  window.addEventListener("pointermove", onMove);
462
479
  window.addEventListener("pointerup", onUp);
463
480
  }, [draggable, openPanel, shellId]);
481
+ // Free-drag the open panel using a top handle. Listeners attach synchronously on
482
+ // pointerdown so the first move event is not dropped behind a useEffect cycle.
464
483
  const onPanelPointerDown = useCallback((e) => {
465
484
  if (!draggable || !panelRef.current)
466
485
  return;
467
- const rect = panelRef.current.getBoundingClientRect();
468
- panelDragState.current = {
486
+ e.preventDefault();
487
+ const panel = panelRef.current;
488
+ panel.setPointerCapture(e.pointerId);
489
+ const rect = panel.getBoundingClientRect();
490
+ const st = {
469
491
  dx: e.clientX - rect.left,
470
492
  dy: e.clientY - rect.top,
471
493
  width: rect.width,
472
494
  height: rect.height,
473
495
  };
474
- setPanelPos(clampPanel(rect.left, rect.top, rect.width, rect.height));
496
+ panelDragState.current = st;
497
+ const initial = clampPanel(rect.left, rect.top, rect.width, rect.height);
498
+ setPanelPos(initial);
499
+ panelDragPending.current = initial;
475
500
  setIsPanelDragging(true);
501
+ const commitPanelPos = (pos) => setPanelPos(pos);
502
+ const onMove = (ev) => {
503
+ if (!panelDragState.current)
504
+ return;
505
+ scheduleRafUpdate(panelDragRaf, panelDragPending, clampPanel(ev.clientX - st.dx, ev.clientY - st.dy, st.width, st.height), commitPanelPos);
506
+ };
507
+ const onUp = (ev) => {
508
+ if (panel.hasPointerCapture(ev.pointerId)) {
509
+ panel.releasePointerCapture(ev.pointerId);
510
+ }
511
+ window.removeEventListener("pointermove", onMove);
512
+ window.removeEventListener("pointerup", onUp);
513
+ panelDragState.current = null;
514
+ setIsPanelDragging(false);
515
+ cancelRafUpdate(panelDragRaf, panelDragPending, commitPanelPos);
516
+ };
517
+ window.addEventListener("pointermove", onMove);
518
+ window.addEventListener("pointerup", onUp);
476
519
  }, [draggable]);
477
520
  if (!shellId) {
478
521
  console.error("[DuctShell] shellId prop is required");
@@ -493,6 +536,8 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
493
536
  });
494
537
  const widthVal = typeof presetDims.width === "number" ? `${presetDims.width}px` : presetDims.width;
495
538
  const heightVal = typeof presetDims.height === "number" ? `${presetDims.height}px` : presetDims.height;
539
+ const panelWidthInset = SHELL_PANEL_VIEWPORT_INSETS.width;
540
+ const panelHeightInset = SHELL_PANEL_VIEWPORT_INSETS.height;
496
541
  // Bubble + panel placement. When the bubble has been dragged we anchor the
497
542
  // panel to the bubble; otherwise we use the default corner.
498
543
  const dragged = bubblePos !== null;
@@ -519,15 +564,16 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
519
564
  const panelStyle = {
520
565
  position: "fixed",
521
566
  ...(panelPos ? { left: `${panelPos.x}px`, top: `${panelPos.y}px` } : panelAnchor),
522
- width: `min(${widthVal}, calc(100vw - 32px))`,
523
- height: `min(${heightVal}, calc(100dvh - 96px))`,
567
+ width: `min(${widthVal}, calc(100vw - ${panelWidthInset}px))`,
568
+ height: `min(${heightVal}, calc(100dvh - ${panelHeightInset}px))`,
524
569
  zIndex: 9998,
525
570
  borderRadius: "16px",
526
571
  overflow: "hidden",
527
572
  boxShadow: "0 24px 64px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.10)",
528
573
  opacity: panelOpen && !isAnimating ? 1 : 0,
529
- transform: panelOpen && !isAnimating ? "translateY(0)" : "translateY(12px)",
574
+ transform: isPanelDragging ? "none" : panelOpen && !isAnimating ? "translateY(0)" : "translateY(12px)",
530
575
  transition: isPanelDragging ? "none" : "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
576
+ willChange: isPanelDragging ? "left, top" : undefined,
531
577
  pointerEvents: panelOpen ? "auto" : "none",
532
578
  visibility: panelVisible ? "visible" : "hidden",
533
579
  ...style,
@@ -563,6 +609,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
563
609
  height: `${BUBBLE_SIZE}px`,
564
610
  cursor: isDragging ? "grabbing" : "pointer",
565
611
  touchAction: draggable ? "none" : undefined,
612
+ willChange: isDragging ? "left, top" : undefined,
566
613
  }, onPointerDown: draggable ? onBubblePointerDown : undefined, onClick: draggable ? undefined : () => openPanel(), "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
567
614
  if (isDragging)
568
615
  return;
@@ -22,6 +22,11 @@ export interface PipelineOptions {
22
22
  apiSpecContent?: string;
23
23
  /** Path label for the spec file (used in prompt context). */
24
24
  apiSpecPath?: string;
25
+ /**
26
+ * Raw content of a cURL script or Postman collection (from --curl-collection flag).
27
+ */
28
+ curlCollectionContent?: string;
29
+ curlCollectionPath?: string;
25
30
  /** Options passed to the deterministic post-processing step. */
26
31
  postProcess?: PostProcessOptions;
27
32
  }
@@ -10,6 +10,7 @@ import { runDeeplinkAgent } from "./deeplink-agent.js";
10
10
  import { runReviewerAgent } from "./reviewer-agent.js";
11
11
  import { applyDeterministicRules } from "../processors/postprocess.js";
12
12
  import { parseOpenApiSpec } from "../processors/openapi-parser.js";
13
+ import { parseCurlCollection } from "../processors/curl-parser.js";
13
14
  // ----------------------------------------------------------------
14
15
  // Default emitter (uses Node EventEmitter)
15
16
  // ----------------------------------------------------------------
@@ -95,7 +96,7 @@ function defaultReview() {
95
96
  * @returns PipelineResult with all agent outputs
96
97
  */
97
98
  export async function runAgentPipeline(sandboxFs, opts = {}) {
98
- const { skipAgents: skipAgentsInput = [], emitter, agentTimeout = 120_000, readList, apiSpecContent, apiSpecPath, postProcess = {}, } = opts;
99
+ const { skipAgents: skipAgentsInput = [], emitter, agentTimeout = 120_000, readList, apiSpecContent, apiSpecPath, curlCollectionContent, curlCollectionPath, postProcess = {}, } = opts;
99
100
  const skipAgents = skipAgentsInput;
100
101
  const startTime = Date.now();
101
102
  emitter?.emitEvent({ type: "start", message: "Starting Duct agent pipeline...", progress: 0 });
@@ -103,7 +104,64 @@ export async function runAgentPipeline(sandboxFs, opts = {}) {
103
104
  let routes;
104
105
  let actions;
105
106
  let auth;
106
- if (apiSpecContent) {
107
+ if (curlCollectionContent) {
108
+ const [curlResult, authResult] = await Promise.all([
109
+ (async () => {
110
+ emitter?.emitEvent({
111
+ type: "agent:start",
112
+ agent: "ApiAgent",
113
+ message: `Parsing cURL collection (${curlCollectionPath ?? "curl"})…`,
114
+ progress: 5,
115
+ });
116
+ try {
117
+ const parsed = await parseCurlCollection(curlCollectionContent, curlCollectionPath ?? "curl-collection.sh");
118
+ emitter?.emitEvent({
119
+ type: "agent:complete",
120
+ agent: "ApiAgent",
121
+ message: `Parsed ${parsed.actions.length} actions from ${parsed.requestCount} requests`,
122
+ result: parsed.actions,
123
+ progress: 30,
124
+ });
125
+ return { routes: parsed.routes, actions: parsed.actions };
126
+ }
127
+ catch (err) {
128
+ const error = err instanceof Error ? err : new Error(String(err));
129
+ emitter?.emitEvent({ type: "agent:error", agent: "ApiAgent", error, progress: 30 });
130
+ return { routes: defaultRoutes(), actions: defaultActions() };
131
+ }
132
+ })(),
133
+ (async () => {
134
+ if (skipAgentsInput.includes("auth"))
135
+ return defaultAuth();
136
+ emitter?.emitEvent({
137
+ type: "agent:start",
138
+ agent: "AuthAgent",
139
+ message: "Analyzing auth configuration…",
140
+ progress: 5,
141
+ });
142
+ try {
143
+ const result = await withTimeout(() => runAuthAgent(sandboxFs, readList?.authFiles), agentTimeout, "AuthAgent");
144
+ emitter?.emitEvent({
145
+ type: "agent:complete",
146
+ agent: "AuthAgent",
147
+ message: `Detected auth: ${result.strategy}`,
148
+ result,
149
+ progress: 30,
150
+ });
151
+ return result;
152
+ }
153
+ catch (err) {
154
+ const error = err instanceof Error ? err : new Error(String(err));
155
+ emitter?.emitEvent({ type: "agent:error", agent: "AuthAgent", error, progress: 30 });
156
+ return defaultAuth();
157
+ }
158
+ })(),
159
+ ]);
160
+ routes = curlResult.routes;
161
+ actions = curlResult.actions;
162
+ auth = authResult;
163
+ }
164
+ else if (apiSpecContent) {
107
165
  // ── Spec mode: parse deterministically (no LLM needed for routes/actions) ──────
108
166
  // Auth agent still runs in parallel since it reads project source files.
109
167
  const [specResult, authResult] = await Promise.all([
@@ -102,7 +102,7 @@ ${pad} sideEffects: ${action.sideEffects},
102
102
  ${pad} // sensitivityLevel controls the minimum auth required for agent access.
103
103
  ${pad} // "low" — any authenticated shell
104
104
  ${pad} // "medium" — requires user consent token
105
- ${pad} // "high" — requires user consent token + explicit allowedCallers entry
105
+ ${pad} // "high" — requires user consent token; also respects allowedCallers restriction if set
106
106
  ${pad} sensitivityLevel: ${JSON.stringify(action.sensitivityLevel)},${params}
107
107
  ${pad} requiresAuth: ${action.requiresAuth},${action.rateLimit !== undefined ? `\n${pad} rateLimit: ${action.rateLimit},` : ""}
108
108
  ${pad} }`;
@@ -157,7 +157,7 @@ function generateAgentPermissions(perms, indentSpaces) {
157
157
  lines.push(`${pad} allowedActions: ${formatStringArray(perms.allowedActions, indentSpaces + 2)},`);
158
158
  }
159
159
  if (perms.allowedCallers && perms.allowedCallers.length > 0) {
160
- lines.push(`${pad} allowedCallers: ${formatStringArray(perms.allowedCallers, indentSpaces + 2)},`);
160
+ lines.push(`${pad} // Optional restriction: when non-empty, only these shell IDs may call this shell cross-shell.`, `${pad} // Absent or empty = any public Duct shell may call (subject to intershell_enabled + registry_visibility).`, `${pad} // To block all cross-shell calls, set intershell_enabled: false instead of maintaining this list.`, `${pad} allowedCallers: ${formatStringArray(perms.allowedCallers, indentSpaces + 2)},`);
161
161
  }
162
162
  if (perms.actionOverrides && Object.keys(perms.actionOverrides).length > 0) {
163
163
  lines.push(`${pad} actionOverrides: ${jsonValue(perms.actionOverrides, indentSpaces + 2)},`);
@@ -320,6 +320,11 @@ export default defineDuctConfig({
320
320
  requireUserConsent: true,
321
321
  },
322
322
 
323
+ // Intershell network settings (both default to isolated/private)
324
+ // Set intershell_enabled: true and registry_visibility: 'public' to join the Duct open network.
325
+ // intershell_enabled: false,
326
+ // registry_visibility: 'private',
327
+
323
328
  // Shell widget appearance
324
329
  widget: {
325
330
  position: "bottom-right",
@@ -375,6 +380,12 @@ export function generateConfigFile(config) {
375
380
  `${i}// Controls what AI agents/shells can do in your shell`,
376
381
  `${i}${generateAgentPermissions(config.agentPermissions, 2)}`,
377
382
  ];
383
+ // Intershell network settings — only emit when explicitly set (non-default)
384
+ const visibility = config.registry_visibility ?? 'private';
385
+ const intershellEnabled = config.intershell_enabled ?? false;
386
+ if (visibility !== 'private' || intershellEnabled !== false) {
387
+ sections.push("", `${i}// Intershell network settings`, `${i}// intershell_enabled: master switch — allows other Duct shells to invoke this shell cross-shell.`, `${i}// registry_visibility: 'public' makes this shell discoverable in the Duct capability network.`, `${i}// Set both to true/public to join the open network; leave as defaults (false/'private') to stay isolated.`, `${i}intershell_enabled: ${intershellEnabled},`, `${i}registry_visibility: ${JSON.stringify(visibility)},`);
388
+ }
378
389
  if (config.widget) {
379
390
  sections.push("", `${i}// Shell widget display configuration`, `${i}${generateWidget(config.widget, 2)}`);
380
391
  }
package/dist/cli/index.js CHANGED
@@ -301,6 +301,7 @@ program
301
301
  .option("--no-interactive", "Write unresolved review decisions to duct-review.json instead of prompting", false)
302
302
  .option("--manual", "Run topology + file selection only (no LLM). Generates a pre-filled template with empty actions/routes.", false)
303
303
  .option("--api-spec <path>", "Path to an OpenAPI/Swagger spec file — skips Route + API agents for instant, high-accuracy init")
304
+ .option("--curl-collection <path>", "Path to a cURL script or Postman collection JSON — skips Route + API agents")
304
305
  .option("--api-url <url>", "Separate API base URL when your API runs on a different domain (e.g., https://api.example.com)")
305
306
  .option("--industry <category>", "Product industry for better modality routing (e.g., fintech, ecommerce, saas, ai)")
306
307
  .action(async (opts) => {
@@ -315,6 +316,7 @@ program
315
316
  yes: opts.yes,
316
317
  noInteractive: Boolean(opts.noInteractive),
317
318
  apiSpec: opts.apiSpec,
319
+ curlCollection: opts.curlCollection,
318
320
  apiUrl: opts.apiUrl,
319
321
  industry: opts.industry,
320
322
  });
@@ -1219,6 +1221,26 @@ program
1219
1221
  }
1220
1222
  });
1221
1223
  // ----------------------------------------------------------------
1224
+ // duct migrate — migration helpers for config schema changes
1225
+ // ----------------------------------------------------------------
1226
+ const migrateCmd = program
1227
+ .command("migrate")
1228
+ .description("Migration helpers for Duct config schema changes");
1229
+ migrateCmd
1230
+ .command("intershell")
1231
+ .description("Check for allowedCallers configs that need updating for the open-network model")
1232
+ .action(async () => {
1233
+ try {
1234
+ const { runMigrateIntershell } = await import("./migrate-intershell.js");
1235
+ await runMigrateIntershell({ cwd: process.cwd() });
1236
+ }
1237
+ catch (err) {
1238
+ const message = err instanceof Error ? err.message : String(err);
1239
+ console.error(chalk.red(`\nError: ${message}\n`));
1240
+ process.exit(1);
1241
+ }
1242
+ });
1243
+ // ----------------------------------------------------------------
1222
1244
  // Error handling
1223
1245
  // ----------------------------------------------------------------
1224
1246
  program.exitOverride();
@@ -17,6 +17,8 @@ export interface InitOptions {
17
17
  manual?: boolean;
18
18
  /** Path to an OpenAPI/Swagger spec file — skips Route + API agents */
19
19
  apiSpec?: string;
20
+ /** Path to a cURL script or Postman collection — skips Route + API agents */
21
+ curlCollection?: string;
20
22
  /** Separate API base URL (for APIs on a different domain from the frontend) */
21
23
  apiUrl?: string;
22
24
  /** Industry/category override (e.g., fintech, ecommerce, saas) */
package/dist/cli/init.js CHANGED
@@ -601,7 +601,8 @@ export async function runInit(opts = {}) {
601
601
  // Skip the LLM check when --api-spec is provided: the deterministic parser
602
602
  // does not require any LLM key, so the pipeline can run without credentials.
603
603
  const hasApiSpec = Boolean(opts.apiSpec);
604
- if (!noAgents && !hasApiSpec) {
604
+ const hasCurlCollection = Boolean(opts.curlCollection);
605
+ if (!noAgents && !hasApiSpec && !hasCurlCollection) {
605
606
  const canRunAgents = await checkLlmCredentialsAndPrompt(noAgents, yes);
606
607
  if (!canRunAgents) {
607
608
  noAgents = true;
@@ -819,6 +820,17 @@ export async function runInit(opts = {}) {
819
820
  console.log(chalk.yellow(` ⚠ Could not read --api-spec file: ${opts.apiSpec}. Falling back to agent scan.\n`));
820
821
  }
821
822
  }
823
+ let curlCollectionContent;
824
+ const curlCollectionPath = opts.curlCollection ? path.resolve(cwd, opts.curlCollection) : undefined;
825
+ if (curlCollectionPath) {
826
+ try {
827
+ curlCollectionContent = await fs.readFile(curlCollectionPath, "utf-8");
828
+ console.log(chalk.gray(` Using cURL collection: ${path.relative(cwd, curlCollectionPath)} — deterministic parse, no LLM needed\n`));
829
+ }
830
+ catch {
831
+ console.log(chalk.yellow(` ⚠ Could not read --curl-collection file: ${opts.curlCollection}. Falling back to agent scan.\n`));
832
+ }
833
+ }
822
834
  // Build a bounded file list before running agents so each agent
823
835
  // receives targeted files as priority context instead of scanning broadly.
824
836
  let readList = !noAgents ? await buildReadList(topo, sandboxFs) : undefined;
@@ -919,6 +931,7 @@ export async function runInit(opts = {}) {
919
931
  emitter,
920
932
  readList,
921
933
  ...(apiSpecContent ? { apiSpecContent, apiSpecPath: opts.apiSpec } : {}),
934
+ ...(curlCollectionContent ? { curlCollectionContent, curlCollectionPath: opts.curlCollection } : {}),
922
935
  postProcess: { yesMode: yes },
923
936
  });
924
937
  pipelineSpinner.stop();
@@ -0,0 +1,3 @@
1
+ export declare function runMigrateIntershell(opts?: {
2
+ cwd?: string;
3
+ }): Promise<void>;
@@ -0,0 +1,108 @@
1
+ // ============================================================
2
+ // @duct/sdk — duct migrate intershell
3
+ // Inspects duct.config.ts for allowedCallers without intershell_enabled
4
+ // and prints guidance on the open-network migration path.
5
+ // Does NOT modify any files — developer must update manually.
6
+ // ============================================================
7
+ import * as fs from "fs/promises";
8
+ import * as path from "path";
9
+ import chalk from "chalk";
10
+ async function findConfigFile(cwd) {
11
+ for (const name of ["duct.config.ts", "duct.config.js"]) {
12
+ const candidate = path.join(cwd, name);
13
+ try {
14
+ await fs.access(candidate);
15
+ return candidate;
16
+ }
17
+ catch {
18
+ // not found — try next
19
+ }
20
+ }
21
+ return null;
22
+ }
23
+ async function inspectConfig(configPath) {
24
+ const source = await fs.readFile(configPath, "utf-8");
25
+ // Simple text-level detection — avoids needing to evaluate the file.
26
+ // Look for non-commented occurrences of the relevant keys.
27
+ const withoutComments = source
28
+ .split("\n")
29
+ .filter((line) => !line.trim().startsWith("//"))
30
+ .join("\n");
31
+ const hasAllowedCallers = /allowedCallers\s*:/.test(withoutComments);
32
+ const hasIntershellEnabled = /intershell_enabled\s*:/.test(withoutComments);
33
+ return {
34
+ configPath,
35
+ hasAllowedCallers,
36
+ hasIntershellEnabled,
37
+ needsMigration: hasAllowedCallers && !hasIntershellEnabled,
38
+ };
39
+ }
40
+ // ----------------------------------------------------------------
41
+ // runMigrateIntershell — main entry point
42
+ // ----------------------------------------------------------------
43
+ export async function runMigrateIntershell(opts = {}) {
44
+ const cwd = opts.cwd ?? process.cwd();
45
+ console.log(chalk.bold("\n ◆ Duct · migrate intershell\n"));
46
+ const configPath = await findConfigFile(cwd);
47
+ if (!configPath) {
48
+ console.log(chalk.yellow(" No duct.config.ts or duct.config.js found in the current directory.\n" +
49
+ " Run `npx duct init` first to generate your config.\n"));
50
+ return;
51
+ }
52
+ console.log(chalk.gray(` Config: ${configPath}\n`));
53
+ let result;
54
+ try {
55
+ result = await inspectConfig(configPath);
56
+ }
57
+ catch (err) {
58
+ const message = err instanceof Error ? err.message : String(err);
59
+ console.error(chalk.red(` Could not read config: ${message}\n`));
60
+ process.exit(1);
61
+ }
62
+ if (!result.hasAllowedCallers) {
63
+ console.log(chalk.green(" ✓ No allowedCallers found — no migration needed.\n\n" +
64
+ " If you want this shell to participate in the Duct open network, add:\n\n" +
65
+ chalk.cyan(" intershell_enabled: true,\n" +
66
+ " registry_visibility: 'public',\n") +
67
+ "\n to your duct.config.ts, then run `npx duct push`.\n"));
68
+ return;
69
+ }
70
+ if (result.hasIntershellEnabled) {
71
+ console.log(chalk.green(" ✓ Config has both allowedCallers and intershell_enabled — already up to date.\n\n" +
72
+ " Reminder: allowedCallers is now an optional restriction (non-empty = restrict to list).\n" +
73
+ " To open the shell to any public Duct shell, remove allowedCallers or leave it empty.\n"));
74
+ return;
75
+ }
76
+ // Needs migration: allowedCallers set, intershell_enabled missing
77
+ console.log(chalk.yellow(" ⚠ Migration notice\n\n" +
78
+ " Your config has allowedCallers but intershell_enabled is not set.\n\n" +
79
+ " In the open-network model:\n" +
80
+ " • allowedCallers is an optional restriction.\n" +
81
+ " When non-empty, only the listed shell IDs can call this shell cross-shell.\n" +
82
+ " When absent or empty, any public Duct shell may call.\n" +
83
+ " • intershell_enabled (default false) is the master on/off switch for cross-shell calls.\n" +
84
+ " If not set, cross-shell calls are disabled regardless of allowedCallers.\n\n" +
85
+ " Action required — update your duct.config.ts manually:\n"));
86
+ console.log(chalk.cyan(" Option A — Enable cross-shell calls and keep the caller restriction:\n\n" +
87
+ " agentPermissions: {\n" +
88
+ " ...\n" +
89
+ " allowedCallers: [...], // keep your existing list\n" +
90
+ " },\n" +
91
+ " intershell_enabled: true,\n" +
92
+ " registry_visibility: 'public', // or 'private' if you don't want discovery\n"));
93
+ console.log(chalk.cyan(" Option B — Enable cross-shell calls and open to all public Duct shells:\n\n" +
94
+ " agentPermissions: {\n" +
95
+ " ...\n" +
96
+ " // remove allowedCallers, or leave empty\n" +
97
+ " },\n" +
98
+ " intershell_enabled: true,\n" +
99
+ " registry_visibility: 'public',\n"));
100
+ console.log(chalk.cyan(" Option C — Disable cross-shell calls entirely (default behaviour):\n\n" +
101
+ " agentPermissions: {\n" +
102
+ " ...\n" +
103
+ " // remove allowedCallers (has no effect when intershell_enabled is false)\n" +
104
+ " },\n" +
105
+ " intershell_enabled: false, // already the default; explicit for clarity\n"));
106
+ console.log(chalk.gray(" After updating, run `npx duct push` to sync changes with Duct cloud.\n" +
107
+ " This command does not modify any files.\n"));
108
+ }
@@ -0,0 +1,21 @@
1
+ import type { ActionManifest, RouteManifest } from "../../core/types.js";
2
+ export interface CurlParseResult {
3
+ actions: ActionManifest[];
4
+ routes: RouteManifest[];
5
+ requestCount: number;
6
+ sourceLabel: string;
7
+ }
8
+ interface ParsedRequest {
9
+ method: string;
10
+ path: string;
11
+ url: string;
12
+ body?: Record<string, unknown>;
13
+ name?: string;
14
+ }
15
+ /** Parse one curl command line (may span continuation with \\). */
16
+ export declare function parseCurlCommand(raw: string): ParsedRequest | null;
17
+ /**
18
+ * Parse a `.sh` curl script, raw curl text, or Postman Collection v2.1 JSON.
19
+ */
20
+ export declare function parseCurlCollection(content: string, filePath?: string): Promise<CurlParseResult>;
21
+ export {};