@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.
Files changed (166) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +418 -264
  3. package/TOKEN_SPEC.md +243 -243
  4. package/dist/cli/action-confusion-format.d.ts +17 -0
  5. package/dist/cli/action-confusion-format.js +24 -0
  6. package/dist/cli/add.d.ts +7 -0
  7. package/dist/cli/add.js +152 -0
  8. package/dist/cli/agent-prompt.d.ts +3 -0
  9. package/dist/cli/agent-prompt.js +39 -0
  10. package/dist/cli/api-sources.d.ts +26 -0
  11. package/dist/cli/api-sources.js +222 -0
  12. package/dist/cli/cloud.d.ts +162 -0
  13. package/dist/cli/cloud.js +306 -0
  14. package/dist/cli/config-loader.d.ts +14 -0
  15. package/dist/cli/config-loader.js +56 -7
  16. package/dist/cli/device-login.d.ts +17 -0
  17. package/dist/cli/device-login.js +75 -0
  18. package/dist/cli/drift.js +6 -6
  19. package/dist/cli/generators/any-stack.d.ts +3 -0
  20. package/dist/cli/generators/any-stack.js +97 -0
  21. package/dist/cli/generators/config.js +3 -2
  22. package/dist/cli/generators/receiver.js +7 -7
  23. package/dist/cli/generators/shell.js +12 -12
  24. package/dist/cli/generators/token-route.js +245 -245
  25. package/dist/cli/generators/wiring-snippets.d.ts +0 -14
  26. package/dist/cli/generators/wiring-snippets.js +188 -305
  27. package/dist/cli/index.js +396 -611
  28. package/dist/cli/mcp-core.d.ts +42 -0
  29. package/dist/cli/mcp-core.js +161 -0
  30. package/dist/cli/mcp-setup.d.ts +4 -0
  31. package/dist/cli/mcp-setup.js +352 -0
  32. package/dist/cli/mcp.d.ts +2 -0
  33. package/dist/cli/mcp.js +457 -0
  34. package/dist/cli/migrate-intershell.js +5 -5
  35. package/dist/cli/policy-defaults.d.ts +37 -0
  36. package/dist/cli/policy-defaults.js +127 -0
  37. package/dist/cli/policy-replay-format.d.ts +9 -0
  38. package/dist/cli/policy-replay-format.js +46 -0
  39. package/dist/cli/processors/integration-audit.js +2 -2
  40. package/dist/cli/processors/openapi-parser.d.ts +5 -0
  41. package/dist/cli/processors/openapi-parser.js +8 -3
  42. package/dist/cli/project-loader.d.ts +58 -0
  43. package/dist/cli/project-loader.js +198 -0
  44. package/dist/cli/project-writer.d.ts +23 -0
  45. package/dist/cli/project-writer.js +171 -0
  46. package/dist/cli/push.d.ts +43 -0
  47. package/dist/cli/push.js +308 -0
  48. package/dist/cli/safety-checks.d.ts +9 -0
  49. package/dist/cli/safety-checks.js +29 -0
  50. package/dist/cli/setup.d.ts +20 -0
  51. package/dist/cli/setup.js +349 -0
  52. package/dist/cli/shell-name.d.ts +8 -0
  53. package/dist/cli/shell-name.js +29 -0
  54. package/dist/cli/shells.d.ts +22 -0
  55. package/dist/cli/shells.js +122 -0
  56. package/dist/cli/split.d.ts +7 -0
  57. package/dist/cli/split.js +71 -0
  58. package/dist/cli/sync.d.ts +25 -0
  59. package/dist/cli/sync.js +120 -0
  60. package/dist/cli/test-runner.d.ts +21 -0
  61. package/dist/cli/test-runner.js +281 -0
  62. package/dist/core/compile.d.ts +43 -0
  63. package/dist/core/compile.js +512 -0
  64. package/dist/core/config.d.ts +538 -19
  65. package/dist/core/config.js +22 -14
  66. package/dist/core/login-handoff.d.ts +1 -1
  67. package/dist/core/login-handoff.js +1 -1
  68. package/dist/core/project.d.ts +1864 -0
  69. package/dist/core/project.js +291 -0
  70. package/dist/core/readiness-checks.js +2 -2
  71. package/dist/core/types.d.ts +10 -1
  72. package/dist/index.d.ts +2 -0
  73. package/dist/index.js +1 -0
  74. package/dist/project.d.ts +4 -0
  75. package/dist/project.js +8 -0
  76. package/dist/server.d.ts +2 -0
  77. package/dist/server.js +1 -0
  78. package/package.json +94 -95
  79. package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
  80. package/dist/adapters/react/page-context-guard.test.js +0 -15
  81. package/dist/cli/agents/api-agent.d.ts +0 -22
  82. package/dist/cli/agents/api-agent.js +0 -761
  83. package/dist/cli/agents/auth-agent.d.ts +0 -7
  84. package/dist/cli/agents/auth-agent.js +0 -212
  85. package/dist/cli/agents/deeplink-agent.d.ts +0 -6
  86. package/dist/cli/agents/deeplink-agent.js +0 -285
  87. package/dist/cli/agents/llm.d.ts +0 -33
  88. package/dist/cli/agents/llm.js +0 -309
  89. package/dist/cli/agents/pipeline.d.ts +0 -72
  90. package/dist/cli/agents/pipeline.js +0 -421
  91. package/dist/cli/agents/reviewer-agent.d.ts +0 -13
  92. package/dist/cli/agents/reviewer-agent.js +0 -450
  93. package/dist/cli/agents/route-agent.d.ts +0 -17
  94. package/dist/cli/agents/route-agent.js +0 -383
  95. package/dist/cli/config-loader.test.d.ts +0 -1
  96. package/dist/cli/config-loader.test.js +0 -63
  97. package/dist/cli/detectors/topology.d.ts +0 -46
  98. package/dist/cli/detectors/topology.js +0 -417
  99. package/dist/cli/generators/config.test.d.ts +0 -1
  100. package/dist/cli/generators/config.test.js +0 -222
  101. package/dist/cli/generators/shell.test.d.ts +0 -1
  102. package/dist/cli/generators/shell.test.js +0 -73
  103. package/dist/cli/generators/token-route.test.d.ts +0 -1
  104. package/dist/cli/generators/token-route.test.js +0 -53
  105. package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
  106. package/dist/cli/generators/wiring-snippets.test.js +0 -80
  107. package/dist/cli/init.d.ts +0 -32
  108. package/dist/cli/init.js +0 -1336
  109. package/dist/cli/manifest-diff.test.d.ts +0 -1
  110. package/dist/cli/manifest-diff.test.js +0 -144
  111. package/dist/cli/processors/curl-parser.test.d.ts +0 -1
  112. package/dist/cli/processors/curl-parser.test.js +0 -24
  113. package/dist/cli/processors/integration-audit.test.d.ts +0 -1
  114. package/dist/cli/processors/integration-audit.test.js +0 -154
  115. package/dist/cli/processors/postprocess.d.ts +0 -22
  116. package/dist/cli/processors/postprocess.js +0 -107
  117. package/dist/cli/processors/prisma-parser.d.ts +0 -35
  118. package/dist/cli/processors/prisma-parser.js +0 -117
  119. package/dist/cli/processors/verify-discovery.d.ts +0 -33
  120. package/dist/cli/processors/verify-discovery.js +0 -193
  121. package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
  122. package/dist/cli/processors/verify-discovery.test.js +0 -153
  123. package/dist/cli/processors/zod-extractor.d.ts +0 -27
  124. package/dist/cli/processors/zod-extractor.js +0 -153
  125. package/dist/cli/prompts/review.d.ts +0 -61
  126. package/dist/cli/prompts/review.js +0 -410
  127. package/dist/cli/selectors/express.d.ts +0 -12
  128. package/dist/cli/selectors/express.js +0 -117
  129. package/dist/cli/selectors/fastapi.d.ts +0 -12
  130. package/dist/cli/selectors/fastapi.js +0 -122
  131. package/dist/cli/selectors/generic.d.ts +0 -10
  132. package/dist/cli/selectors/generic.js +0 -74
  133. package/dist/cli/selectors/index.d.ts +0 -37
  134. package/dist/cli/selectors/index.js +0 -315
  135. package/dist/cli/selectors/next.d.ts +0 -12
  136. package/dist/cli/selectors/next.js +0 -130
  137. package/dist/core/config-policy.test.d.ts +0 -1
  138. package/dist/core/config-policy.test.js +0 -101
  139. package/dist/core/config-roundtrip.test.d.ts +0 -1
  140. package/dist/core/config-roundtrip.test.js +0 -180
  141. package/dist/core/endpoint-guard.test.d.ts +0 -1
  142. package/dist/core/endpoint-guard.test.js +0 -57
  143. package/dist/core/env-diagnostics.test.d.ts +0 -1
  144. package/dist/core/env-diagnostics.test.js +0 -31
  145. package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
  146. package/dist/core/evidence-bundle.conformance.test.js +0 -110
  147. package/dist/core/evidence-bundle.test.d.ts +0 -1
  148. package/dist/core/evidence-bundle.test.js +0 -58
  149. package/dist/core/invariants.test.d.ts +0 -1
  150. package/dist/core/invariants.test.js +0 -217
  151. package/dist/core/login-handoff.test.d.ts +0 -1
  152. package/dist/core/login-handoff.test.js +0 -31
  153. package/dist/core/profile.test.d.ts +0 -1
  154. package/dist/core/profile.test.js +0 -95
  155. package/dist/core/readiness-checks.test.d.ts +0 -1
  156. package/dist/core/readiness-checks.test.js +0 -106
  157. package/dist/core/receipt.test.d.ts +0 -1
  158. package/dist/core/receipt.test.js +0 -75
  159. package/dist/core/sdk-entrypoint.test.d.ts +0 -1
  160. package/dist/core/sdk-entrypoint.test.js +0 -8
  161. package/dist/core/side-effects-review.test.d.ts +0 -1
  162. package/dist/core/side-effects-review.test.js +0 -28
  163. package/dist/core/token.conformance.test.d.ts +0 -1
  164. package/dist/core/token.conformance.test.js +0 -43
  165. package/dist/core/token.test.d.ts +0 -1
  166. package/dist/core/token.test.js +0 -66
@@ -0,0 +1,291 @@
1
+ // ============================================================
2
+ // @duct-sdk/sdk — Project files (the split manifest)
3
+ //
4
+ // A Duct project is a `duct/` folder with one file per concern:
5
+ //
6
+ // duct/project.ts who you are: shell id, product, API origin, auth
7
+ // duct/capabilities.json what your API can do — generated by `duct sync`
8
+ // duct/policy.ts what agents may do — the guardrails you own
9
+ // duct/shell.ts optional: chat UI, routes, deeplinks, LLM hints
10
+ // duct/tests.ts optional: policy expectations checked by `duct test`
11
+ //
12
+ // `duct push` compiles these into the same manifest the Duct gateway has always
13
+ // enforced, so behaviour is identical to a hand-written duct.config.ts.
14
+ //
15
+ // Every .ts file is read statically (never executed): keep values literal.
16
+ // ============================================================
17
+ import { z } from "zod";
18
+ import { ManifestActionSchema, SensitivityLevelSchema, iso8601Schema, } from "@duct-sdk/contracts";
19
+ import { ApprovalStepUpConfigSchema, AuthSchemaSchema, DataModelSchema, DeeplinkDefinitionSchema, ProductConfigSchema, RouteManifestSchema, WebhooksConfigSchema, WidgetConfigSchema, } from "./config.js";
20
+ export const PROJECT_DIR = "duct";
21
+ export const PROJECT_FILES = {
22
+ project: "project.ts",
23
+ capabilities: "capabilities.json",
24
+ policy: "policy.ts",
25
+ shell: "shell.ts",
26
+ tests: "tests.ts",
27
+ };
28
+ /** Marker functions the static loader looks for in each .ts file. */
29
+ export const PROJECT_MARKERS = {
30
+ project: "defineProject(",
31
+ policy: "definePolicy(",
32
+ shell: "defineShell(",
33
+ tests: "defineTests(",
34
+ };
35
+ const ACTION_ID_RE = /^[a-z_][a-z0-9_]*$/;
36
+ // NOTE: schemas imported from @duct-sdk/contracts come from a separate zod copy.
37
+ // z.record(key, value) detects its value schema with `instanceof`, so contract schemas
38
+ // used as record values must be wrapped in z.lazy() or zod silently misreads them.
39
+ const PATTERN_RE = /^[a-z0-9_*]+$/;
40
+ /** Action id or glob over action ids, e.g. `get_*`, `*_order`, `*`. */
41
+ export const ActionPatternSchema = z
42
+ .string()
43
+ .min(1)
44
+ .regex(PATTERN_RE, "Patterns are snake_case action ids with * wildcards (e.g. get_*, refund_*, *)");
45
+ // ----------------------------------------------------------------
46
+ // duct/project.ts
47
+ // ----------------------------------------------------------------
48
+ export const ProjectNetworkSchema = z
49
+ .object({
50
+ registry_visibility: z.enum(["public", "private"]).optional(),
51
+ intershell_enabled: z.boolean().optional(),
52
+ allowedCallers: z.array(z.string()).optional(),
53
+ allowedCallees: z.array(z.string()).optional(),
54
+ })
55
+ .strict();
56
+ export const ProjectFileSchema = z
57
+ .object({
58
+ shellId: z
59
+ .string()
60
+ .min(1)
61
+ .regex(/^shell_[a-z0-9_]+$/, "Shell IDs must match pattern: shell_<company>_<env>"),
62
+ product: ProductConfigSchema,
63
+ /** How your app authenticates users. Only needed for user identity and the chat shell. */
64
+ auth: AuthSchemaSchema.optional(),
65
+ webhooks: WebhooksConfigSchema.optional(),
66
+ /** Cross-shell settings (early access, off by default). */
67
+ network: ProjectNetworkSchema.optional(),
68
+ })
69
+ .strict();
70
+ // ----------------------------------------------------------------
71
+ // duct/capabilities.json
72
+ // ----------------------------------------------------------------
73
+ export const CapabilityActionSchema = ManifestActionSchema.pick({
74
+ id: true,
75
+ name: true,
76
+ description: true,
77
+ method: true,
78
+ path: true,
79
+ sideEffects: true,
80
+ sideEffectsReviewAck: true,
81
+ params: true,
82
+ inputSchema: true,
83
+ responseSchema: true,
84
+ confidence: true,
85
+ evidence: true,
86
+ updatedAt: true,
87
+ })
88
+ .extend({
89
+ sensitivityLevel: SensitivityLevelSchema.default("low"),
90
+ requiresAuth: z.boolean().default(false),
91
+ })
92
+ .strict();
93
+ export const CapabilitySourceSchema = z
94
+ .object({
95
+ kind: z.enum(["openapi", "postman", "curl", "manual", "imported"]),
96
+ /** File path (relative to the project root) or URL the actions were generated from. */
97
+ location: z.string().optional(),
98
+ syncedAt: z.string().optional(),
99
+ })
100
+ .strict();
101
+ export const CapabilitiesFileSchema = z
102
+ .object({
103
+ $schema: z.string().optional(),
104
+ version: z.literal(1),
105
+ source: CapabilitySourceSchema,
106
+ actions: z.array(CapabilityActionSchema),
107
+ })
108
+ .strict()
109
+ .superRefine((value, ctx) => {
110
+ const seen = new Set();
111
+ value.actions.forEach((action, index) => {
112
+ if (seen.has(action.id)) {
113
+ ctx.addIssue({
114
+ code: z.ZodIssueCode.custom,
115
+ path: ["actions", index, "id"],
116
+ message: `Duplicate action id "${action.id}"`,
117
+ });
118
+ }
119
+ seen.add(action.id);
120
+ });
121
+ });
122
+ // ----------------------------------------------------------------
123
+ // duct/policy.ts
124
+ // ----------------------------------------------------------------
125
+ const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean()]);
126
+ /** One comparison on a param: `{ gt: 500 }`, `{ in: ["USD", "EUR"] }`, or a bare value for equality. */
127
+ export const ComparisonSchema = z.union([
128
+ PrimitiveSchema,
129
+ z
130
+ .object({
131
+ gt: PrimitiveSchema,
132
+ gte: PrimitiveSchema,
133
+ lt: PrimitiveSchema,
134
+ lte: PrimitiveSchema,
135
+ eq: PrimitiveSchema,
136
+ neq: PrimitiveSchema,
137
+ in: z.array(PrimitiveSchema).min(1),
138
+ })
139
+ .partial()
140
+ .strict()
141
+ .refine((value) => Object.keys(value).length === 1, {
142
+ message: "Use exactly one operator per comparison (gt, gte, lt, lte, eq, neq, in)",
143
+ }),
144
+ ]);
145
+ export const ConditionSchema = z.lazy(() => z.union([
146
+ z.object({ any: z.array(ConditionSchema).min(1) }).strict(),
147
+ z.object({ all: z.array(ConditionSchema).min(1) }).strict(),
148
+ z
149
+ .record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_.]*$/, "Param names must be identifiers"), ComparisonSchema)
150
+ .refine((value) => Object.keys(value).length > 0, { message: "Condition needs at least one param" }),
151
+ ]));
152
+ export const LimitSpecSchema = z
153
+ .object({
154
+ /** Requests per minute for this action (all callers). */
155
+ perMinute: z.number().int().positive().optional(),
156
+ perHour: z.number().int().positive().optional(),
157
+ perDay: z.number().int().positive().optional(),
158
+ /** Lifetime cap on executions. */
159
+ total: z.number().int().positive().optional(),
160
+ /** Custom rolling window. */
161
+ window: z
162
+ .object({ max: z.number().int().positive(), seconds: z.number().int().positive() })
163
+ .strict()
164
+ .optional(),
165
+ })
166
+ .strict()
167
+ .superRefine((value, ctx) => {
168
+ const windowed = ["perHour", "perDay", "total", "window"].filter((key) => value[key] !== undefined);
169
+ if (windowed.length > 1) {
170
+ ctx.addIssue({
171
+ code: z.ZodIssueCode.custom,
172
+ message: `Use only one of perHour, perDay, total, window per entry (got ${windowed.join(", ")})`,
173
+ });
174
+ }
175
+ if (Object.keys(value).length === 0) {
176
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Limit needs at least one field" });
177
+ }
178
+ });
179
+ export const AgentAccessSchema = z.enum(["none", "read", "write"]);
180
+ export const PolicyAgentsSchema = z
181
+ .object({
182
+ /** Default for agents: none = no access, read = read-only actions, write = all exposed actions. */
183
+ access: AgentAccessSchema.default("read"),
184
+ /** Actions agents may call. Omit to expose every action the access level permits. */
185
+ allow: z.array(ActionPatternSchema).optional(),
186
+ /** Actions agents may never call. Deny always wins. */
187
+ deny: z.array(ActionPatternSchema).optional(),
188
+ /** Per-action access level overrides (advanced). */
189
+ levels: z.record(z.string().regex(ACTION_ID_RE), z.enum(["none", "read", "write", "admin"])).optional(),
190
+ /** Require a user consent token for every agent call that acts for a user. */
191
+ userConsent: z.boolean().default(true),
192
+ /** Limit which actions a user's consent can cover (exact action ids). */
193
+ consentScope: z.array(z.string().regex(ACTION_ID_RE)).optional(),
194
+ /**
195
+ * How many hours a person's approval of an agent lasts, by the most sensitive action it
196
+ * covers. Defaults: low 24, medium 8, high 1 (high includes critical). At most 168.
197
+ * Side-effect actions still need a human approval on every call.
198
+ */
199
+ consentHours: z
200
+ .object({
201
+ low: z.number().positive().max(168).optional(),
202
+ medium: z.number().positive().max(168).optional(),
203
+ high: z.number().positive().max(168).optional(),
204
+ })
205
+ .strict()
206
+ .optional(),
207
+ validFrom: iso8601Schema.optional(),
208
+ validUntil: iso8601Schema.optional(),
209
+ })
210
+ .strict();
211
+ export const PolicyApproversSchema = z
212
+ .object({
213
+ /** Who gets notified when an agent request is waiting for approval. */
214
+ emails: z.array(z.string().email()).optional(),
215
+ reminderLeadMinutes: z.number().int().positive().nullable().optional(),
216
+ /** Re-authentication required to approve sensitive requests. */
217
+ stepUp: ApprovalStepUpConfigSchema.optional(),
218
+ })
219
+ .strict();
220
+ export const PolicyFileSchema = z
221
+ .object({
222
+ agents: PolicyAgentsSchema.default({}),
223
+ /** Require human approval when a call matches the condition. Later entries win. */
224
+ approveWhen: z.record(ActionPatternSchema, ConditionSchema).optional(),
225
+ /** Rate and count limits. Applied top to bottom; later entries override earlier fields. */
226
+ limits: z.record(ActionPatternSchema, LimitSpecSchema).optional(),
227
+ /** Raise or lower sensitivity for matching actions. Later entries win. */
228
+ sensitivity: z.record(ActionPatternSchema, z.lazy(() => SensitivityLevelSchema)).optional(),
229
+ /** Time windows during which matching actions are callable. */
230
+ windows: z
231
+ .record(ActionPatternSchema, z.object({ from: iso8601Schema.optional(), until: iso8601Schema.optional() }).strict())
232
+ .optional(),
233
+ approvers: PolicyApproversSchema.optional(),
234
+ })
235
+ .strict();
236
+ // ----------------------------------------------------------------
237
+ // duct/shell.ts
238
+ // ----------------------------------------------------------------
239
+ export const ShellActionHintsSchema = ManifestActionSchema.pick({
240
+ searchHint: true,
241
+ alwaysInclude: true,
242
+ interruptBehavior: true,
243
+ dependsOn: true,
244
+ semanticType: true,
245
+ outputSchema: true,
246
+ paramMappings: true,
247
+ navigatesTo: true,
248
+ }).strict();
249
+ export const ShellFileSchema = z
250
+ .object({
251
+ widget: WidgetConfigSchema.optional(),
252
+ routes: z.array(RouteManifestSchema).default([]),
253
+ deeplinks: z.array(DeeplinkDefinitionSchema).default([]),
254
+ dataModel: DataModelSchema.optional(),
255
+ /** Chat-only hints per action id: search hints, UI shape, chaining. */
256
+ actionHints: z.record(z.string().regex(ACTION_ID_RE), z.lazy(() => ShellActionHintsSchema)).optional(),
257
+ })
258
+ .strict();
259
+ // ----------------------------------------------------------------
260
+ // duct/tests.ts
261
+ // ----------------------------------------------------------------
262
+ export const PolicyExpectationSchema = z.enum(["allow", "deny", "approval", "blocked"]);
263
+ export const PolicyTestCaseSchema = z
264
+ .object({
265
+ name: z.string().optional(),
266
+ /** Who is calling: an external agent, a signed-in user in the shell, or a guest. */
267
+ as: z.enum(["agent", "user", "guest"]),
268
+ action: z.string().regex(ACTION_ID_RE),
269
+ params: z.record(z.unknown()).optional(),
270
+ withUserConsent: z.boolean().optional(),
271
+ /** `blocked` = must not run without a human (deny or approval). */
272
+ expect: PolicyExpectationSchema,
273
+ })
274
+ .strict();
275
+ export const TestsFileSchema = z
276
+ .object({
277
+ policy: z.array(PolicyTestCaseSchema).default([]),
278
+ })
279
+ .strict();
280
+ export function defineProject(project) {
281
+ return project;
282
+ }
283
+ export function definePolicy(policy) {
284
+ return policy;
285
+ }
286
+ export function defineShell(shell) {
287
+ return shell;
288
+ }
289
+ export function defineTests(tests) {
290
+ return tests;
291
+ }
@@ -41,7 +41,7 @@ export async function buildCliReadinessReport(options) {
41
41
  checks.push(makeCheck('env_duct_url', 'DUCT_URL', env.ductUrl ? 'pass' : 'warn', { message: env.ductUrl || 'Not set — using localhost defaults' }), makeCheck('env_shell_id', 'DUCT_SHELL_ID', env.shellId ? 'pass' : 'warn', { message: env.shellId || 'Not set' }), makeCheck('env_secret_key', 'DUCT_SECRET_KEY', env.secretKey ? 'pass' : 'warn', { message: env.secretKey ? `sk_...${env.secretKey.slice(-4)}` : 'Not set' }), makeCheck('auth_logged_in', 'CLI auth profile', env.authEmail ? 'pass' : 'warn', {
42
42
  message: env.authEmail
43
43
  ? `${env.authEmail} (${env.authSlug ?? 'unknown slug'})`
44
- : 'Not logged in — run: npx duct login',
44
+ : 'Not logged in — run: npx @duct-sdk/sdk login',
45
45
  }));
46
46
  const serviceChecks = [
47
47
  { id: 'auth_reachable', label: 'Auth service', url: endpoints.authHealthUrl },
@@ -132,7 +132,7 @@ export async function buildShellReadinessReport(input) {
132
132
  checks.push(makeCheck('manifest_pushed', 'Manifest pushed', input.manifestPushed ? 'pass' : 'fail', {
133
133
  message: input.manifestPushed
134
134
  ? 'Shell status is live'
135
- : 'Run npx duct push to publish your manifest',
135
+ : 'Run npx @duct-sdk/sdk push to publish your manifest',
136
136
  }));
137
137
  if (!input.productBaseUrl) {
138
138
  checks.push(makeCheck('product_base_url', 'Product base URL', 'warn', {
@@ -190,7 +190,7 @@ export interface AuthSchema {
190
190
  loginDeeplinkId?: string;
191
191
  /**
192
192
  * App route path for sign-in (e.g. `/login`). Used when no login deeplink is
193
- * declared — auto-detected from routes during `duct init` when possible.
193
+ * declared — auto-detected from routes by `duct add identity` when possible.
194
194
  */
195
195
  loginRoutePath?: string;
196
196
  /** Agent detection confidence (0.0–1.0). */
@@ -305,6 +305,15 @@ export interface AgentPermissions {
305
305
  * issuance (auth service) and the Duct gateway on invoke.
306
306
  */
307
307
  consentActionScope?: string[];
308
+ /**
309
+ * Hours a person's approval of an agent lasts, by the most sensitive action it covers
310
+ * (Duct defaults: low 24, medium 8, high 1; at most 168). From policy.agents.consentHours.
311
+ */
312
+ consentGrantHours?: {
313
+ low?: number;
314
+ medium?: number;
315
+ high?: number;
316
+ };
308
317
  }
309
318
  /**
310
319
  * Shell panel size/shape presets.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export declare class DuctSdkWrongEntrypointError extends Error {
4
4
  }
5
5
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
6
6
  export type { ValidatedDuctConfig, ManifestAction, ErrorEnvelope, ConfirmationState } from "./core/config.js";
7
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
8
+ export type { ProjectFile, CapabilitiesFile, PolicyFile, ShellFile, TestsFile } from "./core/project.js";
7
9
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
8
10
  export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, DeeplinkReplayStore, RedisSetClient, } from "./core/token.js";
9
11
  export { verifyReceipt, computeReceiptId } from "./core/receipt.js";
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ catch {
22
22
  }
23
23
  // Core config
24
24
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
25
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
25
26
  // Token utilities
26
27
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
27
28
  // Outcome receipt verification (crypto layer)
@@ -0,0 +1,4 @@
1
+ export { defineProject, definePolicy, defineShell, defineTests, PROJECT_DIR, PROJECT_FILES, ProjectFileSchema, CapabilitiesFileSchema, PolicyFileSchema, ShellFileSchema, TestsFileSchema, } from "./core/project.js";
2
+ export type { ProjectFile, CapabilitiesFile, CapabilityAction, PolicyFile, ShellFile, TestsFile, PolicyTestCase, PolicyExpectation, Condition, Comparison, LimitSpec, AgentAccess, } from "./core/project.js";
3
+ export { compileProject, splitDuctConfig, enforcementDiff, matchesPattern } from "./core/compile.js";
4
+ export type { CompileResult, ProjectInput, SplitResult } from "./core/compile.js";
@@ -0,0 +1,8 @@
1
+ // ============================================================
2
+ // @duct-sdk/sdk/project — typed helpers for duct/*.ts project files
3
+ //
4
+ // Dependency-light entry point: safe to import from any backend (no React,
5
+ // no Node-only APIs). The CLI reads these files statically and never runs them.
6
+ // ============================================================
7
+ export { defineProject, definePolicy, defineShell, defineTests, PROJECT_DIR, PROJECT_FILES, ProjectFileSchema, CapabilitiesFileSchema, PolicyFileSchema, ShellFileSchema, TestsFileSchema, } from "./core/project.js";
8
+ export { compileProject, splitDuctConfig, enforcementDiff, matchesPattern } from "./core/compile.js";
package/dist/server.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
2
2
  export type { ValidatedDuctConfig, ManifestAction, ErrorEnvelope, ConfirmationState } from "./core/config.js";
3
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
4
+ export type { ProjectFile, CapabilitiesFile, PolicyFile, ShellFile, TestsFile } from "./core/project.js";
3
5
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
4
6
  export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, DeeplinkReplayStore, RedisSetClient, } from "./core/token.js";
5
7
  export { verifyReceipt, computeReceiptId } from "./core/receipt.js";
package/dist/server.js CHANGED
@@ -11,6 +11,7 @@
11
11
  // ============================================================
12
12
  // Config
13
13
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
14
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
14
15
  // Token utilities — mint delegated JWTs, verify them, handle deeplinks
15
16
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
16
17
  // Outcome receipt verification (crypto layer)
package/package.json CHANGED
@@ -1,95 +1,94 @@
1
- {
2
- "name": "@duct-sdk/sdk",
3
- "version": "0.5.13",
4
- "type": "module",
5
- "description": "Duct SDK — manifest, CLI, and embed components for permissioned human and agent access to your product APIs.",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "bin": {
9
- "duct": "dist/cli/index.js"
10
- },
11
- "exports": {
12
- ".": "./dist/index.js",
13
- "./server": "./dist/server.js",
14
- "./next": "./dist/adapters/next/index.js",
15
- "./remix": "./dist/adapters/remix/index.js",
16
- "./vite": "./dist/adapters/vite/index.js",
17
- "./sveltekit": "./dist/adapters/sveltekit/index.js",
18
- "./react": "./dist/adapters/react/index.js"
19
- },
20
- "scripts": {
21
- "build": "npm run build --prefix ../contracts && tsc",
22
- "dev": "tsc --watch",
23
- "test": "npm run build && node --test dist/core/*.test.js dist/adapters/react/*.test.js dist/cli/*.test.js dist/cli/generators/*.test.js dist/cli/processors/*.test.js",
24
- "verify:publish": "node scripts/verify-publish.mjs",
25
- "pack:release": "npm run build && npm run verify:publish && node scripts/pack-release.mjs",
26
- "prepublishOnly": "npm run build && npm run verify:publish"
27
- },
28
- "dependencies": {
29
- "@duct-sdk/contracts": "file:../contracts",
30
- "@anthropic-ai/sdk": "^0.24.0",
31
- "jose": "^5.0.0",
32
- "ignore": "^5.0.0",
33
- "commander": "^12.0.0",
34
- "chalk": "^5.0.0",
35
- "ora": "^8.0.0",
36
- "inquirer": "^9.0.0",
37
- "zod": "^3.0.0",
38
- "node-fetch": "^3.0.0",
39
- "glob": "^10.0.0",
40
- "yaml": "^2.0.0"
41
- },
42
- "devDependencies": {
43
- "typescript": "^5.0.0",
44
- "@types/node": "^20.0.0",
45
- "@types/inquirer": "^9.0.0",
46
- "@types/react": "^18.0.0",
47
- "next": "^14.0.0",
48
- "react": "^18.0.0",
49
- "react-dom": "^18.0.0"
50
- },
51
- "peerDependencies": {
52
- "react": "^18.0.0 || ^19.0.0",
53
- "react-dom": "^18.0.0 || ^19.0.0",
54
- "next": ">=14.0.0"
55
- },
56
- "peerDependenciesMeta": {
57
- "react": {
58
- "optional": true
59
- },
60
- "react-dom": {
61
- "optional": true
62
- },
63
- "next": {
64
- "optional": true
65
- }
66
- },
67
- "files": [
68
- "dist",
69
- "assets",
70
- "fixtures",
71
- "README.md",
72
- "CHANGELOG.md",
73
- "TOKEN_SPEC.md"
74
- ],
75
- "keywords": [
76
- "duct",
77
- "ai",
78
- "agent",
79
- "shell",
80
- "cli",
81
- "llm",
82
- "ai-agent",
83
- "deeplink",
84
- "next",
85
- "nextjs",
86
- "remix",
87
- "vite",
88
- "sveltekit",
89
- "sdk"
90
- ],
91
- "publishConfig": {
92
- "registry": "https://registry.npmjs.org",
93
- "access": "public"
94
- }
95
- }
1
+ {
2
+ "name": "@duct-sdk/sdk",
3
+ "version": "0.7.0",
4
+ "type": "module",
5
+ "description": "Duct SDK — CLI, project files, and embed components for policy-enforced agent access to your product APIs.",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "duct": "dist/cli/index.js"
10
+ },
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./server": "./dist/server.js",
14
+ "./project": "./dist/project.js",
15
+ "./next": "./dist/adapters/next/index.js",
16
+ "./remix": "./dist/adapters/remix/index.js",
17
+ "./vite": "./dist/adapters/vite/index.js",
18
+ "./sveltekit": "./dist/adapters/sveltekit/index.js",
19
+ "./react": "./dist/adapters/react/index.js"
20
+ },
21
+ "scripts": {
22
+ "build": "npm run build --prefix ../contracts && tsc",
23
+ "dev": "tsc --watch",
24
+ "test": "npm run build && node --test dist/core/*.test.js dist/adapters/react/*.test.js dist/cli/*.test.js dist/cli/generators/*.test.js dist/cli/processors/*.test.js && node --test tests/*.test.mjs",
25
+ "verify:publish": "node scripts/verify-publish.mjs",
26
+ "pack:release": "npm run build && npm run verify:publish && node scripts/pack-release.mjs",
27
+ "prepublishOnly": "npm run build && npm run verify:publish"
28
+ },
29
+ "dependencies": {
30
+ "@duct-sdk/contracts": "file:../contracts",
31
+ "jose": "^5.0.0",
32
+ "commander": "^12.0.0",
33
+ "chalk": "^5.0.0",
34
+ "ora": "^8.0.0",
35
+ "inquirer": "^9.0.0",
36
+ "zod": "^3.0.0",
37
+ "glob": "^10.0.0",
38
+ "yaml": "^2.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.0.0",
42
+ "@types/node": "^20.0.0",
43
+ "@types/inquirer": "^9.0.0",
44
+ "@types/react": "^18.0.0",
45
+ "next": "^14.0.0",
46
+ "react": "^18.0.0",
47
+ "react-dom": "^18.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react": "^18.0.0 || ^19.0.0",
51
+ "react-dom": "^18.0.0 || ^19.0.0",
52
+ "next": ">=14.0.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "react": {
56
+ "optional": true
57
+ },
58
+ "react-dom": {
59
+ "optional": true
60
+ },
61
+ "next": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "files": [
66
+ "dist",
67
+ "!dist/**/*.test.*",
68
+ "assets",
69
+ "fixtures",
70
+ "README.md",
71
+ "CHANGELOG.md",
72
+ "TOKEN_SPEC.md"
73
+ ],
74
+ "keywords": [
75
+ "duct",
76
+ "ai",
77
+ "agent",
78
+ "shell",
79
+ "cli",
80
+ "llm",
81
+ "ai-agent",
82
+ "deeplink",
83
+ "next",
84
+ "nextjs",
85
+ "remix",
86
+ "vite",
87
+ "sveltekit",
88
+ "sdk"
89
+ ],
90
+ "publishConfig": {
91
+ "registry": "https://registry.npmjs.org",
92
+ "access": "public"
93
+ }
94
+ }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { shouldHandlePageContextRequest } from "./page-context-guard.js";
4
- describe("shouldHandlePageContextRequest", () => {
5
- it("refuses foreign origins when shellHost is configured", () => {
6
- assert.equal(shouldHandlePageContextRequest("http://localhost:3000", "https://evil.example"), false);
7
- });
8
- it("allows the shell origin", () => {
9
- assert.equal(shouldHandlePageContextRequest("http://localhost:3000", "http://localhost:3000"), true);
10
- });
11
- it("fails closed without shellHost", () => {
12
- assert.equal(shouldHandlePageContextRequest(undefined, "http://localhost:3000"), false);
13
- assert.equal(shouldHandlePageContextRequest(undefined, "https://evil.example"), false);
14
- });
15
- });
@@ -1,22 +0,0 @@
1
- import type { SandboxFS } from "../fs/sandbox.js";
2
- import type { ActionManifest } from "../../core/types.js";
3
- export interface ApiScannerStrategy {
4
- readonly name: string;
5
- detect(sandboxFs: SandboxFS): Promise<boolean>;
6
- appendPromptContext(sandboxFs: SandboxFS, lines: string[]): Promise<void>;
7
- }
8
- /**
9
- * Run the API Agent to produce ActionManifest[] from the project's API layer.
10
- *
11
- * Priority:
12
- * 1. inlineSpecContent — spec passed directly from --api-spec flag (skips all discovery)
13
- * 2. openapi.json / openapi.yaml at known paths
14
- * 3. Filesystem scan of API route handlers
15
- *
16
- * @param hintFiles - Optional pre-selected file paths from the file selector.
17
- * @param inlineSpecContent - Raw spec content passed via --api-spec (bypasses sandbox lookup).
18
- * @param inlineSpecPath - Display path for the inline spec (used in prompt context).
19
- */
20
- export declare function runApiAgent(sandboxFs: SandboxFS, hintFiles?: string[], inlineSpecContent?: string, inlineSpecPath?: string, options?: {
21
- retry?: boolean;
22
- }): Promise<ActionManifest[]>;