@alva-ai/toolkit 0.24.0 → 0.25.1

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/dist/dispatch.js CHANGED
@@ -2909,11 +2909,11 @@ function parseSelector(subselects, selector, selectorIndex) {
2909
2909
  ensureNotTraversal();
2910
2910
  tokens.push({ type });
2911
2911
  }
2912
- function addSpecialAttribute(name, action) {
2912
+ function addSpecialAttribute(name, action2) {
2913
2913
  tokens.push({
2914
2914
  type: SelectorType.Attribute,
2915
2915
  name,
2916
- action,
2916
+ action: action2,
2917
2917
  value: getName(1),
2918
2918
  namespace: null,
2919
2919
  ignoreCase: "quirks"
@@ -2995,21 +2995,21 @@ function parseSelector(subselects, selector, selectorIndex) {
2995
2995
  }
2996
2996
  }
2997
2997
  stripWhitespace(0);
2998
- let action = AttributeAction.Exists;
2998
+ let action2 = AttributeAction.Exists;
2999
2999
  const possibleAction = actionTypes.get(selector.charCodeAt(selectorIndex));
3000
3000
  if (possibleAction) {
3001
- action = possibleAction;
3001
+ action2 = possibleAction;
3002
3002
  if (selector.charCodeAt(selectorIndex + 1) !== 61) {
3003
3003
  throw new Error("Expected `=`");
3004
3004
  }
3005
3005
  stripWhitespace(2);
3006
3006
  } else if (selector.charCodeAt(selectorIndex) === 61) {
3007
- action = AttributeAction.Equals;
3007
+ action2 = AttributeAction.Equals;
3008
3008
  stripWhitespace(1);
3009
3009
  }
3010
3010
  let value = "";
3011
3011
  let ignoreCase = null;
3012
- if (action !== "exists") {
3012
+ if (action2 !== "exists") {
3013
3013
  if (isQuote(selector.charCodeAt(selectorIndex))) {
3014
3014
  const quote = selector.charCodeAt(selectorIndex);
3015
3015
  let sectionEnd = selectorIndex + 1;
@@ -3045,7 +3045,7 @@ function parseSelector(subselects, selector, selectorIndex) {
3045
3045
  const attributeSelector = {
3046
3046
  type: SelectorType.Attribute,
3047
3047
  name,
3048
- action,
3048
+ action: action2,
3049
3049
  value,
3050
3050
  namespace,
3051
3051
  ignoreCase
@@ -3210,8 +3210,8 @@ function stringifyToken(token, index, arr) {
3210
3210
  }
3211
3211
  }
3212
3212
  }
3213
- function getActionValue(action) {
3214
- switch (action) {
3213
+ function getActionValue(action2) {
3214
+ switch (action2) {
3215
3215
  case AttributeAction.Equals:
3216
3216
  return "";
3217
3217
  case AttributeAction.Element:
@@ -5953,8 +5953,8 @@ var CliUsageError = class extends Error {
5953
5953
  }
5954
5954
  };
5955
5955
 
5956
- // src/cli/commandDefinitions.ts
5957
- function command(path, {
5956
+ // src/cli/embeddedCommandDefinitions.ts
5957
+ function embeddedCommand(path, {
5958
5958
  values = [],
5959
5959
  booleans = [],
5960
5960
  positionals = [],
@@ -5962,12 +5962,12 @@ function command(path, {
5962
5962
  passthrough = false
5963
5963
  } = {}) {
5964
5964
  const flags = {};
5965
- for (const name of values) {
5966
- flags[name] = "value";
5967
- }
5965
+ for (const name of values) flags[name] = "value";
5968
5966
  for (const name of booleans) {
5969
5967
  if (flags[name] !== void 0) {
5970
- throw new Error(`CLI flag --${name} has conflicting definitions`);
5968
+ throw new Error(
5969
+ `Embedded CLI flag --${name} has conflicting definitions`
5970
+ );
5971
5971
  }
5972
5972
  flags[name] = "boolean";
5973
5973
  }
@@ -5982,53 +5982,79 @@ function command(path, {
5982
5982
  passthrough
5983
5983
  };
5984
5984
  }
5985
- var GLOBAL_FLAG_DEFINITIONS = {
5986
- "api-key": "value",
5987
- "base-url": "value",
5988
- profile: "value",
5989
- "arrays-endpoint": "value",
5990
- help: "boolean"
5991
- };
5992
- var COMMAND_DEFINITIONS = [
5993
- command("configure", {
5994
- values: ["api-key", "base-url", "profile"]
5985
+ function route(path, target, options = {}) {
5986
+ return {
5987
+ ...embeddedCommand(path, options),
5988
+ targetPath: target.split(" ")
5989
+ };
5990
+ }
5991
+ function action(path, options, actionName) {
5992
+ return { ...embeddedCommand(path, options), action: actionName };
5993
+ }
5994
+ var EMBEDDED_COMMAND_DEFINITIONS = [
5995
+ route("account whoami", "whoami"),
5996
+ route("account credits wallet", "credits wallet"),
5997
+ route("account credits items", "credits items", {
5998
+ values: ["last", "start", "end", "session-id", "first", "after"],
5999
+ booleans: ["today"]
5995
6000
  }),
5996
- // Some route-map nodes are also valid help targets. Their handlers preserve
5997
- // the existing bare-command help behavior while the trie still resolves
5998
- // deeper leaves.
5999
- command("auth"),
6000
- command("auth login", {
6001
- values: ["profile", "auth-url", "base-url"],
6002
- booleans: ["browser", "no-browser"]
6001
+ route("account secrets create", "secrets create", {
6002
+ values: ["name", "value"]
6003
6003
  }),
6004
- command("whoami"),
6005
- command("user me"),
6006
- command("fs read", { values: ["path", "offset", "size"] }),
6007
- command("fs write", {
6008
- values: ["path", "data", "file"],
6004
+ route("account secrets list", "secrets list"),
6005
+ route("account secrets get", "secrets get", { values: ["name"] }),
6006
+ route("account secrets update", "secrets update", {
6007
+ values: ["name", "value"]
6008
+ }),
6009
+ route("account secrets delete", "secrets delete", { values: ["name"] }),
6010
+ route("account notifications preferences", "notification-preferences list"),
6011
+ action(
6012
+ "account notifications set-preference",
6013
+ { values: ["session-completed"] },
6014
+ "notification-set-preference"
6015
+ ),
6016
+ route("account service-accounts create", "service-account create", {
6017
+ values: ["name"]
6018
+ }),
6019
+ route("account service-accounts list", "service-account list"),
6020
+ route("account service-accounts delete", "service-account delete", {
6021
+ values: ["id"]
6022
+ }),
6023
+ route("account service-accounts grant", "service-account grant", {
6024
+ values: ["id", "path", "permission"]
6025
+ }),
6026
+ route("account service-accounts revoke", "service-account revoke", {
6027
+ values: ["id", "path", "permission"]
6028
+ }),
6029
+ route("fs read", "fs read", { values: ["path", "offset", "size"] }),
6030
+ route("fs write", "fs write", {
6031
+ values: ["path", "data"],
6009
6032
  booleans: ["mkdir-parents", "append"]
6010
6033
  }),
6011
- command("fs stat", { values: ["path"] }),
6012
- command("fs readdir", {
6034
+ route("fs stat", "fs stat", { values: ["path"] }),
6035
+ route("fs readdir", "fs readdir", {
6013
6036
  values: ["path"],
6014
6037
  booleans: ["recursive"]
6015
6038
  }),
6016
- command("fs mkdir", { values: ["path"] }),
6017
- command("fs remove", {
6039
+ route("fs mkdir", "fs mkdir", { values: ["path"] }),
6040
+ route("fs remove", "fs remove", {
6018
6041
  values: ["path"],
6019
6042
  booleans: ["recursive"]
6020
6043
  }),
6021
- command("fs rename", { values: ["old-path", "new-path"] }),
6022
- command("fs copy", { values: ["src-path", "dst-path"] }),
6023
- command("fs symlink", { values: ["target-path", "link-path"] }),
6024
- command("fs readlink", { values: ["path"] }),
6025
- command("fs chmod", { values: ["path", "mode"] }),
6026
- command("fs grant", { values: ["path", "subject", "permission"] }),
6027
- command("fs revoke", { values: ["path", "subject", "permission"] }),
6028
- command("run", {
6044
+ route("fs rename", "fs rename", { values: ["old-path", "new-path"] }),
6045
+ route("fs copy", "fs copy", { values: ["src-path", "dst-path"] }),
6046
+ route("fs symlink", "fs symlink", { values: ["target-path", "link-path"] }),
6047
+ route("fs readlink", "fs readlink", { values: ["path"] }),
6048
+ route("fs chmod", "fs chmod", { values: ["path", "mode"] }),
6049
+ route("fs grant", "fs grant", {
6050
+ values: ["path", "subject", "permission"]
6051
+ }),
6052
+ route("fs revoke", "fs revoke", {
6053
+ values: ["path", "subject", "permission"]
6054
+ }),
6055
+ route("run", "run", {
6029
6056
  values: [
6030
6057
  "code",
6031
- "local-file",
6032
6058
  "entry-path",
6033
6059
  "working-dir",
6034
6060
  "args",
@@ -6036,170 +6062,133 @@ var COMMAND_DEFINITIONS = [
6036
6062
  "timeout-ms"
6037
6063
  ]
6038
6064
  }),
6039
- command("deploy create", {
6040
- values: [
6041
- "name",
6042
- "path",
6043
- "cron",
6044
- "args",
6045
- "max-heap-size-mb",
6046
- "execution-timeout-seconds",
6047
- "run-as-service-account"
6048
- ],
6049
- booleans: ["push-notify"]
6065
+ route("data-skills list", "data-skills list", { booleans: ["json"] }),
6066
+ route("data-skills summary", "data-skills summary", {
6067
+ booleans: ["json"],
6068
+ positionals: ["skill name"]
6050
6069
  }),
6051
- command("deploy list", { values: ["limit", "cursor"] }),
6052
- command("deploy get", { values: ["id"] }),
6053
- command("deploy update", {
6054
- values: [
6055
- "id",
6056
- "name",
6057
- "cron",
6058
- "args",
6059
- "max-heap-size-mb",
6060
- "execution-timeout-seconds",
6061
- "run-as-service-account"
6062
- ],
6063
- booleans: ["push-notify", "clear-run-as"]
6070
+ route("data-skills endpoint", "data-skills endpoint", {
6071
+ booleans: ["json"],
6072
+ positionals: ["skill name", "endpoint file"]
6064
6073
  }),
6065
- command("deploy delete", { values: ["id"] }),
6066
- command("deploy pause", { values: ["id"] }),
6067
- command("deploy resume", { values: ["id"] }),
6068
- command("deploy trigger", { values: ["id"] }),
6069
- command("deploy runs", { values: ["id", "first", "cursor"] }),
6070
- command("deploy run-status", {
6071
- values: ["id", "workflow-run-id"]
6074
+ route("skillhub list", "skillhub list", {
6075
+ values: ["tag", "username"],
6076
+ booleans: ["json"]
6072
6077
  }),
6073
- command("deploy run-logs", { values: ["id", "run-id"] }),
6074
- command("loop create", {
6075
- values: [
6076
- "goal",
6077
- "cron",
6078
- "channel-id",
6079
- "start",
6080
- "until",
6081
- "runs",
6082
- "name",
6083
- // Retained so the handler can emit the existing migration guidance.
6084
- "expires-in"
6085
- ]
6078
+ route("skillhub tags", "skillhub tags", { booleans: ["json"] }),
6079
+ route("skillhub get", "skillhub get", {
6080
+ booleans: ["json"],
6081
+ positionals: ["playbook skill identifier"]
6086
6082
  }),
6087
- command("service-account create", { values: ["name"] }),
6088
- command("service-account list"),
6089
- command("service-account delete", { values: ["id"] }),
6090
- command("service-account grant", {
6091
- values: ["id", "path", "permission"]
6083
+ route("skillhub file", "skillhub file", {
6084
+ booleans: ["json"],
6085
+ positionals: ["playbook skill identifier", "file path"]
6092
6086
  }),
6093
- command("service-account revoke", {
6094
- values: ["id", "path", "permission"]
6087
+ route("markets narrative", "markets narrative", { values: ["ticker"] }),
6088
+ route("markets earnings", "markets earnings", {
6089
+ values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
6095
6090
  }),
6096
- command("feed list", { values: ["limit", "cursor", "status"] }),
6097
- command("feed stop", { values: ["id"] }),
6098
- command("feed resume", { values: ["id"] }),
6099
- command("feed delete", { values: ["id"] }),
6100
- command("feed set-visibility", { values: ["id", "visibility"] }),
6101
- command("automation list", {
6091
+ action(
6092
+ "automation create",
6093
+ {
6094
+ values: [
6095
+ "name",
6096
+ "path",
6097
+ "cron",
6098
+ "version",
6099
+ "args",
6100
+ "view-json",
6101
+ "description",
6102
+ "changelog",
6103
+ "agent-type",
6104
+ "max-heap-size-mb",
6105
+ "execution-timeout-seconds",
6106
+ "run-as-service-account"
6107
+ ],
6108
+ booleans: ["push-notify", "skip-auto-trigger"]
6109
+ },
6110
+ "automation-create"
6111
+ ),
6112
+ route("automation list", "automation list", {
6102
6113
  values: ["limit", "cursor", "status"],
6103
6114
  booleans: ["json"]
6104
6115
  }),
6105
- command("automation inspect", {
6106
- values: ["id"],
6107
- booleans: ["json"]
6108
- }),
6109
- command("automation publish", {
6110
- values: [
6111
- "name",
6112
- "version",
6113
- "cronjob-id",
6114
- "view-json",
6115
- "description",
6116
- "changelog",
6117
- "agent-type"
6118
- ],
6119
- booleans: ["skip-auto-trigger"]
6120
- }),
6121
- command("automation update", {
6122
- values: [
6123
- "id",
6124
- "version",
6125
- "cronjob-id",
6126
- "description",
6127
- "changelog",
6128
- "agent-type"
6129
- ],
6130
- booleans: ["trigger"]
6116
+ action(
6117
+ "automation inspect",
6118
+ { values: ["id"], booleans: ["json"] },
6119
+ "automation-inspect"
6120
+ ),
6121
+ action(
6122
+ "automation update",
6123
+ {
6124
+ values: [
6125
+ "id",
6126
+ "name",
6127
+ "cron",
6128
+ "version",
6129
+ "args",
6130
+ "description",
6131
+ "changelog",
6132
+ "agent-type",
6133
+ "max-heap-size-mb",
6134
+ "execution-timeout-seconds",
6135
+ "run-as-service-account"
6136
+ ],
6137
+ booleans: ["push-notify", "clear-run-as"]
6138
+ },
6139
+ "automation-update"
6140
+ ),
6141
+ route("automation delivery get", "automation delivery get", {
6142
+ values: ["id"]
6131
6143
  }),
6132
- command("automation delivery"),
6133
- command("automation delivery get", { values: ["id"] }),
6134
- command("automation delivery update", {
6144
+ route("automation delivery update", "automation delivery update", {
6135
6145
  values: ["id", "alva-channel-ids"],
6136
6146
  booleans: ["email-enabled"]
6137
6147
  }),
6138
- command("automation stop", { values: ["id"] }),
6139
- command("automation resume", { values: ["id"] }),
6140
- command("automation delete", { values: ["id"] }),
6141
- command("credits wallet"),
6142
- command("credits items", {
6143
- values: ["last", "start", "end", "session-id", "first", "after"],
6144
- booleans: ["today"]
6145
- }),
6146
- command("playbooks trending", {
6148
+ action("automation delete", { values: ["id"] }, "automation-delete"),
6149
+ action("automation pause", { values: ["id"] }, "automation-pause"),
6150
+ action("automation resume", { values: ["id"] }, "automation-resume"),
6151
+ action("automation trigger", { values: ["id"] }, "automation-trigger"),
6152
+ action(
6153
+ "automation set-visibility",
6154
+ { values: ["id", "visibility"] },
6155
+ "automation-set-visibility"
6156
+ ),
6157
+ action(
6158
+ "automation runs list",
6159
+ { values: ["id", "first", "cursor"] },
6160
+ "automation-runs-list"
6161
+ ),
6162
+ action(
6163
+ "automation runs status",
6164
+ { values: ["id", "workflow-run-id"] },
6165
+ "automation-runs-status"
6166
+ ),
6167
+ action(
6168
+ "automation runs logs",
6169
+ { values: ["id", "run-id"] },
6170
+ "automation-runs-logs"
6171
+ ),
6172
+ route("playbooks trending", "playbooks trending", {
6147
6173
  values: ["keyword", "tags", "tag", "sort", "limit", "cursor", "current"],
6148
6174
  booleans: ["json"]
6149
6175
  }),
6150
- command("playbooks set-visibility", {
6151
- values: ["name", "visibility"]
6152
- }),
6153
- command("playbooks get", {
6154
- values: ["ids", "id", "ref"],
6155
- booleans: ["json"]
6156
- }),
6157
- command("playbooks list", {
6176
+ route("playbooks list", "playbooks list", {
6158
6177
  values: ["owner", "limit", "cursor"],
6159
6178
  booleans: ["json", "all"]
6160
6179
  }),
6161
- command("playbooks mine", {
6180
+ route("playbooks mine", "playbooks mine", {
6162
6181
  values: ["filter", "limit", "cursor"],
6163
6182
  booleans: ["json", "all"]
6164
6183
  }),
6165
- command("functions allowance"),
6166
- command("functions allowance get", { values: ["playbook-id"] }),
6167
- command("functions allowance list"),
6168
- command("functions allowance create", {
6169
- values: ["playbook-id", "amount"]
6170
- }),
6171
- command("functions allowance revoke", { values: ["playbook-id"] }),
6172
- command("functions register", {
6173
- values: [
6174
- "playbook-id",
6175
- "function-name",
6176
- "entry-script-path",
6177
- "params-schema",
6178
- "params-schema-file",
6179
- "run-as-service-account"
6180
- ],
6181
- booleans: ["allow-charges", "clear-run-as"]
6182
- }),
6183
- command("functions list", { values: ["playbook-id"] }),
6184
- command("functions delete", {
6185
- values: ["playbook-id", "function-name"]
6186
- }),
6187
- command("functions invoke", {
6188
- values: ["playbook-id", "function-name", "params"]
6184
+ route("playbooks get", "playbooks get", {
6185
+ values: ["ids", "id", "ref"],
6186
+ booleans: ["json"]
6189
6187
  }),
6190
- command("release feed", {
6191
- values: [
6192
- "name",
6193
- "version",
6194
- "cronjob-id",
6195
- "view-json",
6196
- "description",
6197
- "changelog",
6198
- "agent-type"
6199
- ],
6200
- booleans: ["skip-auto-trigger"]
6188
+ route("playbooks set-visibility", "playbooks set-visibility", {
6189
+ values: ["name", "visibility"]
6201
6190
  }),
6202
- command("release playbook-draft", {
6191
+ route("playbooks draft", "release playbook-draft", {
6203
6192
  values: [
6204
6193
  "name",
6205
6194
  "display-name",
@@ -6210,209 +6199,338 @@ var COMMAND_DEFINITIONS = [
6210
6199
  "tags"
6211
6200
  ]
6212
6201
  }),
6213
- command("release playbook", {
6202
+ route("playbooks release", "release playbook", {
6214
6203
  values: ["name", "version", "feeds", "changelog", "readme-url"],
6215
6204
  booleans: ["bypass-lint"]
6216
6205
  }),
6217
- command("lint playbook", {
6206
+ route("playbooks lint", "lint playbook", {
6218
6207
  values: ["format"],
6219
6208
  positionals: ["file argument"]
6220
6209
  }),
6221
- command("secrets create", { values: ["name", "value"] }),
6222
- command("secrets list"),
6223
- command("secrets get", { values: ["name"] }),
6224
- command("secrets update", { values: ["name", "value"] }),
6225
- command("secrets delete", { values: ["name"] }),
6226
- command("sdk doc", { values: ["name"] }),
6227
- command("sdk partitions"),
6228
- command("sdk partition-summary", { values: ["partition"] }),
6229
- command("data-skills list", { booleans: ["json"] }),
6230
- command("data-skills summary", {
6231
- booleans: ["json"],
6232
- positionals: ["skill name"]
6210
+ action(
6211
+ "playbooks screenshot",
6212
+ {
6213
+ values: [
6214
+ "url",
6215
+ "selector",
6216
+ "xpath",
6217
+ "compress-quality",
6218
+ "compress-max-width"
6219
+ ],
6220
+ booleans: ["full", "compress"]
6221
+ },
6222
+ "screenshot"
6223
+ ),
6224
+ route("playbooks remix", "remix", {
6225
+ values: ["child-username", "child-name", "parents"]
6233
6226
  }),
6234
- command("data-skills endpoint", {
6235
- booleans: ["json"],
6236
- positionals: ["skill name", "endpoint file"]
6227
+ route("playbooks comments create", "comments create", {
6228
+ values: ["username", "name", "content", "parent-id"]
6237
6229
  }),
6238
- command("skillhub list", {
6239
- values: ["tag", "username"],
6240
- booleans: ["json"]
6230
+ route("playbooks comments pin", "comments pin", { values: ["comment-id"] }),
6231
+ route("playbooks comments unpin", "comments unpin", {
6232
+ values: ["comment-id"]
6241
6233
  }),
6242
- command("skillhub tags", { booleans: ["json"] }),
6243
- command("skillhub get", {
6244
- booleans: ["json"],
6245
- positionals: ["playbook skill identifier"]
6234
+ route("playbooks follows list", "subscriptions follows", {
6235
+ values: ["limit", "cursor"]
6246
6236
  }),
6247
- command("skillhub file", {
6248
- booleans: ["json"],
6249
- positionals: ["playbook skill identifier", "file path"]
6237
+ route("playbooks follows follow", "subscriptions follow-playbook", {
6238
+ values: ["username", "name"]
6250
6239
  }),
6251
- command("comments create", {
6252
- values: ["username", "name", "content", "parent-id"]
6240
+ route("playbooks follows unfollow", "subscriptions unfollow-playbook", {
6241
+ values: ["username", "name"]
6253
6242
  }),
6254
- command("comments pin", { values: ["comment-id"] }),
6255
- command("comments unpin", { values: ["comment-id"] }),
6256
- command("notification-history list-feed", {
6243
+ route("playbooks functions allowance", "functions allowance"),
6244
+ route("playbooks functions allowance get", "functions allowance get", {
6245
+ values: ["playbook-id"]
6246
+ }),
6247
+ route("playbooks functions allowance list", "functions allowance list"),
6248
+ route(
6249
+ "playbooks functions allowance create",
6250
+ "functions allowance create",
6251
+ { values: ["playbook-id", "amount"] }
6252
+ ),
6253
+ route(
6254
+ "playbooks functions allowance revoke",
6255
+ "functions allowance revoke",
6256
+ { values: ["playbook-id"] }
6257
+ ),
6258
+ route("playbooks functions register", "functions register", {
6257
6259
  values: [
6258
- "username",
6259
- "name",
6260
- "delivery-provider",
6261
- // Retained so the handler can emit the existing rename guidance.
6262
- "channel",
6263
- "status",
6264
- "since",
6265
- "first",
6266
- "cursor"
6267
- ]
6268
- }),
6269
- command("notification-preferences list"),
6270
- command("notification-preferences enable-session-completed"),
6271
- command("notification-preferences disable-session-completed"),
6272
- command("feedback submit", {
6273
- values: [
6274
- "source",
6275
- "category",
6276
- "severity",
6277
- "summary",
6278
- "details",
6279
- "evidence-json",
6280
- "context-json",
6281
- // Retained so the handler can emit the existing migration guidance.
6282
- "dedupe-key"
6283
- ]
6284
- }),
6285
- command("subscriptions follow-playbook", {
6286
- values: ["username", "name"]
6287
- }),
6288
- command("subscriptions unfollow-playbook", {
6289
- values: ["username", "name"]
6290
- }),
6291
- command("subscriptions subscribe-feed", {
6292
- values: ["username", "name"]
6260
+ "playbook-id",
6261
+ "function-name",
6262
+ "entry-script-path",
6263
+ "params-schema",
6264
+ "run-as-service-account"
6265
+ ],
6266
+ booleans: ["allow-charges", "clear-run-as"]
6293
6267
  }),
6294
- command("subscriptions unsubscribe-feed", {
6295
- values: ["username", "name"]
6268
+ route("playbooks functions list", "functions list", {
6269
+ values: ["playbook-id"]
6296
6270
  }),
6297
- command("subscriptions list", { values: ["first", "cursor"] }),
6298
- command("subscriptions follows", { values: ["limit", "cursor"] }),
6299
- command("subscriptions subscribe", {
6300
- values: ["feed-ids", "channel-id", "playbook-ids"]
6271
+ route("playbooks functions delete", "functions delete", {
6272
+ values: ["playbook-id", "function-name"]
6301
6273
  }),
6302
- command("subscriptions unsubscribe", {
6303
- values: ["feed-ids", "playbook-ids"]
6274
+ route("playbooks functions invoke", "functions invoke", {
6275
+ values: ["playbook-id", "function-name", "params"]
6304
6276
  }),
6305
- command("alert list", {
6277
+ route("alert list", "alert list", {
6306
6278
  values: ["first", "cursor"],
6307
6279
  booleans: ["json"]
6308
6280
  }),
6309
- command("alert follows", { values: ["limit", "cursor"] }),
6310
- command("alert enable", {
6311
- values: [
6312
- "automation",
6313
- "automation-ids",
6314
- "channel-id",
6315
- "playbook",
6316
- "playbook-ids"
6317
- ]
6318
- }),
6319
- command("alert disable", {
6320
- values: ["automation", "automation-ids", "playbook", "playbook-ids"]
6321
- }),
6322
- command("alert group"),
6323
- command("alert group list", {
6324
- values: ["session-id"],
6325
- booleans: ["json"]
6326
- }),
6327
- command("alert group enable", {
6328
- values: ["automation", "automation-ids", "channel-id", "session-id"]
6281
+ route("alert enable", "alert enable", {
6282
+ values: ["automation", "automation-ids", "channel-id"]
6329
6283
  }),
6330
- command("alert group disable", {
6331
- values: ["automation", "automation-ids", "channel-id", "session-id"]
6284
+ route("alert disable", "alert disable", {
6285
+ values: ["automation", "automation-ids"]
6332
6286
  }),
6333
- command("alert history", {
6287
+ route("alert history", "alert history", {
6334
6288
  values: [
6335
6289
  "automation",
6336
- "playbook",
6337
- "playbook-ids",
6338
6290
  "delivery-provider",
6339
- // Retained so the handler can emit the existing rename guidance.
6340
- "channel",
6341
6291
  "status",
6342
6292
  "since",
6343
6293
  "first",
6344
6294
  "cursor"
6345
6295
  ]
6346
6296
  }),
6347
- command("alert preferences"),
6348
- command("alert enable-session-completed"),
6349
- command("alert disable-session-completed"),
6350
- command("remix", {
6351
- values: ["child-username", "child-name", "parents"]
6352
- }),
6353
- command("arrays"),
6354
- command("arrays token"),
6355
- command("arrays token ensure"),
6356
- command("arrays token status"),
6357
- command("screenshot", {
6358
- values: [
6359
- "url",
6360
- "out",
6361
- "selector",
6362
- "xpath",
6363
- "compress-quality",
6364
- "compress-max-width"
6365
- ],
6366
- booleans: ["base64", "full", "compress"]
6367
- }),
6368
- command("portfolio accounts"),
6369
- command("portfolio summary", { values: ["account-id"] }),
6370
- command("portfolio activities", {
6297
+ route("portfolio accounts", "portfolio accounts"),
6298
+ route("portfolio summary", "portfolio summary", { values: ["account-id"] }),
6299
+ route("portfolio activities", "portfolio activities", {
6371
6300
  values: ["account-id", "limit", "page-token"]
6372
6301
  }),
6373
- command("markets narrative", { values: ["ticker"] }),
6374
- command("markets earnings", {
6375
- values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
6376
- }),
6377
- command("trading accounts"),
6378
- command("trading portfolio", { values: ["account-id"] }),
6379
- command("trading orders", {
6302
+ route("portfolio orders", "trading orders", {
6380
6303
  values: ["account-id", "source", "since", "limit"]
6381
6304
  }),
6382
- command("trading subscriptions", { values: ["account-id"] }),
6383
- command("trading equity-history", {
6305
+ route("portfolio equity-history", "trading equity-history", {
6384
6306
  values: ["account-id", "timeframe", "since-ms", "until-ms"]
6385
6307
  }),
6386
- command("trading risk-rules"),
6387
- command("trading subscribe", {
6308
+ route("trading accounts", "broker accounts"),
6309
+ route("trading risk-rules", "broker risk-rules"),
6310
+ route("trading signals subscriptions list", "trading subscriptions", {
6311
+ values: ["account-id"]
6312
+ }),
6313
+ route("trading signals subscriptions subscribe", "trading subscribe", {
6388
6314
  values: [
6389
6315
  "account-id",
6390
6316
  "source-username",
6391
6317
  "source-feed",
6392
6318
  "playbook-id",
6393
6319
  "playbook-version"
6394
- ],
6395
- booleans: ["execute-latest"]
6396
- }),
6397
- command("trading unsubscribe", { values: ["subscription-id"] }),
6398
- command("trading execute", {
6399
- values: ["account-id", "signal", "source-username", "source-feed"],
6400
- booleans: ["dry-run"]
6401
- }),
6402
- command("trading update-risk-rules", {
6403
- values: [
6404
- "max-single-order-value",
6405
- "max-single-order-enabled",
6406
- "max-daily-turnover-value",
6407
- "max-daily-turnover-enabled",
6408
- "max-daily-orders-value",
6409
- "max-daily-orders-enabled"
6410
6320
  ]
6411
6321
  }),
6412
- command("broker", { passthrough: true })
6322
+ route("trading signals subscriptions unsubscribe", "trading unsubscribe", {
6323
+ values: ["subscription-id"]
6324
+ }),
6325
+ action(
6326
+ "trading signals execute",
6327
+ {
6328
+ values: ["account-id", "signal", "source-username", "source-feed"],
6329
+ booleans: ["live"]
6330
+ },
6331
+ "signal-execute"
6332
+ ),
6333
+ route("trading broker", "broker", { passthrough: true })
6413
6334
  ];
6414
6335
 
6415
- // src/cli/commandSchema.ts
6336
+ // src/cli/agentCommandDefinitions.ts
6337
+ var EMBEDDED_GLOBAL_FLAG_DEFINITIONS = {
6338
+ help: "boolean"
6339
+ };
6340
+ var embeddedDefinitions = new Map(
6341
+ EMBEDDED_COMMAND_DEFINITIONS.map((definition) => [
6342
+ definition.path.join(" "),
6343
+ definition
6344
+ ])
6345
+ );
6346
+ function embeddedCommandDefinition(path) {
6347
+ const definition = embeddedDefinitions.get(path.join(" "));
6348
+ if (definition === void 0) {
6349
+ throw new Error(`Embedded CLI route '${path.join(" ")}' is not registered`);
6350
+ }
6351
+ return definition;
6352
+ }
6353
+
6354
+ // src/cli/agentHelp.ts
6355
+ var AGENT_HELP_TEXT = `Usage: alva <command> [options]
6356
+
6357
+ Slim Alva Agent CLI. Authentication and endpoints are owned by Jagent.
6358
+
6359
+ Commands:
6360
+ account Identity, credits, secrets, notifications, service accounts
6361
+ fs Read and manage ALFS paths
6362
+ run Execute Jagent JavaScript
6363
+ data-skills Discover structured Arrays data endpoints
6364
+ skillhub Discover curated methodology blueprints
6365
+ markets Read market narrative and earnings context
6366
+ automation Create and operate scheduled automations
6367
+ playbooks Discover, build, release, and manage Playbooks
6368
+ alert Manage personal automation alert bindings
6369
+ portfolio Read connected accounts, assets, activity, and history
6370
+ trading Inspect controls and use Signal or Broker execution
6371
+
6372
+ Run 'alva <command> --help' for a command tree.`;
6373
+ var AGENT_COMMAND_HELP = {
6374
+ account: `Usage: alva account <subcommand>
6375
+
6376
+ Subcommands:
6377
+ whoami
6378
+ credits wallet|items
6379
+ secrets create|list|get|update|delete
6380
+ notifications preferences|set-preference
6381
+ service-accounts create|list|delete|grant|revoke`,
6382
+ fs: `Usage: alva fs <subcommand>
6383
+
6384
+ Subcommands:
6385
+ read write stat readdir mkdir remove
6386
+ rename copy symlink readlink chmod grant revoke`,
6387
+ run: `Usage: alva run (--code <js> | --entry-path <alfs-path>) [options]
6388
+
6389
+ Execute JavaScript in the Jagent runtime. Local-file flags are unavailable in
6390
+ the embedded Agent; use ALFS paths or inline code.`,
6391
+ "data-skills": `Usage: alva data-skills <subcommand>
6392
+
6393
+ Subcommands:
6394
+ list
6395
+ summary <skill-name>
6396
+ endpoint <skill-name> <endpoint-file>`,
6397
+ skillhub: `Usage: alva skillhub <subcommand>
6398
+
6399
+ Subcommands:
6400
+ list tags get file`,
6401
+ markets: `Usage: alva markets <subcommand>
6402
+
6403
+ Subcommands:
6404
+ narrative
6405
+ earnings`,
6406
+ automation: `Usage: alva automation <subcommand>
6407
+
6408
+ Subcommands:
6409
+ create Create a producer and register its automation
6410
+ list List product automations
6411
+ inspect Inspect one automation
6412
+ update Update producer and/or product metadata
6413
+ delivery Read or update Alva channel and verified-email destinations
6414
+ delete Delete an automation and its producer
6415
+ pause Pause product delivery and its producer
6416
+ resume Resume product delivery and its producer
6417
+ trigger Trigger the effective producer once
6418
+ set-visibility Set automation visibility
6419
+ runs Run history, status, and logs`,
6420
+ "automation delivery": `Usage: alva automation delivery <subcommand> --id <automation-id>
6421
+
6422
+ Subcommands:
6423
+ get
6424
+ update`,
6425
+ "automation runs": `Usage: alva automation runs <subcommand> --id <automation-id>
6426
+
6427
+ Subcommands:
6428
+ list
6429
+ status
6430
+ logs`,
6431
+ playbooks: `Usage: alva playbooks <subcommand>
6432
+
6433
+ Subcommands:
6434
+ trending list mine get set-visibility
6435
+ draft release lint screenshot remix
6436
+ comments follows functions`,
6437
+ "playbooks comments": `Usage: alva playbooks comments <subcommand>
6438
+
6439
+ Subcommands:
6440
+ create pin unpin`,
6441
+ "playbooks follows": `Usage: alva playbooks follows <subcommand>
6442
+
6443
+ Subcommands:
6444
+ list follow unfollow`,
6445
+ "playbooks functions": `Usage: alva playbooks functions <subcommand>
6446
+
6447
+ Subcommands:
6448
+ register list delete invoke allowance`,
6449
+ "playbooks functions allowance": `Usage: alva playbooks functions allowance <subcommand>
6450
+
6451
+ Subcommands:
6452
+ get list create revoke`,
6453
+ alert: `Usage: alva alert <subcommand>
6454
+
6455
+ Subcommands:
6456
+ list enable disable history`,
6457
+ portfolio: `Usage: alva portfolio <subcommand>
6458
+
6459
+ Subcommands:
6460
+ accounts List TREX and SnapTrade connected accounts
6461
+ summary Read one account's holdings and balances
6462
+ activities Read normalized account activity
6463
+ orders Read detailed TREX order history
6464
+ equity-history Read TREX account equity history`,
6465
+ trading: `Usage: alva trading <subcommand>
6466
+
6467
+ Subcommands:
6468
+ accounts List execution-capable TREX accounts
6469
+ risk-rules Read the admission limits enforced by Broker and Signal
6470
+ signals Legacy Signal subscriptions and execution
6471
+ broker Venue-native reads and order execution`,
6472
+ "trading signals": `Usage: alva trading signals <subcommand>
6473
+
6474
+ Legacy Signal/copy-trading surface. It is separate from Broker.
6475
+
6476
+ Subcommands:
6477
+ subscriptions list|subscribe|unsubscribe
6478
+ execute Interpret one Signal; dry-run unless --live is explicit`,
6479
+ "trading signals subscriptions": `Usage: alva trading signals subscriptions <subcommand>
6480
+
6481
+ Subcommands:
6482
+ list subscribe unsubscribe
6483
+
6484
+ Subscriptions never execute the latest stored Signal implicitly.`,
6485
+ "trading broker": `Usage: alva trading broker <broker-command> [venue flags]
6486
+
6487
+ Subcommands:
6488
+ describe balance positions quote ohlcv funding-rate raw
6489
+ order place|cancel|get|list
6490
+
6491
+ Run 'alva trading broker describe' for the live venue contract.`
6492
+ };
6493
+ var AGENT_LEAF_DEFINITIONS = new Map(
6494
+ EMBEDDED_COMMAND_DEFINITIONS.map((definition) => [
6495
+ definition.path.join(" "),
6496
+ definition
6497
+ ])
6498
+ );
6499
+ function formatAgentLeafHelp(definition) {
6500
+ const positionals = definition.positionals.names.map(
6501
+ (name, index) => index < definition.positionals.min ? `<${name}>` : `[<${name}>]`
6502
+ );
6503
+ const usageSuffix = [
6504
+ ...positionals,
6505
+ definition.passthrough === true ? "[arguments...]" : "[options]"
6506
+ ].join(" ");
6507
+ const options = Object.entries(definition.flags).map(
6508
+ ([name, kind]) => kind === "value" ? ` --${name} <value>` : ` --${name} | --no-${name}`
6509
+ );
6510
+ options.push(" --help");
6511
+ return `Usage: alva ${definition.path.join(" ")} ${usageSuffix}
6512
+
6513
+ Options:
6514
+ ${options.join("\n")}`;
6515
+ }
6516
+ function agentHelpFor(args) {
6517
+ const helpIndex = args.findIndex(
6518
+ (argument) => argument === "--help" || argument === "-h"
6519
+ );
6520
+ const path = (helpIndex === -1 ? args : args.slice(0, helpIndex)).filter(
6521
+ (argument) => !argument.startsWith("-")
6522
+ );
6523
+ for (let length = path.length; length > 0; length--) {
6524
+ const command2 = path.slice(0, length).join(" ");
6525
+ const help = AGENT_COMMAND_HELP[command2];
6526
+ if (help !== void 0) return help;
6527
+ const definition = AGENT_LEAF_DEFINITIONS.get(command2);
6528
+ if (definition !== void 0) return formatAgentLeafHelp(definition);
6529
+ }
6530
+ return void 0;
6531
+ }
6532
+
6533
+ // src/cli/commandParser.ts
6416
6534
  function buildCommandTree(definitions) {
6417
6535
  const root = { children: /* @__PURE__ */ new Map() };
6418
6536
  for (const definition of definitions) {
@@ -6442,7 +6560,6 @@ function buildCommandTree(definitions) {
6442
6560
  }
6443
6561
  return root;
6444
6562
  }
6445
- var COMMAND_TREE = buildCommandTree(COMMAND_DEFINITIONS);
6446
6563
  function editDistance(a, b) {
6447
6564
  let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
6448
6565
  for (let row = 1; row <= a.length; row++) {
@@ -6471,11 +6588,11 @@ function closestFlag(input, available) {
6471
6588
  const threshold = input.length <= 4 ? 1 : 2;
6472
6589
  return distance <= threshold ? closest : void 0;
6473
6590
  }
6474
- function mergeFlags(definition) {
6475
- return { ...GLOBAL_FLAG_DEFINITIONS, ...definition.flags };
6591
+ function mergeFlags(definition, globalFlags) {
6592
+ return { ...globalFlags, ...definition.flags };
6476
6593
  }
6477
- function resolveCommand(args) {
6478
- let node = COMMAND_TREE;
6594
+ function resolveCommand(args, tree) {
6595
+ let node = tree;
6479
6596
  let consumed = 0;
6480
6597
  while (consumed < args.length) {
6481
6598
  const input = args[consumed];
@@ -6515,8 +6632,8 @@ function unsupportedFlag(name, definition, available) {
6515
6632
  definition.path[0]
6516
6633
  );
6517
6634
  }
6518
- function parseCommand(args) {
6519
- const { definition, consumed } = resolveCommand(args);
6635
+ function parseWithTree(args, tree, globalFlags) {
6636
+ const { definition, consumed } = resolveCommand(args, tree);
6520
6637
  if (definition.passthrough === true) {
6521
6638
  return {
6522
6639
  path: definition.path,
@@ -6525,7 +6642,7 @@ function parseCommand(args) {
6525
6642
  passthrough: args.slice(consumed)
6526
6643
  };
6527
6644
  }
6528
- const available = mergeFlags(definition);
6645
+ const available = mergeFlags(definition, globalFlags);
6529
6646
  const flags = {};
6530
6647
  const positionals = [];
6531
6648
  for (let index = consumed; index < args.length; index++) {
@@ -6607,6 +6724,481 @@ function parseCommand(args) {
6607
6724
  positionals
6608
6725
  };
6609
6726
  }
6727
+ function createCommandParser(definitions, globalFlags) {
6728
+ const tree = buildCommandTree(definitions);
6729
+ return (args) => parseWithTree(args, tree, globalFlags);
6730
+ }
6731
+
6732
+ // src/cli/embeddedCommandSchema.ts
6733
+ var parseEmbeddedCommand = createCommandParser(
6734
+ EMBEDDED_COMMAND_DEFINITIONS,
6735
+ EMBEDDED_GLOBAL_FLAG_DEFINITIONS
6736
+ );
6737
+
6738
+ // src/cli/commandDefinitions.ts
6739
+ function command(path, {
6740
+ values = [],
6741
+ booleans = [],
6742
+ positionals = [],
6743
+ optionalPositionals = 0,
6744
+ passthrough = false
6745
+ } = {}) {
6746
+ const flags = {};
6747
+ for (const name of values) {
6748
+ flags[name] = "value";
6749
+ }
6750
+ for (const name of booleans) {
6751
+ if (flags[name] !== void 0) {
6752
+ throw new Error(`CLI flag --${name} has conflicting definitions`);
6753
+ }
6754
+ flags[name] = "boolean";
6755
+ }
6756
+ return {
6757
+ path: path.split(" "),
6758
+ flags,
6759
+ positionals: {
6760
+ names: positionals,
6761
+ min: positionals.length - optionalPositionals,
6762
+ max: positionals.length
6763
+ },
6764
+ passthrough
6765
+ };
6766
+ }
6767
+ var GLOBAL_FLAG_DEFINITIONS = {
6768
+ "api-key": "value",
6769
+ "base-url": "value",
6770
+ profile: "value",
6771
+ "arrays-endpoint": "value",
6772
+ help: "boolean"
6773
+ };
6774
+ var COMMAND_DEFINITIONS = [
6775
+ command("configure", {
6776
+ values: ["api-key", "base-url", "profile"]
6777
+ }),
6778
+ // Some route-map nodes are also valid help targets. Their handlers preserve
6779
+ // the existing bare-command help behavior while the trie still resolves
6780
+ // deeper leaves.
6781
+ command("auth"),
6782
+ command("auth login", {
6783
+ values: ["profile", "auth-url", "base-url"],
6784
+ booleans: ["browser", "no-browser"]
6785
+ }),
6786
+ command("whoami"),
6787
+ command("user me"),
6788
+ command("fs read", { values: ["path", "offset", "size"] }),
6789
+ command("fs write", {
6790
+ values: ["path", "data", "file"],
6791
+ booleans: ["mkdir-parents", "append"]
6792
+ }),
6793
+ command("fs stat", { values: ["path"] }),
6794
+ command("fs readdir", {
6795
+ values: ["path"],
6796
+ booleans: ["recursive"]
6797
+ }),
6798
+ command("fs mkdir", { values: ["path"] }),
6799
+ command("fs remove", {
6800
+ values: ["path"],
6801
+ booleans: ["recursive"]
6802
+ }),
6803
+ command("fs rename", { values: ["old-path", "new-path"] }),
6804
+ command("fs copy", { values: ["src-path", "dst-path"] }),
6805
+ command("fs symlink", { values: ["target-path", "link-path"] }),
6806
+ command("fs readlink", { values: ["path"] }),
6807
+ command("fs chmod", { values: ["path", "mode"] }),
6808
+ command("fs grant", { values: ["path", "subject", "permission"] }),
6809
+ command("fs revoke", { values: ["path", "subject", "permission"] }),
6810
+ command("run", {
6811
+ values: [
6812
+ "code",
6813
+ "local-file",
6814
+ "entry-path",
6815
+ "working-dir",
6816
+ "args",
6817
+ "max-heap-size-mb",
6818
+ "timeout-ms"
6819
+ ]
6820
+ }),
6821
+ command("deploy create", {
6822
+ values: [
6823
+ "name",
6824
+ "path",
6825
+ "cron",
6826
+ "args",
6827
+ "max-heap-size-mb",
6828
+ "execution-timeout-seconds",
6829
+ "run-as-service-account"
6830
+ ],
6831
+ booleans: ["push-notify"]
6832
+ }),
6833
+ command("deploy list", { values: ["limit", "cursor"] }),
6834
+ command("deploy get", { values: ["id"] }),
6835
+ command("deploy update", {
6836
+ values: [
6837
+ "id",
6838
+ "name",
6839
+ "cron",
6840
+ "args",
6841
+ "max-heap-size-mb",
6842
+ "execution-timeout-seconds",
6843
+ "run-as-service-account"
6844
+ ],
6845
+ booleans: ["push-notify", "clear-run-as"]
6846
+ }),
6847
+ command("deploy delete", { values: ["id"] }),
6848
+ command("deploy pause", { values: ["id"] }),
6849
+ command("deploy resume", { values: ["id"] }),
6850
+ command("deploy trigger", { values: ["id"] }),
6851
+ command("deploy runs", { values: ["id", "first", "cursor"] }),
6852
+ command("deploy run-status", {
6853
+ values: ["id", "workflow-run-id"]
6854
+ }),
6855
+ command("deploy run-logs", { values: ["id", "run-id"] }),
6856
+ command("loop create", {
6857
+ values: [
6858
+ "goal",
6859
+ "cron",
6860
+ "channel-id",
6861
+ "start",
6862
+ "until",
6863
+ "runs",
6864
+ "name",
6865
+ // Retained so the handler can emit the existing migration guidance.
6866
+ "expires-in"
6867
+ ]
6868
+ }),
6869
+ command("service-account create", { values: ["name"] }),
6870
+ command("service-account list"),
6871
+ command("service-account delete", { values: ["id"] }),
6872
+ command("service-account grant", {
6873
+ values: ["id", "path", "permission"]
6874
+ }),
6875
+ command("service-account revoke", {
6876
+ values: ["id", "path", "permission"]
6877
+ }),
6878
+ command("feed list", { values: ["limit", "cursor", "status"] }),
6879
+ command("feed stop", { values: ["id"] }),
6880
+ command("feed resume", { values: ["id"] }),
6881
+ command("feed delete", { values: ["id"] }),
6882
+ command("feed set-visibility", { values: ["id", "visibility"] }),
6883
+ command("automation list", {
6884
+ values: ["limit", "cursor", "status"],
6885
+ booleans: ["json"]
6886
+ }),
6887
+ command("automation inspect", {
6888
+ values: ["id"],
6889
+ booleans: ["json"]
6890
+ }),
6891
+ command("automation publish", {
6892
+ values: [
6893
+ "name",
6894
+ "version",
6895
+ "cronjob-id",
6896
+ "view-json",
6897
+ "description",
6898
+ "changelog",
6899
+ "agent-type"
6900
+ ],
6901
+ booleans: ["skip-auto-trigger"]
6902
+ }),
6903
+ command("automation update", {
6904
+ values: [
6905
+ "id",
6906
+ "version",
6907
+ "cronjob-id",
6908
+ "description",
6909
+ "changelog",
6910
+ "agent-type"
6911
+ ],
6912
+ booleans: ["trigger"]
6913
+ }),
6914
+ command("automation delivery"),
6915
+ command("automation delivery get", { values: ["id"] }),
6916
+ command("automation delivery update", {
6917
+ values: ["id", "alva-channel-ids"],
6918
+ booleans: ["email-enabled"]
6919
+ }),
6920
+ command("automation stop", { values: ["id"] }),
6921
+ command("automation resume", { values: ["id"] }),
6922
+ command("automation delete", { values: ["id"] }),
6923
+ command("credits wallet"),
6924
+ command("credits items", {
6925
+ values: ["last", "start", "end", "session-id", "first", "after"],
6926
+ booleans: ["today"]
6927
+ }),
6928
+ command("playbooks trending", {
6929
+ values: ["keyword", "tags", "tag", "sort", "limit", "cursor", "current"],
6930
+ booleans: ["json"]
6931
+ }),
6932
+ command("playbooks set-visibility", {
6933
+ values: ["name", "visibility"]
6934
+ }),
6935
+ command("playbooks get", {
6936
+ values: ["ids", "id", "ref"],
6937
+ booleans: ["json"]
6938
+ }),
6939
+ command("playbooks list", {
6940
+ values: ["owner", "limit", "cursor"],
6941
+ booleans: ["json", "all"]
6942
+ }),
6943
+ command("playbooks mine", {
6944
+ values: ["filter", "limit", "cursor"],
6945
+ booleans: ["json", "all"]
6946
+ }),
6947
+ command("functions allowance"),
6948
+ command("functions allowance get", { values: ["playbook-id"] }),
6949
+ command("functions allowance list"),
6950
+ command("functions allowance create", {
6951
+ values: ["playbook-id", "amount"]
6952
+ }),
6953
+ command("functions allowance revoke", { values: ["playbook-id"] }),
6954
+ command("functions register", {
6955
+ values: [
6956
+ "playbook-id",
6957
+ "function-name",
6958
+ "entry-script-path",
6959
+ "params-schema",
6960
+ "params-schema-file",
6961
+ "run-as-service-account"
6962
+ ],
6963
+ booleans: ["allow-charges", "clear-run-as"]
6964
+ }),
6965
+ command("functions list", { values: ["playbook-id"] }),
6966
+ command("functions delete", {
6967
+ values: ["playbook-id", "function-name"]
6968
+ }),
6969
+ command("functions invoke", {
6970
+ values: ["playbook-id", "function-name", "params"]
6971
+ }),
6972
+ command("release feed", {
6973
+ values: [
6974
+ "name",
6975
+ "version",
6976
+ "cronjob-id",
6977
+ "view-json",
6978
+ "description",
6979
+ "changelog",
6980
+ "agent-type"
6981
+ ],
6982
+ booleans: ["skip-auto-trigger"]
6983
+ }),
6984
+ command("release playbook-draft", {
6985
+ values: [
6986
+ "name",
6987
+ "display-name",
6988
+ "description",
6989
+ "feeds",
6990
+ "trading-symbols",
6991
+ "skill-id",
6992
+ "tags"
6993
+ ]
6994
+ }),
6995
+ command("release playbook", {
6996
+ values: ["name", "version", "feeds", "changelog", "readme-url"],
6997
+ booleans: ["bypass-lint"]
6998
+ }),
6999
+ command("lint playbook", {
7000
+ values: ["format"],
7001
+ positionals: ["file argument"]
7002
+ }),
7003
+ command("secrets create", { values: ["name", "value"] }),
7004
+ command("secrets list"),
7005
+ command("secrets get", { values: ["name"] }),
7006
+ command("secrets update", { values: ["name", "value"] }),
7007
+ command("secrets delete", { values: ["name"] }),
7008
+ command("sdk doc", { values: ["name"] }),
7009
+ command("sdk partitions"),
7010
+ command("sdk partition-summary", { values: ["partition"] }),
7011
+ command("data-skills list", { booleans: ["json"] }),
7012
+ command("data-skills summary", {
7013
+ booleans: ["json"],
7014
+ positionals: ["skill name"]
7015
+ }),
7016
+ command("data-skills endpoint", {
7017
+ booleans: ["json"],
7018
+ positionals: ["skill name", "endpoint file"]
7019
+ }),
7020
+ command("skillhub list", {
7021
+ values: ["tag", "username"],
7022
+ booleans: ["json"]
7023
+ }),
7024
+ command("skillhub tags", { booleans: ["json"] }),
7025
+ command("skillhub get", {
7026
+ booleans: ["json"],
7027
+ positionals: ["playbook skill identifier"]
7028
+ }),
7029
+ command("skillhub file", {
7030
+ booleans: ["json"],
7031
+ positionals: ["playbook skill identifier", "file path"]
7032
+ }),
7033
+ command("comments create", {
7034
+ values: ["username", "name", "content", "parent-id"]
7035
+ }),
7036
+ command("comments pin", { values: ["comment-id"] }),
7037
+ command("comments unpin", { values: ["comment-id"] }),
7038
+ command("notification-history list-feed", {
7039
+ values: [
7040
+ "username",
7041
+ "name",
7042
+ "delivery-provider",
7043
+ // Retained so the handler can emit the existing rename guidance.
7044
+ "channel",
7045
+ "status",
7046
+ "since",
7047
+ "first",
7048
+ "cursor"
7049
+ ]
7050
+ }),
7051
+ command("notification-preferences list"),
7052
+ command("notification-preferences enable-session-completed"),
7053
+ command("notification-preferences disable-session-completed"),
7054
+ command("feedback submit", {
7055
+ values: [
7056
+ "source",
7057
+ "category",
7058
+ "severity",
7059
+ "summary",
7060
+ "details",
7061
+ "evidence-json",
7062
+ "context-json",
7063
+ // Retained so the handler can emit the existing migration guidance.
7064
+ "dedupe-key"
7065
+ ]
7066
+ }),
7067
+ command("subscriptions follow-playbook", {
7068
+ values: ["username", "name"]
7069
+ }),
7070
+ command("subscriptions unfollow-playbook", {
7071
+ values: ["username", "name"]
7072
+ }),
7073
+ command("subscriptions subscribe-feed", {
7074
+ values: ["username", "name"]
7075
+ }),
7076
+ command("subscriptions unsubscribe-feed", {
7077
+ values: ["username", "name"]
7078
+ }),
7079
+ command("subscriptions list", { values: ["first", "cursor"] }),
7080
+ command("subscriptions follows", { values: ["limit", "cursor"] }),
7081
+ command("subscriptions subscribe", {
7082
+ values: ["feed-ids", "channel-id", "playbook-ids"]
7083
+ }),
7084
+ command("subscriptions unsubscribe", {
7085
+ values: ["feed-ids", "playbook-ids"]
7086
+ }),
7087
+ command("alert list", {
7088
+ values: ["first", "cursor"],
7089
+ booleans: ["json"]
7090
+ }),
7091
+ command("alert follows", { values: ["limit", "cursor"] }),
7092
+ command("alert enable", {
7093
+ values: [
7094
+ "automation",
7095
+ "automation-ids",
7096
+ "channel-id",
7097
+ "playbook",
7098
+ "playbook-ids"
7099
+ ]
7100
+ }),
7101
+ command("alert disable", {
7102
+ values: ["automation", "automation-ids", "playbook", "playbook-ids"]
7103
+ }),
7104
+ command("alert group"),
7105
+ command("alert group list", {
7106
+ values: ["session-id"],
7107
+ booleans: ["json"]
7108
+ }),
7109
+ command("alert group enable", {
7110
+ values: ["automation", "automation-ids", "channel-id", "session-id"]
7111
+ }),
7112
+ command("alert group disable", {
7113
+ values: ["automation", "automation-ids", "channel-id", "session-id"]
7114
+ }),
7115
+ command("alert history", {
7116
+ values: [
7117
+ "automation",
7118
+ "playbook",
7119
+ "playbook-ids",
7120
+ "delivery-provider",
7121
+ // Retained so the handler can emit the existing rename guidance.
7122
+ "channel",
7123
+ "status",
7124
+ "since",
7125
+ "first",
7126
+ "cursor"
7127
+ ]
7128
+ }),
7129
+ command("alert preferences"),
7130
+ command("alert enable-session-completed"),
7131
+ command("alert disable-session-completed"),
7132
+ command("remix", {
7133
+ values: ["child-username", "child-name", "parents"]
7134
+ }),
7135
+ command("arrays"),
7136
+ command("arrays token"),
7137
+ command("arrays token ensure"),
7138
+ command("arrays token status"),
7139
+ command("screenshot", {
7140
+ values: [
7141
+ "url",
7142
+ "out",
7143
+ "selector",
7144
+ "xpath",
7145
+ "compress-quality",
7146
+ "compress-max-width"
7147
+ ],
7148
+ booleans: ["base64", "full", "compress"]
7149
+ }),
7150
+ command("portfolio accounts"),
7151
+ command("portfolio summary", { values: ["account-id"] }),
7152
+ command("portfolio activities", {
7153
+ values: ["account-id", "limit", "page-token"]
7154
+ }),
7155
+ command("markets narrative", { values: ["ticker"] }),
7156
+ command("markets earnings", {
7157
+ values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
7158
+ }),
7159
+ command("trading accounts"),
7160
+ command("trading portfolio", { values: ["account-id"] }),
7161
+ command("trading orders", {
7162
+ values: ["account-id", "source", "since", "limit"]
7163
+ }),
7164
+ command("trading subscriptions", { values: ["account-id"] }),
7165
+ command("trading equity-history", {
7166
+ values: ["account-id", "timeframe", "since-ms", "until-ms"]
7167
+ }),
7168
+ command("trading risk-rules"),
7169
+ command("trading subscribe", {
7170
+ values: [
7171
+ "account-id",
7172
+ "source-username",
7173
+ "source-feed",
7174
+ "playbook-id",
7175
+ "playbook-version"
7176
+ ],
7177
+ booleans: ["execute-latest"]
7178
+ }),
7179
+ command("trading unsubscribe", { values: ["subscription-id"] }),
7180
+ command("trading execute", {
7181
+ values: ["account-id", "signal", "source-username", "source-feed"],
7182
+ booleans: ["dry-run"]
7183
+ }),
7184
+ command("trading update-risk-rules", {
7185
+ values: [
7186
+ "max-single-order-value",
7187
+ "max-single-order-enabled",
7188
+ "max-daily-turnover-value",
7189
+ "max-daily-turnover-enabled",
7190
+ "max-daily-orders-value",
7191
+ "max-daily-orders-enabled"
7192
+ ]
7193
+ }),
7194
+ command("broker", { passthrough: true })
7195
+ ];
7196
+
7197
+ // src/cli/commandSchema.ts
7198
+ var parseCommand = createCommandParser(
7199
+ COMMAND_DEFINITIONS,
7200
+ GLOBAL_FLAG_DEFINITIONS
7201
+ );
6610
7202
 
6611
7203
  // src/cli/dataSkillsFormat.ts
6612
7204
  function formatSkillsList(payload) {
@@ -10338,7 +10930,7 @@ function validateSerializedArgs(raw) {
10338
10930
  }
10339
10931
 
10340
10932
  // src/cli/dispatch.ts
10341
- var CLI_VERSION = true ? "0.24.0" : "dev";
10933
+ var CLI_VERSION = true ? "0.25.1" : "dev";
10342
10934
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
10343
10935
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
10344
10936
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -10371,58 +10963,6 @@ function isVersionOlderThan(a, b) {
10371
10963
  }
10372
10964
  return false;
10373
10965
  }
10374
- var HELP_TEXT = `Usage: alva <command> [options]
10375
-
10376
- Commands:
10377
- configure Save API key and endpoint to a named profile
10378
- whoami Verify credentials and show current identity
10379
- user User profile operations (me)
10380
- fs Filesystem operations (read, write, stat, readdir, mkdir, remove, rename, copy, symlink, readlink, chmod, grant, revoke)
10381
- run Execute code in the Alva runtime
10382
- deploy Cronjob management (create, list, get, update, delete, pause, resume, runs, run-logs)
10383
- loop Self-scheduled in-channel goal loops (create)
10384
- service-account Restricted run-as identities (create, list, delete, grant, revoke)
10385
- release Feed and playbook releases (feed, playbook-draft, playbook)
10386
- lint Design-system lint (playbook)
10387
- automation Automation management (list, inspect, publish, update, delivery, stop, resume, delete)
10388
- alert Alert management (list, follows, enable, disable, history, preferences, enable-session-completed, disable-session-completed)
10389
- feed Legacy automation alias (list, stop, resume, delete, set-visibility)
10390
- playbooks Playbook discovery (trending, get, list) and visibility
10391
- functions Playbook UDF function management (register, list, delete, invoke, allowance)
10392
- credits Credit wallet and self-scoped usage history (wallet, items)
10393
- secrets Secret management (create, list, get, update, delete)
10394
- sdk SDK documentation (doc, partitions, partition-summary)
10395
- skillhub Playbook skills (list, tags, get, file)
10396
- data-skills Data-skill documentation from the Arrays backend (list, summary, endpoint)
10397
- comments Playbook comments (create, pin, unpin)
10398
- notification-history Feed notification delivery history (list-feed)
10399
- notification-preferences Notification preferences (list, enable-session-completed, disable-session-completed)
10400
- feedback Submit user-confirmed Alva platform feedback (submit)
10401
- subscriptions Playbook follows and feed alert subscriptions
10402
- remix Save playbook remix lineage
10403
- portfolio Connected-account portfolio (accounts, summary, activities)
10404
- markets Company narrative and earnings context (narrative, earnings)
10405
- trading Trading operations (accounts, portfolio, orders, subscriptions, equity-history, risk-rules, subscribe, unsubscribe, execute, update-risk-rules)
10406
- broker Agentic order execution \u2014 venue-native passthrough to trex (accounts, quote, order, balance, positions, ...; run 'alva broker describe')
10407
- auth Authentication (login)
10408
- screenshot Capture a web screenshot as PNG
10409
- arrays Arrays backend operations (token ensure, token status)
10410
-
10411
- Global options:
10412
- --api-key <key> API key (overrides env and config file)
10413
- --base-url <url> API base URL (overrides env and config file)
10414
- --profile <name> Named profile to use (default: "default")
10415
- --arrays-endpoint <url> Arrays backend URL (or ARRAYS_ENDPOINT env; default: https://data-tools.prd.space.id)
10416
- -v, --version Show CLI version
10417
- --help Show help (use 'alva <command> --help' for command details)
10418
-
10419
- Config resolution: --api-key flag > ALVA_API_KEY env > profile in ~/.config/alva/config.json
10420
- Profile resolution: --profile flag > ALVA_PROFILE env > "default"
10421
-
10422
- Quick start:
10423
- npm install -g @alva-ai/toolkit
10424
- alva configure --api-key alva_your_key_here
10425
- alva whoami`;
10426
10966
  var COMMAND_HELP = {
10427
10967
  configure: `Usage: alva configure --api-key <key> [--base-url <url>] [--profile <name>]
10428
10968
 
@@ -11622,34 +12162,6 @@ Examples:
11622
12162
  alva arrays token ensure
11623
12163
  alva arrays token status`
11624
12164
  };
11625
- function parseFlags(argv) {
11626
- const flags = {};
11627
- for (let index = 0; index < argv.length; index++) {
11628
- const argument = argv[index];
11629
- if (!argument.startsWith("--")) continue;
11630
- const equalsIndex = argument.indexOf("=");
11631
- if (equalsIndex !== -1) {
11632
- flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
11633
- continue;
11634
- }
11635
- const name = argument.slice(2);
11636
- if (BOOLEAN_FLAGS.has(name)) {
11637
- flags[name] = "true";
11638
- continue;
11639
- }
11640
- if (name.startsWith("no-") && BOOLEAN_FLAGS.has(name.slice(3))) {
11641
- flags[name.slice(3)] = "false";
11642
- continue;
11643
- }
11644
- const value = argv[index + 1];
11645
- if (value === void 0 || value.startsWith("--")) {
11646
- throw new CliUsageError(`--${name} requires a value`, name);
11647
- }
11648
- flags[name] = value;
11649
- index++;
11650
- }
11651
- return flags;
11652
- }
11653
12165
  function boolFlag(val) {
11654
12166
  if (val === "true") return true;
11655
12167
  if (val === "false") return false;
@@ -11790,7 +12302,7 @@ function runTimeoutMs(flags, deps) {
11790
12302
  return DEFAULT_RUN_TIMEOUT_MS;
11791
12303
  }
11792
12304
  function configureRunFetchTimeout(timeoutMs, deps) {
11793
- if (deps?.mode === "jagent") return;
12305
+ if (deps?.runtime === "jagent") return;
11794
12306
  deps?.configureFetchTimeout?.(timeoutMs);
11795
12307
  }
11796
12308
  function requireCurrentGroupAlertSessionID(client, command2) {
@@ -12233,7 +12745,7 @@ function localFileUnsupported(command2, flag) {
12233
12745
  );
12234
12746
  }
12235
12747
  function assertLocalFileAvailable(command2, flag, deps) {
12236
- if (deps?.mode === "jagent") {
12748
+ if (deps?.runtime === "jagent") {
12237
12749
  throw localFileUnsupported(command2, flag);
12238
12750
  }
12239
12751
  }
@@ -12302,7 +12814,7 @@ function brokerStdinNeedsIntentId(stdin) {
12302
12814
  return input.dryRun === false;
12303
12815
  }
12304
12816
  async function handleBroker(client, brokerArgv, deps) {
12305
- let argv = brokerArgv;
12817
+ let argv = [...brokerArgv];
12306
12818
  const isOrderPlace = brokerArgv[0] === "order" && brokerArgv[1] === "place";
12307
12819
  const hasFlag = (name) => brokerArgv.some((a) => a === name || a.startsWith(`${name}=`));
12308
12820
  const hasHandle = hasFlag("--intent-id") || hasFlag("--client-order-id");
@@ -12320,7 +12832,8 @@ async function handleBroker(client, brokerArgv, deps) {
12320
12832
  throw new Error("Broker live orders require a runtime UUID provider.");
12321
12833
  }
12322
12834
  const intentId = randomUUID();
12323
- deps?.stderr?.write(`alva broker: intent-id ${intentId}
12835
+ const brokerLabel = deps?.runtime === "jagent" ? "alva trading broker" : "alva broker";
12836
+ deps?.stderr?.write(`${brokerLabel}: intent-id ${intentId}
12324
12837
  `);
12325
12838
  argv = [...brokerArgv, "--intent-id", intentId];
12326
12839
  }
@@ -12341,7 +12854,7 @@ async function handleBroker(client, brokerArgv, deps) {
12341
12854
  };
12342
12855
  exit = 2;
12343
12856
  }
12344
- if (deps?.mode === "jagent") {
12857
+ if (deps?.runtime === "jagent") {
12345
12858
  return envelope;
12346
12859
  }
12347
12860
  if (!deps?.writeBrokerResult) {
@@ -12350,28 +12863,11 @@ async function handleBroker(client, brokerArgv, deps) {
12350
12863
  await deps.writeBrokerResult(envelope, exit);
12351
12864
  return void 0;
12352
12865
  }
12353
- async function dispatch(client, args, meta, deps) {
12354
- const group = args[0];
12355
- if (group === "-v" || group === "--version") {
12356
- return `alva version ${CLI_VERSION}`;
12357
- }
12358
- if (!group || group === "--help" || group === "-h") {
12359
- return { _help: true, text: HELP_TEXT };
12360
- }
12361
- if (COMMAND_HELP[group] && (args[1] === "--help" || args[1] === "-h")) {
12362
- return { _help: true, text: COMMAND_HELP[group] };
12363
- }
12364
- if (group === "broker") {
12365
- return handleBroker(client, args.slice(1), deps);
12366
- }
12367
- const parsedCommand = parseCommand(args);
12866
+ async function executeParsedCommand(client, parsedCommand, meta, deps) {
12867
+ const group = parsedCommand.path[0];
12368
12868
  const subcommand = parsedCommand.path[1];
12369
12869
  const flags = parsedCommand.flags;
12370
12870
  const positionals = parsedCommand.positionals;
12371
- if (flags["help"] !== void 0) {
12372
- const helpText = COMMAND_HELP[group];
12373
- if (helpText) return { _help: true, text: helpText };
12374
- }
12375
12871
  if (group === "whoami") {
12376
12872
  const user = await client.user.me();
12377
12873
  const record = projectUserProfileForCLI(
@@ -13212,10 +13708,10 @@ async function dispatch(client, args, meta, deps) {
13212
13708
  const { exitCode, output } = await handleLintPlaybook({
13213
13709
  file,
13214
13710
  format,
13215
- client: deps?.mode === "jagent" ? client : void 0,
13711
+ client: deps?.runtime === "jagent" ? client : void 0,
13216
13712
  readFile: deps?.localFiles?.readText
13217
13713
  });
13218
- if (deps?.mode === "jagent") {
13714
+ if (deps?.runtime === "jagent") {
13219
13715
  if (exitCode !== 0) throw new Error(output);
13220
13716
  return output;
13221
13717
  }
@@ -13999,40 +14495,448 @@ async function dispatch(client, args, meta, deps) {
13999
14495
  throw new CliUsageError(`Unknown command: '${group}'`);
14000
14496
  }
14001
14497
  }
14002
- function stripGlobalFlags(argv) {
14003
- const result = [];
14004
- for (let i = 0; i < argv.length; i++) {
14005
- const a = argv[i];
14006
- if (a === "broker") {
14007
- result.push(...argv.slice(i));
14008
- break;
14498
+
14499
+ // src/cli/embeddedDispatch.ts
14500
+ var ALPI_ALVA_COMMAND_PATHS = Object.freeze(
14501
+ EMBEDDED_COMMAND_DEFINITIONS.map((definition) => definition.path.join(" "))
14502
+ );
14503
+ var ALPI_ALVA_COMMAND_PATH_SET = new Set(ALPI_ALVA_COMMAND_PATHS);
14504
+ var HIDDEN_BROKER_COMMANDS = /* @__PURE__ */ new Set([
14505
+ "accounts",
14506
+ "risk-rules",
14507
+ "venues",
14508
+ "help"
14509
+ ]);
14510
+ function selectedEmbeddedFlagValues(parsed, names) {
14511
+ return Object.fromEntries(
14512
+ names.flatMap((name) => {
14513
+ const value = parsed.flags[name];
14514
+ return value === void 0 ? [] : [[name, value]];
14515
+ })
14516
+ );
14517
+ }
14518
+ function internalCommand(path, flags = {}) {
14519
+ return { path, flags, positionals: [] };
14520
+ }
14521
+ function automationID(parsed, command2) {
14522
+ return requirePositiveIntegerStringFlag(parsed.flags, "id", command2);
14523
+ }
14524
+ function producerIDFromAutomationDetail(detail, automationId) {
14525
+ if (typeof detail !== "object" || detail === null || Array.isArray(detail)) {
14526
+ throw new Error(`Automation ${automationId} returned an invalid detail`);
14527
+ }
14528
+ const raw = detail.cronjob_id;
14529
+ if (raw === void 0 || raw === null) return void 0;
14530
+ if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw <= 0) {
14531
+ throw new Error(`Automation ${automationId} returned an invalid producer`);
14532
+ }
14533
+ return raw;
14534
+ }
14535
+ function producerIDFromCreate(result) {
14536
+ if (typeof result !== "object" || result === null) {
14537
+ throw new Error("Automation producer creation returned an invalid result");
14538
+ }
14539
+ const raw = result.id;
14540
+ if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw <= 0) {
14541
+ throw new Error("Automation producer creation returned an invalid id");
14542
+ }
14543
+ return raw;
14544
+ }
14545
+ async function resolveAutomationProducer(client, automationId) {
14546
+ const detail = await client.automation.inspect({ id: automationId });
14547
+ const producerId = producerIDFromAutomationDetail(detail, automationId);
14548
+ if (producerId === void 0) {
14549
+ throw new Error(`Automation ${automationId} has no active producer`);
14550
+ }
14551
+ return producerId;
14552
+ }
14553
+ async function findAutomationProducer(client, automationId) {
14554
+ const detail = await client.automation.inspect({ id: automationId });
14555
+ return producerIDFromAutomationDetail(detail, automationId);
14556
+ }
14557
+ async function dispatchEmbeddedAutomation(client, parsed, meta, deps) {
14558
+ const definition = embeddedCommandDefinition(parsed.path);
14559
+ switch (definition.action) {
14560
+ case "automation-inspect": {
14561
+ const id = automationID(parsed, "automation inspect");
14562
+ const result = await client.automation.inspect({ id });
14563
+ return parsed.flags.json === "true" ? result : formatAutomationDetail(result);
14564
+ }
14565
+ case "automation-set-visibility": {
14566
+ const id = automationID(parsed, "automation set-visibility");
14567
+ const visibility = requireFlag(
14568
+ parsed.flags,
14569
+ "visibility",
14570
+ "automation set-visibility"
14571
+ );
14572
+ if (visibility !== "public" && visibility !== "private") {
14573
+ throw new CliUsageError(
14574
+ `--visibility must be one of public, private for 'automation set-visibility', got '${visibility}'`,
14575
+ "automation"
14576
+ );
14577
+ }
14578
+ return client.feed.setVisibility({ id, visibility });
14579
+ }
14580
+ case "automation-create": {
14581
+ const name = requireFlag(parsed.flags, "name", "automation create");
14582
+ requireFlag(parsed.flags, "path", "automation create");
14583
+ requireFlag(parsed.flags, "cron", "automation create");
14584
+ const version = requireFlag(parsed.flags, "version", "automation create");
14585
+ const producer = await executeParsedCommand(
14586
+ client,
14587
+ internalCommand(
14588
+ ["deploy", "create"],
14589
+ selectedEmbeddedFlagValues(parsed, [
14590
+ "name",
14591
+ "path",
14592
+ "cron",
14593
+ "args",
14594
+ "max-heap-size-mb",
14595
+ "execution-timeout-seconds",
14596
+ "run-as-service-account",
14597
+ "push-notify"
14598
+ ])
14599
+ ),
14600
+ meta,
14601
+ deps
14602
+ );
14603
+ const cronjobId = producerIDFromCreate(producer);
14604
+ try {
14605
+ const automation = await executeParsedCommand(
14606
+ client,
14607
+ internalCommand(["automation", "publish"], {
14608
+ name,
14609
+ version,
14610
+ "cronjob-id": String(cronjobId),
14611
+ ...selectedEmbeddedFlagValues(parsed, [
14612
+ "view-json",
14613
+ "description",
14614
+ "changelog",
14615
+ "agent-type",
14616
+ "skip-auto-trigger"
14617
+ ])
14618
+ }),
14619
+ meta,
14620
+ deps
14621
+ );
14622
+ return { automation, producer };
14623
+ } catch (error) {
14624
+ throw new Error(
14625
+ `Automation registration failed after producer ${cronjobId} was created; the producer was left intact for recovery: ${error instanceof Error ? error.message : String(error)}`
14626
+ );
14627
+ }
14009
14628
  }
14010
- if (GLOBAL_VALUE_FLAG_SET.has(a)) {
14011
- const value = argv[i + 1];
14012
- if (value === void 0 || value.startsWith("--")) {
14013
- throw new CliUsageError(`${a} requires a value`);
14629
+ case "automation-update": {
14630
+ const id = automationID(parsed, "automation update");
14631
+ const producerFlags = selectedEmbeddedFlagValues(parsed, [
14632
+ "name",
14633
+ "cron",
14634
+ "args",
14635
+ "max-heap-size-mb",
14636
+ "execution-timeout-seconds",
14637
+ "run-as-service-account",
14638
+ "push-notify",
14639
+ "clear-run-as"
14640
+ ]);
14641
+ const productFlags = selectedEmbeddedFlagValues(parsed, [
14642
+ "version",
14643
+ "description",
14644
+ "changelog",
14645
+ "agent-type"
14646
+ ]);
14647
+ if (Object.keys(producerFlags).length === 0 && Object.keys(productFlags).length === 0) {
14648
+ throw new CliUsageError(
14649
+ "'automation update' requires at least one update field",
14650
+ "automation"
14651
+ );
14014
14652
  }
14015
- i++;
14016
- continue;
14653
+ let cronjobId;
14654
+ let producer;
14655
+ if (Object.keys(producerFlags).length > 0) {
14656
+ cronjobId = await resolveAutomationProducer(client, id);
14657
+ producer = await executeParsedCommand(
14658
+ client,
14659
+ internalCommand(["deploy", "update"], {
14660
+ id: String(cronjobId),
14661
+ ...producerFlags
14662
+ }),
14663
+ meta,
14664
+ deps
14665
+ );
14666
+ }
14667
+ let automation;
14668
+ if (Object.keys(productFlags).length > 0) {
14669
+ try {
14670
+ automation = await executeParsedCommand(
14671
+ client,
14672
+ internalCommand(["automation", "update"], {
14673
+ id: String(id),
14674
+ ...productFlags
14675
+ }),
14676
+ meta,
14677
+ deps
14678
+ );
14679
+ } catch (error) {
14680
+ const suffix = Object.keys(producerFlags).length === 0 ? "" : ` after producer ${cronjobId} was updated`;
14681
+ throw new Error(
14682
+ `Automation ${id} metadata update failed${suffix}: ${error instanceof Error ? error.message : String(error)}`
14683
+ );
14684
+ }
14685
+ }
14686
+ return {
14687
+ automation_id: String(id),
14688
+ cronjob_id: cronjobId,
14689
+ automation,
14690
+ producer
14691
+ };
14017
14692
  }
14018
- if (GLOBAL_VALUE_FLAGS.some((flag) => a.startsWith(`${flag}=`))) {
14019
- continue;
14693
+ case "automation-pause": {
14694
+ const id = automationID(parsed, "automation pause");
14695
+ const cronjobId = await resolveAutomationProducer(client, id);
14696
+ await executeParsedCommand(
14697
+ client,
14698
+ internalCommand(["deploy", "pause"], { id: String(cronjobId) }),
14699
+ meta,
14700
+ deps
14701
+ );
14702
+ try {
14703
+ await client.automation.stop({ id });
14704
+ } catch (error) {
14705
+ throw new Error(
14706
+ `Automation ${id} delivery pause failed after producer ${cronjobId} was paused: ${error instanceof Error ? error.message : String(error)}`
14707
+ );
14708
+ }
14709
+ return {
14710
+ automation_id: String(id),
14711
+ cronjob_id: cronjobId,
14712
+ status: "paused"
14713
+ };
14714
+ }
14715
+ case "automation-resume": {
14716
+ const id = automationID(parsed, "automation resume");
14717
+ const cronjobId = await resolveAutomationProducer(client, id);
14718
+ await client.automation.resume({ id });
14719
+ try {
14720
+ await executeParsedCommand(
14721
+ client,
14722
+ internalCommand(["deploy", "resume"], { id: String(cronjobId) }),
14723
+ meta,
14724
+ deps
14725
+ );
14726
+ } catch (error) {
14727
+ throw new Error(
14728
+ `Producer ${cronjobId} resume failed after automation ${id} delivery was resumed: ${error instanceof Error ? error.message : String(error)}`
14729
+ );
14730
+ }
14731
+ return {
14732
+ automation_id: String(id),
14733
+ cronjob_id: cronjobId,
14734
+ status: "active"
14735
+ };
14736
+ }
14737
+ case "automation-delete": {
14738
+ const id = automationID(parsed, "automation delete");
14739
+ const cronjobId = await findAutomationProducer(client, id);
14740
+ if (cronjobId === void 0) {
14741
+ await client.automation.delete({ id });
14742
+ return {
14743
+ automation_id: id,
14744
+ status: "deleted"
14745
+ };
14746
+ }
14747
+ await executeParsedCommand(
14748
+ client,
14749
+ internalCommand(["deploy", "pause"], { id: String(cronjobId) }),
14750
+ meta,
14751
+ deps
14752
+ );
14753
+ try {
14754
+ await client.automation.delete({ id });
14755
+ } catch (error) {
14756
+ throw new Error(
14757
+ `Automation ${id} delete failed after producer ${cronjobId} was paused; the producer remains paused: ${error instanceof Error ? error.message : String(error)}`
14758
+ );
14759
+ }
14760
+ return {
14761
+ automation_id: String(id),
14762
+ cronjob_id: cronjobId,
14763
+ status: "deleted"
14764
+ };
14765
+ }
14766
+ case "automation-trigger": {
14767
+ const id = automationID(parsed, "automation trigger");
14768
+ const cronjobId = await resolveAutomationProducer(client, id);
14769
+ return executeParsedCommand(
14770
+ client,
14771
+ internalCommand(["deploy", "trigger"], { id: String(cronjobId) }),
14772
+ meta,
14773
+ deps
14774
+ );
14775
+ }
14776
+ case "automation-runs-list":
14777
+ case "automation-runs-status":
14778
+ case "automation-runs-logs": {
14779
+ const command2 = parsed.path.join(" ");
14780
+ const id = automationID(parsed, command2);
14781
+ const cronjobId = await resolveAutomationProducer(client, id);
14782
+ const target = definition.action === "automation-runs-list" ? "runs" : definition.action === "automation-runs-status" ? "run-status" : "run-logs";
14783
+ const extra = definition.action === "automation-runs-list" ? selectedEmbeddedFlagValues(parsed, ["first", "cursor"]) : definition.action === "automation-runs-status" ? selectedEmbeddedFlagValues(parsed, ["workflow-run-id"]) : selectedEmbeddedFlagValues(parsed, ["run-id"]);
14784
+ return executeParsedCommand(
14785
+ client,
14786
+ internalCommand(["deploy", target], {
14787
+ id: String(cronjobId),
14788
+ ...extra
14789
+ }),
14790
+ meta,
14791
+ deps
14792
+ );
14793
+ }
14794
+ default:
14795
+ throw new Error(
14796
+ `Agent automation route '${parsed.path.join(" ")}' has no handler`
14797
+ );
14798
+ }
14799
+ }
14800
+ async function dispatchEmbedded(client, args, meta, deps) {
14801
+ const group = args[0];
14802
+ if (group === "-v" || group === "--version") {
14803
+ return `alva version ${CLI_VERSION}`;
14804
+ }
14805
+ if (!group || group === "--help" || group === "-h") {
14806
+ return { _help: true, text: AGENT_HELP_TEXT };
14807
+ }
14808
+ const requestedHelpIndex = args.findIndex(
14809
+ (argument) => argument === "--help" || argument === "-h"
14810
+ );
14811
+ const requestedHelp = requestedHelpIndex !== -1;
14812
+ const brokerNativeHelp = args[0] === "trading" && args[1] === "broker" && requestedHelpIndex > 2;
14813
+ const bareHelp = args.every((argument) => !argument.startsWith("-")) ? AGENT_COMMAND_HELP[args.join(" ")] : void 0;
14814
+ if (bareHelp !== void 0) {
14815
+ return { _help: true, text: bareHelp };
14816
+ }
14817
+ if (requestedHelp && !brokerNativeHelp) {
14818
+ const helpIndex = requestedHelpIndex;
14819
+ const helpPath = args.slice(0, helpIndex);
14820
+ const treeHelp = helpIndex === args.length - 1 && helpPath.every((argument) => !argument.startsWith("-")) ? AGENT_COMMAND_HELP[helpPath.join(" ")] : void 0;
14821
+ if (treeHelp !== void 0 && !ALPI_ALVA_COMMAND_PATH_SET.has(helpPath.join(" "))) {
14822
+ return { _help: true, text: treeHelp };
14823
+ }
14824
+ }
14825
+ const parsed = parseEmbeddedCommand(args);
14826
+ if (requestedHelp && !brokerNativeHelp || parsed.flags.help !== void 0) {
14827
+ return {
14828
+ _help: true,
14829
+ text: agentHelpFor(args) ?? AGENT_HELP_TEXT
14830
+ };
14831
+ }
14832
+ const action2 = embeddedCommandDefinition(parsed.path).action;
14833
+ if (action2?.startsWith("automation-")) {
14834
+ return dispatchEmbeddedAutomation(client, parsed, meta, deps);
14835
+ }
14836
+ if (parsed.path.join(" ") === "trading broker") {
14837
+ const brokerArgv = parsed.passthrough ?? [];
14838
+ const command2 = brokerArgv[0];
14839
+ if (HIDDEN_BROKER_COMMANDS.has(command2)) {
14840
+ const replacement = command2 === "accounts" || command2 === "risk-rules" ? `alva trading ${command2}` : "alva trading broker describe";
14841
+ throw new CliUsageError(
14842
+ `'trading broker ${command2}' is not part of the Slim Broker tree; use '${replacement}'`,
14843
+ "trading"
14844
+ );
14845
+ }
14846
+ const commandSelector = brokerArgv.findIndex(
14847
+ (argument) => argument === "--command"
14848
+ );
14849
+ const describedCommand = brokerArgv[commandSelector + 1];
14850
+ if (command2 === "describe" && commandSelector !== -1 && HIDDEN_BROKER_COMMANDS.has(describedCommand)) {
14851
+ const message = describedCommand === "accounts" || describedCommand === "risk-rules" ? `Shared trading prerequisites are described by 'alva trading ${describedCommand}'` : `'trading broker describe --command ${describedCommand}' is not part of the Slim Broker tree`;
14852
+ throw new CliUsageError(message, "trading");
14853
+ }
14854
+ const result = await handleBroker(client, brokerArgv, deps);
14855
+ return command2 === "describe" ? adaptEmbeddedBrokerDescription(result) : result;
14856
+ }
14857
+ return dispatchEmbeddedTarget(client, parsed, meta, deps);
14858
+ }
14859
+ async function dispatchEmbeddedTarget(client, parsed, meta, deps) {
14860
+ const definition = embeddedCommandDefinition(parsed.path);
14861
+ let target;
14862
+ if (definition.action === "notification-set-preference") {
14863
+ const value = parsed.flags["session-completed"];
14864
+ if (value !== "enabled" && value !== "disabled") {
14865
+ throw new CliUsageError(
14866
+ "--session-completed must be 'enabled' or 'disabled' for 'account notifications set-preference'",
14867
+ "account"
14868
+ );
14020
14869
  }
14021
- result.push(a);
14870
+ target = internalCommand([
14871
+ "notification-preferences",
14872
+ value === "enabled" ? "enable-session-completed" : "disable-session-completed"
14873
+ ]);
14874
+ } else if (definition.action === "signal-execute") {
14875
+ const { live, ...flags } = parsed.flags;
14876
+ target = {
14877
+ ...parsed,
14878
+ path: ["trading", "execute"],
14879
+ flags: live === "true" ? flags : { ...flags, "dry-run": "true" }
14880
+ };
14881
+ } else if (definition.action === "screenshot") {
14882
+ target = {
14883
+ ...parsed,
14884
+ path: ["screenshot"],
14885
+ flags: { ...parsed.flags, base64: "true" }
14886
+ };
14887
+ } else if (definition.targetPath !== void 0) {
14888
+ target = { ...parsed, path: definition.targetPath };
14889
+ } else {
14890
+ throw new Error(
14891
+ `Embedded command '${parsed.path.join(" ")}' has no execution path`
14892
+ );
14022
14893
  }
14023
- return result;
14894
+ try {
14895
+ if (target.path[0] === "broker") {
14896
+ return await handleBroker(
14897
+ client,
14898
+ [...target.path.slice(1), ...target.passthrough ?? []],
14899
+ deps
14900
+ );
14901
+ }
14902
+ return await executeParsedCommand(client, target, meta, deps);
14903
+ } catch (error) {
14904
+ if (!(error instanceof CliUsageError)) throw error;
14905
+ const targetName = target.path.join(" ");
14906
+ const command2 = parsed.path.join(" ");
14907
+ const message = error.message.replaceAll(targetName, command2);
14908
+ throw new CliUsageError(message, parsed.path[0]);
14909
+ }
14910
+ }
14911
+ function adaptEmbeddedBrokerDescription(value, key) {
14912
+ if (typeof value === "string") {
14913
+ return value.replaceAll("alva broker accounts", "alva trading accounts").replaceAll("alva broker risk-rules", "alva trading risk-rules").replaceAll("alva broker", "alva trading broker");
14914
+ }
14915
+ if (Array.isArray(value)) {
14916
+ const items = key === "commands" ? value.filter((item) => {
14917
+ if (typeof item !== "object" || item === null) return true;
14918
+ const name = item.name;
14919
+ return name !== "accounts" && name !== "risk-rules" && name !== "venues" && name !== "help";
14920
+ }) : value;
14921
+ return items.map((item) => adaptEmbeddedBrokerDescription(item));
14922
+ }
14923
+ if (typeof value !== "object" || value === null) return value;
14924
+ return Object.fromEntries(
14925
+ Object.entries(value).map(([field, item]) => [
14926
+ field,
14927
+ adaptEmbeddedBrokerDescription(item, field)
14928
+ ])
14929
+ );
14930
+ }
14931
+ async function dispatch(client, args, meta, deps) {
14932
+ return dispatchEmbedded(client, args, meta, { ...deps, runtime: "jagent" });
14024
14933
  }
14025
14934
  export {
14026
- BOOLEAN_FLAGS,
14935
+ ALPI_ALVA_COMMAND_PATHS,
14027
14936
  CLI_VERSION,
14028
- COMMAND_HELP,
14029
14937
  CliUsageError,
14030
14938
  DEFAULT_RUN_TIMEOUT_MS,
14031
- HELP_TEXT,
14032
- dispatch,
14033
- isVersionOlderThan,
14034
- parseFlags,
14035
- stripGlobalFlags
14939
+ dispatch
14036
14940
  };
14037
14941
  /*! Bundled license information:
14038
14942