@alva-ai/toolkit 0.29.0 → 0.32.0-beta.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.
package/dist/cli.js CHANGED
@@ -6707,6 +6707,166 @@ function connection(value) {
6707
6707
  return invalidResponse();
6708
6708
  return value;
6709
6709
  }
6710
+ var THESIS_RECOMMENDATION_QUERY = `
6711
+ query ToolkitForYouTheses($input: ThesisRecommendationInput) {
6712
+ viewer {
6713
+ thesisRecommendations(input: $input) {
6714
+ listId pageCursor nextCursor exhausted scanLimited
6715
+ pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
6716
+ edges {
6717
+ cursor
6718
+ node {
6719
+ itemKey
6720
+ publication {
6721
+ thesisId playbookId authorVersionId materialVersionId itemKey
6722
+ title body publishedAtMs changeKind visibility
6723
+ closed archived note closingNote researchPaused
6724
+ entityIds categoryIds
6725
+ entityStances { entityId stance }
6726
+ entities { id ticker name }
6727
+ publisher {
6728
+ id displayName avatarUrl bio followersCount
6729
+ viewerState { following }
6730
+ }
6731
+ medias { type coverUrl url }
6732
+ signalFeed { id }
6733
+ snapshotRelease {
6734
+ versionId materialVersionId publishedAtMs changeKind
6735
+ sourceRefs {
6736
+ title sourceKind sourceContentId publicUrl sourceTimeMs locator
6737
+ }
6738
+ }
6739
+ }
6740
+ }
6741
+ }
6742
+ }
6743
+ }
6744
+ }
6745
+ `.trim();
6746
+ function validateForYouThesesParams(params) {
6747
+ if (!record(params)) throw new Error("Thesis parameters must be an object");
6748
+ const first = params.first === void 0 ? 10 : params.first;
6749
+ if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 10) {
6750
+ throw new Error("first must be an integer between 1 and 10");
6751
+ }
6752
+ if (params.after !== void 0 && (typeof params.after !== "string" || !params.after.trim())) {
6753
+ throw new Error("after must be a non-empty cursor");
6754
+ }
6755
+ }
6756
+ function graphqlViewerField(response, field) {
6757
+ if (!record(response)) {
6758
+ throw new AlvaError(
6759
+ "GRAPHQL_INVALID_RESPONSE",
6760
+ `GraphQL returned an invalid viewer.${field} response`,
6761
+ 502
6762
+ );
6763
+ }
6764
+ if (response.errors !== void 0) {
6765
+ if (!Array.isArray(response.errors)) {
6766
+ throw new AlvaError(
6767
+ "GRAPHQL_INVALID_RESPONSE",
6768
+ `GraphQL returned an invalid viewer.${field} response`,
6769
+ 502
6770
+ );
6771
+ }
6772
+ if (response.errors.length > 0) {
6773
+ const messages = response.errors.flatMap(
6774
+ (error) => record(error) && typeof error.message === "string" ? [error.message] : []
6775
+ );
6776
+ throw new AlvaError(
6777
+ "GRAPHQL_ERROR",
6778
+ messages.join("; ") || "GraphQL request failed",
6779
+ 400,
6780
+ { errors: response.errors }
6781
+ );
6782
+ }
6783
+ }
6784
+ if (!record(response.data) || !record(response.data.viewer) || response.data.viewer[field] == null) {
6785
+ throw new AlvaError(
6786
+ "GRAPHQL_EMPTY_RESPONSE",
6787
+ `GraphQL response did not include viewer.${field}`,
6788
+ 502
6789
+ );
6790
+ }
6791
+ return response.data.viewer[field];
6792
+ }
6793
+ function invalidPage() {
6794
+ throw new AlvaError(
6795
+ "GRAPHQL_INVALID_RESPONSE",
6796
+ "GraphQL returned an invalid Thesis recommendation page",
6797
+ 502
6798
+ );
6799
+ }
6800
+ function positiveInt64List(value) {
6801
+ return Array.isArray(value) && value.every(isPositiveInt64);
6802
+ }
6803
+ function stanceList(value) {
6804
+ return Array.isArray(value) && value.every(
6805
+ (item) => record(item) && isPositiveInt64(item.entityId) && typeof item.stance === "string" && item.stance.trim() !== ""
6806
+ );
6807
+ }
6808
+ function entityList(value) {
6809
+ return Array.isArray(value) && value.every(
6810
+ (item) => record(item) && typeof item.id === "string" && item.id.trim() !== "" && typeof item.ticker === "string" && typeof item.name === "string"
6811
+ );
6812
+ }
6813
+ function mediaList(value) {
6814
+ return Array.isArray(value) && value.every(
6815
+ (item) => record(item) && typeof item.type === "string" && item.type.trim() !== "" && typeof item.coverUrl === "string" && (item.url === null || typeof item.url === "string")
6816
+ );
6817
+ }
6818
+ function sourceRefList(value) {
6819
+ return Array.isArray(value) && value.every(
6820
+ (item) => record(item) && (item.title === null || typeof item.title === "string") && typeof item.sourceKind === "string" && typeof item.sourceContentId === "string" && typeof item.publicUrl === "string" && nullableMs(item.sourceTimeMs) && typeof item.locator === "string"
6821
+ );
6822
+ }
6823
+ function nullableMs(value) {
6824
+ return value === null || typeof value === "number" && Number.isFinite(value);
6825
+ }
6826
+ function snapshot(value) {
6827
+ return record(value) && isPositiveInt64(value.versionId) && isPositiveInt64(value.materialVersionId) && typeof value.publishedAtMs === "number" && Number.isFinite(value.publishedAtMs) && typeof value.changeKind === "string" && value.changeKind.trim() !== "" && sourceRefList(value.sourceRefs);
6828
+ }
6829
+ function publisher(value) {
6830
+ return record(value) && typeof value.id === "string" && value.id.trim() !== "" && typeof value.displayName === "string" && typeof value.avatarUrl === "string" && typeof value.bio === "string" && typeof value.followersCount === "number" && Number.isInteger(value.followersCount) && record(value.viewerState) && (value.viewerState.following === null || typeof value.viewerState.following === "boolean");
6831
+ }
6832
+ function publication(value) {
6833
+ if (!record(value)) return false;
6834
+ for (const field of [
6835
+ "thesisId",
6836
+ "playbookId",
6837
+ "authorVersionId",
6838
+ "materialVersionId"
6839
+ ]) {
6840
+ if (!isPositiveInt64(value[field])) return false;
6841
+ }
6842
+ if (typeof value.itemKey !== "string" || !value.itemKey.trim() || typeof value.title !== "string" || typeof value.body !== "string" || typeof value.publishedAtMs !== "number" || !Number.isFinite(value.publishedAtMs) || typeof value.changeKind !== "string" || !value.changeKind.trim() || typeof value.visibility !== "string" || typeof value.note !== "string" || typeof value.closingNote !== "string") {
6843
+ return false;
6844
+ }
6845
+ for (const field of ["closed", "archived", "researchPaused"]) {
6846
+ if (typeof value[field] !== "boolean") return false;
6847
+ }
6848
+ if (!positiveInt64List(value.entityIds) || !positiveInt64List(value.categoryIds) || !stanceList(value.entityStances) || !entityList(value.entities) || !mediaList(value.medias) || !publisher(value.publisher) || !snapshot(value.snapshotRelease)) {
6849
+ return false;
6850
+ }
6851
+ return value.signalFeed === null || record(value.signalFeed) && isPositiveInt64(value.signalFeed.id);
6852
+ }
6853
+ function recommendationPage(value) {
6854
+ if (!record(value) || !Array.isArray(value.edges) || !record(value.pageInfo) || typeof value.listId !== "string" || typeof value.pageCursor !== "string" || typeof value.exhausted !== "boolean" || typeof value.scanLimited !== "boolean" || value.nextCursor !== null && typeof value.nextCursor !== "string") {
6855
+ return invalidPage();
6856
+ }
6857
+ const page = value.pageInfo;
6858
+ if (typeof page.startCursor !== "string" || typeof page.endCursor !== "string" || typeof page.hasNextPage !== "boolean" || typeof page.hasPreviousPage !== "boolean" || page.hasNextPage !== (value.nextCursor !== null)) {
6859
+ return invalidPage();
6860
+ }
6861
+ for (const edge of value.edges) {
6862
+ if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node) || typeof edge.node.itemKey !== "string" || !edge.node.itemKey.trim() || !publication(edge.node.publication)) {
6863
+ return invalidPage();
6864
+ }
6865
+ }
6866
+ const first = value.edges[0];
6867
+ if (page.startCursor !== (first?.cursor ?? "")) return invalidPage();
6868
+ return value;
6869
+ }
6710
6870
  var ForYouResource = class {
6711
6871
  constructor(client) {
6712
6872
  this.client = client;
@@ -6729,29 +6889,29 @@ var ForYouResource = class {
6729
6889
  }
6730
6890
  }
6731
6891
  });
6732
- if (!record(response)) return invalidResponse();
6733
- if (response.errors !== void 0) {
6734
- if (!Array.isArray(response.errors)) return invalidResponse();
6735
- if (response.errors.length > 0) {
6736
- const messages = response.errors.flatMap(
6737
- (error) => record(error) && typeof error.message === "string" ? [error.message] : []
6738
- );
6739
- throw new AlvaError(
6740
- "GRAPHQL_ERROR",
6741
- messages.join("; ") || "GraphQL request failed",
6742
- 400,
6743
- { errors: response.errors }
6744
- );
6892
+ return connection(graphqlViewerField(response, "forYou"));
6893
+ }
6894
+ /**
6895
+ * One ranked page of Thesis recommendations -- the stream the Feed App reads,
6896
+ * which is not the chronological `list` stream. Page to `exhausted` and filter
6897
+ * on `publication.publishedAtMs` yourself; the order is slot-mixed, so a time
6898
+ * bound is never a reason to stop paging. Publications the viewer already saw
6899
+ * are withheld by an upstream cooldown, so a window read is "recommended and
6900
+ * recent", not every publication in the window.
6901
+ */
6902
+ async theses(params = {}) {
6903
+ validateForYouThesesParams(params);
6904
+ this.client._requireAuth();
6905
+ const response = await this.client._request("POST", "/query", {
6906
+ body: {
6907
+ query: THESIS_RECOMMENDATION_QUERY,
6908
+ variables: {
6909
+ input: { first: params.first ?? 10, after: params.after }
6910
+ }
6745
6911
  }
6746
- }
6747
- if (!record(response.data) || !record(response.data.viewer) || response.data.viewer.forYou == null) {
6748
- throw new AlvaError(
6749
- "GRAPHQL_EMPTY_RESPONSE",
6750
- "GraphQL response did not include viewer.forYou",
6751
- 502
6752
- );
6753
- }
6754
- return connection(response.data.viewer.forYou);
6912
+ });
6913
+ const field = graphqlViewerField(response, "thesisRecommendations");
6914
+ return recommendationPage(field);
6755
6915
  }
6756
6916
  };
6757
6917
 
@@ -9669,9 +9829,7 @@ function requireDeliveryId(value, label = "delivery id") {
9669
9829
  throw invalid2(`${label} must be a positive integer`);
9670
9830
  return value;
9671
9831
  }
9672
- function requireDeliveryIds(values) {
9673
- if (values.length === 0)
9674
- throw invalid2("at least one delivery id is required");
9832
+ function normalizeDeliveryIds(values) {
9675
9833
  const unique = /* @__PURE__ */ new Set();
9676
9834
  for (const value of values) {
9677
9835
  requireDeliveryId(value);
@@ -9680,6 +9838,11 @@ function requireDeliveryIds(values) {
9680
9838
  }
9681
9839
  return [...unique];
9682
9840
  }
9841
+ function requireDeliveryIds(values) {
9842
+ if (values.length === 0)
9843
+ throw invalid2("at least one delivery id is required");
9844
+ return normalizeDeliveryIds(values);
9845
+ }
9683
9846
  function requireDecision(value) {
9684
9847
  if (!DECISIONS.has(value))
9685
9848
  throw invalid2("decision must be one of immediate, digest, suppress");
@@ -9762,7 +9925,10 @@ var StewardResource = class {
9762
9925
  inboxPath: requireInboxPath(params),
9763
9926
  requestId: requireRequestId(params.requestId),
9764
9927
  body: params.body,
9765
- deliveryIds: requireDeliveryIds(params.deliveryIds)
9928
+ // A For-You-only Brief covers no ledger delivery, so an empty (or
9929
+ // omitted) set is valid here; the backend accepts it. `briefed` still
9930
+ // requires ids.
9931
+ deliveryIds: normalizeDeliveryIds(params.deliveryIds ?? [])
9766
9932
  }
9767
9933
  });
9768
9934
  const message = data.postStewardMessage?.message;
@@ -10036,6 +10202,56 @@ var ThesesResource = class {
10036
10202
  this.client = client;
10037
10203
  }
10038
10204
  client;
10205
+ async assetCandidates(text) {
10206
+ this.client._requireAuth();
10207
+ const source = requireBody(text);
10208
+ const response = await this.client._request("POST", "/query", {
10209
+ body: {
10210
+ query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
10211
+ viewer { thesisAssetCandidates(input: $input) {
10212
+ mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
10213
+ } }
10214
+ }`,
10215
+ variables: { input: { text: source } }
10216
+ }
10217
+ });
10218
+ if (Array.isArray(response?.errors) && response.errors.length > 0) {
10219
+ throw new AlvaError("GRAPHQL_ERROR", "Asset extraction failed", 400, {
10220
+ errors: response.errors
10221
+ });
10222
+ }
10223
+ const data = response?.data;
10224
+ const viewer = isRecord2(data) ? data.viewer : void 0;
10225
+ const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
10226
+ if (!isRecord2(result) || !Array.isArray(result.mentions)) {
10227
+ throw invalidResponse2("asset candidates response must contain mentions");
10228
+ }
10229
+ const mentions = result.mentions.map((item, index) => {
10230
+ if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
10231
+ item.resolution
10232
+ ) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
10233
+ throw invalidResponse2(`asset mention ${index} is invalid`);
10234
+ }
10235
+ const candidates = item.candidates.map((candidate) => {
10236
+ if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
10237
+ candidate.kind
10238
+ )) {
10239
+ throw invalidResponse2(`asset mention ${index} has invalid candidate`);
10240
+ }
10241
+ return {
10242
+ entityId: responseID(
10243
+ candidate.entityId,
10244
+ `asset mention ${index} candidate.entityId`
10245
+ ),
10246
+ ticker: candidate.ticker,
10247
+ name: candidate.name,
10248
+ kind: candidate.kind
10249
+ };
10250
+ });
10251
+ return { ...item, candidates };
10252
+ });
10253
+ return { mentions };
10254
+ }
10039
10255
  async create(params) {
10040
10256
  this.client._requireAuth();
10041
10257
  const body = createBody(params);
@@ -10180,8 +10396,36 @@ function createBody(params) {
10180
10396
  };
10181
10397
  if (params.tickers !== void 0)
10182
10398
  body.tickers = requireTickers(params.tickers);
10399
+ if (params.entity_stances !== void 0) {
10400
+ body.entity_stances = requireEntityStances(
10401
+ params.entity_stances,
10402
+ body.entity_ids
10403
+ );
10404
+ }
10183
10405
  return body;
10184
10406
  }
10407
+ function requireEntityStances(value, entityIDs) {
10408
+ if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
10409
+ throw invalidArgument("entity_stances must contain at most 100 values");
10410
+ const allowed = new Set(entityIDs);
10411
+ const seen = /* @__PURE__ */ new Set();
10412
+ return value.map((item, index) => {
10413
+ if (!isRecord2(item))
10414
+ throw invalidArgument(`entity_stances[${index}] must be an object`);
10415
+ const entityID = requireID(
10416
+ item.entity_id,
10417
+ `entity_stances[${index}].entity_id`
10418
+ );
10419
+ if (!allowed.has(entityID) || seen.has(entityID))
10420
+ throw invalidArgument(
10421
+ "entity stance must reference one unique entity_id"
10422
+ );
10423
+ seen.add(entityID);
10424
+ if (!["unknown", "bullish", "bearish"].includes(item.stance))
10425
+ throw invalidArgument(`entity_stances[${index}].stance is invalid`);
10426
+ return { entity_id: entityID, stance: item.stance };
10427
+ });
10428
+ }
10185
10429
  function updateBody(params) {
10186
10430
  return {
10187
10431
  request_id: requireRequestID(params.request_id),
@@ -10220,6 +10464,20 @@ function thesisResponse(response) {
10220
10464
  author_kind: responseText(thesis.author_kind, "thesis.author_kind"),
10221
10465
  author_ref: responseText(thesis.author_ref, "thesis.author_ref")
10222
10466
  };
10467
+ if (thesis.entity_stances !== void 0) {
10468
+ if (!Array.isArray(thesis.entity_stances))
10469
+ throw invalidResponse2("thesis.entity_stances must be an array");
10470
+ value.entity_stances = thesis.entity_stances.map((item) => {
10471
+ if (!isRecord2(item))
10472
+ throw invalidResponse2("thesis.entity_stances contains invalid entry");
10473
+ const entityID = responseID(item.entity_id, "entity_stances.entity_id");
10474
+ if (!value.entity_ids.includes(entityID))
10475
+ throw invalidResponse2("entity stance must reference a thesis entity");
10476
+ if (!["unknown", "bullish", "bearish"].includes(item.stance))
10477
+ throw invalidResponse2("thesis.entity_stances contains invalid stance");
10478
+ return { entity_id: entityID, stance: item.stance };
10479
+ });
10480
+ }
10223
10481
  return { thesis: value };
10224
10482
  }
10225
10483
  function thesisGetResponse(response) {
@@ -10383,10 +10641,13 @@ function requireID(value, field) {
10383
10641
  }
10384
10642
  return value;
10385
10643
  }
10644
+ var MAX_ENTITY_IDS = 100;
10386
10645
  function requireIDs(value, field) {
10387
10646
  if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`);
10388
- if (value.length > 20) {
10389
- throw invalidArgument(`${field} must contain at most 20 IDs`);
10647
+ if (value.length > MAX_ENTITY_IDS) {
10648
+ throw invalidArgument(
10649
+ `${field} must contain at most ${MAX_ENTITY_IDS} IDs`
10650
+ );
10390
10651
  }
10391
10652
  return value.map((item, index) => requireID(item, `${field}[${index}]`));
10392
10653
  }
@@ -10457,8 +10718,10 @@ function responseID(value, field) {
10457
10718
  }
10458
10719
  function responseIDs(value, field) {
10459
10720
  if (!Array.isArray(value)) throw invalidResponse2(`${field} must be an array`);
10460
- if (value.length > 20) {
10461
- throw invalidResponse2(`${field} must contain at most 20 IDs`);
10721
+ if (value.length > MAX_ENTITY_IDS) {
10722
+ throw invalidResponse2(
10723
+ `${field} must contain at most ${MAX_ENTITY_IDS} IDs`
10724
+ );
10462
10725
  }
10463
10726
  return value.map((item, index) => responseID(item, `${field}[${index}]`));
10464
10727
  }
@@ -11203,11 +11466,13 @@ var COMMAND_DEFINITIONS = [
11203
11466
  "body-file",
11204
11467
  "title",
11205
11468
  "entity-ids",
11469
+ "entity-stances",
11206
11470
  "tickers",
11207
11471
  "visibility"
11208
11472
  ],
11209
11473
  booleans: ["body-stdin"]
11210
11474
  }),
11475
+ command("thesis asset-candidates", { values: ["text"] }),
11211
11476
  command("thesis get", { values: ["id"] }),
11212
11477
  command("thesis version get", {
11213
11478
  values: ["id", "author-version-id"]
@@ -11294,6 +11559,7 @@ var COMMAND_DEFINITIONS = [
11294
11559
  command("for-you list", {
11295
11560
  values: ["limit", "cursor", "newer-than", "feed-id"]
11296
11561
  }),
11562
+ command("for-you theses", { values: ["limit", "cursor"] }),
11297
11563
  command("credits items", {
11298
11564
  values: ["last", "start", "end", "session-id", "first", "after"],
11299
11565
  booleans: ["today"]
@@ -15903,7 +16169,7 @@ function formatTradingPairResolved(result) {
15903
16169
  }
15904
16170
 
15905
16171
  // src/cli/dispatch.ts
15906
- var CLI_VERSION = true ? "0.29.0" : "dev";
16172
+ var CLI_VERSION = true ? "0.32.0-beta.0" : "dev";
15907
16173
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
15908
16174
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
15909
16175
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -16010,7 +16276,7 @@ Subcommands:
16010
16276
  Flags:
16011
16277
  --inbox-path <path> Steward Session Inbox (terminal CLI only)
16012
16278
  --delivery-id <id> One delivery (decide, forward)
16013
- --delivery-ids <a,b,c> Comma-separated deliveries (send, briefed)
16279
+ --delivery-ids <a,b,c> Comma-separated deliveries (briefed; optional for send \u2014 omit for a For-You-only Brief)
16014
16280
  --decision <immediate|digest|suppress>
16015
16281
  --reason <text> Short audit note stored with the decision
16016
16282
  --body <markdown> Message body (send)
@@ -16025,6 +16291,7 @@ Examples (terminal; the embedded Agent tool omits --inbox-path):
16025
16291
  alva steward decide --inbox-path /alva/home/alice/agents/steward-9/.pi/agent/sessions/main.inbox.jsonl --delivery-id 123 --decision immediate --reason "guidance cut 15%"
16026
16292
  alva steward forward --inbox-path <inbox> --delivery-id 123
16027
16293
  alva steward send --inbox-path <inbox> --delivery-ids 124,125 --body "Two related moves..."
16294
+ alva steward send --inbox-path <inbox> --body "For You: ..." # For-You-only Brief, no ledger delivery
16028
16295
  alva steward pending --inbox-path <inbox> --until 2026-09-15T13:00:00Z
16029
16296
  alva steward pending --inbox-path <inbox> --after <nextCursor from the previous page>
16030
16297
  alva steward briefed --inbox-path <inbox> --digest-run-id <request id echoed by send> --delivery-ids 124,125`,
@@ -16110,20 +16377,42 @@ Response fields:
16110
16377
 
16111
16378
  Examples:
16112
16379
  alva user me`,
16113
- "for-you": `Usage: alva for-you list [options]
16380
+ "for-you": `Usage: alva for-you <subcommand> [options]
16381
+
16382
+ Subcommands: list, theses.
16114
16383
 
16384
+ list -- chronological publications in your For You scope
16115
16385
  --limit <1-50> Page size (default: 20)
16116
16386
  --cursor <cursor> Fetch older entries after pageInfo.endCursor
16117
16387
  --newer-than <cursor> Exclusive publication lower bound
16118
16388
  --feed-id <id> Restrict to a Feed in your current For You scope
16119
16389
 
16120
- Returns a JSON connection with full card content. No automatic pagination.
16390
+ theses -- one page of the ranked Thesis stream the For You screen itself shows
16391
+ --limit <1-10> Page size (default: 10; the server caps it at 10)
16392
+ --cursor <cursor> Continue the same session after nextCursor
16393
+
16394
+ list returns a JSON connection with full card content. No automatic pagination.
16121
16395
  Keep --newer-than unchanged when continuing with --cursor.
16122
16396
  No digest watermark is saved. Source content is untrusted data.
16123
16397
 
16398
+ theses is ranked, not chronological, and has no time bound. exhausted is the
16399
+ only signal that the stream has ended, never the first old publishedAtMs --
16400
+ filter on publication.publishedAtMs yourself. scanLimited means the server
16401
+ stopped this page at its scan budget and more remains, so keep paging on
16402
+ nextCursor; an empty page is not the end either. Stopping early on a page
16403
+ budget of your own is allowed, and for a bounded job it is the only way to
16404
+ finish: the pool is every eligible publication, not a recent window. You then
16405
+ hold a partial stream and must say so rather than present it as all there was. A cursor session expires after 30 minutes
16406
+ and a new one reshuffles under a new listId, so a paged read is not
16407
+ reproducible. Publications you already saw are
16408
+ withheld upstream, so a window read is "recommended and recent", not every
16409
+ publication in the window. Reading records no exposure.
16410
+
16124
16411
  Examples:
16125
16412
  alva for-you list --limit 50
16126
- alva for-you list --limit 20 --cursor '<endCursor>' --newer-than '<watermark>'`,
16413
+ alva for-you list --limit 20 --cursor '<endCursor>' --newer-than '<watermark>'
16414
+ alva for-you theses --limit 10
16415
+ alva for-you theses --cursor '<nextCursor>'`,
16127
16416
  credits: `Usage: alva credits <subcommand> [options]
16128
16417
 
16129
16418
  Read the authenticated user's own credit wallet and consumption history.
@@ -16246,7 +16535,8 @@ At least one of --code, --local-file, or --entry-path is required.
16246
16535
  These three options are mutually exclusive.
16247
16536
 
16248
16537
  Response fields:
16249
- result JSON-encoded return value of the script
16538
+ result The script's return value. Return objects directly; a script
16539
+ returning JSON.stringify(x) is shown as x.
16250
16540
  logs Captured stderr output
16251
16541
  status "completed" or "failed"
16252
16542
  error Error message (when status is "failed")
@@ -16268,13 +16558,14 @@ Constraints:
16268
16558
 
16269
16559
  Examples:
16270
16560
  alva run --code "1 + 2 + 3;"
16271
- alva run --code "JSON.stringify(require('env').args);" --args '{"symbol":"BTC"}'
16561
+ alva run --code "require('env').args;" --args '{"symbol":"BTC"}'
16272
16562
  alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
16273
16563
  alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
16274
16564
  alva run --local-file ./my-script.js --args '{"symbol":"BTC"}'
16275
16565
  printf '%s' '{"symbol":"BTC"}' | alva run --local-file ./my-script.js --args-stdin
16276
16566
  alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
16277
- alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000`,
16567
+ alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000
16568
+ alva run --local-file ./research.js > research.json && jq -c '.result.income[:4]' research.json`,
16278
16569
  deploy: `Usage: alva deploy <subcommand> [options]
16279
16570
 
16280
16571
  Manage scheduled cronjobs that run your scripts on a cron schedule.
@@ -17302,7 +17593,8 @@ the backend; do not send a fresh ID. Create defaults --visibility to public.
17302
17593
  Update requires --visibility explicitly so it cannot inadvertently publish.
17303
17594
 
17304
17595
  Other flags:
17305
- create --request-id <uuid> --body ... [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--visibility <value>]
17596
+ create --request-id <uuid> --body ... [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--entity-stances <json>] [--visibility <value>]
17597
+ asset-candidates --text <unsaved thesis text>
17306
17598
  get --id <signed-int64-decimal>
17307
17599
  version get --id <signed-int64-decimal> --author-version-id <signed-int64-decimal>
17308
17600
  signals --id <id> [--first <1-50>] [--cursor <opaque-cursor>]
@@ -17319,7 +17611,7 @@ it must not invent factual evidence, numbers, or citations. Rewrite returns a
17319
17611
  candidate only: it never creates, updates, retries, or chooses a mode from body
17320
17612
  length or errors.
17321
17613
 
17322
- IDs are decimal strings, never JavaScript numbers; provide at most 20 entity
17614
+ IDs are decimal strings, never JavaScript numbers; provide at most 100 entity
17323
17615
  IDs. Body text must be nonblank,
17324
17616
  valid Unicode, and at most 65536 UTF-8 bytes; title is optional and at most
17325
17617
  500 UTF-8 bytes. Text is passed without trimming or newline conversion.
@@ -17958,6 +18250,24 @@ function assertLocalFileAvailable(command2, flag, deps) {
17958
18250
  throw localFileUnsupported(command2, flag);
17959
18251
  }
17960
18252
  }
18253
+ function decodeRunResult(result) {
18254
+ let value;
18255
+ try {
18256
+ value = JSON.parse(result);
18257
+ } catch {
18258
+ return result;
18259
+ }
18260
+ let inner = value;
18261
+ while (typeof inner === "string") {
18262
+ try {
18263
+ inner = JSON.parse(inner);
18264
+ } catch {
18265
+ break;
18266
+ }
18267
+ if (inner !== null && typeof inner === "object") return inner;
18268
+ }
18269
+ return value;
18270
+ }
17961
18271
  function readLocalTextFile(path, command2, flag, deps) {
17962
18272
  assertLocalFileAvailable(command2, flag, deps);
17963
18273
  if (!deps?.localFiles) {
@@ -18021,6 +18331,19 @@ function thesisTickers(flags) {
18021
18331
  }
18022
18332
  return tickers;
18023
18333
  }
18334
+ function thesisEntityStances(flags) {
18335
+ const raw = flags["entity-stances"];
18336
+ if (raw === void 0) return void 0;
18337
+ let parsed;
18338
+ try {
18339
+ parsed = JSON.parse(raw);
18340
+ } catch {
18341
+ throw new CliUsageError("--entity-stances must be a JSON array", "thesis");
18342
+ }
18343
+ if (!Array.isArray(parsed))
18344
+ throw new CliUsageError("--entity-stances must be a JSON array", "thesis");
18345
+ return parsed;
18346
+ }
18024
18347
  function strictThesisUTF8(value, command2, flag) {
18025
18348
  const bytes = toByteView(value);
18026
18349
  if (bytes === void 0) {
@@ -18367,7 +18690,8 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
18367
18690
  );
18368
18691
  }
18369
18692
  }
18370
- return serializedArgs === void 0 ? client.run.execute(params) : client.run._executeSerializedArgs(params, serializedArgs);
18693
+ const response = serializedArgs === void 0 ? await client.run.execute(params) : await client.run._executeSerializedArgs(params, serializedArgs);
18694
+ return { ...response, result: decodeRunResult(response.result) };
18371
18695
  }
18372
18696
  case "deploy": {
18373
18697
  if (!subcommand)
@@ -18553,7 +18877,12 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
18553
18877
  "inbox-path",
18554
18878
  `steward ${subcommand}`
18555
18879
  );
18556
- const ids = (name) => requireFlag(flags, name, `steward ${subcommand}`).split(",").map((value) => value.trim()).filter((value) => value !== "");
18880
+ const splitIds = (raw) => raw.split(",").map((value) => value.trim()).filter((value) => value !== "");
18881
+ const ids = (name) => splitIds(requireFlag(flags, name, `steward ${subcommand}`));
18882
+ const optionalIds = (name) => {
18883
+ const raw = flags[name];
18884
+ return raw === void 0 ? [] : splitIds(raw);
18885
+ };
18557
18886
  switch (subcommand) {
18558
18887
  case "decide":
18559
18888
  return client.steward.decide({
@@ -18574,7 +18903,7 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
18574
18903
  return client.steward.send({
18575
18904
  inboxPath,
18576
18905
  body: requireFlag(flags, "body", "steward send"),
18577
- deliveryIds: ids("delivery-ids"),
18906
+ deliveryIds: optionalIds("delivery-ids"),
18578
18907
  requestId: flags["request-id"]
18579
18908
  });
18580
18909
  case "pending": {
@@ -18623,9 +18952,14 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
18623
18952
  body: await thesisBodyFromFlags(flags, "thesis create", deps),
18624
18953
  title: flags.title ?? "",
18625
18954
  entity_ids: thesisEntityIDs(flags),
18955
+ entity_stances: thesisEntityStances(flags),
18626
18956
  tickers: thesisTickers(flags),
18627
18957
  visibility: flags.visibility === void 0 ? "public" : thesisVisibility(flags.visibility)
18628
18958
  });
18959
+ case "asset-candidates":
18960
+ return client.theses.assetCandidates(
18961
+ requireFlag(flags, "text", "thesis asset-candidates")
18962
+ );
18629
18963
  case "get":
18630
18964
  return client.theses.get(requireFlag(flags, "id", "thesis get"));
18631
18965
  case "version":
@@ -18846,8 +19180,32 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
18846
19180
  }
18847
19181
  }
18848
19182
  case "for-you": {
19183
+ if (subcommand === "theses") {
19184
+ const params2 = {
19185
+ first: optionalBoundedIntegerFlag(
19186
+ flags,
19187
+ "limit",
19188
+ "for-you theses",
19189
+ 1,
19190
+ 10
19191
+ ),
19192
+ after: flags.cursor
19193
+ };
19194
+ try {
19195
+ validateForYouThesesParams(params2);
19196
+ } catch (error) {
19197
+ throw new CliUsageError(
19198
+ error instanceof Error ? error.message : String(error),
19199
+ "for-you"
19200
+ );
19201
+ }
19202
+ return client.forYou.theses(params2);
19203
+ }
18849
19204
  if (subcommand !== "list") {
18850
- throw new CliUsageError("Expected for-you list", "for-you");
19205
+ throw new CliUsageError(
19206
+ "Expected for-you list or for-you theses",
19207
+ "for-you"
19208
+ );
18851
19209
  }
18852
19210
  const params = {
18853
19211
  first: optionalBoundedIntegerFlag(
@@ -20300,7 +20658,8 @@ async function main() {
20300
20658
  } else if (typeof result === "string") {
20301
20659
  process.stdout.write(result);
20302
20660
  } else if (result !== void 0) {
20303
- process.stdout.write(JSON.stringify(result, null, 2) + "\n");
20661
+ const indent = process.stdout.isTTY ? 2 : void 0;
20662
+ process.stdout.write(JSON.stringify(result, null, indent) + "\n");
20304
20663
  }
20305
20664
  } catch (error) {
20306
20665
  if (error instanceof CliUsageError) {