@lotics/cli 0.106.0 → 0.109.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/AGENTS.md CHANGED
@@ -57,5 +57,20 @@ whether something exists, read `lotics --help` § COMMANDS — the whole section
57
57
  half — an agent's `tool_names`/`inputs`/`outputs`, a workflow's schemas — is authored by the
58
58
  `set_app_*` tools. A manifest alias with no server binding only fails at the app's first call, so
59
59
  deploy warns about the mismatch.
60
+
61
+ **The five `lotics.*` keys look alike and point in three different directions.** Before editing one,
62
+ know which you are touching — this is the single most expensive thing to get wrong in a manifest:
63
+
64
+ | `lotics.<key>` | Owned by | Your edit reaches the app via |
65
+ |---|---|---|
66
+ | `queries`, `capabilities` | the manifest | `app deploy` — re-synced on every one (an absent `capabilities` block turns them all OFF) |
67
+ | `knowledge`, `config` | the manifest | `opctl app publish` / `app release` — package authoring only |
68
+ | `workflows` | the workflow row's verified contract | `app workflow set`, which type-checks the BODY against your declaration and refuses a schema the body cannot satisfy |
69
+ | `agents` | the app row | **nothing.** It is a mirror: `app codegen` re-silvers it from the app, and an agent is changed with `set_app_agent` |
70
+
71
+ `agents` is the one that bites, because editing a mirror still retypes `useAgentRun` — green
72
+ locally, unchanged in production. `app codegen` reverts such an edit and `app deploy` refuses while
73
+ the two disagree. An agent's PROSE is not in the manifest at all: it lives in
74
+ `src/agents/<alias>.md` and is pushed by `app agent set`.
60
75
  - **OAuth connections.** Attaching a connected account is web-only; the CLI can list them.
61
76
  - **Anything needing a browser.** `app dev` and `file preview` shell out to a local Chrome.
package/README.md CHANGED
@@ -209,6 +209,11 @@ lotics app versions app_... # ...for any app, without pulling it
209
209
  # use this after a rename, or when a pull ran offline.
210
210
  lotics app codegen # import { F, OPT } from "../.lotics/app_fields"
211
211
 
212
+ # Every deploy pre-flight, WITHOUT the build or the version row: agent schemas vs
213
+ # the live app, aliases the code calls that nothing bound, undeclared capabilities,
214
+ # query drift. Exits 1 on what a deploy refuses, so CI can gate on it.
215
+ lotics app check
216
+
212
217
  # Execute a bound app workflow end-to-end (inputs: inline / @file / stdin)
213
218
  lotics app workflow run issueInvoice '{"record_id":"rec_..."}'
214
219
  cat inputs.json | lotics app workflow run importRates # bulk inputs bypass ARG_MAX
package/dist/src/cli.js CHANGED
@@ -70180,11 +70180,58 @@ async function fetchLatestNpmVersion(packageName) {
70180
70180
  return null;
70181
70181
  }
70182
70182
  }
70183
+ function orderedLike(value, template) {
70184
+ if (Array.isArray(value)) {
70185
+ const t = Array.isArray(template) ? template : [];
70186
+ return value.map((v, i2) => orderedLike(v, t[i2]));
70187
+ }
70188
+ if (value === null || typeof value !== "object") return value;
70189
+ const from = value;
70190
+ const tmpl = template !== null && typeof template === "object" && !Array.isArray(template) ? template : {};
70191
+ const has2 = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
70192
+ const first3 = Object.keys(tmpl).filter((k) => has2(from, k));
70193
+ const taken = new Set(first3);
70194
+ const rest = Object.keys(from).filter((k) => !taken.has(k));
70195
+ return Object.fromEntries(
70196
+ [...first3, ...rest].map((k) => [k, orderedLike(from[k], tmpl[k])])
70197
+ );
70198
+ }
70183
70199
  function toManifestAgents(agents) {
70184
70200
  return Object.fromEntries(
70185
70201
  Object.entries(agents).map(([alias, { instructions: _prose, ...typed }]) => [alias, typed])
70186
70202
  );
70187
70203
  }
70204
+ var AGENT_TYPED_KEYS = ["inputs", "outputs"];
70205
+ function sameSchema(a, b) {
70206
+ const canonical = (v) => {
70207
+ if (Array.isArray(v)) return v.map(canonical);
70208
+ if (v && typeof v === "object") {
70209
+ return Object.fromEntries(
70210
+ Object.entries(v).sort(([x2], [y]) => x2 < y ? -1 : x2 > y ? 1 : 0).map(([k, val]) => [k, canonical(val)])
70211
+ );
70212
+ }
70213
+ return v;
70214
+ };
70215
+ return JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
70216
+ }
70217
+ function agentTypeDivergences(manifestAgents, liveAgents) {
70218
+ const out = [];
70219
+ for (const [alias, declared] of Object.entries(manifestAgents ?? {})) {
70220
+ const live = (liveAgents ?? {})[alias];
70221
+ if (!live) {
70222
+ out.push(
70223
+ `${alias} \u2014 typed locally but NOT bound on the app, so useAgentRun("${alias}") 400s at runtime`
70224
+ );
70225
+ continue;
70226
+ }
70227
+ for (const key of AGENT_TYPED_KEYS) {
70228
+ if (!sameSchema(declared[key], live[key])) {
70229
+ out.push(`${alias}.${key} \u2014 local types disagree with the live agent`);
70230
+ }
70231
+ }
70232
+ }
70233
+ return out;
70234
+ }
70188
70235
  var WORKFLOWS_DIR = path5.join("src", "workflows");
70189
70236
  var WORKFLOW_GLOBALS_DIR = path5.join(".lotics", "workflows");
70190
70237
  var AGENTS_DIR = path5.join("src", "agents");
@@ -70631,8 +70678,9 @@ async function appCodegen(args) {
70631
70678
  );
70632
70679
  return;
70633
70680
  }
70681
+ let app = null;
70634
70682
  try {
70635
- const app = await args.client.getApp(meta3.app_id);
70683
+ app = await args.client.getApp(meta3.app_id);
70636
70684
  await writeGeneratedAppFields(
70637
70685
  args.client,
70638
70686
  projectDir,
@@ -70642,6 +70690,20 @@ async function appCodegen(args) {
70642
70690
  } catch (err2) {
70643
70691
  warnAppFieldsUnwritten(projectDir, err2);
70644
70692
  }
70693
+ if (app) {
70694
+ const refreshedAgents = orderedLike(toManifestAgents(app.agents ?? {}), meta3.agents);
70695
+ if (!sameSchema(meta3.agents ?? {}, refreshedAgents)) {
70696
+ writeAppMeta(projectDir, { ...meta3, agents: refreshedAgents });
70697
+ writeAppDts(projectDir, {
70698
+ workflows: meta3.workflows,
70699
+ queries: meta3.queries,
70700
+ agents: refreshedAgents
70701
+ });
70702
+ console.error(
70703
+ `Refreshed package.json#lotics.agents from the app \u2014 that block reflects it, so a hand edit retypes useAgentRun without changing the agent. To change one: set_app_agent.`
70704
+ );
70705
+ }
70706
+ }
70645
70707
  await refreshWorkflowGlobals(args.client, projectDir, meta3.app_id, meta3.workflows ?? {});
70646
70708
  }
70647
70709
  async function refreshWorkflowGlobals(client, projectDir, app_id, workflows) {
@@ -70883,24 +70945,27 @@ async function appDeploy(client, args) {
70883
70945
  const projectDir = path5.resolve(args.projectDir ?? process.cwd());
70884
70946
  const meta3 = readAppMeta(projectDir);
70885
70947
  warnIfDeployingLinkedKit(projectDir);
70886
- const sourceText = readAppSourceText(projectDir);
70887
- const called = calledAppAliases(sourceText);
70888
- if (called.dynamic.length > 0) {
70948
+ const liveApp = await client.getApp(meta3.app_id);
70949
+ const divergences = agentTypeDivergences(meta3.agents, liveApp.agents);
70950
+ if (divergences.length > 0) {
70889
70951
  console.error(
70890
70952
  `
70891
- \u26A0 This app calls ${called.dynamic.join(" / ")} with an alias it computes at runtime, which this deploy cannot read.
70892
- The version records only the aliases named as literals, so removing a binding this app reaches dynamically will NOT be refused.`
70893
- );
70894
- }
70895
- const undeclared = undeclaredCapabilities(sourceText, meta3.capabilities);
70896
- if (undeclared.length > 0) {
70897
- const block = JSON.stringify(Object.fromEntries(undeclared.map((c) => [c, true])));
70898
- console.error(
70899
- `
70900
- \u26A0 This app calls capability-gated SDK functions for ${undeclared.join(", ")} but the manifest doesn't declare ${undeclared.length > 1 ? "them" : "it"} \u2014 those calls will 403 at runtime.
70901
- Add to package.json#lotics.capabilities: ${block}`
70953
+ Refusing to deploy \u2014 package.json#lotics.agents disagrees with the live app:
70954
+ ` + divergences.map((d) => ` \u2022 ${d}`).join("\n") + `
70955
+
70956
+ lotics.agents is a REFLECTION of the app, not an authoring surface, but it is what
70957
+ types useAgentRun \u2014 so this build was checked against an agent that does not exist.
70958
+ To take the app's shape: lotics app codegen (refreshes the block + the types)
70959
+ To CHANGE the agent instead: lotics run set_app_agent '{"app_id":"${meta3.app_id}","alias":"\u2026","outputs":{\u2026}}'
70960
+ (send only what changes \u2014 the server merges), then codegen.`
70902
70961
  );
70962
+ process.exit(1);
70903
70963
  }
70964
+ const sourceText = readAppSourceText(projectDir);
70965
+ const called = calledAppAliases(sourceText);
70966
+ warnIfAgentProseDiffers(projectDir, liveApp.agents);
70967
+ warnIfDynamicAliases(called);
70968
+ warnIfUndeclaredCapabilities(sourceText, meta3.capabilities);
70904
70969
  writeAppDts(projectDir, { workflows: meta3.workflows, queries: meta3.queries, agents: meta3.agents });
70905
70970
  console.error("Building...");
70906
70971
  await runNpm(["run", "build"], projectDir);
@@ -71019,6 +71084,63 @@ function warnIfQueriesDiffer(app, manifest) {
71019
71084
  (or one alias at a time), or adopt the app's with 'lotics app pull'.`
71020
71085
  );
71021
71086
  }
71087
+ async function appCheck(client, args = {}) {
71088
+ const projectDir = path5.resolve(args.projectDir ?? process.cwd());
71089
+ const meta3 = readAppMeta(projectDir);
71090
+ const app = await client.getApp(meta3.app_id);
71091
+ const sourceText = readAppSourceText(projectDir);
71092
+ const called = calledAppAliases(sourceText);
71093
+ const divergences = agentTypeDivergences(meta3.agents, app.agents);
71094
+ for (const d of divergences) {
71095
+ console.error(`\u2717 package.json#lotics.agents.${d}`);
71096
+ }
71097
+ if (divergences.length > 0) {
71098
+ console.error(
71099
+ ` A deploy REFUSES this: the bundle would be typed against an agent that does not exist.
71100
+ Take the app's shape with 'lotics app pull ${meta3.app_id}', or change the agent with set_app_agent.`
71101
+ );
71102
+ }
71103
+ warnIfDeployingLinkedKit(projectDir);
71104
+ warnIfAgentProseDiffers(projectDir, app.agents);
71105
+ warnIfDynamicAliases(called);
71106
+ warnIfUndeclaredCapabilities(sourceText, meta3.capabilities);
71107
+ warnIfUnboundAliases(app, called);
71108
+ warnIfQueriesDiffer(app, meta3.queries ?? {});
71109
+ warnIfUnbranded(app);
71110
+ if (divergences.length > 0) process.exit(1);
71111
+ console.error("Checked the app's bindings, capabilities and agent schemas \u2014 nothing blocking.");
71112
+ }
71113
+ function warnIfAgentProseDiffers(projectDir, liveAgents) {
71114
+ for (const [alias, live] of Object.entries(liveAgents ?? {})) {
71115
+ const file2 = agentFilePath2(projectDir, alias);
71116
+ if (!fs4.existsSync(file2)) continue;
71117
+ const local = stripAgentHeader(fs4.readFileSync(file2, "utf-8"));
71118
+ if (local === "" || local === (live.instructions ?? "")) continue;
71119
+ console.error(
71120
+ `
71121
+ \u26A0 ${path5.relative(projectDir, file2)} differs from the live agent's instructions.
71122
+ A deploy does not push prose. Send it with 'lotics app agent set ${alias}'.`
71123
+ );
71124
+ }
71125
+ }
71126
+ function warnIfDynamicAliases(called) {
71127
+ if (called.dynamic.length === 0) return;
71128
+ console.error(
71129
+ `
71130
+ \u26A0 This app calls ${called.dynamic.join(" / ")} with an alias it computes at runtime, which no static check can read.
71131
+ A version records only the aliases named as literals, so removing a binding this app reaches dynamically will NOT be refused.`
71132
+ );
71133
+ }
71134
+ function warnIfUndeclaredCapabilities(sourceText, capabilities) {
71135
+ const undeclared = undeclaredCapabilities(sourceText, capabilities);
71136
+ if (undeclared.length === 0) return;
71137
+ const block = JSON.stringify(Object.fromEntries(undeclared.map((c) => [c, true])));
71138
+ console.error(
71139
+ `
71140
+ \u26A0 This app calls capability-gated SDK functions for ${undeclared.join(", ")} but the manifest doesn't declare ${undeclared.length > 1 ? "them" : "it"} \u2014 those calls will 403 at runtime.
71141
+ Add to package.json#lotics.capabilities: ${block}`
71142
+ );
71143
+ }
71022
71144
  function warnIfUnboundAliases(app, called) {
71023
71145
  const {
71024
71146
  queries: unboundQueries,
@@ -92068,6 +92190,11 @@ COMMANDS
92068
92190
  * marks the currently served version)
92069
92191
  lotics app codegen [path] Regenerate .lotics/* (types + field/option ids)
92070
92192
  from the manifest + workspace schema \u2014 no deploy
92193
+ lotics app check Run every deploy pre-flight WITHOUT building or
92194
+ shipping: agent schemas vs the live app, aliases
92195
+ the code calls but nothing bound, undeclared
92196
+ capabilities, query drift. Exits 1 on what a
92197
+ deploy would refuse, so CI can gate on it
92071
92198
  lotics app workflow run <alias> '<json>' Execute a bound app workflow end-to-end
92072
92199
  (inputs: inline JSON, @file, or stdin;
92073
92200
  --print-created reports created records +
@@ -92085,10 +92212,11 @@ COMMANDS
92085
92212
  (inputs: inline JSON, @file, or stdin; streams
92086
92213
  progress to stderr, reports the settled run;
92087
92214
  --session <id> continues a thread; --json)
92088
- lotics app agent set <alias> Push the edited src/agents/<alias>.md instructions
92089
- + the manifest's typed fields through set_app_agent
92090
- (set_app_agent REPLACES the declaration \u2014 this
92091
- sends it whole so nothing is silently dropped)
92215
+ lotics app agent set <alias> Push the edited src/agents/<alias>.md instructions,
92216
+ and ONLY those \u2014 the server merges, so the typed
92217
+ fields keep whatever is bound (a manifest is a
92218
+ snapshot; replaying it would revert them). Change
92219
+ those with set_app_agent, then pull.
92092
92220
  lotics app subdomain <new-subdomain> Rename the app's public <slug>.lotics.app address
92093
92221
  lotics app rename "<new name>" Rename the app's display name (launcher title)
92094
92222
  lotics app dev [path] Run the app locally with HMR (RPC forwarded to prod)
@@ -92608,6 +92736,7 @@ async function main() {
92608
92736
  console.error(" lotics app deploy -m <message> Build + upload the current directory (-m required)");
92609
92737
  console.error(" lotics app versions [app_id] Show deploy history (version, when, who, message)");
92610
92738
  console.error(" lotics app codegen [path] Regenerate .lotics/* (types + field ids) \u2014 no deploy");
92739
+ console.error(" lotics app check Deploy's pre-flight without the build (exits 1 on a blocker)");
92611
92740
  console.error(" lotics app workflow run <alias> '<json>' Execute a bound app workflow end-to-end");
92612
92741
  console.error(" lotics app workflow set <alias> Push the edited src/workflows/<alias>.ts body");
92613
92742
  console.error(" lotics app workflow pull Rewrite src/workflows/*.ts from the server");
@@ -92823,6 +92952,10 @@ Available workspaces:`);
92823
92952
  await appVersions(client, { app_id: appId });
92824
92953
  return;
92825
92954
  }
92955
+ if (subcommand === "check") {
92956
+ await appCheck(client, {});
92957
+ return;
92958
+ }
92826
92959
  if (subcommand === "workflow") {
92827
92960
  const action = toolArgs;
92828
92961
  const workflowUsage = () => {
@@ -32,10 +32,11 @@ Per-command syntax, flags, contracts, and gotchas for the public `lotics` CLI. S
32
32
  | `lotics app pull <app_id> [path]` | Download source archive from R2 (presigned), extract, npm install, stamp package.json's `lotics` field. With no `[path]`: refresh the cwd IN PLACE when it's already this app's own project (its manifest `app_id` matches — the documented `cd <app> && lotics app pull` flow), else clone into an `<name>/` subdir; this avoids the stray nested `./<name>/` subdir a pull-from-inside-the-app used to drop. — `workflows` and `agents` are sourced from the live App row (NOT the archived manifest), so `set_app_workflow` / `set_app_agent` authoring survives the pull. Regenerates `.lotics/app_{workflows,queries,agents}.d.ts` so `useWorkflow` / `useQuery` / `useAgentRun` stay typed, AND the runtime `.lotics/app_fields.ts` (the same linked-vs-bespoke branch `app codegen` runs, off the app row already fetched — see that row for the two forms). That one is not optional: `app deploy` tars source with `--exclude=.lotics`, so no archive can carry it, and a pulled project whose `src/` imports `F`/`OPT` would fail to build with `Could not resolve "../../.lotics/app_fields"` until `app codegen` was run by hand. The write NAMES the form and the reason, because an in-place pull can FLIP a project between them (`opctl app publish` links an origin, `package eject` unlinks it) and that changes what the module does at load. Skipped under `--view-as` (the schema is read as that member and silently drops tables they cannot see — a narrowed `F` map compiles and then throws at runtime, worse than the missing module). A binding/schema fetch failure is non-fatal and names the right recovery for what is on disk: an existing file is kept, an ABSENT one warns about the build error and points at `app codegen`. Pull GENERATES but never RECONCILES `.lotics/` — deleting a companion whose alias the manifest no longer declares is `app codegen`'s alone, since pull's authority is the server's alias set and a declared-but-not-yet-`set` alias is supported. Also writes one `src/workflows/<alias>.ts` per bound workflow (faithful body from `get_app_workflow`) and one `src/agents/<alias>.md` per bound agent (its instructions, straight off the live row) — so the prose an author actually edits lives in a file, and pull always overwrites it from live, leaving no second copy to drift. A legacy workflow alias with no rendered source, or an agent with no instructions, warns and is skipped. The stamped `lotics.agents` map carries the TYPED half only (`inputs`/`outputs`/`tool_names`/`model_id`/…) — an agent's prose lives solely in its `.md`, so there is never a second local copy to desync; a stale `instructions` left by an older CLI is inert and disappears on the next pull |
33
33
  | `lotics app deploy -m <message>` | **`-m` is REQUIRED** (CLI errors without a non-empty message) — each deploy is a version row read back by `lotics app versions`, so a blank message loses the audit trail. npm run build; tar source + dist; POST /v1/apps/{id}/versions multipart. Carries code + capabilities only — **neither queries nor workflow/agent bindings are a deploy concern** (`set_app_workflow` / `remove_app_workflow` own `apps.workflows`; the manifest's `workflows` map is a pulled reflection, read by `useWorkflow` codegen and by `app workflow set`, never written by a deploy). Deploy DOES send the manifest's `lotics.workflows` alias KEYS (not the bindings) as `workflow_aliases`, recorded on the version row so `remove_app_workflow` can refuse to unbind an alias the served version still declares. It also reports any `lotics.queries` alias whose declaration DIFFERS from the app's, naming both recoveries (`app query set --all` to push yours, `app pull` to adopt the app's) — a deploy no longer writes them, so the two are allowed to drift. After a successful deploy it **warns loudly about any alias the source CALLS that is NOT bound on the server** (a `getApp` diff via `warnIfUnboundAliases`) — since deploy never binds them, that would otherwise throw only at the app's first `useWorkflow` / `useAgentRun` call; the warning points to `lotics app workflow set` / `set_app_agent`. Advisory only (never fails the deploy). |
34
34
  | `lotics app versions [app_id]` | `GET /v1/apps/{id}/versions` — print deploy history newest-first (version number, timestamp, deployer name, build status, the `-m` message; `*` marks the currently-served version). app_id from the local manifest, or pass one to inspect any app without pulling it. Admin-only server-side (mirrors deploy + source download). Answers "what shipped, when, by whom" — e.g. whether a fix was live at an incident's time. The deploy pipeline already persisted all of this in `app_versions`; this is the read surface. Title → stderr, table → stdout (pipeable). |
35
- | `lotics app codegen [path]` | Regenerate `.lotics/*` from the manifest + workspace schema **without a deploy**. The three `.d.ts` companions (`app_{workflows,queries,agents}.d.ts`) are always rewritten (synchronous, no network). When credentials resolve, also rewrites the **runtime** `.lotics/app_fields.ts` — **branched on whether the app is a package installation** (`getApp().package_id` set, from `generate_package_fields.ts`): a **linked/published** app emits the BINDING form (`F`/`OPT`/`ROLE` resolved from the installation's LIVE binding — via `appBinding` / the `binding` RPC — at module load through `getAppBinding()` + top-level await, so the source stays portable across every install); a **bespoke** app emits the BAKED form (`generate_app_fields.ts`) — a real `.ts` exporting `F` (table→field→`"fld_…"`) + `OPT` (table→select-field→option→`"opt_…"`) keyed by display-name aliases, for the tables the app's queries reference (+ optional `package.json#lotics.codegen.tables` allowlist). Both forms share the `F`/`OPT` shape (contract aliases derive from the same slugified display names), so a published origin's deployed source compiles unchanged. Writing the BINDING form also heals the project's vitest setup (`ensureAppVitestSetup`, folded into the same write boundary): the binding form awaits `getAppBinding()` (a network call) at module load, so without a stub `npm test` fails to collect any test that imports the app graph — the heal writes `vitest.setup.ts` (mocks only `getAppBinding`, returning an echo binding: any alias → a self-identifying `fld:test:…`/`opt:test:…`/`grp:test:…` id) if absent, and warns the one-liner to add to `vite.config.ts`'s `test.setupFiles` if the wiring is missing (TS source isn't safely munged, mirroring `ensureAppTsconfig`'s JSONC-tsconfig warn). New scaffolds ship both. Also refreshes each bound workflow's `.lotics/workflows/<alias>.globals.d.ts` + re-wraps its EXISTING `src/workflows/<alias>.ts` body in the current envelope (strips + re-wraps; never re-fetches the body, so local edits survive). **`.lotics/` is reconciled to the manifest, not merely added to** — a `<alias>.globals.d.ts` whose alias the manifest no longer declares is DELETED (that directory is read as the app's alias inventory, so a companion for a binding nobody can reach misreports what the app has). Only that exact filename shape is removed; anything else in the directory is left alone. The reconcile runs before the credential branch, so it happens offline too. The authored counterpart is never deleted — a `src/workflows/<alias>.ts` the manifest does not declare is NAMED instead (`check` and `set` both take their alias set from the manifest, so editing an undeclared body is a silent no-op). A getApp / binding / schema / dts-fetch failure is non-fatal (warns, keeps the last-generated files). |
35
+ | `lotics app codegen [path]` | Regenerate `.lotics/*` from the manifest + workspace schema **without a deploy**. The three `.d.ts` companions (`app_{workflows,queries,agents}.d.ts`) are always rewritten (synchronous, no network). When credentials resolve, also rewrites the **runtime** `.lotics/app_fields.ts` — **branched on whether the app is a package installation** (`getApp().package_id` set, from `generate_package_fields.ts`): a **linked/published** app emits the BINDING form (`F`/`OPT`/`ROLE` resolved from the installation's LIVE binding — via `appBinding` / the `binding` RPC — at module load through `getAppBinding()` + top-level await, so the source stays portable across every install); a **bespoke** app emits the BAKED form (`generate_app_fields.ts`) — a real `.ts` exporting `F` (table→field→`"fld_…"`) + `OPT` (table→select-field→option→`"opt_…"`) keyed by display-name aliases, for the tables the app's queries reference (+ optional `package.json#lotics.codegen.tables` allowlist). Both forms share the `F`/`OPT` shape (contract aliases derive from the same slugified display names), so a published origin's deployed source compiles unchanged. Writing the BINDING form also heals the project's vitest setup (`ensureAppVitestSetup`, folded into the same write boundary): the binding form awaits `getAppBinding()` (a network call) at module load, so without a stub `npm test` fails to collect any test that imports the app graph — the heal writes `vitest.setup.ts` (mocks only `getAppBinding`, returning an echo binding: any alias → a self-identifying `fld:test:…`/`opt:test:…`/`grp:test:…` id) if absent, and warns the one-liner to add to `vite.config.ts`'s `test.setupFiles` if the wiring is missing (TS source isn't safely munged, mirroring `ensureAppTsconfig`'s JSONC-tsconfig warn). New scaffolds ship both. Also refreshes each bound workflow's `.lotics/workflows/<alias>.globals.d.ts` + re-wraps its EXISTING `src/workflows/<alias>.ts` body in the current envelope (strips + re-wraps; never re-fetches the body, so local edits survive). **`.lotics/` is reconciled to the manifest, not merely added to** — a `<alias>.globals.d.ts` whose alias the manifest no longer declares is DELETED (that directory is read as the app's alias inventory, so a companion for a binding nobody can reach misreports what the app has). Only that exact filename shape is removed; anything else in the directory is left alone. The reconcile runs before the credential branch, so it happens offline too. The authored counterpart is never deleted — a `src/workflows/<alias>.ts` the manifest does not declare is NAMED instead (`check` and `set` both take their alias set from the manifest, so editing an undeclared body is a silent no-op). A getApp / binding / schema / dts-fetch failure is non-fatal (warns, keeps the last-generated files). **Re-silvers `package.json#lotics.agents`** from the live app row whenever its `inputs`/`outputs` disagree, then rewrites the agent `.d.ts` from the refreshed block: that block is a mirror AND the offline seed for `useAgentRun` typings, so a stale copy types the app against an agent that does not exist. Refreshing here makes the divergence self-healing on a command already in the loop and keeps the remedy off `app pull` (which rewrites `src/workflows/*.ts` and would eat uncommitted body edits). The write is surgical and order-preserving (`orderedLike`), so it changes only the fields that actually differ. A hand edit to that block is therefore reverted — it never changed the agent anyway; to change one, `set_app_agent`. |
36
+ | `lotics app check` | Every pre-flight `deploy` runs, WITHOUT building or shipping: the manifest's agent schemas against the live app row, aliases the source calls that nothing bound (queries, workflows AND agents), capability-gated SDK calls the manifest doesn't declare, `lotics.queries` drift, a missing icon/theme, and a notice for any alias the source computes at runtime (invisible to every check here and to the deploy's unbind guard). Adds no rule of its own — each finding is the same helper `deploy` calls, so a green check means a deploy will not complain. **Exits 1 only on what `deploy` REFUSES** (an agent schema that disagrees with the live app), so CI can gate on it while advisories stay advisory. It also names any `src/agents/<alias>.md` that differs from the live agent's instructions — a WARNING, not a gate, because `deploy` never pushes prose and shipping unrelated UI while a prompt is mid-edit is normal; a stale prompt does not make the bundle lie about its own types the way a stale schema does. The point is the question being ASKABLE: these checks used to cost a build, a tar, an upload and a version row in the audit trail, which is expensive enough that the honest move was to skip them and find out in production. |
36
37
  | `lotics app workflow run <alias> '<json>'` | Execute a bound app workflow end-to-end via `appWorkflow`. `app_id` comes from the local manifest; the alias must be bound (`set_app_workflow`). Inputs ingest exactly like `lotics run` (inline JSON / `@file` / stdin — bulk inputs bypass `ARG_MAX`). Prints the full `{status,message,data,files,side_effects}` JSON to stdout + a one-line summary to stderr; exits non-zero on `status:"error"` (assertable). `--print-created` (alias `--report-effects`) renders the honest post-run harvest: created records grouped by table, a paste-ready `lotics run delete_records …` per table, then the **mandatory caveat** naming what cannot be auto-undone (external integrations + notifications) and that sub-workflows may have run. `--cleanup` (DEFAULT OFF, implies the report) additionally runs the deletes for harvested records ONLY — never files / external / notifications. Neither is a rollback — a rollback is structurally impossible here. |
37
38
  | `lotics app workflow set <alias>` | Push the edited `src/workflows/<alias>.ts` body through `set_app_workflow` (the single author of `apps.workflows`). Reads the body from disk (header + `/// <reference>` + `export {};` marker + the `__workflow` wrapper all stripped) + the typed `inputs`/`outputs` **and the `description`** from `package.json#lotics.workflows.<alias>`; the **server** re-verifies the body and echoes the bound `outputs` (declared, else DERIVED from `return({ data })`). The `description` is the one line an agent reads when choosing between the app's aliases (the workflow counterpart to a query's) — authored in the manifest so it lives beside the body in version control and rides every push; omit it and the workflow keeps whatever description it already has, so a push can never blank one set elsewhere. When the manifest declared NO `outputs`, the DERIVED echo is written back into `package.json#lotics.workflows.<alias>.outputs` (a SURGICAL write — preserves `knowledge`/`config` and every other manifest field) and that alias's types are refreshed in place, so `useWorkflow("<alias>")`'s `result.data` is typed immediately with no hand-copy and no second `lotics app codegen`; an explicitly-declared `outputs` is authoritative and never overwritten. Deploy still never authors workflows — this is a CLI convenience over the existing tool. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a verify failure. |
38
- | `lotics app agent set <alias>` | Push the edited `src/agents/<alias>.md` instructions back through `set_app_agent` — the agent mirror of `app workflow set`, and the deploy-free authoring path for `apps.agents`. Reads the prose from disk (the `<!-- lotics: … -->` header stripped) and the typed fields (`inputs`/`outputs`/`tool_names`/`model_id`/`effort_level`/`knowledge_doc_ids`/`query_aliases`/`workflow_aliases`) from `package.json#lotics.agents.<alias>`, then sends them as ONE declaration. That assembly is the point: **`set_app_agent` REPLACES the declaration rather than patching it**, so a hand-built payload that sets one field silently drops the instructions, the output schema and the model pin — a silent, unrecoverable edit against a live prompt. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a file that is empty once the header is stripped (refusing to push an empty prompt). `app pull` writes the file; edit, then `set`. |
39
+ | `lotics app agent set <alias>` | Push the edited `src/agents/<alias>.md` instructions back through `set_app_agent` — the agent mirror of `app workflow set`, and the deploy-free authoring path for an agent's PROSE. It sends the instructions and nothing else: the server merges against the stored declaration, so every typed field keeps exactly what is bound. This is deliberate and it is the opposite of what the symmetry with `app workflow set` suggests — **the manifest is a snapshot from the last `app pull`, so replaying its typed half would silently revert whatever was bound since** (the chat authoring agent adding `knowledge_doc_ids`, another operator granting `query_aliases`), and the CLI would print success while the agent quietly lost its knowledge and its read surface. To change a typed field, call `set_app_agent` with just that field (`lotics run set_app_agent '{"app_id":…,"alias":…,"outputs":{…}}'` — it merges), then `app pull` to bring the manifest back in step. Editing `package.json#lotics.agents` by hand pushes nothing, and since that block is what types `useAgentRun`, `codegen` warns and `deploy` REFUSES while it disagrees with the live app. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a file that is empty once the header is stripped (refusing to push an empty prompt). `app pull` writes the file; edit, then `set`. |
39
40
  | `lotics app query set <alias>` \| `--all` | Push `package.json#lotics.queries` (`{ ast, params? }` per alias) to `apps.queries` through `set_app_query` — **the only author of a query binding**, the mirror of `app workflow set`. A deploy ships code and binds nothing. The **server** validates each one exactly as it always did (alias identifier, workspace-only tables, resolvable fields, declared params). `--all` pushes every declared alias, alias-sorted, stopping at the first failure and naming what already landed. Clear error + non-zero exit on an alias absent from the manifest or a validation failure. |
40
41
  | `lotics app agent run <app_id> <alias> ['<json>'\|@file\|stdin]` | Run a bound app agent end-to-end. A run needs no deployed UI bundle — just the app row + the bound agent declaration + member auth — so the **`app_id` is explicit** (not read from a local manifest). Inputs ingest exactly like `lotics run` (inline JSON / `@file` / stdin; empty = `{}`). Opens the run's SSE (`appAgentRunStream`), streams `text-delta` prose to **stderr** as live progress, then reports from the **settled run RECORD** (`listAgentRuns`, polled to a terminal status — the client stream can close a beat before the run settles, or drop while it runs on server-side): default prints the run's structured `output` (JSON) or final text to **stdout** + a status line to stderr; `--json` prints the full run summary to stdout. Selects THIS run by the `x-app-agent-run-id` header (ordering-independent). Exits 0 **only** when the settled status is `completed`; otherwise non-zero with the run's error surfaced. A settled run that never appears fails loudly (never a silent success). A fresh `session_id` is minted per run (self-contained); `--session <id>` continues an existing thread (prior runs become the agent's context). |
41
42
  | `lotics app workflow pull` | Rewrite every `src/workflows/<alias>.ts` from the server (faithful body per bound alias via `get_app_workflow`) **+ its `.lotics/workflows/<alias>.globals.d.ts`** (via `getAppWorkflowDts`, so the body is locally typecheckable via `lotics app workflow check`) without a full `app pull` (no source archive, no npm install). A legacy alias with no rendered source warns and is skipped; a dts-fetch failure is non-fatal (body still written with the fallback wrapper, typecheck degraded). Each alias's `description` is folded back into `package.json#lotics.workflows.<alias>` from the same read — the alias binding the manifest is otherwise stamped from carries `inputs`/`outputs` but not the description, which lives on the workflow ROW, so without this a pull would erase an authored one. The server's GENERATED default is skipped, so an app that never described its workflows gains no manifest noise. Also idempotently patches the main `tsconfig.json` `exclude` to cover `src/workflows` + `.lotics/workflows` so a pre-existing app's `npm run typecheck` never loads the bodies or the colliding per-alias globals. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/cli",
3
- "version": "0.106.0",
3
+ "version": "0.109.0",
4
4
  "description": "Lotics SDK and CLI for AI agents",
5
5
  "type": "module",
6
6
  "bin": {