@workser/cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +16 -1
  2. package/dist/index.js +54 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -75,15 +75,30 @@ platform plans in `workser-agents-platform/`.
75
75
  | Resolves | Precedence |
76
76
  |---|---|
77
77
  | **endpoint** | `--endpoint` → `$WORKSER_DAEMON_URL` → `~/.workser/session.json` → cloud default |
78
+ | **cloud default** | `$WORKSER_API_URL` → `$WORKSER_ENV` → `prod` |
78
79
  | **token** | `--token` → `$WORKSER_TOKEN` → session file |
79
80
  | **project** | `--project` → `<cwd>/.workser/project.json` → session default |
80
81
 
82
+ `$WORKSER_ENV` names a backend rather than a URL:
83
+
84
+ | `WORKSER_ENV` | Base URL |
85
+ |---|---|
86
+ | unset / `prod` | `https://api.workser.ai` |
87
+ | `dev` | `https://dev-api.workser.ai` |
88
+ | `local` | `http://localhost:8000` (a core-api you run yourself) |
89
+
90
+ An unrecognised value is a hard error, not a silent fall-back to prod. Run
91
+ `workser doctor` to see the resolved env, endpoint, and which of the two it
92
+ came from.
93
+
81
94
  - **Inside Workser Orbit (primary):** the app writes `~/.workser/session.json`
82
95
  pointing at its **local daemon** (`http://127.0.0.1:<port>`). Calls flow through
83
96
  the cockpit, which handles **auth (bridge JWT), approval gates, and live progress
84
97
  in the UI**. This is how the user *sees* what the agent does.
85
98
  - **Standalone / CI:** `workser login --token <t>` saves a session against the
86
- **cloud API** (`https://api.workser.ai`). Same commands, no desktop app.
99
+ **cloud API** for the current `$WORKSER_ENV`. Same commands, no desktop app.
100
+ Note the session file records the endpoint it logged in against, so switching
101
+ `$WORKSER_ENV` afterwards needs a fresh `workser login` (or `--endpoint`).
87
102
 
88
103
  Both speak the same `/v1/...` contract (see `src/client.ts`).
89
104
 
package/dist/index.js CHANGED
@@ -4263,8 +4263,37 @@ function readProjectLink(cwd) {
4263
4263
  }
4264
4264
  }
4265
4265
 
4266
+ // src/env.ts
4267
+ var ENV_BASE_URLS = {
4268
+ local: "http://localhost:8000",
4269
+ dev: "https://dev-api.workser.ai",
4270
+ prod: "https://api.workser.ai"
4271
+ };
4272
+ var ALIASES = {
4273
+ local: "local",
4274
+ localhost: "local",
4275
+ development: "dev",
4276
+ dev: "dev",
4277
+ staging: "dev",
4278
+ prod: "prod",
4279
+ production: "prod"
4280
+ };
4281
+ function resolveEnv(raw = process.env.WORKSER_ENV) {
4282
+ if (!raw || !raw.trim()) return "prod";
4283
+ const env = ALIASES[raw.trim().toLowerCase()];
4284
+ if (!env) {
4285
+ throw new WorkserError(
4286
+ `Unknown WORKSER_ENV "${raw}". Expected one of: local, dev, prod.`,
4287
+ { code: "bad_env" }
4288
+ );
4289
+ }
4290
+ return env;
4291
+ }
4292
+ function cloudBaseUrl() {
4293
+ return process.env.WORKSER_API_URL || ENV_BASE_URLS[resolveEnv()];
4294
+ }
4295
+
4266
4296
  // src/context.ts
4267
- var CLOUD_DEFAULT = process.env.WORKSER_API_URL || "https://api.workser.ai";
4268
4297
  function buildContext(opts) {
4269
4298
  const session = readSession();
4270
4299
  const cwd = opts.cwd ? resolve(opts.cwd) : process.cwd();
@@ -4273,7 +4302,7 @@ function buildContext(opts) {
4273
4302
  opts.endpoint || opts.token || process.env.WORKSER_DAEMON_URL || process.env.WORKSER_TOKEN
4274
4303
  );
4275
4304
  const socketPath = overridden ? void 0 : session.socketPath;
4276
- const endpointRaw = socketPath ? "http://localhost" : opts.endpoint || process.env.WORKSER_DAEMON_URL || session.endpoint || CLOUD_DEFAULT;
4305
+ const endpointRaw = socketPath ? "http://localhost" : opts.endpoint || process.env.WORKSER_DAEMON_URL || session.endpoint || cloudBaseUrl();
4277
4306
  const endpoint = endpointRaw.replace(/\/+$/, "");
4278
4307
  const mode2 = socketPath ? "daemon" : /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:|\/|$)/i.test(endpoint) ? "daemon" : "cloud";
4279
4308
  const link = readProjectLink(cwd);
@@ -5340,12 +5369,16 @@ function registerDoctor(program3) {
5340
5369
  action(({ ctx, opts }) => {
5341
5370
  const session = readSession();
5342
5371
  const link = readProjectLink(ctx.cwd);
5372
+ const env = resolveEnv();
5373
+ const envIgnored = Boolean(process.env.WORKSER_ENV) && ctx.mode === "cloud" && ctx.endpoint !== ENV_BASE_URLS[env];
5343
5374
  const tokenSource = opts.token ? "--token" : process.env.WORKSER_TOKEN ? "$WORKSER_TOKEN" : session.token ? "session" : void 0;
5344
- const endpointSource = opts.endpoint ? "--endpoint" : process.env.WORKSER_DAEMON_URL ? "$WORKSER_DAEMON_URL" : session.endpoint ? "session" : "cloud-default";
5375
+ const endpointSource = opts.endpoint ? "--endpoint" : process.env.WORKSER_DAEMON_URL ? "$WORKSER_DAEMON_URL" : session.endpoint ? "session" : process.env.WORKSER_API_URL ? "$WORKSER_API_URL" : `cloud-default: ${env}`;
5345
5376
  const projectSource = opts.project ? "--project" : link?.projectId ? ".workser link" : session.defaultProjectId ? "session" : void 0;
5346
5377
  const report = {
5347
5378
  endpoint: ctx.endpoint,
5348
5379
  endpointSource,
5380
+ env,
5381
+ envIgnored,
5349
5382
  mode: ctx.mode,
5350
5383
  token: {
5351
5384
  present: Boolean(ctx.token),
@@ -5363,6 +5396,9 @@ function registerDoctor(program3) {
5363
5396
  ok(report, () => {
5364
5397
  line(import_picocolors13.default.bold("workser doctor"));
5365
5398
  line(` endpoint: ${ctx.endpoint} ${import_picocolors13.default.dim(`(${endpointSource})`)}`);
5399
+ line(
5400
+ ` env: ${env === "prod" ? import_picocolors13.default.yellow(env) : env}` + import_picocolors13.default.dim(process.env.WORKSER_ENV ? " ($WORKSER_ENV)" : " (default)")
5401
+ );
5366
5402
  line(` mode: ${ctx.mode}`);
5367
5403
  line(
5368
5404
  ` token: ${ctx.token ? `${maskToken(ctx.token)} ${import_picocolors13.default.dim(`(${tokenSource})`)}` : import_picocolors13.default.yellow("none \u2014 run `workser login`")}`
@@ -5371,6 +5407,20 @@ function registerDoctor(program3) {
5371
5407
  ` project: ${ctx.projectId ?? import_picocolors13.default.dim("none")}` + (link?.name ? ` ${import_picocolors13.default.dim(`(${link.name})`)}` : "") + (projectSource ? import_picocolors13.default.dim(` [${projectSource}]`) : "")
5372
5408
  );
5373
5409
  line(` cwd: ${ctx.cwd}`);
5410
+ if (envIgnored) {
5411
+ line("");
5412
+ line(
5413
+ import_picocolors13.default.yellow(
5414
+ ` WORKSER_ENV=${env} is not in effect \u2014 ${endpointSource} wins.`
5415
+ )
5416
+ );
5417
+ line(
5418
+ import_picocolors13.default.dim(
5419
+ ` Re-run \`workser login\` to switch (the saved token is tied to ${ctx.endpoint}),`
5420
+ )
5421
+ );
5422
+ line(import_picocolors13.default.dim(` or pass --endpoint ${ENV_BASE_URLS[env]}.`));
5423
+ }
5374
5424
  });
5375
5425
  })
5376
5426
  );
@@ -6070,7 +6120,7 @@ function extract(response) {
6070
6120
 
6071
6121
  // src/index.ts
6072
6122
  var pkg = {
6073
- version: true ? "0.2.0" : "0.0.0-dev"
6123
+ version: true ? "0.2.1" : "0.0.0-dev"
6074
6124
  };
6075
6125
  var program2 = new Command();
6076
6126
  program2.name("workser").description(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workser/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Workser CLI — give your local AI agent native DevOps & infrastructure on Workser. The agent runs `workser …` to provision, deploy, and manage real apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",