Skip to content

Commit 47f0856

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-nm6rj5
2 parents 575e00b + 780c6c3 commit 47f0856

27 files changed

Lines changed: 2193 additions & 67 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/cli': patch
3+
'create-objectstack': patch
4+
---
5+
6+
feat(cli): `os deploy` — one command from a local checkout to your ObjectOS Cloud environment; installs pick the organization's only environment, keep it across `os cloud login`, and refuse before any write when none resolves
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
**`os deploy`** (new). With no flags it builds the app (the same compile `os build` runs), publishes it as `<manifest.version>-dev.<YYYYMMDDHHMMSS>` (a UTC semver pre-release, so deploying again never needs a version bump and never collides with an existing version), installs exactly that version into your organization's environment, and waits until the environment serves it (it reads the control plane's served-version report for the package and, since an environment rebuilds only when it gets a request, sends the environment one on every poll). A failed local build prints its errors and exits 1 having published nothing; a build the environment reports as failed prints the environment's reason and exits 1. Flags only for the uncommon case: `--env <id>` when your account reaches several environments, `--no-wait`, `--wait-timeout <seconds>` (default 600: a failing build is reported only after three failed rounds in a row). Against a control plane that does not yet report which version an environment serves, the command says so and does not claim the version is live.
12+
13+
**`os package publish --install`** keeps its meaning (a release version, the manifest's own), and now resolves its environment like `os deploy`: `--env` / `$OS_ENVIRONMENT_ID`, then the environment `os environments switch` recorded for this control plane, then the organization's only environment, asked of the control plane and printed. With none, several, or an unreadable list it exits 1 **before registering the package or publishing anything**, naming how to pass one. It used to print "Skipping auto-install", publish anyway and exit 0.
14+
15+
**`os cloud login`** no longer drops the active environment: re-logging in to the same control plane as the same account keeps `activeEnvironmentId` in `~/.objectstack/cloud.json`. A different control plane or a different account still starts without one.
16+
17+
**`os dev`** offers the deploy on a key once the local server is up: press `d` to run `os deploy` in the same terminal; when not logged in to ObjectOS Cloud, the same key logs in first. There is no deploy on save. **`os build`** ends with the next step (`os deploy`), and bare `os` lists the everyday commands first. New projects from `create-objectstack` (and `os init`'s app template) ship `npm run deploy`.

‎content/docs/deployment/cli.mdx‎

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ Starts development mode. Three usage shapes:
166166
2. **With a pre-built artifact** (`--artifact <path|url>`) — skips auto-compile and boots the artifact directly. No `objectstack.config.ts` needed in cwd. Useful for *trying out a published app in dev mode without cloning its source.*
167167
3. **Monorepo root** (cwd has `pnpm-workspace.yaml`) — orchestrates `pnpm -r dev` across packages.
168168

169+
Once the local server is up, `os dev` in an interactive terminal offers
170+
**`d` to deploy**: it runs [`os deploy`](#os-deploy) in the same terminal, and
171+
when you are not logged in to ObjectOS Cloud the same key runs `os cloud login`
172+
first. Saving a file never deploys.
173+
169174
```bash
170175
os dev # Auto-compile cwd config, then start
171176
os dev my-package # Workspace package (monorepo orchestration mode)
@@ -3063,7 +3068,9 @@ os cloud login --email me@acme.com --password secret # CI
30633068
Like `os login`, in an interactive terminal it uses the browser-based device
30643069
flow: it prints a one-time verification URL and polls until you approve. If
30653070
cloud credentials already exist it exits successfully with "Already logged in";
3066-
pass `--force` to re-authenticate.
3071+
pass `--force` to re-authenticate. Re-authenticating to the same control plane
3072+
as the same account keeps the active environment recorded in `cloud.json`; a
3073+
different control plane or account starts without one.
30673074
30683075
##### `os cloud login --json` is NDJSON — the same exception as `os login`
30693076
@@ -3139,6 +3146,53 @@ os environments bind <environment-id> --artifact ./dist/objectstack.json --build
31393146
is reserved for the server-side reseed endpoint; use it only when that endpoint
31403147
is available in your deployment.
31413148

3149+
### Deploy
3150+
3151+
#### `os deploy`
3152+
3153+
Puts the app in the current directory on your ObjectOS Cloud environment, with
3154+
no flags. It builds the app (the compile [`os build`](#os-compile) runs),
3155+
publishes it as `<manifest.version>-dev.<YYYYMMDDHHMMSS>` — a UTC semver
3156+
pre-release, so deploying again never needs a version bump — installs that
3157+
version into your organization's environment, and waits until the environment
3158+
serves it. Scaffolded projects run it as `npm run deploy`, and
3159+
[`os dev`](#os-dev) runs it when you press `d`.
3160+
3161+
```bash
3162+
os cloud login # once per machine
3163+
os deploy
3164+
os deploy --env env_abc123 # your account reaches several environments
3165+
os deploy --no-wait # return once the install is recorded
3166+
```
3167+
3168+
The environment is resolved exactly as
3169+
[`os package publish --install`](#os-package-publish) resolves it: `--env`,
3170+
then the active environment for this control plane, then your organization's
3171+
only environment. Every refusal comes before anything is written: not logged
3172+
in, no environment to name, a failed build (its errors are printed), or a
3173+
`manifest.version` that is not semver. A build the environment itself reports
3174+
as failed prints the environment's reason and exits `1`; so does a wait that
3175+
times out, naming what it waited for. An environment rebuilds only when it gets
3176+
a request, so while it waits the command sends it one on every poll. A failing
3177+
build is reported only after three failed rounds in a row, so it can read as
3178+
still building for a few minutes before the reason appears. On a control plane
3179+
that does not yet report which version an environment serves, the command says
3180+
so and does not claim the new version is live.
3181+
3182+
There is no deploy on save: on ObjectOS Cloud your organization's environment
3183+
is its production, so a deploy is always a deliberate act.
3184+
3185+
| Flag | Env equivalent | Purpose |
3186+
|---|---|---|
3187+
| `--env <id>` | `OS_ENVIRONMENT_ID` | Environment to deploy into (default: the active one for this control plane, then your organization's only one) |
3188+
| `--no-wait` | — | Return once the install is recorded |
3189+
| `--wait-timeout <seconds>` | — | How long to wait for the environment to serve the new version (default `600`) |
3190+
| `-s, --server <url>` | `OS_CLOUD_URL` | Control-plane URL. Default `https://cloud.objectos.ai`, or the URL recorded by `os cloud login` |
3191+
| `-t, --token <key>` | `OS_CLOUD_API_KEY` | Bearer token; `$OS_TOKEN` and `~/.objectstack/cloud.json` are the fallbacks |
3192+
3193+
`os package publish` stays the command for a **release**: it publishes the
3194+
version the manifest declares, with `--install` optional.
3195+
31423196
### Packages
31433197
31443198
The two commands that move a compiled app onto a platform. They target
@@ -3191,6 +3245,14 @@ resolves an install target by bare id, with no name or short-id rescue. A value
31913245
written by an older CLI into `credentials.json` is copied across once, and only
31923246
when both files' `url`s agree.
31933247

3248+
With neither `--env` nor an active environment, `--install` asks the control
3249+
plane for your organization's environments and uses the only one, printing
3250+
which; archived and platform environments are not counted. On ObjectOS Cloud
3251+
every organization has exactly one environment, so this is the usual case.
3252+
None, several, or a list that cannot be read is a refusal: the command exits
3253+
`1` before it registers the package or publishes a version, and lists the
3254+
candidates with how to pass `--env`.
3255+
31943256
**Options:**
31953257
31963258
| Flag | Env equivalent | Purpose |
@@ -3205,8 +3267,8 @@ when both files' `url`s agree.
32053267
| `--category <slug>` | — | Marketplace category slug (`crm`, `hr`, `devtools`, …) |
32063268
| `--visibility <level>` | — | `org` (installable across your organization) · `private` (explicit grants only) · `marketplace` (public after review). Omitted: not sent, so the control plane decides — an existing package keeps its visibility, a new one gets the control plane's default (`org` on ObjectOS Cloud) |
32073269
| `--org <id>` | `OS_ORG_ID` | `owner_org_id`. Required with a bearer key in service mode; ignored in user mode |
3208-
| `--env <id>` | `OS_ENVIRONMENT_ID` | Environment to install the new version into. Defaults to the environment [`os environments switch`](#cloud-environments) — or `os environments create --activate` — recorded **for this control plane** in `~/.objectstack/cloud.json` |
3209-
| `--install` | — | Auto-install into `--env` after publishing. With no `--env`, no `$OS_ENVIRONMENT_ID` and no active environment for this control plane, it reports that and publishes without installing |
3270+
| `--env <id>` | `OS_ENVIRONMENT_ID` | Environment to install the new version into. Defaults to the environment [`os environments switch`](#cloud-environments) — or `os environments create --activate` — recorded **for this control plane** in `~/.objectstack/cloud.json`, then to your organization's only environment |
3271+
| `--install` | — | Install the new version after publishing, into `--env` or the environment it defaults to. With no environment to name — none, several, or a list the control plane would not give — it exits `1` **before publishing anything**, naming how to pass one |
32103272
| `--seed-sample-data` | — | Include sample data in that auto-install |
32113273
| `--pre-release` | — | Mark the version as a pre-release (also inferred — see below) |
32123274
| `--submit` | — | Submit the new version for marketplace review. Needs the package's visibility to be `marketplace` (already stored, or set with `--visibility marketplace`) and a complete listing |

‎packages/cli/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"oclif": {
4747
"bin": "os",
4848
"dirname": "objectstack",
49+
"helpClass": "./dist/help.js",
4950
"commands": {
5051
"strategy": "pattern",
5152
"target": "./dist/commands",

‎packages/cli/src/commands/build.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ export default class Build extends Compile {
77

88
/** `os build` is what a deployment runs, so it says what the artifact leaves behind. */
99
protected override reportsLocalCustomizations = true;
10+
11+
/** `os build` is the step before `os deploy`, so it says so (`utils/next-steps.ts`). */
12+
protected override printsNextStep = true;
1013
}

‎packages/cli/src/commands/cloud/login.ts‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,33 @@ import { Command, Flags } from '@oclif/core';
7575
import type { CliExitCode } from '../../utils/format.js';
7676
import { printHeader, printKV, printSuccess, printError, emitJson, errorCodeFields } from '../../utils/format.js';
7777
import { loginWithBrowser, loginWithPassword } from '../../utils/auth-flows.js';
78-
import { DEFAULT_CLOUD_URL, readCloudConfig, writeCloudConfig } from '../../utils/cloud-config.js';
78+
import { DEFAULT_CLOUD_URL, readCloudConfig, tryReadCloudConfig, writeCloudConfig, type CloudConfig } from '../../utils/cloud-config.js';
79+
import { isSameControlPlane } from '../../utils/active-environment.js';
80+
81+
/**
82+
* The `cloud.json` a successful login writes: the new credential, plus the
83+
* active environment the previous file recorded — when it is still about the
84+
* same control plane and the same account.
85+
*
86+
* A login used to rewrite the file whole, so `activeEnvironmentId` (written by
87+
* `os environments switch` / `os environments create --activate`, read back as
88+
* the install target by `os package publish --install` and `os deploy`) was
89+
* gone after every login and the next install refused for want of it.
90+
*
91+
* Kept only when both hold, because an environment id only resolves on the
92+
* server it was chosen on (`active-environment.ts`) and only for an account
93+
* that can reach it:
94+
* - the previous file's url names the same control plane as this login's;
95+
* - it is the same account — the user ids agree, or one side recorded none.
96+
* Otherwise the id is dropped, exactly as before. Nothing else is carried
97+
* over: every other key is the new login's.
98+
*/
99+
export function mergeCloudLogin(previous: CloudConfig | undefined, next: CloudConfig): CloudConfig {
100+
if (!previous?.activeEnvironmentId) return next;
101+
if (!isSameControlPlane(previous.url, next.url)) return next;
102+
if (previous.userId && next.userId && previous.userId !== next.userId) return next;
103+
return { ...next, activeEnvironmentId: previous.activeEnvironmentId };
104+
}
79105

80106
/**
81107
* Emit ONE NDJSON record on stdout — the only `--json` writer in this command.
@@ -219,13 +245,15 @@ export default class CloudLogin extends Command {
219245
})
220246
: await this.fallbackPasswordPrompt(url, flags.email);
221247

222-
await writeCloudConfig({
223-
url,
224-
token: result.token,
225-
email: result.user?.email,
226-
userId: result.user?.id,
227-
createdAt: new Date().toISOString(),
228-
});
248+
await writeCloudConfig(
249+
mergeCloudLogin(await tryReadCloudConfig(), {
250+
url,
251+
token: result.token,
252+
email: result.user?.email,
253+
userId: result.user?.id,
254+
createdAt: new Date().toISOString(),
255+
}),
256+
);
229257

230258
if (flags.json) {
231259
// Record 2 of 2 on the device path, and the only record on the
@@ -237,7 +265,7 @@ export default class CloudLogin extends Command {
237265
if (result.user?.id) printKV('User ID', result.user.id);
238266
console.log('');
239267
console.log(' Credentials stored in ~/.objectstack/cloud.json');
240-
console.log(' Next: `os package publish` to push a package, `os cloud whoami` to verify.');
268+
console.log(' Next: `os deploy` to put this app on your cloud environment, `os cloud whoami` to verify.');
241269
console.log('');
242270
}
243271
} catch (error: any) {

‎packages/cli/src/commands/compile.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import { findExtensionFieldSuffixRefusals } from '../utils/extension-field-suffi
8888
// 3a-vii runs, over the automation engine's own judge.
8989
import { findFlowCycleRefusals } from '../utils/flow-undeclared-cycle.js';
9090
import { localCustomizationNotice, readLocalCustomizations } from '../utils/local-customizations.js';
91+
import { BUILD_NEXT_STEP } from '../utils/next-steps.js';
9192

9293
export default class Compile extends Command {
9394
static override description = 'Compile ObjectStack configuration to JSON artifact';
@@ -129,6 +130,13 @@ export default class Compile extends Command {
129130
*/
130131
protected reportsLocalCustomizations = false;
131132

133+
/**
134+
* Whether a successful text-face run ends with the next step
135+
* (`BUILD_NEXT_STEP`). On for `os build` only: `os compile` is what `os dev`
136+
* runs on every boot and rebuild, where a line per rebuild is noise.
137+
*/
138+
protected printsNextStep = false;
139+
132140
async run(): Promise<void> {
133141
const { args, flags } = await this.parse(Compile);
134142
const timer = createTimer();
@@ -1471,6 +1479,11 @@ export default class Compile extends Command {
14711479
}
14721480
}
14731481

1482+
if (this.printsNextStep) {
1483+
console.log(chalk.cyan(` ${BUILD_NEXT_STEP}`));
1484+
console.log('');
1485+
}
1486+
14741487
} catch (error: any) {
14751488
if (isExitSignal(error)) throw error;
14761489
if (flags.json) {

0 commit comments

Comments
 (0)