@sequenceholdings/studio-cli 0.9.15 → 0.9.17

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.
@@ -0,0 +1,133 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { realpathSync, readFileSync } from 'node:fs';
3
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { gt, lt, prerelease, valid } from 'semver';
8
+ const PACKAGE = '@sequenceholdings/studio-cli';
9
+ const PACKAGE_PATH = join('@sequenceholdings', 'studio-cli');
10
+ function trackPath() { return join(homedir(), '.config', 'lattice', 'update-track.json'); }
11
+ function installedPackageRoot() {
12
+ return dirname(dirname(fileURLToPath(import.meta.url)));
13
+ }
14
+ function globalPackageRoot() {
15
+ const result = spawnSync('pnpm', ['root', '-g'], { encoding: 'utf8', timeout: 5000 });
16
+ if (result.status !== 0)
17
+ return null;
18
+ const root = result.stdout.trim();
19
+ if (!root)
20
+ return null;
21
+ try {
22
+ const global = realpathSync(join(root, PACKAGE_PATH));
23
+ return global === realpathSync(installedPackageRoot()) ? root : null;
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ export function isGlobalPnpmInstallation() { return globalPackageRoot() !== null; }
30
+ export async function globalUpdateTrack() {
31
+ try {
32
+ const parsed = JSON.parse(await readFile(trackPath(), 'utf8'));
33
+ const track = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'track') : null;
34
+ return track === 'next' ? 'next' : 'latest';
35
+ }
36
+ catch {
37
+ return 'latest';
38
+ }
39
+ }
40
+ export async function setGlobalUpdateTrack(track) {
41
+ if (!isGlobalPnpmInstallation())
42
+ return false;
43
+ const path = trackPath();
44
+ await mkdir(dirname(path), { recursive: true });
45
+ const temporary = `${path}.${process.pid}.tmp`;
46
+ await writeFile(temporary, JSON.stringify({ track }) + '\n', { mode: 0o600 });
47
+ await rename(temporary, path);
48
+ return true;
49
+ }
50
+ export async function updaterCommand(args) {
51
+ const [action, track] = args;
52
+ if (!action || action === '--help' || action === '-h' || action === 'help') {
53
+ console.log('usage: seq-studio updater status | track latest|next');
54
+ return 0;
55
+ }
56
+ const root = globalPackageRoot();
57
+ if (!root) {
58
+ console.error('Automatic updates require a global pnpm installation of seq-studio; project dependencies remain pinned.');
59
+ return 1;
60
+ }
61
+ if (action === 'status') {
62
+ console.log(`Global pnpm seq-studio ${packageVersion(root) ?? 'unknown'} (${await globalUpdateTrack()})`);
63
+ return 0;
64
+ }
65
+ if (action === 'track' && (track === 'latest' || track === 'next')) {
66
+ await setGlobalUpdateTrack(track);
67
+ console.log(`seq-studio now follows npm ${track}`);
68
+ return 0;
69
+ }
70
+ console.error('usage: seq-studio updater status | track latest|next');
71
+ return 1;
72
+ }
73
+ function packageVersion(root) {
74
+ try {
75
+ const parsed = JSON.parse(readFileSync(join(root, PACKAGE_PATH, 'package.json'), 'utf8'));
76
+ const version = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'version') : null;
77
+ return typeof version === 'string' ? version : null;
78
+ }
79
+ catch {
80
+ return null;
81
+ }
82
+ }
83
+ /** Runs only in the detached registry-refresh worker, never in a CLI command. */
84
+ export async function maybeUpgradeGlobalPnpm(available, expectedTrack) {
85
+ const ci = process.env['CI']?.trim().toLowerCase();
86
+ if (process.env['SEQ_STUDIO_NO_AUTO_UPDATE'] === '1' || process.env['SEQ_STUDIO_TOKEN_FILE'] || (ci && ci !== 'false' && ci !== '0'))
87
+ return false;
88
+ if (!valid(available))
89
+ return false;
90
+ const root = globalPackageRoot();
91
+ if (!root)
92
+ return false;
93
+ if (expectedTrack && await globalUpdateTrack() !== expectedTrack)
94
+ return false;
95
+ const previous = packageVersion(root);
96
+ if (!previous || !valid(previous) || available === previous)
97
+ return false;
98
+ // Leaving next can select an older stable release. Honor that explicit track
99
+ // change, but never downgrade one stable release to another on a stale tag.
100
+ const returnsToStable = prerelease(previous) !== null && prerelease(available) === null;
101
+ if (!gt(available, previous) && !returnsToStable)
102
+ return false;
103
+ const pnpm = spawnSync('pnpm', ['--version'], { encoding: 'utf8', timeout: 5000 });
104
+ const pnpmVersion = pnpm.stdout.trim();
105
+ if (pnpm.status !== 0 || !valid(pnpmVersion) || lt(pnpmVersion, '10.28.2') || !lt(pnpmVersion, '11.0.0'))
106
+ return false;
107
+ if (expectedTrack && await globalUpdateTrack() !== expectedTrack)
108
+ return false;
109
+ const result = spawnSync('pnpm', ['add', '-g', '--ignore-scripts', '--registry', 'https://registry.npmjs.org/', `${PACKAGE}@${available}`], {
110
+ encoding: 'utf8', timeout: 300000,
111
+ env: {
112
+ ...process.env,
113
+ npm_config_minimum_release_age: '10080',
114
+ npm_config_minimum_release_age_exclude: '["@sequenceholdings/*"]',
115
+ },
116
+ });
117
+ if (result.status !== 0 || packageVersion(root) !== available)
118
+ return false;
119
+ let summary;
120
+ try {
121
+ const parsed = JSON.parse(await readFile(join(root, PACKAGE_PATH, 'release-summary.json'), 'utf8'));
122
+ const value = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, available) : null;
123
+ if (typeof value === 'string' && value.length <= 300)
124
+ summary = value;
125
+ }
126
+ catch { /* An update notice can omit the summary. */ }
127
+ const notices = join(homedir(), '.config', 'lattice');
128
+ await mkdir(notices, { recursive: true });
129
+ const temporary = join(notices, `update-installed.${process.pid}.tmp`);
130
+ await writeFile(temporary, JSON.stringify({ from: previous, to: available, summary }) + '\n', { mode: 0o600 });
131
+ await rename(temporary, join(notices, 'update-installed.json'));
132
+ return true;
133
+ }
@@ -1,18 +1,14 @@
1
1
  /** The version of this installed package (dist/../package.json). */
2
2
  export declare function currentVersion(): string;
3
- export declare function updateCheckCachePath(): string;
3
+ export declare function updateCheckCachePath(installationFile?: string): string;
4
4
  /** Exclusive-create marker that makes "who spawns the refresh?" atomic. */
5
5
  export declare function updateCheckClaimPath(): string;
6
6
  /** Receipt is scoped to the local user cache and installed/available pair. */
7
7
  export declare function updateNoticeReceiptPath(installed: string, available: string): string;
8
- /**
9
- * True when `candidate` is a strictly newer semver than `current`.
10
- * Prerelease suffixes are ignored — the published channel is plain
11
- * major.minor.patch and this only drives a notice, not resolution.
12
- */
8
+ /** True when `candidate` is a strictly newer semver than `current`. */
13
9
  export declare function isNewerVersion(candidate: string, current: string): boolean;
14
10
  /**
15
- * Poll the registry and persist the result. Runs in the detached background
11
+ * Poll the registry, upgrade an eligible global pnpm install, and persist the result. Runs in the detached background
16
12
  * process (see update-check-refresh.ts) — never on a command's exit path.
17
13
  * Failed fetches still record `lastCheckedAt` (keeping any previously known
18
14
  * version) so attempts are throttled to once per interval either way. The
@@ -1,16 +1,17 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash } from 'node:crypto';
3
- import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
3
+ import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
4
4
  import { readFileSync } from 'node:fs';
5
5
  import { homedir } from 'node:os';
6
6
  import { dirname, join } from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
+ import { gt, valid } from 'semver';
8
9
  /**
9
- * Update notice: tell CLI users and agents when a newer version is on npm.
10
+ * Update discovery: tell CLI users and agents when a newer version is on npm.
10
11
  *
11
- * Zero foreground latency is the design constraint. The command path only
12
- * ever *reads* the on-disk cache (~/.config/lattice/update-check.json) and
13
- * prints; the registry poll runs in a detached background process spawned
12
+ * Zero foreground network latency is the design constraint. The command path
13
+ * reads the on-disk cache (~/.config/lattice/update-check.json) and prints;
14
+ * the registry poll and eligible global pnpm upgrade run in a detached process spawned
14
15
  * at most once per CHECK_INTERVAL_MS — including after failures, which
15
16
  * record their attempt time so a downed registry doesn't retry on every
16
17
  * command. An exclusive claim file elects a single refresher even across
@@ -19,7 +20,7 @@ import { fileURLToPath } from 'node:url';
19
20
  * installed/available version pair for this local user. Its write is the
20
21
  * notification claim, so concurrent invocations cannot print duplicates.
21
22
  *
22
- * The structured notice goes to stderr, leaving JSON stdout intact. CI and
23
+ * Notices go to stderr, leaving JSON stdout intact. CI and
23
24
  * explicitly offline commands skip discovery. Opt out entirely with
24
25
  * SEQ_STUDIO_NO_UPDATE_CHECK=1. Everything is best-effort: failures are
25
26
  * silent and never affect the command's exit code.
@@ -36,8 +37,11 @@ export function currentVersion() {
36
37
  const version = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'version') : null;
37
38
  return typeof version === 'string' ? version : '0.0.0';
38
39
  }
39
- export function updateCheckCachePath() {
40
- return join(homedir(), '.config', 'lattice', 'update-check.json');
40
+ export function updateCheckCachePath(installationFile = fileURLToPath(import.meta.url)) {
41
+ // A project-pinned CLI must not consume the global installation's daily
42
+ // check. pnpm versions live at distinct real paths, so hash the package path.
43
+ const installation = createHash('sha256').update(dirname(installationFile)).digest('hex').slice(0, 16);
44
+ return join(homedir(), '.config', 'lattice', `update-check-${installation}.json`);
41
45
  }
42
46
  /** Exclusive-create marker that makes "who spawns the refresh?" atomic. */
43
47
  export function updateCheckClaimPath() {
@@ -48,24 +52,9 @@ export function updateNoticeReceiptPath(installed, available) {
48
52
  const installation = createHash('sha256').update(dirname(fileURLToPath(import.meta.url))).digest('hex').slice(0, 16);
49
53
  return join(dirname(updateCheckCachePath()), 'update-notices', installation, `${encodeURIComponent(installed)}--${encodeURIComponent(available)}.receipt`);
50
54
  }
51
- /**
52
- * True when `candidate` is a strictly newer semver than `current`.
53
- * Prerelease suffixes are ignored — the published channel is plain
54
- * major.minor.patch and this only drives a notice, not resolution.
55
- */
55
+ /** True when `candidate` is a strictly newer semver than `current`. */
56
56
  export function isNewerVersion(candidate, current) {
57
- const parse = (v) => v
58
- .replace(/^v/, '')
59
- .split('-')[0]
60
- .split('.')
61
- .map((part) => Number.parseInt(part, 10) || 0);
62
- const [a, b] = [parse(candidate), parse(current)];
63
- for (let i = 0; i < 3; i++) {
64
- const diff = (a[i] ?? 0) - (b[i] ?? 0);
65
- if (diff !== 0)
66
- return diff > 0;
67
- }
68
- return false;
57
+ return valid(candidate) !== null && valid(current) !== null && gt(candidate, current);
69
58
  }
70
59
  async function readCache() {
71
60
  try {
@@ -78,7 +67,8 @@ async function readCache() {
78
67
  if (typeof candidate.latestVersion !== 'string' && candidate.latestVersion !== null) {
79
68
  return null;
80
69
  }
81
- return { lastCheckedAt: candidate.lastCheckedAt, latestVersion: candidate.latestVersion };
70
+ return { lastCheckedAt: candidate.lastCheckedAt, latestVersion: candidate.latestVersion,
71
+ track: candidate.track === 'next' ? 'next' : 'latest' };
82
72
  }
83
73
  catch {
84
74
  return null;
@@ -89,15 +79,28 @@ async function writeCache(cache) {
89
79
  await mkdir(dirname(path), { recursive: true });
90
80
  await writeFile(path, JSON.stringify(cache, null, 2) + '\n', 'utf8');
91
81
  }
92
- async function fetchLatestVersion() {
82
+ async function fetchLatestVersion(track) {
93
83
  const controller = new AbortController();
94
84
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
95
85
  try {
96
- const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal: controller.signal });
86
+ const response = await fetch(track === 'next' ? `https://registry.npmjs.org/${PACKAGE_NAME.replace('/', '%2f')}` : `https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal: controller.signal });
97
87
  if (!response.ok)
98
88
  return null;
99
- const body = (await response.json());
100
- return typeof body.version === 'string' ? body.version : null;
89
+ const body = await response.json();
90
+ if (typeof body !== 'object' || body === null)
91
+ return null;
92
+ if (track === 'latest') {
93
+ const version = Reflect.get(body, 'version');
94
+ return typeof version === 'string' ? version : null;
95
+ }
96
+ const tags = Reflect.get(body, 'dist-tags');
97
+ if (typeof tags !== 'object' || tags === null)
98
+ return null;
99
+ const latest = Reflect.get(tags, 'latest');
100
+ const next = Reflect.get(tags, 'next');
101
+ if (typeof latest !== 'string' || valid(latest) === null)
102
+ return null;
103
+ return typeof next === 'string' && isNewerVersion(next, latest) ? next : latest;
101
104
  }
102
105
  catch {
103
106
  return null;
@@ -107,7 +110,7 @@ async function fetchLatestVersion() {
107
110
  }
108
111
  }
109
112
  /**
110
- * Poll the registry and persist the result. Runs in the detached background
113
+ * Poll the registry, upgrade an eligible global pnpm install, and persist the result. Runs in the detached background
111
114
  * process (see update-check-refresh.ts) — never on a command's exit path.
112
115
  * Failed fetches still record `lastCheckedAt` (keeping any previously known
113
116
  * version) so attempts are throttled to once per interval either way. The
@@ -116,17 +119,49 @@ async function fetchLatestVersion() {
116
119
  */
117
120
  export async function refreshUpdateCache() {
118
121
  try {
122
+ const { globalUpdateTrack, maybeUpgradeGlobalPnpm } = await import('./pnpm-auto-update.js');
123
+ const track = await globalUpdateTrack();
119
124
  const previous = await readCache();
120
- const fetched = await fetchLatestVersion();
125
+ const fetched = await fetchLatestVersion(track);
126
+ // Track selection can change while the network request is in flight.
127
+ if (await globalUpdateTrack() !== track)
128
+ return;
129
+ if (fetched && fetched !== currentVersion()) {
130
+ await maybeUpgradeGlobalPnpm(fetched, track).catch(() => false);
131
+ }
121
132
  await writeCache({
122
133
  lastCheckedAt: Date.now(),
123
- latestVersion: fetched ?? previous?.latestVersion ?? null,
134
+ latestVersion: fetched ?? (previous?.track === track ? previous.latestVersion : null),
135
+ track,
124
136
  });
125
137
  }
126
138
  finally {
127
139
  await rm(updateCheckClaimPath(), { force: true }).catch(() => { });
128
140
  }
129
141
  }
142
+ async function printInstalledNotice() {
143
+ const path = join(dirname(updateCheckCachePath()), 'update-installed.json');
144
+ const claimed = `${path}.${process.pid}.claimed`;
145
+ try {
146
+ await rename(path, claimed);
147
+ const parsed = JSON.parse(await readFile(claimed, 'utf8'));
148
+ if (typeof parsed !== 'object' || parsed === null)
149
+ return;
150
+ const from = Reflect.get(parsed, 'from');
151
+ const to = Reflect.get(parsed, 'to');
152
+ const summary = Reflect.get(parsed, 'summary');
153
+ if (typeof from === 'string' && typeof to === 'string' && to === currentVersion()) {
154
+ process.stderr.write(`seq-studio updated ${from} → ${to}.${typeof summary === 'string' ? ` ${summary}` : ''} Future commands use ${to}.\n`);
155
+ }
156
+ else if (typeof from === 'string' && typeof to === 'string') {
157
+ await writeFile(path, JSON.stringify(parsed) + '\n', { flag: 'wx', mode: 0o600 }).catch(() => { });
158
+ }
159
+ }
160
+ catch { /* A notice must never affect a command. */ }
161
+ finally {
162
+ await rm(claimed, { force: true }).catch(() => { });
163
+ }
164
+ }
130
165
  /**
131
166
  * Atomically claim the right to spawn a refresh. The `wx` flag makes the
132
167
  * create exclusive at the filesystem level, so concurrent CLI processes
@@ -198,7 +233,11 @@ export async function maybeNotifyUpdate() {
198
233
  return;
199
234
  if (isCiEnvironment())
200
235
  return;
201
- const cache = await readCache();
236
+ await printInstalledNotice();
237
+ const { globalUpdateTrack } = await import('./pnpm-auto-update.js');
238
+ const selectedTrack = await globalUpdateTrack();
239
+ const storedCache = await readCache();
240
+ const cache = storedCache?.track === selectedTrack ? storedCache : null;
202
241
  if (!cache || Date.now() - cache.lastCheckedAt > CHECK_INTERVAL_MS) {
203
242
  // Exactly one process refreshes: the exclusive claim file elects a
204
243
  // single refresher even across concurrent CLI invocations, and the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.9.15",
3
+ "version": "0.9.17",
4
4
  "description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth whoami`. Includes Auth0 browser login shared with seqapi.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -33,6 +33,7 @@
33
33
  "files": [
34
34
  "dist",
35
35
  "templates",
36
+ "release-summary.json",
36
37
  "README.md"
37
38
  ],
38
39
  "dependencies": {
@@ -44,16 +45,16 @@
44
45
  "tsx": "^4.20.3",
45
46
  "yaml": "^2.8.4",
46
47
  "zod": "4.6.6",
47
- "@sequenceholdings/agent-spec": "0.1.5",
48
+ "@sequenceholdings/artifact-studio": "0.11.15",
48
49
  "@sequenceholdings/lattice": "0.1.8",
49
- "@sequenceholdings/managed-functions": "0.5.10",
50
- "@sequenceholdings/artifact-studio": "0.11.14",
50
+ "@sequenceholdings/managed-functions": "0.5.11",
51
51
  "@sequenceholdings/storage": "0.1.7",
52
+ "@sequenceholdings/agent-spec": "0.1.5",
52
53
  "@sequenceholdings/platform": "0.1.4"
53
54
  },
54
55
  "peerDependencies": {
55
- "@sequenceholdings/pipeline-spec": "0.3.9",
56
- "@sequenceholdings/orm": "2.9.0"
56
+ "@sequenceholdings/pipeline-spec": "0.3.10",
57
+ "@sequenceholdings/orm": "2.10.0"
57
58
  },
58
59
  "peerDependenciesMeta": {
59
60
  "@sequenceholdings/orm": {
@@ -69,8 +70,8 @@
69
70
  "@types/semver": "^7.8.0",
70
71
  "typescript": "^5.6.0",
71
72
  "vitest": "^4.1.12",
72
- "@sequenceholdings/orm": "2.9.0",
73
- "@sequenceholdings/pipeline-spec": "0.3.9"
73
+ "@sequenceholdings/orm": "2.10.0",
74
+ "@sequenceholdings/pipeline-spec": "0.3.10"
74
75
  },
75
76
  "engines": {
76
77
  "node": ">=20"
@@ -0,0 +1,3 @@
1
+ {
2
+ "0.9.17": "Global pnpm 10 installs now update automatically to latest after a background check. If a command fails to start during an update, retry it. Use seq-studio updater track next for previews."
3
+ }