@alva-ai/toolkit 0.38.0-beta.0 → 0.38.0-beta.2

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.d.ts CHANGED
@@ -2106,6 +2106,25 @@ interface ThesisPositionReturn {
2106
2106
  end: 'PENDING' | 'NEXT_UPDATE' | 'LATEST';
2107
2107
  positionReturn: number;
2108
2108
  currency: string;
2109
+ /** The Update's target share of this position; equal shares when it states none. */
2110
+ weight: number;
2111
+ }
2112
+ /** One long or short of a target portfolio. */
2113
+ interface ThesisHolding {
2114
+ entityId: string;
2115
+ symbol: string;
2116
+ direction: 'BULLISH' | 'BEARISH';
2117
+ /** Target share as a fraction; equal shares when the Update states none. */
2118
+ weight: number;
2119
+ }
2120
+ /**
2121
+ * The current target portfolio: the shares the latest Update set, not drifted
2122
+ * with prices. Holdings and cash sum to 1; cash is 1 with no direction or
2123
+ * while archived.
2124
+ */
2125
+ interface ThesisAllocation {
2126
+ holdings: ThesisHolding[];
2127
+ cash: number;
2109
2128
  }
2110
2129
  /** One Update on the return chart. */
2111
2130
  interface ThesisUpdateReturn {
@@ -2124,6 +2143,8 @@ interface ThesisReturnValue {
2124
2143
  stale: boolean;
2125
2144
  computedAtMs: number;
2126
2145
  updates: ThesisUpdateReturn[];
2146
+ /** The current target portfolio, with detail; null on card reads. */
2147
+ allocation: ThesisAllocation | null;
2127
2148
  }
2128
2149
  interface ThesisReturnResult {
2129
2150
  playbookId: string;
@@ -2159,6 +2180,14 @@ interface ThesisEntityStance {
2159
2180
  stance: ThesisAssetStance;
2160
2181
  /** Full direction in responses; stance reports none as unknown there. */
2161
2182
  direction?: ThesisAssetStance;
2183
+ /**
2184
+ * The Update's share of this long or short as a fraction (0.4 is 40%), with
2185
+ * at most four decimals. On create and update give one to every bullish or
2186
+ * bearish entity, and the rest is cash, or to none, and the shares follow
2187
+ * the default rules and what the body says. Responses carry it only on an
2188
+ * Update published with weights.
2189
+ */
2190
+ weight?: number;
2162
2191
  }
2163
2192
  /** GraphQL direction, including NONE. */
2164
2193
  type ThesisDirection = 'UNKNOWN' | 'BULLISH' | 'BEARISH' | 'NONE';
@@ -2236,6 +2265,10 @@ interface Thesis {
2236
2265
  interface ThesisResponse {
2237
2266
  thesis: Thesis;
2238
2267
  }
2268
+ /** A created Thesis and its clickable web url, e.g. `https://alva.ai/thesis/123`. */
2269
+ interface ThesisCreateResponse extends ThesisResponse {
2270
+ url: string;
2271
+ }
2239
2272
  interface ThesisAuthor {
2240
2273
  id: ThesisID;
2241
2274
  kind: string;
@@ -2312,6 +2345,25 @@ interface CreateThesisParams {
2312
2345
  visibility?: 'public' | 'private';
2313
2346
  /** Thesis return switch; omitted keeps the default (on). */
2314
2347
  track_return?: boolean;
2348
+ /** Which Signals the Thesis shows; omitted shows every Signal. */
2349
+ signal_preferences?: ThesisSignalPreferences;
2350
+ }
2351
+ /** What a Thesis Signal is about. */
2352
+ type ThesisSignalKind = 'fundamentals' | 'macro' | 'technicals' | 'commentary';
2353
+ /** The least important Signals a Thesis shows; notable means notable and major. */
2354
+ type ThesisSignalMinImportance = 'all' | 'notable' | 'major';
2355
+ /**
2356
+ * Which Signals a Thesis shows to every reader, chosen by its author. Signals
2357
+ * without a label always show.
2358
+ */
2359
+ interface ThesisSignalPreferences {
2360
+ kinds: ThesisSignalKind[];
2361
+ min_importance: ThesisSignalMinImportance;
2362
+ }
2363
+ interface ThesisSignalPreferencesResponse {
2364
+ /** The Thesis read or written; null for the caller's last choice. */
2365
+ thesis_id: ThesisID | null;
2366
+ preferences: ThesisSignalPreferences;
2315
2367
  }
2316
2368
  interface UpdateThesisParams {
2317
2369
  /** Full media replacement; pass current medias for a text-only update. */
@@ -2379,7 +2431,7 @@ declare class ThesesResource {
2379
2431
  * things the Thesis depends on, or that would show it right or wrong.
2380
2432
  */
2381
2433
  watchpoints(id: ThesisID): Promise<ThesisWatchpointsResult>;
2382
- create(params: CreateThesisParams): Promise<ThesisResponse>;
2434
+ create(params: CreateThesisParams): Promise<ThesisCreateResponse>;
2383
2435
  get(id: ThesisID): Promise<ThesisGetResponse>;
2384
2436
  getVersion(id: ThesisID, authorVersionID: ThesisID): Promise<ThesisResponse>;
2385
2437
  /** Lists reader-visible Updates, with editorial revisions folded together. */
@@ -2399,6 +2451,17 @@ declare class ThesesResource {
2399
2451
  */
2400
2452
  setArchived(id: ThesisID, params: SetThesisArchivedParams): Promise<ThesisResponse>;
2401
2453
  setStarred(id: ThesisID, isStarred: boolean): Promise<ThesisStarredResponse>;
2454
+ /**
2455
+ * Reads which Signals one of the caller's Theses shows: its setting, or every
2456
+ * kind and `all` when it has none. Without an id, reads the setting the caller
2457
+ * last saved, which prefills a new Thesis. Only the Thesis's author can read it.
2458
+ */
2459
+ getSignalPreferences(id?: ThesisID): Promise<ThesisSignalPreferencesResponse>;
2460
+ /**
2461
+ * Replaces which Signals one of the caller's Theses shows, for every reader,
2462
+ * and records it as the caller's last choice. Author only.
2463
+ */
2464
+ setSignalPreferences(id: ThesisID, preferences: ThesisSignalPreferences): Promise<ThesisSignalPreferencesResponse>;
2402
2465
  setSignalEnabled(id: ThesisID, enabled: boolean): Promise<ThesisSignalEnabledResponse>;
2403
2466
  setVisibility(id: ThesisID, params: SetThesisVisibilityParams): Promise<ThesisResponse>;
2404
2467
  rewrite(params: RewriteThesisParams): Promise<RewriteThesisResponse>;
@@ -2512,12 +2575,10 @@ interface FollowingThesesParams {
2512
2575
  first?: number;
2513
2576
  }
2514
2577
  /** The author of a Thesis in the following feed. */
2578
+ /** The followed user who wrote a Thesis Update. Persons cannot be followed. */
2515
2579
  interface FollowingThesisAuthor {
2516
- kind: 'user' | 'person';
2517
- /** Set for a user. */
2518
- username?: string;
2519
- /** Set for a person. */
2520
- slug?: string;
2580
+ kind: 'user';
2581
+ username: string;
2521
2582
  display_name: string;
2522
2583
  }
2523
2584
  interface FollowingThesisItem {
package/dist/cli.js CHANGED
@@ -7250,6 +7250,20 @@ function graphQLErrorMessage(errors) {
7250
7250
  return messages.length > 0 ? messages.join("; ") : "GraphQL request failed";
7251
7251
  }
7252
7252
 
7253
+ // src/resources/webOrigin.ts
7254
+ function webOriginFromApiBase(apiBaseUrl) {
7255
+ try {
7256
+ const host = new URL(apiBaseUrl).hostname;
7257
+ const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
7258
+ if (match) {
7259
+ const env = match[1].toLowerCase();
7260
+ return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
7261
+ }
7262
+ } catch {
7263
+ }
7264
+ return "https://alva.ai";
7265
+ }
7266
+
7253
7267
  // src/resources/playbooks.ts
7254
7268
  var PLAYBOOK_VISIBILITIES = [
7255
7269
  "public",
@@ -7401,18 +7415,6 @@ var PlaybooksResource = class {
7401
7415
  );
7402
7416
  }
7403
7417
  };
7404
- function webOriginFromApiBase(apiBaseUrl) {
7405
- try {
7406
- const host = new URL(apiBaseUrl).hostname;
7407
- const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
7408
- if (match) {
7409
- const env = match[1].toLowerCase();
7410
- return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
7411
- }
7412
- } catch {
7413
- }
7414
- return "https://alva.ai";
7415
- }
7416
7418
  function toAgentPlaybook(raw, webOrigin) {
7417
7419
  const username = raw.creator?.name ?? "";
7418
7420
  const name = raw.name ?? "";
@@ -8969,7 +8971,8 @@ var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
8969
8971
  thesisReturn(detail: $detail) {
8970
8972
  live value firstFillAtMs pricedAtMs stale computedAtMs
8971
8973
  updates { authorVersionId publishedAtMs startValue updateReturn
8972
- positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
8974
+ positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency weight } }
8975
+ allocation { holdings { entityId symbol direction weight } cash }
8973
8976
  }
8974
8977
  } } } }
8975
8978
  }`;
@@ -9038,16 +9041,21 @@ async function thesisWatchpoints(client, id) {
9038
9041
  return { playbookId: id, watchpoints };
9039
9042
  }
9040
9043
  function validThesisReturn(value) {
9041
- if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
9044
+ if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates) || value.allocation !== null && !validAllocation(value.allocation))
9042
9045
  return false;
9043
9046
  return value.updates.every(
9044
9047
  (update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
9045
9048
  (position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
9046
9049
  position.end
9047
- ) && typeof position.positionReturn === "number"
9050
+ ) && typeof position.positionReturn === "number" && typeof position.weight === "number"
9048
9051
  )
9049
9052
  );
9050
9053
  }
9054
+ function validAllocation(value) {
9055
+ return record2(value) && typeof value.cash === "number" && Array.isArray(value.holdings) && value.holdings.every(
9056
+ (holding) => record2(holding) && nonempty(holding.entityId) && nonempty(holding.symbol) && ["BULLISH", "BEARISH"].includes(holding.direction) && typeof holding.weight === "number"
9057
+ );
9058
+ }
9051
9059
  async function graphql(client, document, variables) {
9052
9060
  const response = await client._request("POST", "/query", {
9053
9061
  body: { query: document, variables }
@@ -9104,6 +9112,13 @@ function notFound() {
9104
9112
  }
9105
9113
 
9106
9114
  // src/resources/theses.ts
9115
+ var THESIS_SIGNAL_KINDS = [
9116
+ "fundamentals",
9117
+ "macro",
9118
+ "technicals",
9119
+ "commentary"
9120
+ ];
9121
+ var THESIS_SIGNAL_MIN_IMPORTANCES = ["all", "notable", "major"];
9107
9122
  var SET_THESIS_STARRED = `mutation SetThesisStarred($input: SetThesisStarredInput!) {
9108
9123
  setThesisStarred(input: $input) {
9109
9124
  thesisId
@@ -9209,9 +9224,12 @@ var ThesesResource = class {
9209
9224
  async create(params) {
9210
9225
  this.client._requireAuth();
9211
9226
  const body = createBody(params);
9212
- return thesisResponse(
9227
+ const response = thesisResponse(
9213
9228
  await this.client._request("POST", "/api/v1/theses", { body })
9214
9229
  );
9230
+ requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
9231
+ const webOrigin = webOriginFromApiBase(this.client.baseUrl);
9232
+ return { ...response, url: `${webOrigin}/thesis/${response.thesis.id}` };
9215
9233
  }
9216
9234
  async get(id) {
9217
9235
  this.client._requireAuth();
@@ -9300,6 +9318,7 @@ var ThesesResource = class {
9300
9318
  if (response.thesis.id !== thesisID) {
9301
9319
  throw invalidResponse3("update response must match the requested thesis");
9302
9320
  }
9321
+ requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
9303
9322
  return response;
9304
9323
  }
9305
9324
  /**
@@ -9334,7 +9353,11 @@ var ThesesResource = class {
9334
9353
  body: current.thesis.body,
9335
9354
  title: current.thesis.title,
9336
9355
  entity_ids: current.thesis.entity_ids,
9337
- entity_stances: current.thesis.entity_stances,
9356
+ // Directions only: archiving keeps the current Update and unarchiving
9357
+ // keeps its shares without restating them.
9358
+ entity_stances: current.thesis.entity_stances?.map(
9359
+ ({ entity_id, stance }) => ({ entity_id, stance })
9360
+ ),
9338
9361
  visibility: current.thesis.visibility,
9339
9362
  archived: params.archived,
9340
9363
  medias: current.thesis.medias,
@@ -9381,6 +9404,45 @@ var ThesesResource = class {
9381
9404
  is_starred: returnedStarred
9382
9405
  };
9383
9406
  }
9407
+ /**
9408
+ * Reads which Signals one of the caller's Theses shows: its setting, or every
9409
+ * kind and `all` when it has none. Without an id, reads the setting the caller
9410
+ * last saved, which prefills a new Thesis. Only the Thesis's author can read it.
9411
+ */
9412
+ async getSignalPreferences(id) {
9413
+ this.client._requireAuth();
9414
+ if (id === void 0) {
9415
+ return signalPreferencesResponse(
9416
+ await this.client._request("GET", "/api/v1/theses/signal-preferences"),
9417
+ null
9418
+ );
9419
+ }
9420
+ const thesisID = requireID(id, "id");
9421
+ return signalPreferencesResponse(
9422
+ await this.client._request(
9423
+ "GET",
9424
+ `/api/v1/theses/${thesisID}/signal-preferences`
9425
+ ),
9426
+ thesisID
9427
+ );
9428
+ }
9429
+ /**
9430
+ * Replaces which Signals one of the caller's Theses shows, for every reader,
9431
+ * and records it as the caller's last choice. Author only.
9432
+ */
9433
+ async setSignalPreferences(id, preferences) {
9434
+ this.client._requireAuth();
9435
+ const thesisID = requireID(id, "id");
9436
+ const input = requireSignalPreferences(preferences);
9437
+ return signalPreferencesResponse(
9438
+ await this.client._request(
9439
+ "PUT",
9440
+ `/api/v1/theses/${thesisID}/signal-preferences`,
9441
+ { body: { signal_preferences: input } }
9442
+ ),
9443
+ thesisID
9444
+ );
9445
+ }
9384
9446
  async setSignalEnabled(id, enabled) {
9385
9447
  this.client._requireAuth();
9386
9448
  const thesisID = requireID(id, "id");
@@ -9487,6 +9549,10 @@ function createBody(params) {
9487
9549
  body.tickers = requireTickers(params.tickers);
9488
9550
  if (params.track_return !== void 0)
9489
9551
  body.track_return = requireTrackReturn(params.track_return);
9552
+ if (params.signal_preferences !== void 0)
9553
+ body.signal_preferences = requireSignalPreferences(
9554
+ params.signal_preferences
9555
+ );
9490
9556
  if (params.entity_stances !== void 0) {
9491
9557
  body.entity_stances = requireEntityStances(
9492
9558
  params.entity_stances,
@@ -9495,6 +9561,43 @@ function createBody(params) {
9495
9561
  }
9496
9562
  return body;
9497
9563
  }
9564
+ function requireSignalPreferences(value) {
9565
+ if (!isRecord(value) || !Array.isArray(value.kinds))
9566
+ throw invalidArgument(
9567
+ "signal_preferences must have kinds and min_importance"
9568
+ );
9569
+ const kinds = [...new Set(value.kinds)];
9570
+ if (kinds.length === 0 || !kinds.every(
9571
+ (kind) => THESIS_SIGNAL_KINDS.includes(kind)
9572
+ ))
9573
+ throw invalidArgument(
9574
+ `signal kinds must be one or more of ${THESIS_SIGNAL_KINDS.join(", ")}`
9575
+ );
9576
+ if (!THESIS_SIGNAL_MIN_IMPORTANCES.includes(
9577
+ value.min_importance
9578
+ ))
9579
+ throw invalidArgument(
9580
+ `min_importance must be ${THESIS_SIGNAL_MIN_IMPORTANCES.join(", ")}`
9581
+ );
9582
+ return {
9583
+ kinds,
9584
+ min_importance: value.min_importance
9585
+ };
9586
+ }
9587
+ function signalPreferencesResponse(value, thesisID) {
9588
+ if (!isRecord(value) || value.thesis_id !== thesisID)
9589
+ throw invalidResponse3(
9590
+ "Signal setting response must name the requested thesis"
9591
+ );
9592
+ try {
9593
+ return {
9594
+ thesis_id: thesisID,
9595
+ preferences: requireSignalPreferences(value.signal_preferences)
9596
+ };
9597
+ } catch {
9598
+ throw invalidResponse3("response contains an unknown Signal setting");
9599
+ }
9600
+ }
9498
9601
  var ENTITY_STANCES = [
9499
9602
  "unknown",
9500
9603
  "bullish",
@@ -9560,9 +9663,44 @@ function requireEntityStances(value, entityIDs) {
9560
9663
  seen.add(entityID);
9561
9664
  if (!ENTITY_STANCES.includes(item.stance))
9562
9665
  throw invalidArgument(`entity_stances[${index}].stance is invalid`);
9563
- return { entity_id: entityID, stance: item.stance };
9666
+ const stance = {
9667
+ entity_id: entityID,
9668
+ stance: item.stance
9669
+ };
9670
+ if (item.weight !== void 0) {
9671
+ if (!validWeight(item.weight))
9672
+ throw invalidArgument(
9673
+ `entity_stances[${index}].weight must be a fraction in (0, 1] with at most four decimals`
9674
+ );
9675
+ if (stance.stance !== "bullish" && stance.stance !== "bearish")
9676
+ throw invalidArgument(
9677
+ `entity_stances[${index}].weight needs a bullish or bearish stance`
9678
+ );
9679
+ stance.weight = item.weight;
9680
+ }
9681
+ return stance;
9564
9682
  });
9565
9683
  }
9684
+ function validWeight(value) {
9685
+ if (typeof value !== "number" || !Number.isFinite(value)) return false;
9686
+ const bps = Math.round(value * 1e4);
9687
+ return bps >= 1 && bps <= 1e4 && Math.abs(value * 1e4 - bps) <= 1e-6;
9688
+ }
9689
+ function requireKeptWeights(sent, returned) {
9690
+ if (!Array.isArray(sent)) return;
9691
+ const weights = /* @__PURE__ */ new Map();
9692
+ for (const item of returned ?? []) {
9693
+ if (item.weight !== void 0) weights.set(item.entity_id, item.weight);
9694
+ }
9695
+ for (const item of sent) {
9696
+ if (item.weight === void 0) continue;
9697
+ const kept = weights.get(item.entity_id);
9698
+ if (kept === void 0 || Math.abs(kept - item.weight) > 1e-9)
9699
+ throw invalidResponse3(
9700
+ "the Update was published without the weights sent: the server predates weights"
9701
+ );
9702
+ }
9703
+ }
9566
9704
  function updateBody(params) {
9567
9705
  const body = {
9568
9706
  request_id: requireRequestID(params.request_id),
@@ -9670,6 +9808,13 @@ function thesisResponse(response) {
9670
9808
  );
9671
9809
  stance.direction = item.direction;
9672
9810
  }
9811
+ if (item.weight !== void 0) {
9812
+ if (!validWeight(item.weight))
9813
+ throw invalidResponse3(
9814
+ "thesis.entity_stances contains invalid weight"
9815
+ );
9816
+ stance.weight = item.weight;
9817
+ }
9673
9818
  return stance;
9674
9819
  });
9675
9820
  }
@@ -10544,13 +10689,12 @@ function followingThesesPage(value) {
10544
10689
  }
10545
10690
  function followingThesisAuthor(value) {
10546
10691
  if (value === null) return null;
10547
- if (!record3(value) || value.kind !== "user" && value.kind !== "person" || typeof value.display_name !== "string" || value.username !== void 0 && typeof value.username !== "string" || value.slug !== void 0 && typeof value.slug !== "string") {
10692
+ if (!record3(value) || value.kind !== "user" || typeof value.username !== "string" || typeof value.display_name !== "string") {
10548
10693
  throw invalidFollowingTheses("invalid following theses author");
10549
10694
  }
10550
10695
  return {
10551
10696
  kind: value.kind,
10552
- ...value.username === void 0 ? {} : { username: value.username },
10553
- ...value.slug === void 0 ? {} : { slug: value.slug },
10697
+ username: value.username,
10554
10698
  display_name: value.display_name
10555
10699
  };
10556
10700
  }
@@ -12818,6 +12962,41 @@ function getProfile(config, profileName) {
12818
12962
  }
12819
12963
  return {};
12820
12964
  }
12965
+ async function assertConfigWritable(deps) {
12966
+ const path = configPath(deps);
12967
+ const cannot = (action, err) => {
12968
+ const reason = err instanceof Error ? err.message : String(err);
12969
+ return new Error(
12970
+ `Cannot ${action} ${path} (${reason}), where login stores the key. Allow reading and writing there and run \`alva auth login\` again; nothing was signed in.`
12971
+ );
12972
+ };
12973
+ let exists = true;
12974
+ try {
12975
+ await deps.readFile(path);
12976
+ } catch (err) {
12977
+ if (err?.code !== "ENOENT") {
12978
+ throw cannot("read", err);
12979
+ }
12980
+ exists = false;
12981
+ }
12982
+ try {
12983
+ if (exists) {
12984
+ await deps.writeFile(path, "", { mode: 384, flag: "a" });
12985
+ } else {
12986
+ await deps.mkdir(configDir(deps), { recursive: true });
12987
+ await deps.writeFile(
12988
+ path,
12989
+ JSON.stringify({ profiles: {} }, null, 2) + "\n",
12990
+ {
12991
+ mode: 384,
12992
+ flag: "wx"
12993
+ }
12994
+ );
12995
+ }
12996
+ } catch (err) {
12997
+ throw cannot("write", err);
12998
+ }
12999
+ }
12821
13000
  async function writeConfig(config, deps, profileName = "default") {
12822
13001
  const path = configPath(deps);
12823
13002
  const dir = configDir(deps);
@@ -13087,7 +13266,9 @@ var COMMAND_DEFINITIONS = [
13087
13266
  "entity-stances",
13088
13267
  "tickers",
13089
13268
  "visibility",
13090
- "track-return"
13269
+ "track-return",
13270
+ "signal-kinds",
13271
+ "signal-min-importance"
13091
13272
  ],
13092
13273
  booleans: ["body-stdin"]
13093
13274
  }),
@@ -13121,6 +13302,10 @@ var COMMAND_DEFINITIONS = [
13121
13302
  command("thesis star", { values: ["id"] }),
13122
13303
  command("thesis unstar", { values: ["id"] }),
13123
13304
  command("thesis set-signal-enabled", { values: ["id", "enabled"] }),
13305
+ command("thesis signal-preferences get", { values: ["id"] }),
13306
+ command("thesis signal-preferences set", {
13307
+ values: ["id", "kinds", "min-importance"]
13308
+ }),
13124
13309
  command("thesis update", {
13125
13310
  values: [
13126
13311
  "id",
@@ -13929,6 +14114,7 @@ async function handleAuthLogin(args, deps) {
13929
14114
  const oobRedirectUrl = deriveOobRedirectUrl(authUrl);
13930
14115
  const timeout = d.timeout ?? 12e4;
13931
14116
  const mintedKeyName = d.keyName?.(flags.agent);
14117
+ await assertConfigWritable(d.writeConfigDeps);
13932
14118
  const state = d.generateState();
13933
14119
  const codeVerifier = d.generateCodeVerifier();
13934
14120
  const codeChallenge = deriveChallenge(codeVerifier);
@@ -13989,7 +14175,11 @@ async function handleAuthLogin(args, deps) {
13989
14175
  keyName: mintedKeyName
13990
14176
  }).then(async (apiKey) => {
13991
14177
  if (settled) return;
13992
- await writeConfig({ apiKey }, d.writeConfigDeps, profileName);
14178
+ await writeConfig(
14179
+ { apiKey, baseUrl },
14180
+ d.writeConfigDeps,
14181
+ profileName
14182
+ );
13993
14183
  settle(() => {
13994
14184
  server.close();
13995
14185
  resolve({ status: "logged_in", apiKey, profile: profileName });
@@ -14062,7 +14252,11 @@ async function handleAuthLogin(args, deps) {
14062
14252
  keyName: mintedKeyName
14063
14253
  });
14064
14254
  if (settled) return;
14065
- await writeConfig({ apiKey }, d.writeConfigDeps, profileName);
14255
+ await writeConfig(
14256
+ { apiKey, baseUrl },
14257
+ d.writeConfigDeps,
14258
+ profileName
14259
+ );
14066
14260
  settle(() => {
14067
14261
  server.close();
14068
14262
  resolve({ status: "logged_in", apiKey, profile: profileName });
@@ -14165,6 +14359,7 @@ async function handleAuthLoginNoBrowser(args, deps) {
14165
14359
  const authUrl = flags["auth-url"] || DEFAULT_AUTH_URL;
14166
14360
  const baseUrl = flags["base-url"] || DEFAULT_BASE_URL2;
14167
14361
  const oobRedirectUrl = d.oobRedirectUrl || deriveOobRedirectUrl(authUrl);
14362
+ await assertConfigWritable(d.writeConfigDeps);
14168
14363
  const state = d.generateState();
14169
14364
  const codeVerifier = d.generateCodeVerifier();
14170
14365
  const codeChallenge = deriveChallenge(codeVerifier);
@@ -14205,7 +14400,7 @@ async function handleAuthLoginNoBrowser(args, deps) {
14205
14400
  fetch: d.fetch,
14206
14401
  keyName: d.keyName?.(flags.agent)
14207
14402
  });
14208
- await writeConfig({ apiKey }, d.writeConfigDeps, profileName);
14403
+ await writeConfig({ apiKey, baseUrl }, d.writeConfigDeps, profileName);
14209
14404
  return { status: "logged_in", apiKey, profile: profileName };
14210
14405
  } catch (err) {
14211
14406
  const msg = err instanceof Error ? err.message : String(err);
@@ -17897,7 +18092,7 @@ function formatTradingPairResolved(result) {
17897
18092
  }
17898
18093
 
17899
18094
  // src/cli/dispatch.ts
17900
- var CLI_VERSION = true ? "0.38.0-beta.0" : "dev";
18095
+ var CLI_VERSION = true ? "0.38.0-beta.2" : "dev";
17901
18096
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
17902
18097
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
17903
18098
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -19385,6 +19580,7 @@ Create and update never rewrite text automatically.
19385
19580
 
19386
19581
  Subcommands:
19387
19582
  create Create a thesis
19583
+ asset-candidates Read catalog IDs and the directions publishing would store, without publishing
19388
19584
  list Read theses by author or market entity
19389
19585
  related Read related current publications
19390
19586
  get Get one thesis
@@ -19392,11 +19588,13 @@ Subcommands:
19392
19588
  version list List visible Updates with editorial revisions folded together
19393
19589
  signals Read published Signal history
19394
19590
  watchpoints List a Thesis's current watchpoints
19591
+ return Read the Thesis return
19395
19592
  set-visibility Change current access without publishing a version
19396
19593
  archive Archive the current author version
19397
19594
  star Add the Thesis to your bookmarks
19398
19595
  unstar Remove the Thesis from your bookmarks
19399
19596
  set-signal-enabled Enable or disable managed Signal research
19597
+ signal-preferences get|set Read or change which Signals your Thesis shows
19400
19598
  update Publish a new Update replacing body, title, entities, visibility (all sent in full);
19401
19599
  with --archived false it also unarchives the Thesis
19402
19600
  rewrite Explicitly request a candidate body rewrite; never called by another command
@@ -19409,11 +19607,14 @@ Body input (create, update, rewrite): choose exactly one:
19409
19607
  Create and update require --request-id: a caller-supplied non-zero UUID. The
19410
19608
  toolkit does not generate or retry request IDs. If a response is ambiguous
19411
19609
  after a write, reuse the same request ID only after resolving that ambiguity with
19412
- the backend; do not send a fresh ID. Create defaults --visibility to public.
19413
- Update requires --visibility explicitly so it cannot inadvertently publish.
19610
+ the backend; do not send a fresh ID. Create and update require --visibility
19611
+ explicitly so neither can publish by accident. Create returns the Thesis's web
19612
+ url.
19414
19613
 
19415
19614
  Other flags:
19416
- create --request-id <uuid> --body ... [--images <json-array-of-https-urls>] [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--entity-stances <json>] [--visibility <value>] [--track-return true|false]
19615
+ create --request-id <uuid> --body ... [--images <json-array-of-https-urls>] [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--entity-stances <json>] --visibility public|private [--track-return true|false] [--signal-kinds <kind,kind>] [--signal-min-importance all|notable|major]
19616
+ Signals: omit both to show every Signal. Kinds: fundamentals, macro,
19617
+ technicals, commentary; with only one flag the other keeps its default.
19417
19618
  Images: public creation only, at most 20 in display order. Upload selected files
19418
19619
  with the existing host upload tool after publication confirmation. Private
19419
19620
  images and local/ALFS paths are not supported; this flag does not upload.
@@ -19435,6 +19636,8 @@ Other flags:
19435
19636
  --no-discovery only classifies --entity-ids (no ticker discovery) and
19436
19637
  returns returnPreview: the directions publishing would store, the return
19437
19638
  switch (askSwitch) and lastLegRemoved. --thesis-id seeds an Update.
19639
+ A mention resolved UNRESOLVED or a direction UNKNOWN is an answer, not
19640
+ an error: the text names no catalog asset or no clear direction.
19438
19641
  return --id <id> [--detail] the Thesis return; --detail adds each Update's positions
19439
19642
  get --id <signed-int64-decimal>
19440
19643
  version get --id <signed-int64-decimal> --author-version-id <signed-int64-decimal>
@@ -19454,6 +19657,13 @@ Other flags:
19454
19657
  archive --id <id> --request-id <uuid> [--note <text>]
19455
19658
  star|unstar --id <id>
19456
19659
  set-signal-enabled --id <id> --enabled true|false
19660
+ signal-preferences get [--id <id>]
19661
+ Which Signals your Thesis shows to every reader: {thesis_id, preferences:
19662
+ {kinds, min_importance}}. Without --id: the setting you last saved, which
19663
+ prefills a new Thesis. Only the author can read or set it.
19664
+ signal-preferences set --id <id> [--kinds <kind,kind>] [--min-importance all|notable|major]
19665
+ Changes only what is given. Applies to every reader, the Thesis's
19666
+ deliveries and, from its next daily run, its Overview.
19457
19667
 
19458
19668
  Maintenance behavior:
19459
19669
  archive reads the current Thesis first, preserves its body, title,
@@ -19493,7 +19703,7 @@ valid Unicode, and at most 65536 UTF-8 bytes; title is optional and at most
19493
19703
  500 UTF-8 bytes. Text is passed without trimming or newline conversion.
19494
19704
 
19495
19705
  Examples:
19496
- alva thesis create --request-id 123e4567-e89b-42d3-a456-426614174000 --body $'line one\\r\\nline two'
19706
+ alva thesis create --request-id 123e4567-e89b-42d3-a456-426614174000 --body $'line one\\r\\nline two' --visibility private
19497
19707
  alva thesis set-visibility --id 9223372036854775807 --visibility private
19498
19708
  alva thesis update --id 9223372036854775807 --request-id 123e4567-e89b-42d3-a456-426614174000 --expected-author-version-id 9223372036854775806 --body-file ./thesis.md --visibility private
19499
19709
  printf '%s' 'Draft body' | alva thesis rewrite --body-stdin --mode shorten`
@@ -20377,6 +20587,22 @@ function thesisImages(flags) {
20377
20587
  "thesis"
20378
20588
  );
20379
20589
  }
20590
+ function thesisSignalKindList(raw, flag) {
20591
+ const kinds = raw.split(",").map((kind) => kind.trim());
20592
+ if (kinds.some((kind) => kind === "")) {
20593
+ throw new CliUsageError(`${flag} must not contain empty kinds`, "thesis");
20594
+ }
20595
+ return kinds;
20596
+ }
20597
+ function thesisCreateSignalPreferences(flags) {
20598
+ const kinds = flags["signal-kinds"];
20599
+ const minImportance = flags["signal-min-importance"];
20600
+ if (kinds === void 0 && minImportance === void 0) return void 0;
20601
+ return {
20602
+ kinds: kinds === void 0 ? [...THESIS_SIGNAL_KINDS] : thesisSignalKindList(kinds, "--signal-kinds"),
20603
+ min_importance: minImportance ?? "all"
20604
+ };
20605
+ }
20380
20606
  function thesisTrackReturn(flags, command2) {
20381
20607
  const raw = flags["track-return"];
20382
20608
  if (raw === void 0) return void 0;
@@ -21075,8 +21301,11 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
21075
21301
  entity_ids: thesisEntityIDs(flags),
21076
21302
  entity_stances: thesisEntityStances(flags),
21077
21303
  tickers: thesisTickers(flags),
21078
- visibility: flags.visibility === void 0 ? "public" : thesisCreateVisibility(flags.visibility),
21079
- track_return: thesisTrackReturn(flags, "thesis create")
21304
+ visibility: thesisCreateVisibility(
21305
+ requireFlag(flags, "visibility", "thesis create")
21306
+ ),
21307
+ track_return: thesisTrackReturn(flags, "thesis create"),
21308
+ signal_preferences: thesisCreateSignalPreferences(flags)
21080
21309
  });
21081
21310
  case "asset-candidates":
21082
21311
  return client.theses.assetCandidates(
@@ -21181,6 +21410,23 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
21181
21410
  requireFlag(flags, "id", "thesis unstar"),
21182
21411
  false
21183
21412
  );
21413
+ case "signal-preferences": {
21414
+ if (parsedCommand.path[2] === "get") {
21415
+ return client.theses.getSignalPreferences(flags.id);
21416
+ }
21417
+ const id = requireFlag(flags, "id", "thesis signal-preferences set");
21418
+ if (flags.kinds === void 0 && flags["min-importance"] === void 0) {
21419
+ throw new CliUsageError(
21420
+ "thesis signal-preferences set needs --kinds or --min-importance",
21421
+ "thesis"
21422
+ );
21423
+ }
21424
+ const current = await client.theses.getSignalPreferences(id);
21425
+ return client.theses.setSignalPreferences(id, {
21426
+ kinds: flags.kinds === void 0 ? current.preferences.kinds : thesisSignalKindList(flags.kinds, "--kinds"),
21427
+ min_importance: flags["min-importance"] === void 0 ? current.preferences.min_importance : flags["min-importance"]
21428
+ });
21429
+ }
21184
21430
  case "set-signal-enabled":
21185
21431
  return client.theses.setSignalEnabled(
21186
21432
  requireFlag(flags, "id", "thesis set-signal-enabled"),