@north-light/api 0.3.738 → 0.3.739

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.
@@ -5,7 +5,7 @@ import { piAgentDir } from '../../core/runtime/package-health.js';
5
5
  import { basename, dirname, join, relative, resolve } from 'node:path';
6
6
  import { isDeepStrictEqual } from 'node:util';
7
7
  import { BINDING_CATALOG, normalizeGesture, splitGestureExpression, inboxShortcut, resolveKeybindings, } from '../../core/keybindings/index.js';
8
- import { runtimeManifest } from './shared.js';
8
+ import { builtinPiPackageDir } from '../../core/scope.js';
9
9
  import { atomicWriteJson, readJsonIfExists, readJsonOrNull } from '../../core/fs-utils.js';
10
10
  import { resolveBundledPiCliPath } from '../../core/runtime/pi-cli.js';
11
11
  import { crtrVersion } from '../../shared/crtr-version.js';
@@ -272,7 +272,7 @@ const LOCAL_PACKAGE_NAME_ALIASES = {
272
272
  'dev-plugin': [],
273
273
  };
274
274
  function selectedPiPackageDir(name) {
275
- return join(runtimeManifest.runtimeHome(), 'selected', 'dist', 'builtin-pi-packages', name);
275
+ return builtinPiPackageDir(name);
276
276
  }
277
277
  export function buildSetupManifest(resolveBuiltinPackageDir = selectedPiPackageDir) {
278
278
  // Order matters at execution: the marketplace source registers before the
@@ -123,8 +123,9 @@ export const sysSigninLeaf = defineLeaf({
123
123
  ],
124
124
  },
125
125
  run: async (input) => {
126
- // A fresh home has no daemon yet, and the move reads the canvas through it: start it (a no-op when it already serves) before anything else.
127
- await spawnDaemon();
126
+ // A computer with local records needs its daemon (the move reads the canvas through it) and a machine's daemon is the machine role; a fresh computer starts none until it is registered.
127
+ if (readMachineConfig() !== undefined || hasLocalCanvas())
128
+ await spawnDaemon();
128
129
  const oldPackage = oldPackageInstalled();
129
130
  if (oldPackage !== undefined)
130
131
  process.stderr.write(`${oldPackage.message}\n`);
@@ -237,9 +237,12 @@ export async function ensureRootProfile() {
237
237
  }
238
238
  return await createProfile(ROOT_PROFILE_NAME, [], { grantee: 'app:terminal' });
239
239
  }
240
- const existing = getStoredProfile(ROOT_PROFILE_ID);
240
+ // A computer signed in to an account that already has a root profile (made on another computer, so with another id) uses that one.
241
+ const existing = getStoredProfile(ROOT_PROFILE_ID)
242
+ ?? listProfiles().find((p) => p.manifest.name === ROOT_PROFILE_NAME && profileApp(p.manifest) === 'app:terminal')
243
+ ?? null;
241
244
  if (existing !== null) {
242
- scaffoldProfile(ROOT_PROFILE_ID, existing.manifest);
245
+ scaffoldProfile(existing.profileId, existing.manifest);
243
246
  return existing;
244
247
  }
245
248
  const next = {
@@ -48,3 +48,5 @@ export declare const installIdPath: () => string;
48
48
  export declare function readOrCreateInstallId(): string;
49
49
  /** Whether this computer still holds a local canvas from before crtr was fleet-only (a supervised Postgres or a SQLite file). */
50
50
  export declare const hasLocalCanvas: () => boolean;
51
+ /** A computer with no `machine.json`, no local records and no join registration has not been set up: it has no control plane to reach until `crtr sys signin`. */
52
+ export declare const computerIsUnset: () => boolean;
@@ -7,6 +7,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync }
7
7
  import { randomBytes } from 'node:crypto';
8
8
  import { dirname, join } from 'node:path';
9
9
  import { runtimeRoot, secretsDir } from '../../core/layout.js';
10
+ import { joinedIssuer } from '../../core/directory/join.js';
10
11
  import { CrtrError } from '../../core/errors.js';
11
12
  import { atomicWriteJson } from '../../core/fs-utils.js';
12
13
  import { ExitCode } from '../../types.js';
@@ -75,3 +76,5 @@ export function readOrCreateInstallId() {
75
76
  }
76
77
  /** Whether this computer still holds a local canvas from before crtr was fleet-only (a supervised Postgres or a SQLite file). */
77
78
  export const hasLocalCanvas = () => ['pg', 'canvas.db', 'canvas.db.imported'].some((name) => existsSync(join(runtimeRoot(), name)));
79
+ /** A computer with no `machine.json`, no local records and no join registration has not been set up: it has no control plane to reach until `crtr sys signin`. */
80
+ export const computerIsUnset = () => readMachineConfig() === undefined && !hasLocalCanvas() && joinedIssuer() === null;
@@ -16,7 +16,7 @@ import { hostExecPath } from '../core/runtime/branded-host.js';
16
16
  // reaches openDb) so the CLI daemon front door stays canvas.db-free (plan B-0).
17
17
  import { isDaemonRunning, readPidfile, isPidAlive } from './pidfile.js';
18
18
  import { DAEMON_STARTUP_WINDOW_MS } from './startup-policy.js';
19
- import { readMachineConfig } from './machine-link/config.js';
19
+ import { computerIsUnset, readMachineConfig } from './machine-link/config.js';
20
20
  import { exclusiveLockOwnerPid } from '../core/exclusive-lock.js';
21
21
  import { onDiskMigrationLockPath } from '../core/canvas/paths.js';
22
22
  import { envNoDaemonAutostart } from '../shared/env.js';
@@ -694,6 +694,9 @@ export function ensureDaemon(deps = {}) {
694
694
  const now = deps.now ?? Date.now;
695
695
  if (autostartDisabled())
696
696
  return;
697
+ // A computer with no `machine.json` and no local records is not set up: no command starts a local control plane there (`crtr sys signin` comes first).
698
+ if (!deps.spawnDaemon && computerIsUnset())
699
+ return;
697
700
  if (autostartInFlight)
698
701
  return;
699
702
  if (now() < autostartNextAttemptAt)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.738",
3
+ "version": "0.3.739",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",