dataiku-sdk 0.12.6 → 1.0.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 (55) hide show
  1. package/README.md +60 -14
  2. package/bin/dss.js +1 -1
  3. package/dist/packages/types/src/index.d.ts +128 -3
  4. package/dist/packages/types/src/index.js +106 -3
  5. package/dist/src/cli/coerce.d.ts +2 -1
  6. package/dist/src/cli/coerce.js +84 -26
  7. package/dist/src/cli/commands/app.js +6 -6
  8. package/dist/src/cli/commands/code.js +2 -2
  9. package/dist/src/cli/commands/dashboard.js +102 -13
  10. package/dist/src/cli/commands/data-quality.js +8 -8
  11. package/dist/src/cli/commands/dataset.js +11 -7
  12. package/dist/src/cli/commands/folder.js +5 -4
  13. package/dist/src/cli/commands/future.js +2 -2
  14. package/dist/src/cli/commands/index.js +2 -0
  15. package/dist/src/cli/commands/job.js +11 -11
  16. package/dist/src/cli/commands/notebook.js +1 -1
  17. package/dist/src/cli/commands/project-git.d.ts +2 -0
  18. package/dist/src/cli/commands/project-git.js +563 -0
  19. package/dist/src/cli/commands/project.js +2 -2
  20. package/dist/src/cli/commands/recipe.js +14 -17
  21. package/dist/src/cli/commands/scenario.js +4 -4
  22. package/dist/src/cli/contract.d.ts +5 -4
  23. package/dist/src/cli/contract.js +432 -62
  24. package/dist/src/cli/doctor.js +6 -6
  25. package/dist/src/cli/flags.js +25 -2
  26. package/dist/src/cli/helpers/dataset.js +1 -1
  27. package/dist/src/cli/output.d.ts +2 -1
  28. package/dist/src/cli/output.js +2 -6
  29. package/dist/src/cli/usage.d.ts +1 -1
  30. package/dist/src/cli/usage.js +2 -1
  31. package/dist/src/cli/version.d.ts +2 -2
  32. package/dist/src/cli/version.js +2 -2
  33. package/dist/src/cli.js +43 -26
  34. package/dist/src/client.d.ts +4 -0
  35. package/dist/src/client.js +12 -0
  36. package/dist/src/errors.d.ts +1 -1
  37. package/dist/src/index.d.ts +3 -2
  38. package/dist/src/index.js +2 -1
  39. package/dist/src/resources/connections.d.ts +3 -1
  40. package/dist/src/resources/connections.js +82 -21
  41. package/dist/src/resources/dashboards.d.ts +14 -0
  42. package/dist/src/resources/dashboards.js +156 -4
  43. package/dist/src/resources/datasets.js +42 -2
  44. package/dist/src/resources/folders.js +7 -3
  45. package/dist/src/resources/project-git.d.ts +154 -0
  46. package/dist/src/resources/project-git.js +427 -0
  47. package/dist/src/resources/recipes.js +4 -4
  48. package/dist/src/schemas.d.ts +2 -2
  49. package/dist/src/schemas.js +1 -1
  50. package/dist/src/skill.js +9 -211
  51. package/package.json +7 -4
  52. package/packages/types/dist/index.d.ts +128 -3
  53. package/packages/types/dist/index.js +106 -3
  54. package/plugin.json +15 -0
  55. package/skills/dataiku-dss/SKILL.md +220 -0
@@ -4,7 +4,7 @@ import { validateCredentials, } from "../auth.js";
4
4
  import { getCredentialsPath, saveCredentials, } from "../config.js";
5
5
  import { DataikuError, } from "../errors.js";
6
6
  import { APP_MANIFEST_CONCURRENCY_CONTROL, } from "../resources/applications.js";
7
- import { jobBuildTargetTypeFromFlags, json, jsonInput, num, parseBooleanOption, parseJsonObject, requiredJsonInput, rewritePairsFromFlags, schemaColumnsInput, stringField, textInput, } from "./coerce.js";
7
+ import { jobBuildTargetTypeFromFlags, json, jsonInput, num, parseBooleanOption, parseJsonObject, recipeInputDatasetsFromFlags, requiredJsonInput, rewritePairsFromFlags, schemaColumnsInput, stringField, textInput, } from "./coerce.js";
8
8
  import { commands, } from "./commands/index.js";
9
9
  import { dataikuEnvironmentEnabled, } from "./env.js";
10
10
  import { BOOLEAN_FLAGS, FLAG_ALIASES, KNOWN_LONG_FLAGS, SHORT_FLAGS, } from "./flags.js";
@@ -151,7 +151,64 @@ const PROJECT_SCOPED_RESOURCES = new Set([
151
151
  "saved-model",
152
152
  "wiki",
153
153
  ]);
154
- const GLOBAL_AGENT_FLAGS = ["json", "verbose", "fields",];
154
+ /**
155
+ * Project Git actions that only observe repository state. Everything else in the
156
+ * `project-git` resource is a mutation: the verb-shaped names (`fetch`, `pull`,
157
+ * `switch`, `commit`, `reset-*`, `revert-*`, `drop-and-rebuild`, `future-abort`)
158
+ * match none of the mutating-verb patterns and would otherwise fall through to
159
+ * the read default, advertising network and history writes as safe reads.
160
+ */
161
+ const PROJECT_GIT_READ_ACTIONS = {
162
+ branches: true,
163
+ "current-branch": true,
164
+ diff: true,
165
+ "future-status": true,
166
+ "future-wait": true,
167
+ "get-remote": true,
168
+ "list-libraries": true,
169
+ log: true,
170
+ status: true,
171
+ tags: true,
172
+ };
173
+ /**
174
+ * Git mutations that destroy work rather than add to it: `drop-and-rebuild`
175
+ * discards the repository and rebuilds it from DSS, the resets and reverts throw
176
+ * away local commits or working state, `remove-library` can delete the checked
177
+ * out directory, and the branch/tag deletions can remove remote refs.
178
+ */
179
+ const PROJECT_GIT_DESTRUCTIVE_ACTIONS = {
180
+ "delete-branch": true,
181
+ "delete-tag": true,
182
+ "drop-and-rebuild": true,
183
+ "future-abort": true,
184
+ "remove-library": true,
185
+ "reset-all-libraries": true,
186
+ "reset-library": true,
187
+ "reset-to-head": true,
188
+ "reset-to-upstream": true,
189
+ "revert-commit": true,
190
+ "revert-to-revision": true,
191
+ };
192
+ /** Project Git actions that hand back a DSS future (`{jobId}`) instead of a result. */
193
+ const PROJECT_GIT_FUTURE_ACTIONS = {
194
+ "add-library": true,
195
+ "future-abort": true,
196
+ "future-status": true,
197
+ "future-wait": true,
198
+ "push-all-libraries": true,
199
+ "push-library": true,
200
+ "reset-all-libraries": true,
201
+ "reset-library": true,
202
+ };
203
+ /** Git mutations that converge: replaying them lands on the same repository state. */
204
+ const PROJECT_GIT_CONVERGENT_ACTIONS = {
205
+ fetch: true,
206
+ "reset-all-libraries": true,
207
+ "reset-library": true,
208
+ "reset-to-head": true,
209
+ "reset-to-upstream": true,
210
+ };
211
+ const GLOBAL_AGENT_FLAGS = ["verbose", "fields",];
155
212
  const AUTHENTICATED_AGENT_FLAGS = [
156
213
  "url",
157
214
  "api-key",
@@ -160,19 +217,21 @@ const AUTHENTICATED_AGENT_FLAGS = [
160
217
  "insecure",
161
218
  "ca-cert",
162
219
  ];
163
- export const COMMANDS_USAGE = "dss commands run [--fields PATHS] [--json]";
164
- const COMMANDS_DESCRIPTION = "Print the machine-readable command registry for agent planning; scope it with --fields RESOURCE, RESOURCE.ACTION, or RESOURCE.ACTION.FIELD instead of reading the whole registry.";
220
+ export const COMMANDS_USAGE = "dss commands run [--fields PATHS] [--output PATH]";
221
+ const COMMANDS_DESCRIPTION = "Print a compact resource/action summary by default; use --fields for scoped command metadata or --output PATH to export the full registry without sending it through stdout.";
165
222
  const COMMANDS_EXAMPLES = [
166
- "dss commands run --fields dataset --json",
167
- "dss commands run --fields dataset.create --json",
168
- "dss commands run --fields dataset.create.usage,dataset.create.description,dataset.create.flags,dataset.create.examples --json",
223
+ "dss commands run",
224
+ "dss commands run --fields dataset",
225
+ "dss commands run --fields dataset.create",
226
+ "dss commands run --fields dataset.create.usage,dataset.create.description,dataset.create.flags,dataset.create.examples",
227
+ "dss commands run --output commands.json",
169
228
  ];
170
229
  export const AGENT_CONTRACT_COMMAND = "dss agent contract";
171
- export const AGENT_CONTRACT_USAGE = "dss agent contract [--fields PATHS] [--json]";
230
+ export const AGENT_CONTRACT_USAGE = "dss agent contract [--fields PATHS]";
172
231
  const AGENT_CONTRACT_DESCRIPTION = "Print the versioned JSON agent contract; scope bootstrap fields, use commands.actions to enumerate the surface, and read schemas only when needed.";
173
232
  const AGENT_CONTRACT_EXAMPLES = [
174
- "dss agent contract --fields protocol,agentContractVersion,cli,stdio,planning,compatibility --json",
175
- "dss agent contract --fields commands.actions --json",
233
+ "dss agent contract --fields protocol,agentContractVersion,cli,stdio,planning,compatibility",
234
+ "dss agent contract --fields commands.actions",
176
235
  ];
177
236
  const VERSION_USAGE = "dss version";
178
237
  const VERSION_DESCRIPTION = "Print the CLI version and git revision as JSON.";
@@ -189,11 +248,11 @@ const CLEANUP_EXAMPLES = [
189
248
  "dss cleanup --file cleanup.jsonl",
190
249
  "dss cleanup --file cleanup.jsonl --apply",
191
250
  ];
192
- const FIXTURES_USAGE = "dss fixtures [--json] [--project-key KEY] [--allow-types CSV]";
251
+ const FIXTURES_USAGE = "dss fixtures [--project-key KEY] [--allow-types CSV]";
193
252
  const FIXTURES_DESCRIPTION = "Discover safe live-test fixtures for agent workflows.";
194
253
  const FIXTURES_EXAMPLES = [
195
- "dss fixtures --json",
196
- "dss fixtures --json --allow-types Filesystem,Inline",
254
+ "dss fixtures",
255
+ "dss fixtures --allow-types Filesystem,Inline",
197
256
  ];
198
257
  const ALLOWED_CLEANUP_ACTIONS = new Set([
199
258
  // Must mirror every cleanup.argv shape emitted by cleanupLedgerEntry().
@@ -395,7 +454,7 @@ function shortFlagPattern(flags) {
395
454
  * between `dss` and the first positional. Synthetic single-action commands
396
455
  * whose usage omits their action token (e.g. `dss batch ...`, `dss version`)
397
456
  * use an actionless prefix, while real command paths that spell `run` in their
398
- * usage (e.g. `dss commands run [--json]`) keep the action token.
457
+ * usage (e.g. `dss commands run`) keep the action token.
399
458
  */
400
459
  function argvPrefix(resource, action, usage) {
401
460
  const usageTokens = usage.split(/\s+/).filter((token) => token.length > 0);
@@ -481,18 +540,8 @@ function argvJsonSchema(resource, action, flags, usage, requiredFlags, requiredO
481
540
  },
482
541
  };
483
542
  }
484
- function unsafeOutputs(resource, action, flags, producesLocalFile) {
543
+ function unsafeOutputs(resource, action, producesLocalFile) {
485
544
  const outputs = [];
486
- if (flags.some((flag) => flag.name === "raw")) {
487
- outputs.push({
488
- condition: "--raw without --output",
489
- kind: "raw-stdout",
490
- detail: `${resource} ${action} can intentionally write raw payload bytes/text instead of JSON.`,
491
- safeAlternative: flags.some((flag) => flag.name === "output")
492
- ? "Pass --output PATH so stdout remains a JSON string containing the path."
493
- : "Omit --raw when a JSON stdout value is required.",
494
- });
495
- }
496
545
  if (producesLocalFile) {
497
546
  const sensitivePermissions = resource === "app" && action === "permissions-snapshot";
498
547
  outputs.push({
@@ -519,7 +568,7 @@ export function buildCommandSchemas(resource, action, flags, requiredFlags, requ
519
568
  }
520
569
  const EXPLICIT_REGISTRY_OVERRIDES = {
521
570
  "dashboard.create": {
522
- examplePayload: { pages: [], },
571
+ examplePayload: { name: "Agent dashboard", pages: [], },
523
572
  },
524
573
  "dashboard.update": {
525
574
  examplePayload: { name: "Updated dashboard", },
@@ -583,13 +632,19 @@ function inferSideEffect(resource, action) {
583
632
  }
584
633
  if (resource === "install-skill")
585
634
  return "write";
586
- // `project export` streams an archive over the API and writes it to a local
587
- // path; the DSS-side project is untouched, so it reads remotely and only
588
- // mutates the local filesystem.
589
- if (resource === "project" && action === "export")
635
+ // Project and dashboard exports stream a rendered/archive artifact and write it
636
+ // locally; the DSS-side resource is untouched.
637
+ if ((resource === "project" || resource === "dashboard") && action === "export")
590
638
  return "read";
591
639
  if (resource === "data-quality" && action === "compute")
592
640
  return "write";
641
+ // Project Git is classified from the explicit read table, not by verb shape:
642
+ // `switch`, `fetch`, `pull`, `push`, `commit`, the `reset-*`/`revert-*`
643
+ // families, `drop-and-rebuild`, and `future-abort` all mutate repository or
644
+ // future state yet match none of the mutating-verb patterns.
645
+ if (resource === "project-git") {
646
+ return PROJECT_GIT_READ_ACTIONS[action] === true ? "read" : "write";
647
+ }
593
648
  if (READ_ACTIONS.has(action))
594
649
  return "read";
595
650
  if (/^(create|clone|restore|update|delete|set|save|upload|run|build|abort|move|refresh|clear|unload|install|login|logout|add|remove|publish|activate|deploy|import|export|preload|upgrade|start|stop|restart|duplicate|put|rename|reply|compute|organize)/
@@ -607,13 +662,15 @@ function inferRequiresAuth(resource) {
607
662
  && resource !== "install-skill"
608
663
  && resource !== "version";
609
664
  }
610
- export function inferRequiresProject(resource, _action, usage) {
665
+ export function inferRequiresProject(resource, action, usage) {
611
666
  if (resource === "agent" || resource === "auth" || resource === "doctor" || resource === "commands"
612
667
  || resource === "install-skill" || resource === "version") {
613
668
  return false;
614
669
  }
615
670
  if (PROJECT_SCOPED_RESOURCES.has(resource))
616
671
  return true;
672
+ if (resource === "project-git")
673
+ return !action.startsWith("future-");
617
674
  return usage.includes("--project-key");
618
675
  }
619
676
  const ARRAY_OUTPUT_ACTIONS = new Set([
@@ -640,6 +697,13 @@ const STRING_OUTPUT_ACTIONS = new Set([
640
697
  "log-url",
641
698
  ]);
642
699
  function inferOutputShape(resource, action) {
700
+ if (resource === "project-git") {
701
+ if (action === "branches" || action === "tags" || action === "list-libraries")
702
+ return "array";
703
+ if (action === "set-library")
704
+ return "string";
705
+ return "object";
706
+ }
643
707
  if (resource === "agent" || resource === "auth" || resource === "commands"
644
708
  || resource === "install-skill"
645
709
  || resource === "version") {
@@ -831,9 +895,12 @@ export function supportsCleanupLedger(resource, action) {
831
895
  return cleanupCommandFromDeleteUsage(resource, action) !== undefined
832
896
  || `${resource}.${action}` === "folder.upload";
833
897
  }
834
- function inferDestructiveLevel(sideEffect, action) {
898
+ function inferDestructiveLevel(resource, sideEffect, action) {
835
899
  if (sideEffect !== "write")
836
900
  return "none";
901
+ if (resource === "project-git") {
902
+ return PROJECT_GIT_DESTRUCTIVE_ACTIONS[action] === true ? "destructive" : "reversible";
903
+ }
837
904
  if (/^(delete|abort|clear|unload|logout)/.test(action))
838
905
  return "destructive";
839
906
  return "reversible";
@@ -851,6 +918,10 @@ function inferAsyncKind(resource, action) {
851
918
  }
852
919
  if (resource === "data-quality" && action === "compute")
853
920
  return "future";
921
+ // Project Git mutation results carry a future job id only for the library
922
+ // calls and the future lifecycle itself; plain Git actions settle inline.
923
+ if (resource === "project-git" && PROJECT_GIT_FUTURE_ACTIONS[action] === true)
924
+ return "future";
854
925
  if (resource === "code" && action === "run")
855
926
  return "future";
856
927
  if (resource === "app"
@@ -873,6 +944,11 @@ function inferIdempotency(resource, sideEffect, action, usage) {
873
944
  // error, so replaying the delete cannot fail on absence alone.
874
945
  if (`${resource}.${action}` === "app.delete-instance")
875
946
  return "convergent";
947
+ // Git fetch and the repository resets converge: replaying them lands on the
948
+ // same repository state instead of failing on an already-applied change.
949
+ if (resource === "project-git" && PROJECT_GIT_CONVERGENT_ACTIONS[action] === true) {
950
+ return "convergent";
951
+ }
876
952
  if (/^(clear|refresh|set|save)/.test(action))
877
953
  return "convergent";
878
954
  return "none";
@@ -891,6 +967,10 @@ const LEDGER_ONLY_CLEANUP_KEYS = {
891
967
  };
892
968
  const LEDGER_ONLY_CLEANUP_HINT = "Pass `--record-cleanup PATH` when creating, then recover with `dss cleanup --file PATH --apply`. Do not issue direct instance deletion as cleanup: it bypasses the creation-future gate and can delete the project while DSS is still creating it.";
893
969
  export function inferCleanupHint(resource, action) {
970
+ // Git mutations are not cleanup-ledger operations: no project-git branch or
971
+ // tag create has a generic `delete` command to close it out.
972
+ if (resource === "project-git")
973
+ return undefined;
894
974
  if (!(action.startsWith("create") || action === "clone"))
895
975
  return undefined;
896
976
  if (LEDGER_ONLY_CLEANUP_KEYS[`${resource}.${action}`] === true) {
@@ -915,7 +995,7 @@ function buildRegistryEntry(resource, action, meta) {
915
995
  const requiresAuth = inferRequiresAuth(resource);
916
996
  const requiresProject = inferRequiresProject(resource, action, meta.usage);
917
997
  const sideEffect = inferSideEffect(resource, action);
918
- const destructive = inferDestructiveLevel(sideEffect, action);
998
+ const destructive = inferDestructiveLevel(resource, sideEffect, action);
919
999
  const asyncKind = inferAsyncKind(resource, action);
920
1000
  const mutatesDss = sideEffect === "write" && resource !== "auth" && resource !== "install-skill";
921
1001
  const supportsPlan = mutatesDss || sideEffect === "write";
@@ -981,7 +1061,7 @@ function buildRegistryEntry(resource, action, meta) {
981
1061
  || meta.usage.includes("--output-file PATH");
982
1062
  const uniqueRequiredFlags = uniqueStrings(requiredFlags);
983
1063
  const uniqueOptionalFlags = uniqueStrings(optionalFlags);
984
- const unsafe = unsafeOutputs(resource, action, flagMetadata, producesLocalFile);
1064
+ const unsafe = unsafeOutputs(resource, action, producesLocalFile);
985
1065
  return {
986
1066
  resource,
987
1067
  action,
@@ -1230,7 +1310,7 @@ export function agentContractJsonSchema() {
1230
1310
  },
1231
1311
  };
1232
1312
  }
1233
- function commandActionSummary(registry) {
1313
+ export function commandActionSummary(registry) {
1234
1314
  const summary = {};
1235
1315
  for (const [resource, actions,] of Object.entries(registry)) {
1236
1316
  summary[resource] = Object.keys(actions).sort();
@@ -1245,15 +1325,14 @@ export function buildAgentContract() {
1245
1325
  cli: cliVersionResult(),
1246
1326
  commands: {
1247
1327
  discoveryCommand: "dss commands run",
1248
- scopedDiscoveryCommand: "dss commands run --fields RESOURCE[.ACTION[.FIELD...]] --json",
1249
- actionIndexCommand: "dss agent contract --fields commands.actions --json",
1250
- compactOutputFlag: "--json",
1251
- compactOutputHint: "Pass --json to emit compact single-line JSON and reduce agent context usage.",
1328
+ fullRegistryExportCommand: "dss commands run --output PATH",
1329
+ scopedDiscoveryCommand: "dss commands run --fields RESOURCE[.ACTION[.FIELD...]]",
1330
+ actionIndexCommand: "dss agent contract --fields commands.actions",
1252
1331
  scopedDiscoveryExamples: [
1253
- "dss commands run --fields dataset --json",
1254
- "dss commands run --fields dataset.create --json",
1332
+ "dss commands run --fields dataset",
1333
+ "dss commands run --fields dataset.create",
1255
1334
  ],
1256
- scopedDiscoveryHint: "--fields RESOURCE returns every action of one resource; --fields RESOURCE.ACTION returns a single registry entry keyed by the dotted path; append .FIELD paths to project nested metadata. Comma-separate paths to select several.",
1335
+ scopedDiscoveryHint: "`dss commands run` returns the resource/action summary. --fields RESOURCE returns every action of one resource; --fields RESOURCE.ACTION returns a single registry entry keyed by the dotted path; append .FIELD paths to project nested metadata. Comma-separate paths to select several. Use --output PATH to export the full registry.",
1257
1336
  actions: commandActionSummary(registry),
1258
1337
  },
1259
1338
  schemas: {
@@ -1266,28 +1345,22 @@ export function buildAgentContract() {
1266
1345
  },
1267
1346
  stdio: {
1268
1347
  stdout: {
1348
+ format: "compact-json",
1269
1349
  success: "single-json-value",
1270
- rawEscapeHatches: [
1271
- "recipe get-payload --raw without --output",
1272
- "recipe cat --raw without --output",
1273
- ],
1350
+ failure: "structured-error-object",
1351
+ richFailureResults: "doctor/batch/cleanup nonzero outcomes are their own compact result on stdout ({ok:false,...}) with the command's exit code; not re-wrapped.",
1274
1352
  },
1275
1353
  stderr: {
1276
1354
  format: "jsonl",
1277
- events: ["warning", "trace", "error",],
1278
- error: "single-final-error-event-on-nonzero-exit",
1279
- failureRouting: {
1280
- commandFailure: "doctor/batch/cleanup failures: single JSON stdout; empty stderr",
1281
- dispatchFailure: "usage/unknown/transport/internal failures: empty stdout; single JSON error stderr",
1282
- },
1355
+ events: ["warning", "trace",],
1283
1356
  },
1284
1357
  },
1285
1358
  planning: {
1286
1359
  discoveryCommand: "dss commands run",
1287
1360
  contractCommand: AGENT_CONTRACT_COMMAND,
1288
- bootstrapCommand: "dss agent contract --fields protocol,agentContractVersion,cli,stdio,planning,compatibility --json",
1289
- preferredDiscoveryCommand: "dss commands run --fields RESOURCE.ACTION --json",
1290
- actionIndexCommand: "dss agent contract --fields commands.actions --json",
1361
+ bootstrapCommand: "dss agent contract --fields protocol,agentContractVersion,cli,stdio,planning,compatibility",
1362
+ preferredDiscoveryCommand: "dss commands run --fields RESOURCE.ACTION",
1363
+ actionIndexCommand: "dss agent contract --fields commands.actions",
1291
1364
  mutatingCommandsAdvertisePlan: true,
1292
1365
  },
1293
1366
  compatibility: {
@@ -1376,6 +1449,67 @@ function querySuffix(params) {
1376
1449
  const raw = search.toString();
1377
1450
  return raw ? `?${raw}` : "";
1378
1451
  }
1452
+ /**
1453
+ * Git and future API mount. The official Python client mounts these routes on
1454
+ * `/dip/publicapi`, which is also what the project-git resource uses; do not
1455
+ * normalize them to the repo-wide `/public/api`.
1456
+ */
1457
+ const PROJECT_GIT_API_ROOT = "/dip/publicapi";
1458
+ function projectGitEndpoint(projectKey, suffix) {
1459
+ if (!projectKey)
1460
+ throw new UsageError("--project-key is required for project-git mutations.");
1461
+ return `${PROJECT_GIT_API_ROOT}/projects/${encodeURIComponent(projectKey)}/git${suffix}`;
1462
+ }
1463
+ function projectGitFutureEndpoint(jobId) {
1464
+ return `${PROJECT_GIT_API_ROOT}/futures/${encodeURIComponent(jobId)}`;
1465
+ }
1466
+ /** Encode a library reference path per segment, mirroring the resource helper. */
1467
+ function encodeGitReferencePath(pathValue) {
1468
+ const normalized = pathValue.replace(/^\/+/, "").replace(/\/+$/, "");
1469
+ return normalized.split("/").map((segment) => encodeURIComponent(segment)).join("/");
1470
+ }
1471
+ /**
1472
+ * `--plan` bypasses the SDK boundary guard, so HTTP(S) URLs with embedded
1473
+ * userinfo are rejected here before any plan is printed. SSH/scp-style URLs
1474
+ * (`git@host:org/repo.git`, `ssh://...`) remain valid.
1475
+ */
1476
+ function validatedPlanRepositoryUrl(url, flag, usage) {
1477
+ const candidate = url.trim();
1478
+ if (/[\u0000-\u001f\u007f]/u.test(candidate)) {
1479
+ throw new UsageError(`--${flag} must not contain control characters. Usage: ${usage}`);
1480
+ }
1481
+ if (/^https?:/i.test(candidate)) {
1482
+ if (candidate.includes("\\")) {
1483
+ throw new UsageError(`--${flag} must be a valid HTTP(S) URL. Usage: ${usage}`);
1484
+ }
1485
+ if (!/^https?:\/\//i.test(candidate)) {
1486
+ throw new UsageError(`--${flag} must be a valid HTTP(S) URL. Usage: ${usage}`);
1487
+ }
1488
+ let parsed;
1489
+ try {
1490
+ parsed = new URL(candidate);
1491
+ }
1492
+ catch {
1493
+ throw new UsageError(`--${flag} must be a valid HTTP(S) URL. Usage: ${usage}`);
1494
+ }
1495
+ if (parsed.username !== "" || parsed.password !== "") {
1496
+ throw new UsageError(`--${flag} must not contain embedded credentials (userinfo). Usage: ${usage}`);
1497
+ }
1498
+ }
1499
+ return candidate;
1500
+ }
1501
+ function requiredPlanRepositoryUrl(flags, flag, usage) {
1502
+ const url = requiredPlanFlag(flags, flag, usage);
1503
+ return validatedPlanRepositoryUrl(url, flag, usage);
1504
+ }
1505
+ /** Wait procedure advertised for the library calls that return a job id. */
1506
+ function projectGitFutureWait() {
1507
+ return {
1508
+ when: "after-dispatch",
1509
+ endpoint: `${PROJECT_GIT_API_ROOT}/futures/{jobId}?peek=false`,
1510
+ description: "Poll the returned job id until the future reports a result; never abort it.",
1511
+ };
1512
+ }
1379
1513
  function jobBuildPayload(target, projectKey, flags) {
1380
1514
  const targetType = jobBuildTargetTypeFromFlags(flags);
1381
1515
  const partition = flags["partition"];
@@ -1449,18 +1583,31 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
1449
1583
  identifiers: { article: id, },
1450
1584
  };
1451
1585
  case "dashboard.create": {
1452
- const name = requiredPlanFlag(flags, "name", entry.usage);
1586
+ const data = jsonInput(flags);
1587
+ const flagName = flags["name"];
1588
+ const dataName = data?.["name"];
1589
+ const name = flagName ?? (typeof dataName === "string" ? dataName : undefined);
1590
+ if (!name) {
1591
+ throw new UsageError("--name or dashboard settings containing a string name are required. Usage: dss dashboard create --name NAME");
1592
+ }
1593
+ const listed = parseBooleanOption(flags["listed"], "--listed");
1594
+ const payload = { ...(data ?? { pages: [], }), name, };
1595
+ if (listed !== undefined)
1596
+ payload.listed = listed;
1453
1597
  return {
1454
1598
  method: "POST",
1455
1599
  endpoint: projectEndpoint("/dashboards/"),
1456
1600
  identifiers: { name, },
1457
- payload: { ...(jsonInput(flags) ?? { pages: [], }), name, },
1601
+ payload,
1458
1602
  };
1459
1603
  }
1460
1604
  case "dashboard.update": {
1461
1605
  const payload = { ...jsonInput(flags), };
1462
1606
  if (typeof flags["name"] === "string")
1463
1607
  payload.name = flags["name"];
1608
+ const listed = parseBooleanOption(flags["listed"], "--listed");
1609
+ if (listed !== undefined)
1610
+ payload.listed = listed;
1464
1611
  return {
1465
1612
  method: "PUT",
1466
1613
  endpoint: projectEndpoint(`/dashboards/${encodeURIComponent(id)}/`),
@@ -1597,8 +1744,11 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
1597
1744
  };
1598
1745
  case "dataset.create": {
1599
1746
  const name = requiredPlanFlag(flags, "name", entry.usage);
1600
- const connection = requiredPlanFlag(flags, "connection", entry.usage);
1747
+ const connection = flags["connection"];
1601
1748
  const dsType = requiredPlanFlag(flags, "type", entry.usage);
1749
+ if (!connection && dsType.toLowerCase() !== "uploadedfiles") {
1750
+ throw new UsageError("--connection is required unless --type is UploadedFiles.");
1751
+ }
1602
1752
  return {
1603
1753
  method: "POST",
1604
1754
  endpoint: projectEndpoint("/datasets/"),
@@ -1728,7 +1878,7 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
1728
1878
  payload: {
1729
1879
  type,
1730
1880
  name: flags["name"],
1731
- inputDatasets: flags["input"] ? [flags["input"],] : undefined,
1881
+ inputDatasets: recipeInputDatasetsFromFlags(flags),
1732
1882
  outputDataset,
1733
1883
  outputFolder,
1734
1884
  outputConnection: flags["output-connection"],
@@ -1828,8 +1978,8 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
1828
1978
  };
1829
1979
  case "folder.create": {
1830
1980
  const name = requiredPlanFlag(flags, "name", entry.usage);
1831
- const type = requiredPlanFlag(flags, "type", entry.usage);
1832
- const connection = requiredPlanFlag(flags, "connection", entry.usage);
1981
+ const type = flags["type"];
1982
+ const connection = flags["connection"];
1833
1983
  return {
1834
1984
  method: "POST",
1835
1985
  endpoint: projectEndpoint("/managedfolders/"),
@@ -2643,7 +2793,7 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
2643
2793
  method: "PUT",
2644
2794
  endpoint: projectEndpoint(`/sql-notebooks/${encodeURIComponent(id)}/history`),
2645
2795
  identifiers: { id, cellId: flags["cell-id"], },
2646
- payload: { retain: num(flags["retain"]), },
2796
+ payload: { retain: num(flags["retain"], "--retain"), },
2647
2797
  };
2648
2798
  case "project.create": {
2649
2799
  const settings = jsonInput(flags) ?? null;
@@ -2743,6 +2893,226 @@ export function commandPlanShape(resource, action, args, flags, entry, projectKe
2743
2893
  endpoint: projectEndpoint("/flow/zones"),
2744
2894
  payload: jsonInput(flags),
2745
2895
  };
2896
+ /* ---- project-git: mutations only; reads are never planned ---- */
2897
+ case "project-git.set-remote": {
2898
+ const remote = flags["name"] ?? "origin";
2899
+ return {
2900
+ method: "POST",
2901
+ endpoint: projectGitEndpoint(projectKey, `/remotes/${encodeURIComponent(remote)}`),
2902
+ identifiers: { remote, },
2903
+ payload: { url: requiredPlanRepositoryUrl(flags, "repository", entry.usage), },
2904
+ };
2905
+ }
2906
+ case "project-git.remove-remote": {
2907
+ const remote = flags["name"] ?? "origin";
2908
+ return {
2909
+ method: "DELETE",
2910
+ endpoint: projectGitEndpoint(projectKey, `/remotes/${encodeURIComponent(remote)}`),
2911
+ identifiers: { remote, },
2912
+ };
2913
+ }
2914
+ case "project-git.create-branch":
2915
+ return {
2916
+ method: "POST",
2917
+ endpoint: projectGitEndpoint(projectKey, "/branches/"),
2918
+ identifiers: { name: id, },
2919
+ payload: {
2920
+ name: id,
2921
+ commit: flags["commit"] ?? null,
2922
+ duplicateProject: parseBooleanOption(flags["duplicate-project"], "--duplicate-project") ?? false,
2923
+ targetProjectKey: flags["target-project-key"] ?? null,
2924
+ targetProjectFolderId: flags["target-project-folder-id"] ?? null,
2925
+ },
2926
+ };
2927
+ case "project-git.delete-branch": {
2928
+ const remote = parseBooleanOption(flags["remote"], "--remote") ?? false;
2929
+ return {
2930
+ method: "POST",
2931
+ endpoint: projectGitEndpoint(projectKey, "/actions/deleteBranch"),
2932
+ identifiers: { name: id, remote, },
2933
+ payload: {
2934
+ name: id,
2935
+ remote,
2936
+ deleteRemotely: parseBooleanOption(flags["delete-remotely"], "--delete-remotely") ?? false,
2937
+ forceDelete: parseBooleanOption(flags["force-delete"], "--force-delete") ?? false,
2938
+ },
2939
+ };
2940
+ }
2941
+ case "project-git.switch":
2942
+ return {
2943
+ method: "POST",
2944
+ endpoint: projectGitEndpoint(projectKey, `/actions/switchBranch${querySuffix({ branchName: id, })}`),
2945
+ identifiers: { branch: id, },
2946
+ };
2947
+ case "project-git.create-tag":
2948
+ return {
2949
+ method: "POST",
2950
+ endpoint: projectGitEndpoint(projectKey, "/tags/"),
2951
+ identifiers: { name: id, },
2952
+ payload: {
2953
+ name: id,
2954
+ reference: flags["reference"] ?? "HEAD",
2955
+ message: flags["message"] ?? "",
2956
+ },
2957
+ };
2958
+ case "project-git.delete-tag":
2959
+ return {
2960
+ method: "POST",
2961
+ endpoint: projectGitEndpoint(projectKey, "/actions/deleteTag"),
2962
+ identifiers: { name: id, },
2963
+ payload: { name: id, },
2964
+ };
2965
+ case "project-git.fetch":
2966
+ return {
2967
+ method: "POST",
2968
+ endpoint: projectGitEndpoint(projectKey, "/actions/fetch"),
2969
+ };
2970
+ case "project-git.pull":
2971
+ return {
2972
+ method: "POST",
2973
+ endpoint: projectGitEndpoint(projectKey, `/actions/pullRebase${querySuffix({
2974
+ branchName: flags["branch"],
2975
+ })}`),
2976
+ ...(flags["branch"] !== undefined
2977
+ ? { identifiers: { branch: flags["branch"], }, }
2978
+ : {}),
2979
+ };
2980
+ case "project-git.push":
2981
+ return {
2982
+ method: "POST",
2983
+ endpoint: projectGitEndpoint(projectKey, `/actions/push${querySuffix({
2984
+ branchName: flags["branch"],
2985
+ })}`),
2986
+ ...(flags["branch"] !== undefined
2987
+ ? { identifiers: { branch: flags["branch"], }, }
2988
+ : {}),
2989
+ };
2990
+ case "project-git.commit": {
2991
+ const message = requiredPlanFlag(flags, "message", entry.usage);
2992
+ return {
2993
+ method: "POST",
2994
+ endpoint: projectGitEndpoint(projectKey, "/actions/commit"),
2995
+ identifiers: { message, },
2996
+ payload: { message, },
2997
+ };
2998
+ }
2999
+ case "project-git.revert-to-revision":
3000
+ return {
3001
+ method: "POST",
3002
+ endpoint: projectGitEndpoint(projectKey, `/actions/revertToRevision${querySuffix({ commit: id, })}`),
3003
+ identifiers: { commit: id, },
3004
+ };
3005
+ case "project-git.revert-commit":
3006
+ return {
3007
+ method: "POST",
3008
+ endpoint: projectGitEndpoint(projectKey, `/actions/revertCommit${querySuffix({ commit: id, })}`),
3009
+ identifiers: { commit: id, },
3010
+ };
3011
+ case "project-git.reset-to-head":
3012
+ return {
3013
+ method: "POST",
3014
+ endpoint: projectGitEndpoint(projectKey, "/actions/resetToLocalHeadState"),
3015
+ };
3016
+ case "project-git.reset-to-upstream":
3017
+ return {
3018
+ method: "POST",
3019
+ endpoint: projectGitEndpoint(projectKey, "/actions/resetToRemoteHeadState"),
3020
+ };
3021
+ case "project-git.drop-and-rebuild": {
3022
+ if (parseBooleanOption(flags["i-know-what-i-am-doing"], "--i-know-what-i-am-doing") !== true) {
3023
+ throw new UsageError(`--i-know-what-i-am-doing is required to acknowledge the irreversible Git history loss. Usage: ${entry.usage}`);
3024
+ }
3025
+ return {
3026
+ method: "POST",
3027
+ endpoint: projectGitEndpoint(projectKey, `/actions/dropAndRebuild${querySuffix({ iKnowWhatIAmDoing: true, })}`),
3028
+ };
3029
+ }
3030
+ case "project-git.add-library": {
3031
+ const targetPath = id;
3032
+ return {
3033
+ method: "POST",
3034
+ endpoint: projectGitEndpoint(projectKey, "/lib-git-refs/"),
3035
+ identifiers: { localTargetPath: targetPath, },
3036
+ payload: {
3037
+ repository: requiredPlanRepositoryUrl(flags, "repository", entry.usage),
3038
+ login: flags["login"] ?? null,
3039
+ password: flags["password-env"] !== undefined ? "***" : null,
3040
+ pathInGitRepository: flags["path-in-repository"] ?? "",
3041
+ localTargetPath: targetPath,
3042
+ checkout: requiredPlanFlag(flags, "checkout", entry.usage),
3043
+ addToPythonPath: parseBooleanOption(flags["no-add-to-python-path"], "--no-add-to-python-path") !== true,
3044
+ },
3045
+ wait: projectGitFutureWait(),
3046
+ };
3047
+ }
3048
+ case "project-git.set-library": {
3049
+ const targetPath = id;
3050
+ return {
3051
+ method: "PUT",
3052
+ endpoint: projectGitEndpoint(projectKey, `/lib-git-refs/${encodeGitReferencePath(targetPath)}`),
3053
+ identifiers: { library: targetPath, },
3054
+ payload: {
3055
+ repository: requiredPlanRepositoryUrl(flags, "repository", entry.usage),
3056
+ login: flags["login"] ?? null,
3057
+ password: flags["password-env"] !== undefined ? "***" : null,
3058
+ pathInGitRepository: flags["path-in-repository"] ?? "",
3059
+ checkout: requiredPlanFlag(flags, "checkout", entry.usage),
3060
+ },
3061
+ };
3062
+ }
3063
+ case "project-git.remove-library": {
3064
+ const targetPath = id;
3065
+ return {
3066
+ method: "DELETE",
3067
+ endpoint: projectGitEndpoint(projectKey, `/lib-git-refs/${encodeGitReferencePath(targetPath)}${querySuffix({
3068
+ deleteDirectory: parseBooleanOption(flags["delete-directory"], "--delete-directory") ?? false,
3069
+ })}`),
3070
+ identifiers: { library: targetPath, },
3071
+ };
3072
+ }
3073
+ case "project-git.reset-library": {
3074
+ const targetPath = id;
3075
+ return {
3076
+ method: "POST",
3077
+ endpoint: projectGitEndpoint(projectKey, "/lib-git-refs/action/reset"),
3078
+ identifiers: { library: targetPath, },
3079
+ payload: { gitRef: targetPath, },
3080
+ wait: projectGitFutureWait(),
3081
+ };
3082
+ }
3083
+ case "project-git.push-library": {
3084
+ const targetPath = id;
3085
+ const message = requiredPlanFlag(flags, "message", entry.usage);
3086
+ return {
3087
+ method: "POST",
3088
+ endpoint: projectGitEndpoint(projectKey, "/lib-git-refs/action/push"),
3089
+ identifiers: { library: targetPath, message, },
3090
+ payload: { gitRef: targetPath, commitMessage: message, },
3091
+ wait: projectGitFutureWait(),
3092
+ };
3093
+ }
3094
+ case "project-git.push-all-libraries": {
3095
+ const message = requiredPlanFlag(flags, "message", entry.usage);
3096
+ return {
3097
+ method: "POST",
3098
+ endpoint: projectGitEndpoint(projectKey, "/actions/git-refs/push-all"),
3099
+ identifiers: { message, },
3100
+ payload: { commitMessage: message, },
3101
+ wait: projectGitFutureWait(),
3102
+ };
3103
+ }
3104
+ case "project-git.reset-all-libraries":
3105
+ return {
3106
+ method: "POST",
3107
+ endpoint: projectGitEndpoint(projectKey, "/actions/git-refs/reset-all"),
3108
+ wait: projectGitFutureWait(),
3109
+ };
3110
+ case "project-git.future-abort":
3111
+ return {
3112
+ method: "DELETE",
3113
+ endpoint: projectGitFutureEndpoint(id),
3114
+ identifiers: { jobId: id, },
3115
+ };
2746
3116
  default:
2747
3117
  return {
2748
3118
  method: action.startsWith("delete") || action === "abort" ? "DELETE" : "POST",