@oalo-ai/cli 0.4.2 → 0.4.4

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.
@@ -8,7 +8,8 @@ description: Build and change an Oalo workspace (the person's Oalo Base) from th
8
8
  Oalo runs chatbots, chat flows, loops (background automations) and code tools in
9
9
  the cloud. You edit their definitions locally and push them; they run on the
10
10
  server. A push is a deploy: a saved flow or loop is live for real customers the
11
- moment it saves, with no staging copy. (Data and apps do have two: dev and prod.)
11
+ moment it saves, with no staging copy. (Data, booking data and apps do have two
12
+ envs: dev, which is staging, and prod, which is live. See rule 9.)
12
13
 
13
14
  Don't guess a command, flag or endpoint: `oalo help <command>` has every flag,
14
15
  `oalo docs --search "<words>"` finds Oalo's own pages, and `oalo call --list
@@ -66,8 +67,11 @@ Over MCP the same steps are `oalo_node_catalog`, `oalo_get_flow` / `oalo_get_loo
66
67
  the first message even while it's off, so test a new flow before anyone
67
68
  turns it on.
68
69
  7. **Test conversations do real work.** They never reach a customer's phone,
69
- but the bot's tools and flows run: contact details are saved, handoffs
70
- happen. Use a test bot, or flows whose side effects are fine to repeat.
70
+ but the bot's tools and flows run and handoffs happen. Use a test bot, or
71
+ flows whose side effects are fine to repeat. `oalo qa` only sends text: it
72
+ can't fill in a web form or tap a widget. Collected contact details reach a
73
+ contact only when the test chat has one linked, and a WhatsApp or SMS test
74
+ contact is removed when the run ends.
71
75
  Test a loop with `oalo loops test <name>`: sends are simulated.
72
76
  To test a loop's trigger, `oalo emit <event> --dry-run` (MCP: `oalo_emit`
73
77
  with `dry_run`) lists the loops an event would fire. Without `--dry-run` it
@@ -76,13 +80,27 @@ Over MCP the same steps are `oalo_node_catalog`, `oalo_get_flow` / `oalo_get_loo
76
80
  8. **Customer-facing words are product copy.** Keep the bot's language and
77
81
  tone, and never show customers internal names: SKUs, codes, step ids, tool
78
82
  names.
83
+ 9. **Know which env each step uses: dev is staging, prod is live.** A draft
84
+ (unpublished) bot reads and writes dev: it searches dev tables and books
85
+ against dev booking data. A published bot uses prod, in a test conversation
86
+ too. So setup for a draft bot goes to dev: rows with `oalo data push ...
87
+ --env dev`, booking types and hours with `"env": "dev"` (the booking events
88
+ default to prod). `oalo loops test` runs on dev; loops fired by real
89
+ triggers, `oalo emit` included, run on prod. `oalo metrics`, `oalo
90
+ dashboards add`, `oalo sources create` and `oalo db dump` default to prod;
91
+ data, db query, deploy, env, logs and run loop use the project's env from
92
+ `oalo link --env` (default dev); MCP tools never read it. When it matters,
93
+ don't rely on a default: pass `--env` (MCP and `oalo call`: `"env"`) every
94
+ time. Each command's `Env:` line in `oalo help <command>` says what it uses.
95
+ `oalo data promote <table>` copies rows dev to prod, only when the person
96
+ wants them live.
79
97
 
80
98
  ## Flows and loops differ
81
99
 
82
100
  | | Chat flow | Loop |
83
101
  |---|---|---|
84
102
  | First step | `graph.entry` (required) | `entry` if set, else the first node no edge points to |
85
- | Reading an earlier step | `{{state.<id>.<field>}}` | `{{<id>.<field>}}`; the previous step is `{{input}}` |
103
+ | Reading an earlier step | `{{<id>.<field>}}` (`{{state.<id>.<field>}}` still works) | `{{<id>.<field>}}`; the previous step is `{{input}}` |
86
104
  | Several conditions match | the first match wins | every match is followed |
87
105
  | No condition matches, no default edge | the flow ends quietly | the run fails |
88
106
  | Action settings | keys on the node | inside `params` |
@@ -187,7 +205,9 @@ Over MCP: `oalo_list_models`, `oalo_create_model`, `oalo_read_rows`,
187
205
  2. **Always give rows an id** (`--id-field`), usually the source system's own
188
206
  key. Then sending a row again updates it instead of adding a copy.
189
207
  3. **Write to dev, check, then promote.** Rows written to prod sync to live apps
190
- at once, so writing there needs `--env prod` and the person's go-ahead.
208
+ at once, so writing there needs `--env prod` and the person's go-ahead. A
209
+ draft bot reads dev and a published one prod, so load rows where the bot
210
+ you're testing reads them (rule 9).
191
211
  4. **For an app's own server** (mirroring its database into Oalo, reading data
192
212
  out): a server app hosted on Oalo already has `OALO_URL` and
193
213
  `OALO_SYNC_TOKEN` in its environment, locked to its own env's data. Use
@@ -389,7 +409,9 @@ oalo dashboards add Sales orders --title "Revenue by plan" --kind bars --sum tot
389
409
  ```
390
410
 
391
411
  1. **A question about numbers** (how many, how much, per week): `oalo metrics`
392
- (MCP `oalo_query_metrics`). Don't read rows and add them up.
412
+ (MCP `oalo_query_metrics`). Don't read rows and add them up. A model's rows
413
+ are counted in prod unless you pass `--env dev` (MCP `"env": "dev"`), so
414
+ rows from tests and draft bots need `--env dev`, on a chart too.
393
415
  2. **A chart the person wants to keep** goes on a dashboard with `oalo
394
416
  dashboards add` (MCP `oalo_save_dashboard_widget`); the dashboard is made
395
417
  when none has that name. Check `oalo dashboards` first: the same title
@@ -412,7 +434,8 @@ oalo channels # WhatsApp, Instagram, emai
412
434
 
413
435
  1. **To make a bot answer from a table,** vectorize the table, then attach it
414
436
  with `oalo bots knowledge`. Attaching alone does nothing for a table that
415
- isn't searchable.
437
+ isn't searchable. The rows must be in the env the bot reads: dev while it's
438
+ a draft, prod once published (`oalo bots` shows its status).
416
439
  2. **Read a setting with `--explain` before changing it.** Don't guess keys or
417
440
  values.
418
441
  3. **A published bot is live for customers.** `set` on one shows the change and
@@ -64,6 +64,16 @@
64
64
  32
65
65
  ]
66
66
  },
67
+ {
68
+ "clear_word": null,
69
+ "default": false,
70
+ "doc": "After each graph rebuild, a small AI model labels the links between similar passages (one depends on another, defines it, or is related), so a match can bring in what it depends on. Off: links are by similarity only. Needs a built graph (`oalo bots graph <bot> --build`).",
71
+ "effect": "uses AI credit at each graph rebuild, for the links whose pages changed",
72
+ "group": "knowledge",
73
+ "key": "graph_classify_edges",
74
+ "type": "true or false",
75
+ "values": null
76
+ },
67
77
  {
68
78
  "clear_word": null,
69
79
  "default": "retrieval",
@@ -116,6 +126,45 @@
116
126
  "shallow"
117
127
  ]
118
128
  },
129
+ {
130
+ "clear_word": null,
131
+ "default": "fixed",
132
+ "doc": "How much a turn packs. fixed: a set number of retrieved passages, and the whole conversation. fit: a budget from the model's window. What loads every turn goes first (frame, persona, resident topics, tools), then recent history (at most half of what's left), then retrieved knowledge fills the rest. The Context Inspector shows the split.",
133
+ "effect": null,
134
+ "group": "knowledge",
135
+ "key": "context.budget.policy",
136
+ "type": "one of",
137
+ "values": [
138
+ "fixed",
139
+ "fit"
140
+ ]
141
+ },
142
+ {
143
+ "clear_word": null,
144
+ "default": 50,
145
+ "doc": "With context.budget.policy=fit: the percent of the model's window a turn may fill (after room for the answer). Higher packs more retrieved knowledge and history, at more cost a turn.",
146
+ "effect": null,
147
+ "group": "knowledge",
148
+ "key": "context.budget.share",
149
+ "type": "number",
150
+ "values": [
151
+ 10,
152
+ 100
153
+ ]
154
+ },
155
+ {
156
+ "clear_word": null,
157
+ "default": 400000,
158
+ "doc": "With context.budget.policy=fit: the most tokens a turn may fill, whatever the window. Keeps a model with a huge window from packing it.",
159
+ "effect": null,
160
+ "group": "knowledge",
161
+ "key": "context.budget.cap",
162
+ "type": "number",
163
+ "values": [
164
+ 10000,
165
+ 2000000
166
+ ]
167
+ },
119
168
  {
120
169
  "clear_word": null,
121
170
  "default": "band",
@@ -326,6 +375,19 @@
326
375
  "link"
327
376
  ]
328
377
  },
378
+ {
379
+ "clear_word": null,
380
+ "default": "last",
381
+ "doc": "With guardrails on, the reply is checked before it's sent. last keeps the text after the bot's last tool call (drops lead-ins like \"let me check\"); all keeps every step's text, for a bot that answers, shows cards, then asks.",
382
+ "effect": null,
383
+ "group": "replies",
384
+ "key": "guarded_reply",
385
+ "type": "one of",
386
+ "values": [
387
+ "last",
388
+ "all"
389
+ ]
390
+ },
329
391
  {
330
392
  "clear_word": null,
331
393
  "default": "off",
@@ -14,6 +14,7 @@ import { dim } from "../events.js";
14
14
  * oalo bots settings <bot> every setting and its value
15
15
  * oalo bots settings <bot> set key=value ... [--yes] [--dry-run]
16
16
  * oalo bots settings --explain [key] what each setting does
17
+ * oalo bots graph <bot> [--build] [--reset --yes] its knowledge graph
17
18
  *
18
19
  * A source is a table made searchable with `oalo data vectorize`: its handle
19
20
  * (`model:products`, `table:prod.faq`) or just its name when that's unique.
@@ -27,8 +28,8 @@ export async function bots(flags, rest, opts = {}) {
27
28
  if (!url || !token) return fail(`oalo bots needs a CLI token.\n\n${HOW_TO_CONNECT}`, 2);
28
29
 
29
30
  const sub = rest[1];
30
- if (sub && !["knowledge", "settings", "tools"].includes(sub)) return fail(`unknown bots command: ${sub}\n\n${USAGE}`, 2);
31
- if ((sub === "knowledge" || sub === "tools") && !rest[2]) return fail(USAGE, 2);
31
+ if (sub && !["knowledge", "settings", "tools", "graph"].includes(sub)) return fail(`unknown bots command: ${sub}\n\n${USAGE}`, 2);
32
+ if ((sub === "knowledge" || sub === "tools" || sub === "graph") && !rest[2]) return fail(USAGE, 2);
32
33
  if (sub === "settings" && !rest[2] && !flags.explain) return fail(USAGE, 2);
33
34
 
34
35
  if (!opts.channel) {
@@ -45,6 +46,7 @@ export async function bots(flags, rest, opts = {}) {
45
46
  if (sub === "knowledge") return await knowledge(ch, rest[2], flags);
46
47
  if (sub === "settings") return await settings(ch, rest.slice(2), flags);
47
48
  if (sub === "tools") return await tools(ch, rest[2], flags);
49
+ if (sub === "graph") return await graph(ch, rest[2], flags);
48
50
  return await list(ch, flags, url);
49
51
  } catch (e) {
50
52
  return fail(e.message, 1);
@@ -60,6 +62,7 @@ const USAGE = [
60
62
  " oalo bots settings <bot> [--json]",
61
63
  " oalo bots settings <bot> set key=value [key=value ...] [--yes] [--dry-run]",
62
64
  " oalo bots settings --explain [key]",
65
+ " oalo bots graph <bot> [--build] [--reset --yes] [--json]",
63
66
  ].join("\n");
64
67
 
65
68
  async function list(ch, flags, url) {
@@ -125,6 +128,38 @@ async function knowledge(ch, botId, flags) {
125
128
  }
126
129
  }
127
130
 
131
+ // ── graph ────────────────────────────────────────────────────────────────
132
+
133
+ // The graph links the bot's passages, so a match can bring in related ones.
134
+ // It's opt in: --build makes it from the documents, and after that each new
135
+ // document keeps it current. How answers use it is in `oalo bots settings`.
136
+ async function graph(ch, botId, flags) {
137
+ if (!/^bot_[A-Za-z0-9_-]+$/.test(botId)) return fail(`name the bot by its public id (bot_...), as \`oalo bots\` prints it (got ${botId})`, 2);
138
+ if (flags.build && flags.reset) return fail("--build or --reset, not both", 2);
139
+
140
+ if (flags.reset) {
141
+ if (!flags.yes) return fail(`--reset deletes ${botId}'s whole graph, links added by hand or imported included. Add --yes to go ahead.`, 2);
142
+ const r = await ch.call("kg:reset", { bot_id: botId });
143
+ if (flags.json) return void console.log(JSON.stringify({ bot: botId, reset: true, nodes_deleted: r.nodes_deleted }, null, 2));
144
+ return void console.log(`${botId}: graph deleted (${r.nodes_deleted} topics). The bot answers from its documents alone until you --build again.`);
145
+ }
146
+
147
+ if (flags.build) await ch.call("kg:rebuild", { bot_id: botId });
148
+ const [cfg, counts] = await Promise.all([ch.call("kg:config", { bot_id: botId }), ch.call("kg:counts", { bot_id: botId })]);
149
+ if (flags.json) {
150
+ return void console.log(JSON.stringify({ bot: botId, built: cfg.built, building: !!flags.build, classify_edges: cfg.classify_edges, nodes: counts.nodes, edges: counts.edges, est_tokens: counts.est_tokens }, null, 2));
151
+ }
152
+
153
+ if (flags.build) console.log(`${botId}: building the graph in the background, usually within a minute or two. Run \`oalo bots graph ${botId}\` again to see it.`);
154
+ if (!cfg.built) {
155
+ if (!flags.build) console.log(`${botId} has no knowledge graph. --build makes one from its documents; after that, each new document keeps it current.`);
156
+ } else {
157
+ console.log(`${botId}: ${counts.nodes} topics, ${counts.edges} links, about ${counts.est_tokens} tokens of text`);
158
+ console.log(` labeled links ${cfg.classify_edges ? "on" : "off"} ${dim("(graph_classify_edges)")}`);
159
+ }
160
+ console.log(dim(`\nHow answers use it: oalo bots settings ${botId} (graph_retrieval, ancestor_preload_depth, graph_classify_edges). --reset --yes deletes it.`));
161
+ }
162
+
128
163
  // ── tools ────────────────────────────────────────────────────────────────
129
164
 
130
165
  const TRANSPORTS = { app: "your app", http_webhook: "webhook", builtin: "built in", wasm: "code", container_mcp: "action" };
@@ -171,7 +206,9 @@ async function settings(ch, args, flags) {
171
206
 
172
207
  if (flags.explain) {
173
208
  const { settings: spec } = await ch.call("chat:bots:settings", {});
174
- const key = typeof flags.explain === "string" ? flags.explain : botId;
209
+ const asked = typeof flags.explain === "string" ? flags.explain : botId;
210
+ // `all` (as the help offers) means every setting, like no key.
211
+ const key = asked === "all" ? undefined : asked;
175
212
  const pick = key ? spec.filter((s) => s.key === key || s.key.startsWith(`${key}.`) || s.group === key) : spec;
176
213
  if (!pick.length) return fail(`no setting ${key}. \`oalo bots settings --explain\` lists them all.`, 2);
177
214
  if (flags.json) return void console.log(JSON.stringify(pick, null, 2));
@@ -1,3 +1,4 @@
1
+ import { readFileSync, fstatSync } from "node:fs";
1
2
  import { OaloChannel } from "../channel.js";
2
3
  import { resolve as resolveConfig, controlPlane, HOW_TO_CONNECT } from "../config.js";
3
4
  import { requireFeature } from "../server.js";
@@ -119,6 +120,63 @@ function printNamespaces() {
119
120
  );
120
121
  }
121
122
 
123
+ /**
124
+ * The params for a call: inline JSON, `@file.json` (that file), or `-` (stdin).
125
+ * With no argument, stdin is read only when something is piped or redirected
126
+ * into it (a FIFO or a file), so a bare call never waits on a terminal or on
127
+ * /dev/null. Errors name where the JSON came from.
128
+ */
129
+ export async function readParams(raw, { stdin = process.stdin, piped = stdinPiped() } = {}) {
130
+ let text;
131
+ let from;
132
+ if (raw === "-" || (raw === undefined && piped)) {
133
+ from = "stdin";
134
+ text = await readAll(stdin);
135
+ if (raw === undefined && !text.trim()) return {};
136
+ } else if (typeof raw === "string" && raw.startsWith("@")) {
137
+ const path = raw.slice(1);
138
+ if (!path) throw new Error("@ needs a file name: oalo call <event> @params.json");
139
+ from = path;
140
+ try {
141
+ text = readFileSync(path, "utf8");
142
+ } catch (e) {
143
+ throw new Error(`can't read params file ${path}: ${e.code === "ENOENT" ? "no such file" : e.code || e.message}`);
144
+ }
145
+ } else if (raw === undefined || raw === "") {
146
+ return {};
147
+ } else {
148
+ from = null;
149
+ text = raw;
150
+ }
151
+
152
+ let params;
153
+ try {
154
+ params = JSON.parse(text);
155
+ } catch (e) {
156
+ throw new Error(from ? `params in ${from} must be valid JSON: ${e.message}` : `params must be valid JSON: ${e.message}`);
157
+ }
158
+ if (params === null || typeof params !== "object" || Array.isArray(params)) {
159
+ throw new Error(from ? `params in ${from} must be a JSON object` : "params must be a JSON object");
160
+ }
161
+ return params;
162
+ }
163
+
164
+ function stdinPiped() {
165
+ try {
166
+ const s = fstatSync(0);
167
+ return s.isFIFO() || s.isFile();
168
+ } catch {
169
+ return false;
170
+ }
171
+ }
172
+
173
+ async function readAll(stream) {
174
+ let text = "";
175
+ stream.setEncoding?.("utf8");
176
+ for await (const chunk of stream) text += chunk;
177
+ return text;
178
+ }
179
+
122
180
  export async function call(flags, rest) {
123
181
  if (flags.list || flags.namespaces) {
124
182
  await list(flags, rest);
@@ -127,27 +185,19 @@ export async function call(flags, rest) {
127
185
 
128
186
  const event = rest[1];
129
187
  if (!event) {
130
- console.error("usage: oalo call <event> ['<json params>']\n");
188
+ console.error("usage: oalo call <event> ['<json params>' | @file.json | -]\n");
131
189
  console.error("Run `oalo call --list` to see the events you can call.");
132
190
  process.exitCode = 2;
133
191
  return;
134
192
  }
135
193
 
136
- let params = {};
137
- const raw = rest[2];
138
- if (raw) {
139
- try {
140
- params = JSON.parse(raw);
141
- } catch (e) {
142
- console.error(`params must be valid JSON: ${e.message}`);
143
- process.exitCode = 2;
144
- return;
145
- }
146
- if (params === null || typeof params !== "object" || Array.isArray(params)) {
147
- console.error("params must be a JSON object");
148
- process.exitCode = 2;
149
- return;
150
- }
194
+ let params;
195
+ try {
196
+ params = await readParams(rest[2]);
197
+ } catch (e) {
198
+ console.error(e.message);
199
+ process.exitCode = 2;
200
+ return;
151
201
  }
152
202
 
153
203
  const cfg = resolveConfig(flags);
@@ -46,8 +46,11 @@ export async function deploy(flags) {
46
46
  } catch {
47
47
  return fail("not inside a git repo. oalo deploy --new makes an app from this repo's commits.", 2);
48
48
  }
49
- app = slugify(typeof flags.new === "string" ? flags.new : top.split("/").pop());
49
+ const typed = typeof flags.new === "string" ? flags.new : top.split("/").pop();
50
+ app = slugify(typed);
50
51
  if (!app) return fail("give the new app a name: oalo deploy --new <name>", 2);
52
+ const note = slugNote(typed, app, typeof flags.new === "string" ? "the name" : "this repo's folder name");
53
+ if (note) console.error(note);
51
54
  }
52
55
  if (!app) return fail("which app? Pass --app <slug> (`oalo apps` lists them), save it with `oalo link --app <slug>`, or make one from this repo with `oalo deploy --new`.", 2);
53
56
 
@@ -206,8 +209,11 @@ async function fromGit(url, token, flags, opts = {}) {
206
209
  if (!gitToken) return fail(`${name} is empty or not set. Put the access token in it, then run this again.`, 2);
207
210
  }
208
211
 
209
- const app = slugify(typeof flags.new === "string" ? flags.new : repoName(from));
212
+ const typed = typeof flags.new === "string" ? flags.new : repoName(from);
213
+ const app = slugify(typed);
210
214
  if (!app) return fail("give the new app a name: oalo deploy --new <name> --from <url>", 2);
215
+ const note = slugNote(typed, app, typeof flags.new === "string" ? "the name" : "the repository's name");
216
+ if (note) console.error(note);
211
217
 
212
218
  try {
213
219
  await requireFeature(url, "deploy_from_git", "oalo deploy --from");
@@ -446,6 +452,23 @@ export const _releases = releases;
446
452
  // new release has a minute to answer. Wait longer than that.
447
453
  export const ROLLBACK_WAIT_MS = 35 * 60_000;
448
454
 
455
+ /**
456
+ * One line saying which slug a new app gets, when it isn't what was typed
457
+ * (`tc3_routedesk_relay` becomes `tc3-routedesk-relay`), so the next command
458
+ * uses the slug. Null when the name was already a slug.
459
+ */
460
+ export function slugNote(typed, slug, from = "the name") {
461
+ const name = String(typed || "");
462
+ if (!slug || name === slug) return null;
463
+ const inner = name.replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, "");
464
+ const why = [];
465
+ if (/[A-Z]/.test(name)) why.push("capitals are lowered");
466
+ if (/[^A-Za-z0-9-]|--/.test(inner)) why.push("anything else becomes a dash");
467
+ if (inner !== name) why.push("dashes at either end are dropped");
468
+ if (inner.replace(/[^A-Za-z0-9]+/g, "-").length > 40) why.push("it is cut to 40 characters");
469
+ return `the new app's slug is ${slug}, made from ${from} ${JSON.stringify(name)}: a slug (the app's address, and what --app takes) has only lowercase letters, digits and single dashes, so ${why.join(", ") || "it was changed"}. Use --app ${slug} from now on.`;
470
+ }
471
+
449
472
  /** An app slug from a name: lowercase letters, digits and dashes. */
450
473
  export function slugify(name) {
451
474
  return String(name || "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
@@ -18,7 +18,9 @@ import { dim } from "../events.js";
18
18
  export async function docs(flags, rest) {
19
19
  // `oalo docs list` (and `ls`) is what people and agents type for the list:
20
20
  // there is no page by either name.
21
- const slug = ["list", "ls"].includes(rest[1]) ? undefined : rest[1];
21
+ // `oalo docs search <words>` is what people type for --search.
22
+ if (rest[1] === "search" && rest.length > 2 && typeof flags.search !== "string") flags.search = rest.slice(2).join(" ");
23
+ const slug = ["list", "ls"].includes(rest[1]) || typeof flags.search === "string" ? undefined : rest[1];
22
24
  const cfg = resolveConfig(flags);
23
25
  const { url, token } = controlPlane(cfg);
24
26
  if (!url || !token) {
@@ -73,13 +73,9 @@ export async function emit(flags, rest) {
73
73
 
74
74
  if (flags.json) return void console.log(JSON.stringify(r, null, 2));
75
75
 
76
- const names = r.loops.map((l) => l.name);
76
+ const names = (r.loops || []).map((l) => l.name);
77
77
  if (r.dry_run) {
78
- console.log(
79
- names.length
80
- ? `${type} would fire ${names.length} loop${names.length > 1 ? "s" : ""}: ${names.join(", ")}`
81
- : `no enabled loop listens for ${type}${Object.keys(payload).length ? " with this payload" : ""}. Nothing would fire.`,
82
- );
78
+ for (const line of dryRunLines(type, payload, r)) console.log(line);
83
79
  console.log(dim("dry run: nothing was emitted"));
84
80
  } else {
85
81
  console.log(`emitted ${type} (event ${r.event_id}), tagged as a test from the CLI`);
@@ -98,6 +94,29 @@ export async function emit(flags, rest) {
98
94
  }
99
95
  }
100
96
 
97
+ /**
98
+ * What a dry run found: the loops that would fire, the ones that would match
99
+ * but are off (the loop or its trigger), and the ones listening for the type
100
+ * whose filter doesn't match this payload. Newer Bases send `off` and
101
+ * `filtered_out`; an older one only `loops`.
102
+ */
103
+ export function dryRunLines(type, payload, r) {
104
+ const fire = (r.loops || []).map((l) => l.name);
105
+ const off = r.off || [];
106
+ const filtered = r.filtered_out || [];
107
+ const lines = [];
108
+ if (fire.length) lines.push(`${type} would fire ${fire.length} loop${fire.length > 1 ? "s" : ""}: ${fire.join(", ")}`);
109
+ for (const l of off) lines.push(`would match but is off: ${l.name} (the loop or its trigger is off; oalo loops on ${l.name} turns the loop on)`);
110
+ for (const l of filtered) lines.push(`filter doesn't match: ${l.name} (filter ${JSON.stringify(l.filter ?? {})})`);
111
+ if (!fire.length) {
112
+ // An older Base sends neither list, and its `loops` holds enabled ones only.
113
+ const older = r.off === undefined && r.filtered_out === undefined;
114
+ const why = off.length || filtered.length ? "" : `no ${older ? "enabled " : ""}loop listens for ${type}${Object.keys(payload || {}).length ? " with this payload" : ""}. `;
115
+ lines.push(`${why}Nothing would fire.`);
116
+ }
117
+ return lines;
118
+ }
119
+
101
120
  function printList(events) {
102
121
  const byCat = new Map();
103
122
  for (const e of events) {
@@ -98,6 +98,11 @@ async function list(ch, app, env, flags) {
98
98
  }
99
99
  }
100
100
  if (!vars.length) console.log(dim(` none yet: oalo env set NAME=value --app ${r.app}${env === "prod" ? " --env prod" : ""}`));
101
+ // Secret is the default for any name without a public prefix, so say how to
102
+ // keep a value that is safe to show as plain (found by the CLI trial).
103
+ if (vars.some((v) => v.secret)) {
104
+ console.log(dim(` secret values are never shown. A variable is secret unless its name has a public prefix (VITE_, EXPO_PUBLIC_, ...). To store one as plain, set it again with --public: oalo env set NAME=value --public${env === "prod" ? " --env prod" : ""}`));
105
+ }
101
106
  }
102
107
 
103
108
  async function set(ch, app, env, vars, flags) {
@@ -14,6 +14,7 @@ import {
14
14
  writeGraphFile,
15
15
  removeFile,
16
16
  listGraphFiles,
17
+ expandTargets,
17
18
  locallyModified,
18
19
  standing,
19
20
  rel,
@@ -129,11 +130,11 @@ function botKey(bots, flow) {
129
130
  return bot?.public_bot_id || String(flow.bot_id);
130
131
  }
131
132
 
132
- /** Resolve the files a command acts on: the ones named, or every file. */
133
+ /** Resolve the files a command acts on: the ones named (a folder means the files in it), or every file. */
133
134
  function targetFiles(rest) {
134
135
  const named = rest.slice(1);
135
136
  if (named.length === 0) return listGraphFiles();
136
- return named.map((p) => resolvePath(p));
137
+ return expandTargets(named.map((p) => resolvePath(p)));
137
138
  }
138
139
 
139
140
  function load(path) {
@@ -311,15 +312,18 @@ export async function status(flags, rest) {
311
312
 
312
313
  // ---- lint ------------------------------------------------------------------
313
314
 
314
- export async function lint(flags, rest) {
315
+ // Lint has no check for a tool's code: it is compiled when pushed.
316
+ export const TOOL_NOT_LINTED = "not checked by lint: a tool's code is compiled and checked when you push it";
317
+
318
+ export async function lint(flags, rest, opts = {}) {
315
319
  const paths = targetFiles(rest);
316
320
  if (paths.length === 0) {
317
- console.error("no flow or loop files under .oalo/. Run `oalo pull` first, or name a file.");
321
+ console.error(rest.length > 1 ? `no flow, loop or tool files in ${rest.slice(1).join(", ")}` : "no flow or loop files under .oalo/. Run `oalo pull` first, or name a file.");
318
322
  process.exitCode = 1;
319
323
  return;
320
324
  }
321
325
 
322
- const ws = await openWorkspace(flags, "lint").catch((e) => (console.error(`lint failed: ${e.message}`), null));
326
+ const ws = await openWorkspace(flags, "lint", opts).catch((e) => (console.error(`lint failed: ${e.message}`), null));
323
327
  if (!ws) return void (process.exitCode = process.exitCode || 2);
324
328
  const { ch } = ws;
325
329
  let errors = 0;
@@ -332,6 +336,11 @@ export async function lint(flags, rest) {
332
336
  errors++;
333
337
  continue;
334
338
  }
339
+ if (file.kind === "tool") {
340
+ if (flags.json) console.log(JSON.stringify({ path: rel(path), findings: [], note: TOOL_NOT_LINTED }));
341
+ else console.log(`${rel(path)}\n ${TOOL_NOT_LINTED}`);
342
+ continue;
343
+ }
335
344
  const findings = await lintFile(ch, file);
336
345
  if (flags.json) {
337
346
  console.log(JSON.stringify({ path: rel(path), findings }));
@@ -545,7 +554,9 @@ const describeTrigger = (t) =>
545
554
  .join(" ");
546
555
 
547
556
  export async function push(flags, rest) {
548
- const explicit = rest.length > 1;
557
+ // A file named directly is pushed even when unchanged; the files in a named
558
+ // folder are pushed only when changed, like a bare push.
559
+ const named = new Set(rest.slice(1).map((p) => resolvePath(p)));
549
560
  const paths = targetFiles(rest);
550
561
  if (paths.length === 0) {
551
562
  console.error("no flow or loop files under .oalo/. Run `oalo pull` first, or name a file.");
@@ -568,7 +579,7 @@ export async function push(flags, rest) {
568
579
  continue;
569
580
  }
570
581
  // Without named files, push only what changed (or is new).
571
- if (!explicit && !locallyModified(file) && !flags.all) continue;
582
+ if (!named.has(path) && !locallyModified(file) && !flags.all) continue;
572
583
 
573
584
  console.log(`${rel(path)}`);
574
585
  const r = await pushOne(ch, path, file, flags);
@@ -17,9 +17,13 @@ export async function incidents(flags, rest, opts = {}) {
17
17
 
18
18
  const ch = (opts.channel || ((o) => new OaloChannel(o)))({ url, token });
19
19
  let r;
20
+ let live = null;
20
21
  try {
21
22
  await ch.connect();
22
23
  r = await ch.call("incidents:list", { app });
24
+ // Only a live launch is checked. With nothing on record, find out whether
25
+ // there is one, so "no incidents" doesn't claim checks that never ran.
26
+ if (!flags.json && !(r.incidents || []).length) live = await liveRelease(ch, app);
23
27
  } catch (e) {
24
28
  return fail(e.message, 1);
25
29
  } finally {
@@ -28,7 +32,7 @@ export async function incidents(flags, rest, opts = {}) {
28
32
  if (flags.json) return void console.log(JSON.stringify(r, null, 2));
29
33
 
30
34
  const list = r.incidents || [];
31
- if (!list.length) return void console.log(`${r.app}: no incidents. The live app is checked every minute.`);
35
+ if (!list.length) return void console.log(noIncidents(r.app || app, live));
32
36
  const when = (iso) => String(iso).slice(0, 16).replace("T", " ");
33
37
  for (const i of list) {
34
38
  const state = i.resolved_at ? `${when(i.opened_at)} to ${when(i.resolved_at)}` : `open since ${when(i.opened_at)}`;
@@ -38,6 +42,25 @@ export async function incidents(flags, rest, opts = {}) {
38
42
  if (list.some((i) => !i.resolved_at)) process.exitCode = 1;
39
43
  }
40
44
 
45
+ /** true when the app has a live release, false when it has none, null when that can't be told. */
46
+ async function liveRelease(ch, slug) {
47
+ try {
48
+ const { apps = [] } = await ch.call("list_apps", {});
49
+ const a = apps.find((x) => x.slug === slug || x.id === slug);
50
+ if (!a) return null;
51
+ const rel = await ch.call("get_release", { app_id: a.id });
52
+ return Boolean(rel?.release?.commit_hash);
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+
58
+ export function noIncidents(app, live) {
59
+ if (live === false) return `${app}: no live launch yet, so there is nothing to check. Oalo's uptime check watches the live app (every minute) once \`oalo deploy --app ${app} --env prod\` has launched it; the preview isn't checked (\`oalo logs --app ${app}\` shows it).`;
60
+ if (live === true) return `${app}: no incidents. The live app is checked every minute.`;
61
+ return `${app}: no incidents on record. Only a live launch is checked (every minute), never the preview.`;
62
+ }
63
+
41
64
  function fail(message, code) {
42
65
  console.error(message);
43
66
  process.exitCode = code;
@@ -124,6 +124,8 @@ async function status(flags) {
124
124
  }
125
125
 
126
126
  console.log(`workspace ${cfg.serverUrl}`);
127
+ // A link found in a parent folder of this repository (see findConfig).
128
+ if (cfg.configDir && cfg.configDir !== process.cwd()) console.log(`linked by ${cfg.configDir}/.oalo/config.json`);
127
129
  console.log(`env ${cfg.env}`);
128
130
  console.log(`app ${cfg.appId || "(none)"}`);
129
131
  console.log(`sync token ${cfg.token ? "present" : "MISSING"} (${credentialsPath()})`);
@@ -1,6 +1,6 @@
1
1
  import { hostname } from "node:os";
2
2
  import { spawn } from "node:child_process";
3
- import { readConfig, writeToken, readEntry, forgetWorkspace, credentialsPath } from "../config.js";
3
+ import { findConfig, writeToken, readEntry, forgetWorkspace, credentialsPath } from "../config.js";
4
4
  import { OaloChannel } from "../channel.js";
5
5
  import { dim } from "../events.js";
6
6
 
@@ -22,7 +22,7 @@ import { dim } from "../events.js";
22
22
  // A bare name is the workspace's own address: `oalo login acme` is
23
23
  // https://acme.oalo.ai, what the signup's last screen shows.
24
24
  function serverFrom(flags, rest = []) {
25
- const cfg = readConfig() || {};
25
+ const cfg = findConfig()?.config || {};
26
26
  const arg = rest[1];
27
27
  const fromArg = !arg ? "" : /^[a-z0-9][a-z0-9-]{0,62}$/i.test(arg) ? `https://${arg.toLowerCase()}.oalo.ai` : /^https?:\/\//.test(arg) ? arg : "";
28
28
  return (flags.server || fromArg || process.env.OALO_URL || cfg.serverUrl || "").replace(/\/$/, "");