@standardagents/cli 0.38.0 → 0.38.2

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command, Option } from 'commander';
3
3
  import path7 from 'path';
4
- import fs3 from 'fs';
4
+ import fs4 from 'fs';
5
5
  import crypto from 'crypto';
6
6
  import os3 from 'os';
7
7
  import net from 'net';
@@ -48,15 +48,26 @@ var logger = {
48
48
  console.log(message);
49
49
  }
50
50
  };
51
+ function writePrivateFileSync(filePath, content) {
52
+ const descriptor = fs4.openSync(filePath, "w", 384);
53
+ try {
54
+ fs4.fchmodSync(descriptor, 384);
55
+ fs4.writeFileSync(descriptor, content, "utf8");
56
+ } finally {
57
+ fs4.closeSync(descriptor);
58
+ }
59
+ }
60
+
61
+ // src/utils/bootstrap-state.ts
51
62
  var STATE_RELATIVE_PATH = path7.join(".agents", "bootstrap-session.json");
52
63
  function getBootstrapStatePath(projectPath) {
53
64
  return path7.join(projectPath, STATE_RELATIVE_PATH);
54
65
  }
55
66
  function loadBootstrapState(projectPath) {
56
67
  const statePath = getBootstrapStatePath(projectPath);
57
- if (!fs3.existsSync(statePath)) return null;
68
+ if (!fs4.existsSync(statePath)) return null;
58
69
  try {
59
- const parsed = JSON.parse(fs3.readFileSync(statePath, "utf-8"));
70
+ const parsed = JSON.parse(fs4.readFileSync(statePath, "utf-8"));
60
71
  if (parsed.version !== 1) return null;
61
72
  if (!parsed.endpoint || !parsed.user?.id || !parsed.account?.id) return null;
62
73
  if (parsed.session_cookie !== void 0 && typeof parsed.session_cookie !== "string") return null;
@@ -67,13 +78,13 @@ function loadBootstrapState(projectPath) {
67
78
  }
68
79
  function persistBootstrapState(projectPath, state) {
69
80
  const statePath = getBootstrapStatePath(projectPath);
70
- fs3.mkdirSync(path7.dirname(statePath), { recursive: true });
71
- fs3.writeFileSync(statePath, JSON.stringify(state, null, 2) + "\n", "utf-8");
81
+ fs4.mkdirSync(path7.dirname(statePath), { recursive: true });
82
+ writePrivateFileSync(statePath, JSON.stringify(state, null, 2) + "\n");
72
83
  }
73
84
  function clearBootstrapState(projectPath) {
74
85
  const statePath = getBootstrapStatePath(projectPath);
75
- if (fs3.existsSync(statePath)) {
76
- fs3.unlinkSync(statePath);
86
+ if (fs4.existsSync(statePath)) {
87
+ fs4.unlinkSync(statePath);
77
88
  }
78
89
  }
79
90
  function getWebSocketCtor() {
@@ -254,13 +265,13 @@ function getScaffoldStandardAgentsVersion() {
254
265
  if (process.env.STANDARDAGENTS_WORKSPACE === "1") {
255
266
  return "workspace:*";
256
267
  }
257
- return "0.38.0";
268
+ return "0.38.2";
258
269
  }
259
270
  function findViteConfig(cwd) {
260
271
  const candidates = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs"];
261
272
  for (const candidate of candidates) {
262
273
  const configPath = path7.join(cwd, candidate);
263
- if (fs3.existsSync(configPath)) {
274
+ if (fs4.existsSync(configPath)) {
264
275
  return configPath;
265
276
  }
266
277
  }
@@ -279,12 +290,12 @@ function setPackageDependency(packageJsonText, section, packageName, version) {
279
290
  }
280
291
  function updatePackageDependencies(cwd, versions = {}) {
281
292
  const packageJsonPath = path7.join(cwd, "package.json");
282
- if (!fs3.existsSync(packageJsonPath)) {
293
+ if (!fs4.existsSync(packageJsonPath)) {
283
294
  logger.warning("No package.json found. Install @standardagents/builder manually.");
284
295
  return false;
285
296
  }
286
297
  try {
287
- const text = fs3.readFileSync(packageJsonPath, "utf-8");
298
+ const text = fs4.readFileSync(packageJsonPath, "utf-8");
288
299
  const pkg = JSON.parse(text);
289
300
  const desiredBuilderVersion = versions.standardAgents ?? getScaffoldStandardAgentsVersion();
290
301
  const builderSection = dependencySectionFor(pkg, "@standardagents/builder", "dependencies");
@@ -298,7 +309,7 @@ function updatePackageDependencies(cwd, versions = {}) {
298
309
  logger.info("package.json already has current Standard Agents dependencies");
299
310
  return true;
300
311
  }
301
- fs3.writeFileSync(packageJsonPath, `${result.trimEnd()}
312
+ fs4.writeFileSync(packageJsonPath, `${result.trimEnd()}
302
313
  `, "utf-8");
303
314
  logger.success("Updated package.json with current Standard Agents dependencies");
304
315
  return true;
@@ -310,7 +321,7 @@ function updatePackageDependencies(cwd, versions = {}) {
310
321
  async function modifyViteConfig(configPath, force) {
311
322
  try {
312
323
  const mod = await loadFile(configPath);
313
- const code = fs3.readFileSync(configPath, "utf-8");
324
+ const code = fs4.readFileSync(configPath, "utf-8");
314
325
  const hasAgentBuilder = code.includes("@standardagents/builder") || code.includes("builder()") || code.includes("agentbuilder()");
315
326
  if (hasAgentBuilder && !force) {
316
327
  logger.info("Vite config already includes builder plugin");
@@ -342,12 +353,12 @@ function createDirectoriesAndDocs(cwd) {
342
353
  function writeAgentsDocWithClaudeSymlink(dirPath, doc, label) {
343
354
  const agentsDocPath = path7.join(dirPath, "AGENTS.md");
344
355
  const claudeDocPath = path7.join(dirPath, "CLAUDE.md");
345
- if (!fs3.existsSync(agentsDocPath)) {
346
- fs3.writeFileSync(agentsDocPath, doc, "utf-8");
356
+ if (!fs4.existsSync(agentsDocPath)) {
357
+ fs4.writeFileSync(agentsDocPath, doc, "utf-8");
347
358
  logger.success(`Created ${label}/AGENTS.md`);
348
359
  }
349
- if (!fs3.existsSync(claudeDocPath)) {
350
- fs3.symlinkSync("AGENTS.md", claudeDocPath);
360
+ if (!fs4.existsSync(claudeDocPath)) {
361
+ fs4.symlinkSync("AGENTS.md", claudeDocPath);
351
362
  logger.success(`Created ${label}/CLAUDE.md symlink`);
352
363
  }
353
364
  }
@@ -362,8 +373,8 @@ function createDirectoriesAndDocs(cwd) {
362
373
  ];
363
374
  for (const dir of directories) {
364
375
  const dirPath = path7.join(cwd, dir.path);
365
- if (!fs3.existsSync(dirPath)) {
366
- fs3.mkdirSync(dirPath, { recursive: true });
376
+ if (!fs4.existsSync(dirPath)) {
377
+ fs4.mkdirSync(dirPath, { recursive: true });
367
378
  logger.success(`Created ${dir.path}`);
368
379
  }
369
380
  writeAgentsDocWithClaudeSymlink(dirPath, dir.doc, dir.path);
@@ -371,12 +382,12 @@ function createDirectoriesAndDocs(cwd) {
371
382
  }
372
383
  function updateTsConfig(cwd) {
373
384
  const tsconfigPath = path7.join(cwd, "tsconfig.json");
374
- if (!fs3.existsSync(tsconfigPath)) {
385
+ if (!fs4.existsSync(tsconfigPath)) {
375
386
  logger.info("No tsconfig.json found, skipping TypeScript configuration");
376
387
  return;
377
388
  }
378
389
  try {
379
- const text = fs3.readFileSync(tsconfigPath, "utf-8");
390
+ const text = fs4.readFileSync(tsconfigPath, "utf-8");
380
391
  const config = parse(text);
381
392
  let result = text;
382
393
  const types = config.compilerOptions?.types || [];
@@ -397,7 +408,7 @@ function updateTsConfig(cwd) {
397
408
  result = applyEdits(result, edits);
398
409
  }
399
410
  if (newTypes.length > 0 || newIncludes.length > 0) {
400
- fs3.writeFileSync(tsconfigPath, result, "utf-8");
411
+ fs4.writeFileSync(tsconfigPath, result, "utf-8");
401
412
  logger.success("Updated tsconfig.json with Standard Agents types");
402
413
  } else {
403
414
  logger.info("tsconfig.json already configured");
@@ -424,20 +435,20 @@ function cleanupViteDefaults(cwd) {
424
435
  const dirsToRemove = ["src", "public", "worker"];
425
436
  for (const file of filesToRemove) {
426
437
  const filePath = path7.join(cwd, file);
427
- if (fs3.existsSync(filePath)) {
438
+ if (fs4.existsSync(filePath)) {
428
439
  try {
429
- fs3.unlinkSync(filePath);
440
+ fs4.unlinkSync(filePath);
430
441
  } catch {
431
442
  }
432
443
  }
433
444
  }
434
445
  for (const dir of dirsToRemove) {
435
446
  const dirPath = path7.join(cwd, dir);
436
- if (fs3.existsSync(dirPath)) {
447
+ if (fs4.existsSync(dirPath)) {
437
448
  try {
438
- const files = fs3.readdirSync(dirPath);
449
+ const files = fs4.readdirSync(dirPath);
439
450
  if (files.length === 0) {
440
- fs3.rmdirSync(dirPath);
451
+ fs4.rmdirSync(dirPath);
441
452
  }
442
453
  } catch {
443
454
  }
@@ -1287,16 +1298,16 @@ function normalizeProjectName(raw) {
1287
1298
  return toKebabCase(raw.trim());
1288
1299
  }
1289
1300
  function isNonEmptyDirectory(targetPath) {
1290
- if (!fs3.existsSync(targetPath)) return false;
1291
- const stat = fs3.statSync(targetPath);
1301
+ if (!fs4.existsSync(targetPath)) return false;
1302
+ const stat = fs4.statSync(targetPath);
1292
1303
  if (!stat.isDirectory()) return false;
1293
- return fs3.readdirSync(targetPath).length > 0;
1304
+ return fs4.readdirSync(targetPath).length > 0;
1294
1305
  }
1295
1306
  function hasBuilderDependency(targetPath) {
1296
1307
  const packageJsonPath = path7.join(targetPath, "package.json");
1297
- if (!fs3.existsSync(packageJsonPath)) return false;
1308
+ if (!fs4.existsSync(packageJsonPath)) return false;
1298
1309
  try {
1299
- const pkg = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
1310
+ const pkg = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
1300
1311
  const deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
1301
1312
  return typeof deps === "object" && Object.prototype.hasOwnProperty.call(deps, "@standardagents/builder");
1302
1313
  } catch {
@@ -1305,11 +1316,11 @@ function hasBuilderDependency(targetPath) {
1305
1316
  }
1306
1317
  function isStandardAgentsProjectDir(targetPath) {
1307
1318
  const agentsDir = path7.join(targetPath, "agents");
1308
- if (!fs3.existsSync(agentsDir) || !fs3.statSync(agentsDir).isDirectory()) {
1319
+ if (!fs4.existsSync(agentsDir) || !fs4.statSync(agentsDir).isDirectory()) {
1309
1320
  return false;
1310
1321
  }
1311
1322
  if (hasBuilderDependency(targetPath)) return true;
1312
- return fs3.existsSync(path7.join(targetPath, "vite.config.ts")) && fs3.existsSync(path7.join(targetPath, "tsconfig.json"));
1323
+ return fs4.existsSync(path7.join(targetPath, "vite.config.ts")) && fs4.existsSync(path7.join(targetPath, "tsconfig.json"));
1313
1324
  }
1314
1325
  async function resolveProjectTarget(cwd, initialProjectName, options, promptProjectName = prompt) {
1315
1326
  if (!initialProjectName && isStandardAgentsProjectDir(cwd)) {
@@ -1348,8 +1359,8 @@ async function resolveProjectTarget(cwd, initialProjectName, options, promptProj
1348
1359
  logger.info(`Using project directory "${projectName}"`);
1349
1360
  }
1350
1361
  const projectPath = path7.join(cwd, projectName);
1351
- const exists = fs3.existsSync(projectPath);
1352
- if (exists && !fs3.statSync(projectPath).isDirectory()) {
1362
+ const exists = fs4.existsSync(projectPath);
1363
+ if (exists && !fs4.statSync(projectPath).isDirectory()) {
1353
1364
  if (options.yes) {
1354
1365
  throw new Error(`Path "${projectName}" already exists and is not a directory`);
1355
1366
  }
@@ -1384,10 +1395,10 @@ function detectPackageManager() {
1384
1395
  if (userAgent.includes("yarn")) return "yarn";
1385
1396
  if (userAgent.includes("bun")) return "bun";
1386
1397
  }
1387
- if (fs3.existsSync("pnpm-lock.yaml")) return "pnpm";
1388
- if (fs3.existsSync("yarn.lock")) return "yarn";
1389
- if (fs3.existsSync("bun.lockb")) return "bun";
1390
- if (fs3.existsSync("package-lock.json")) return "npm";
1398
+ if (fs4.existsSync("pnpm-lock.yaml")) return "pnpm";
1399
+ if (fs4.existsSync("yarn.lock")) return "yarn";
1400
+ if (fs4.existsSync("bun.lockb")) return "bun";
1401
+ if (fs4.existsSync("package-lock.json")) return "npm";
1391
1402
  return "npm";
1392
1403
  }
1393
1404
  function resolvePackageManager(requested, detected) {
@@ -1554,7 +1565,7 @@ async function ensurePlatformAuth(options, quietLogs = false, context = {}) {
1554
1565
  return { connected: true, mode: "standardagents" };
1555
1566
  }
1556
1567
  function getCliVersion() {
1557
- return "0.38.0";
1568
+ return "0.38.2";
1558
1569
  }
1559
1570
  function getSipVersion() {
1560
1571
  return "1.0.1";
@@ -1582,7 +1593,7 @@ function resolveStandardAgentsPackageSpecifier(packageName, packageSpecifier) {
1582
1593
  function findWorkspaceRoot(startDir) {
1583
1594
  let currentDir = startDir;
1584
1595
  while (true) {
1585
- if (fs3.existsSync(path7.join(currentDir, "pnpm-workspace.yaml"))) {
1596
+ if (fs4.existsSync(path7.join(currentDir, "pnpm-workspace.yaml"))) {
1586
1597
  return currentDir;
1587
1598
  }
1588
1599
  const parentDir = path7.dirname(currentDir);
@@ -1596,9 +1607,9 @@ function findStandardAgentsWorkspaceRoot(startDir = path7.dirname(fileURLToPath(
1596
1607
  const workspaceRoot = findWorkspaceRoot(startDir);
1597
1608
  if (!workspaceRoot) return null;
1598
1609
  const rootPackageJsonPath = path7.join(workspaceRoot, "package.json");
1599
- if (!fs3.existsSync(rootPackageJsonPath)) return null;
1610
+ if (!fs4.existsSync(rootPackageJsonPath)) return null;
1600
1611
  try {
1601
- const rootPackageJson = JSON.parse(fs3.readFileSync(rootPackageJsonPath, "utf-8"));
1612
+ const rootPackageJson = JSON.parse(fs4.readFileSync(rootPackageJsonPath, "utf-8"));
1602
1613
  return rootPackageJson.name === "standardagents" ? workspaceRoot : null;
1603
1614
  } catch {
1604
1615
  return null;
@@ -1627,10 +1638,10 @@ function workspacePackageDir(workspaceRoot, packageName) {
1627
1638
  }
1628
1639
  function validateWorkspacePackageDir(packageName, packageDir) {
1629
1640
  const dependencyPackageJsonPath = path7.join(packageDir, "package.json");
1630
- if (!fs3.existsSync(dependencyPackageJsonPath)) {
1641
+ if (!fs4.existsSync(dependencyPackageJsonPath)) {
1631
1642
  throw new Error(`Could not find workspace package for ${packageName} at ${packageDir}`);
1632
1643
  }
1633
- const dependencyPackageJson = JSON.parse(fs3.readFileSync(dependencyPackageJsonPath, "utf-8"));
1644
+ const dependencyPackageJson = JSON.parse(fs4.readFileSync(dependencyPackageJsonPath, "utf-8"));
1634
1645
  if (dependencyPackageJson.name !== packageName) {
1635
1646
  throw new Error(
1636
1647
  `Expected ${packageDir} to contain ${packageName}, found ${dependencyPackageJson.name ?? "unknown package"}`
@@ -1639,7 +1650,7 @@ function validateWorkspacePackageDir(packageName, packageDir) {
1639
1650
  }
1640
1651
  function rewriteStandardAgentsDependenciesForWorkspace(projectPath, workspaceRoot) {
1641
1652
  const packageJsonPath = path7.join(projectPath, "package.json");
1642
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
1653
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
1643
1654
  const dependencies = packageJson.dependencies ?? {};
1644
1655
  const linkedPackages = [];
1645
1656
  for (const packageName of GENERATED_STANDARD_AGENTS_PACKAGES) {
@@ -1651,7 +1662,7 @@ function rewriteStandardAgentsDependenciesForWorkspace(projectPath, workspaceRoo
1651
1662
  }
1652
1663
  if (linkedPackages.length > 0) {
1653
1664
  packageJson.dependencies = dependencies;
1654
- fs3.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
1665
+ fs4.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
1655
1666
  `, "utf-8");
1656
1667
  }
1657
1668
  return linkedPackages;
@@ -1676,9 +1687,9 @@ function findWorkspaceCommandRoot(projectPath) {
1676
1687
  let current = path7.dirname(projectPath);
1677
1688
  while (true) {
1678
1689
  const packageJsonPath = path7.join(current, "package.json");
1679
- if (fs3.existsSync(packageJsonPath)) {
1690
+ if (fs4.existsSync(packageJsonPath)) {
1680
1691
  try {
1681
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
1692
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
1682
1693
  if (packageJson?.scripts && typeof packageJson.scripts["sandbox:hmr"] === "string") {
1683
1694
  return current;
1684
1695
  }
@@ -1694,12 +1705,12 @@ function findWorkspaceCommandRoot(projectPath) {
1694
1705
  }
1695
1706
  function configureWorkspaceProjectScripts(projectPath, projectName) {
1696
1707
  const packageJsonPath = path7.join(projectPath, "package.json");
1697
- if (!fs3.existsSync(packageJsonPath)) return false;
1708
+ if (!fs4.existsSync(packageJsonPath)) return false;
1698
1709
  const workspaceRoot = findWorkspaceCommandRoot(projectPath);
1699
1710
  if (!workspaceRoot) return false;
1700
1711
  const workspacePackageJsonPath = path7.join(workspaceRoot, "package.json");
1701
- const workspacePackageJson = JSON.parse(fs3.readFileSync(workspacePackageJsonPath, "utf-8"));
1702
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
1712
+ const workspacePackageJson = JSON.parse(fs4.readFileSync(workspacePackageJsonPath, "utf-8"));
1713
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
1703
1714
  const scripts = packageJson.scripts && typeof packageJson.scripts === "object" ? packageJson.scripts : {};
1704
1715
  const relativeRoot = path7.relative(projectPath, workspaceRoot) || ".";
1705
1716
  scripts["sandbox:hmr"] = `pnpm -C ${shellQuote(relativeRoot)} sandbox:hmr -- ${shellQuote(projectName)}`;
@@ -1707,15 +1718,15 @@ function configureWorkspaceProjectScripts(projectPath, projectName) {
1707
1718
  scripts["cli:login:workspace"] = `pnpm -C ${shellQuote(relativeRoot)} cli:login:workspace -- ${shellQuote(projectName)}`;
1708
1719
  }
1709
1720
  packageJson.scripts = scripts;
1710
- fs3.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
1721
+ fs4.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
1711
1722
  return true;
1712
1723
  }
1713
1724
  function resolvePostInitRunCommand(packageManager, projectPath, workspacePackages) {
1714
1725
  if (workspacePackages) {
1715
1726
  const packageJsonPath = path7.join(projectPath, "package.json");
1716
- if (fs3.existsSync(packageJsonPath)) {
1727
+ if (fs4.existsSync(packageJsonPath)) {
1717
1728
  try {
1718
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
1729
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
1719
1730
  if (packageJson?.scripts && typeof packageJson.scripts["sandbox:hmr"] === "string") {
1720
1731
  return packageManager === "npm" ? "npm run sandbox:hmr" : `${packageManager} sandbox:hmr`;
1721
1732
  }
@@ -1896,7 +1907,7 @@ function gitCloneArgs(project, projectName) {
1896
1907
  return args;
1897
1908
  }
1898
1909
  function platformGitCredentialHelperCommand(cliEntry = process.argv[1] ?? "") {
1899
- if (process.env.STANDARDAGENTS_WORKSPACE === "1" && cliEntry && fs3.existsSync(cliEntry)) {
1910
+ if (process.env.STANDARDAGENTS_WORKSPACE === "1" && cliEntry && fs4.existsSync(cliEntry)) {
1900
1911
  return `!node ${shellQuote(path7.resolve(cliEntry))} git-credential`;
1901
1912
  }
1902
1913
  if (process.env.STANDARD_AGENTS_GIT_HELPER?.trim()) {
@@ -2056,12 +2067,12 @@ function hasEnvLine(lines, key) {
2056
2067
  }
2057
2068
  function appendGitignoreEntries(projectPath, heading, entries) {
2058
2069
  const gitignorePath = path7.join(projectPath, ".gitignore");
2059
- const gitignoreContent = fs3.existsSync(gitignorePath) ? fs3.readFileSync(gitignorePath, "utf-8") : "";
2070
+ const gitignoreContent = fs4.existsSync(gitignorePath) ? fs4.readFileSync(gitignorePath, "utf-8") : "";
2060
2071
  const existingEntries = new Set(gitignoreContent.split(/\r?\n/));
2061
2072
  const missingEntries = entries.filter((entry) => !existingEntries.has(entry));
2062
2073
  if (missingEntries.length === 0) return;
2063
2074
  const prefix = gitignoreContent.length === 0 ? "" : gitignoreContent.endsWith("\n") ? "\n" : "\n\n";
2064
- fs3.appendFileSync(gitignorePath, `${prefix}${heading}
2075
+ fs4.appendFileSync(gitignorePath, `${prefix}${heading}
2065
2076
  ${missingEntries.join("\n")}
2066
2077
  `);
2067
2078
  }
@@ -2076,9 +2087,9 @@ function writeStandardAgentsSupportFiles(projectPath, params) {
2076
2087
  }
2077
2088
  })) {
2078
2089
  const targetPath = path7.join(projectPath, supportFile.path);
2079
- if (fs3.existsSync(targetPath)) continue;
2080
- fs3.mkdirSync(path7.dirname(targetPath), { recursive: true });
2081
- fs3.writeFileSync(targetPath, supportFile.content, "utf-8");
2090
+ if (fs4.existsSync(targetPath)) continue;
2091
+ fs4.mkdirSync(path7.dirname(targetPath), { recursive: true });
2092
+ fs4.writeFileSync(targetPath, supportFile.content, "utf-8");
2082
2093
  written.push(supportFile.path);
2083
2094
  }
2084
2095
  appendGitignoreEntries(projectPath, "# Standard Agents local dev state", [
@@ -2112,7 +2123,7 @@ function supportFiles(options = {}) {
2112
2123
  }
2113
2124
  function writeStandardAgentsEnv(projectPath, params) {
2114
2125
  const envPath = path7.join(projectPath, ".dev.vars");
2115
- const existing = fs3.existsSync(envPath) ? fs3.readFileSync(envPath, "utf-8") : "";
2126
+ const existing = fs4.existsSync(envPath) ? fs4.readFileSync(envPath, "utf-8") : "";
2116
2127
  let lines = existing.split(/\r?\n/).filter(
2117
2128
  (line) => line.trim().length > 0 && !line.startsWith("STANDARD_AGENTS_API_KEY=") && !line.startsWith("PLATFORM_ENDPOINT=") && !line.startsWith("STANDARD_AGENTS_API_URL=")
2118
2129
  );
@@ -2137,7 +2148,7 @@ function writeStandardAgentsEnv(projectPath, params) {
2137
2148
  lines = upsertEnvLine(lines, "STANDARD_AGENTS_API_KEY", params.apiKey);
2138
2149
  lines = upsertEnvLine(lines, "PLATFORM_ENDPOINT", params.platformEndpoint);
2139
2150
  lines = upsertEnvLine(lines, "STANDARD_AGENTS_API_URL", params.platformEndpoint);
2140
- fs3.writeFileSync(envPath, lines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n", "utf-8");
2151
+ fs4.writeFileSync(envPath, lines.join("\n").replace(/\n{3,}/g, "\n\n").trim() + "\n", "utf-8");
2141
2152
  appendGitignoreEntries(projectPath, "# Standard Agents local platform token", [".dev.vars"]);
2142
2153
  return envPath;
2143
2154
  }
@@ -2182,7 +2193,7 @@ async function runPlatformInit(projectNameArg, options) {
2182
2193
  process.exit(1);
2183
2194
  }
2184
2195
  const requestedProjectName = projectNameArg?.trim() || void 0;
2185
- if (requestedProjectName && fs3.existsSync(path7.join(cwd, requestedProjectName))) {
2196
+ if (requestedProjectName && fs4.existsSync(path7.join(cwd, requestedProjectName))) {
2186
2197
  logger.error(`Directory "${requestedProjectName}" already exists`);
2187
2198
  process.exit(1);
2188
2199
  }
@@ -2218,7 +2229,7 @@ async function runPlatformInit(projectNameArg, options) {
2218
2229
  const projectName = resolvePlatformProjectDirectoryName(project, requestedProjectName);
2219
2230
  const projectPackageManager = resolvePlatformProjectPackageManager(project.package_manager, pm);
2220
2231
  const projectPath = path7.join(cwd, projectName);
2221
- if (fs3.existsSync(projectPath)) {
2232
+ if (fs4.existsSync(projectPath)) {
2222
2233
  logger.error(`Directory "${projectName}" already exists`);
2223
2234
  process.exit(1);
2224
2235
  }
@@ -2573,14 +2584,14 @@ async function init(projectNameArg, options = {}) {
2573
2584
  process.exit(1);
2574
2585
  }
2575
2586
  const viteConfigPath = path7.join(projectPath, "vite.config.ts");
2576
- if (!fs3.existsSync(viteConfigPath)) {
2587
+ if (!fs4.existsSync(viteConfigPath)) {
2577
2588
  const viteConfigContent = `import { defineConfig } from 'vite'
2578
2589
 
2579
2590
  export default defineConfig({
2580
2591
  plugins: [],
2581
2592
  })
2582
2593
  `;
2583
- fs3.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
2594
+ fs4.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
2584
2595
  logSuccess("Created vite.config.ts");
2585
2596
  }
2586
2597
  } else if (resumeBootstrap) {
@@ -2589,12 +2600,12 @@ export default defineConfig({
2589
2600
  logInfo(`Detected existing Standard Agents project in "${projectName}".`);
2590
2601
  }
2591
2602
  const packageJsonPath = path7.join(projectPath, "package.json");
2592
- if (fs3.existsSync(packageJsonPath)) {
2593
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
2603
+ if (fs4.existsSync(packageJsonPath)) {
2604
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
2594
2605
  const kebabName = toKebabCase(projectName);
2595
2606
  if (packageJson.name !== kebabName) {
2596
2607
  packageJson.name = kebabName;
2597
- fs3.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
2608
+ fs4.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
2598
2609
  }
2599
2610
  if (packageSpecifier === "workspace:*" && configureWorkspaceProjectScripts(projectPath, projectName)) {
2600
2611
  logInfo("Configured local workspace helper scripts for sandbox HMR and re-auth.");
@@ -2731,13 +2742,13 @@ export default defineConfig({
2731
2742
  }
2732
2743
  devVarsLines.push("");
2733
2744
  const devVarsPath = path7.join(projectPath, ".dev.vars");
2734
- fs3.writeFileSync(devVarsPath, devVarsLines.join("\n"), "utf-8");
2745
+ fs4.writeFileSync(devVarsPath, devVarsLines.join("\n"), "utf-8");
2735
2746
  logSuccess("Created .dev.vars with encryption key");
2736
2747
  const gitignorePath = path7.join(projectPath, ".gitignore");
2737
- if (fs3.existsSync(gitignorePath)) {
2738
- const gitignoreContent = fs3.readFileSync(gitignorePath, "utf-8");
2748
+ if (fs4.existsSync(gitignorePath)) {
2749
+ const gitignoreContent = fs4.readFileSync(gitignorePath, "utf-8");
2739
2750
  if (!gitignoreContent.includes(".dev.vars")) {
2740
- fs3.appendFileSync(gitignorePath, "\n# Local environment variables\n.dev.vars\n");
2751
+ fs4.appendFileSync(gitignorePath, "\n# Local environment variables\n.dev.vars\n");
2741
2752
  logSuccess("Added .dev.vars to .gitignore");
2742
2753
  }
2743
2754
  }
@@ -2791,7 +2802,7 @@ function upsertEnvLine2(lines, key, value) {
2791
2802
  }
2792
2803
  function syncProjectAuthEnv(projectPath, endpoint, state) {
2793
2804
  const devVarsPath = path7.join(projectPath, DEV_VARS_FILENAME);
2794
- const existing = fs3.existsSync(devVarsPath) ? fs3.readFileSync(devVarsPath, "utf-8") : "";
2805
+ const existing = fs4.existsSync(devVarsPath) ? fs4.readFileSync(devVarsPath, "utf-8") : "";
2795
2806
  const lines = existing ? existing.split("\n") : [];
2796
2807
  if (endpoint.trim()) {
2797
2808
  upsertEnvLine2(lines, "PLATFORM_ENDPOINT", endpoint.trim());
@@ -2805,7 +2816,7 @@ function syncProjectAuthEnv(projectPath, endpoint, state) {
2805
2816
  upsertEnvLine2(lines, "STANDARDAGENTS_BOOTSTRAP_SESSION_COOKIE", state.session_cookie);
2806
2817
  }
2807
2818
  const normalized = lines.join("\n").replace(/\n*$/, "\n");
2808
- fs3.writeFileSync(devVarsPath, normalized, "utf-8");
2819
+ fs4.writeFileSync(devVarsPath, normalized, "utf-8");
2809
2820
  }
2810
2821
 
2811
2822
  // src/commands/login.ts
@@ -2989,7 +3000,7 @@ function stateFilePath() {
2989
3000
  return path7.join(configDir(), "auth-state.json");
2990
3001
  }
2991
3002
  function ensureStateDir() {
2992
- fs3.mkdirSync(path7.dirname(stateFilePath()), { recursive: true });
3003
+ fs4.mkdirSync(path7.dirname(stateFilePath()), { recursive: true });
2993
3004
  }
2994
3005
  function securityCommand(args) {
2995
3006
  const result = spawnSync("security", args, { encoding: "utf8" });
@@ -3032,11 +3043,11 @@ function readFromKeychain(orgId) {
3032
3043
  }
3033
3044
  function readCliAuthState() {
3034
3045
  const file = stateFilePath();
3035
- if (!fs3.existsSync(file)) {
3046
+ if (!fs4.existsSync(file)) {
3036
3047
  return { active_org_id: null, orgs: {} };
3037
3048
  }
3038
3049
  try {
3039
- const parsed = JSON.parse(fs3.readFileSync(file, "utf8"));
3050
+ const parsed = JSON.parse(fs4.readFileSync(file, "utf8"));
3040
3051
  return {
3041
3052
  active_org_id: parsed.active_org_id ?? null,
3042
3053
  orgs: parsed.orgs ?? {},
@@ -3067,7 +3078,7 @@ function parseCliGitAuthRecord(value) {
3067
3078
  }
3068
3079
  function writeCliAuthState(state) {
3069
3080
  ensureStateDir();
3070
- fs3.writeFileSync(stateFilePath(), JSON.stringify(state, null, 2) + "\n", "utf8");
3081
+ writePrivateFileSync(stateFilePath(), JSON.stringify(state, null, 2) + "\n");
3071
3082
  }
3072
3083
  function hasStoredCliAuth() {
3073
3084
  const state = readCliAuthState();
@@ -3181,18 +3192,18 @@ function stripOrgContextFromDevVars(content) {
3181
3192
  }
3182
3193
  function clearLocalOrgContext(projectPath) {
3183
3194
  const statePath = getBootstrapStatePath(projectPath);
3184
- const stateCleared = fs3.existsSync(statePath);
3195
+ const stateCleared = fs4.existsSync(statePath);
3185
3196
  clearBootstrapState(projectPath);
3186
3197
  const devVarsPath = path7.join(projectPath, DEV_VARS_FILENAME2);
3187
- if (!fs3.existsSync(devVarsPath)) {
3198
+ if (!fs4.existsSync(devVarsPath)) {
3188
3199
  return { stateCleared, envCleared: false };
3189
3200
  }
3190
- const content = fs3.readFileSync(devVarsPath, "utf-8");
3201
+ const content = fs4.readFileSync(devVarsPath, "utf-8");
3191
3202
  const stripped = stripOrgContextFromDevVars(content);
3192
3203
  if (!stripped.removed) {
3193
3204
  return { stateCleared, envCleared: false };
3194
3205
  }
3195
- fs3.writeFileSync(devVarsPath, stripped.updated, "utf-8");
3206
+ fs4.writeFileSync(devVarsPath, stripped.updated, "utf-8");
3196
3207
  return { stateCleared, envCleared: true };
3197
3208
  }
3198
3209
  function logLocalClearResult(result) {
@@ -3246,7 +3257,7 @@ function getReactPackageVersion() {
3246
3257
  try {
3247
3258
  const __dirname = path7.dirname(fileURLToPath(import.meta.url));
3248
3259
  const pkgPath = path7.resolve(__dirname, "../package.json");
3249
- const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
3260
+ const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
3250
3261
  const version = pkg.version;
3251
3262
  const prereleaseMatch = version.match(/-([a-z]+)\./i);
3252
3263
  if (prereleaseMatch) {
@@ -3300,10 +3311,10 @@ function detectPackageManager2() {
3300
3311
  if (userAgent.includes("yarn")) return "yarn";
3301
3312
  if (userAgent.includes("bun")) return "bun";
3302
3313
  }
3303
- if (fs3.existsSync("pnpm-lock.yaml")) return "pnpm";
3304
- if (fs3.existsSync("yarn.lock")) return "yarn";
3305
- if (fs3.existsSync("bun.lockb")) return "bun";
3306
- if (fs3.existsSync("package-lock.json")) return "npm";
3314
+ if (fs4.existsSync("pnpm-lock.yaml")) return "pnpm";
3315
+ if (fs4.existsSync("yarn.lock")) return "yarn";
3316
+ if (fs4.existsSync("bun.lockb")) return "bun";
3317
+ if (fs4.existsSync("package-lock.json")) return "npm";
3307
3318
  return "npm";
3308
3319
  }
3309
3320
  async function selectPackageManager2(detected) {
@@ -3513,10 +3524,10 @@ async function detectAgentbuilderInstance() {
3513
3524
  return null;
3514
3525
  }
3515
3526
  function copyDir(src, dest, skip = []) {
3516
- if (!fs3.existsSync(dest)) {
3517
- fs3.mkdirSync(dest, { recursive: true });
3527
+ if (!fs4.existsSync(dest)) {
3528
+ fs4.mkdirSync(dest, { recursive: true });
3518
3529
  }
3519
- const entries = fs3.readdirSync(src, { withFileTypes: true });
3530
+ const entries = fs4.readdirSync(src, { withFileTypes: true });
3520
3531
  for (const entry of entries) {
3521
3532
  if (skip.includes(entry.name)) continue;
3522
3533
  const srcPath = path7.join(src, entry.name);
@@ -3524,14 +3535,14 @@ function copyDir(src, dest, skip = []) {
3524
3535
  if (entry.isDirectory()) {
3525
3536
  copyDir(srcPath, destPath, skip);
3526
3537
  } else {
3527
- fs3.copyFileSync(srcPath, destPath);
3538
+ fs4.copyFileSync(srcPath, destPath);
3528
3539
  }
3529
3540
  }
3530
3541
  }
3531
3542
  async function initChat(projectNameArg, options = {}) {
3532
3543
  const cwd = process.cwd();
3533
3544
  const chatSourceDir = getChatSourceDir();
3534
- if (!fs3.existsSync(chatSourceDir)) {
3545
+ if (!fs4.existsSync(chatSourceDir)) {
3535
3546
  logger.error("Chat source files not found. This CLI installation may be corrupted.");
3536
3547
  process.exit(1);
3537
3548
  }
@@ -3547,7 +3558,7 @@ async function initChat(projectNameArg, options = {}) {
3547
3558
  process.exit(1);
3548
3559
  }
3549
3560
  const projectPath = path7.join(cwd, projectName);
3550
- if (fs3.existsSync(projectPath)) {
3561
+ if (fs4.existsSync(projectPath)) {
3551
3562
  logger.error(`Directory "${projectName}" already exists`);
3552
3563
  process.exit(1);
3553
3564
  }
@@ -3590,7 +3601,7 @@ async function initChat(projectNameArg, options = {}) {
3590
3601
  logger.log("");
3591
3602
  logger.info(`Creating ${framework === "vite" ? "Vite" : "Next.js"} project...`);
3592
3603
  logger.log("");
3593
- fs3.mkdirSync(projectPath, { recursive: true });
3604
+ fs4.mkdirSync(projectPath, { recursive: true });
3594
3605
  const reactVersion = getReactPackageVersion();
3595
3606
  if (framework === "vite") {
3596
3607
  await scaffoldVite(projectPath, chatSourceDir, projectName, serverUrl, reactVersion);
@@ -3644,13 +3655,13 @@ async function scaffoldVite(projectPath, chatSourceDir, projectName, serverUrl,
3644
3655
  copyDir(path7.join(chatSourceDir, "src"), path7.join(projectPath, "src"), []);
3645
3656
  logger.success("Copied src/");
3646
3657
  const viteDir = path7.join(chatSourceDir, "vite");
3647
- let indexHtml = fs3.readFileSync(path7.join(viteDir, "index.html"), "utf-8");
3658
+ let indexHtml = fs4.readFileSync(path7.join(viteDir, "index.html"), "utf-8");
3648
3659
  indexHtml = indexHtml.replace('src="/main.tsx"', 'src="/src/main.tsx"');
3649
- fs3.writeFileSync(path7.join(projectPath, "index.html"), indexHtml, "utf-8");
3660
+ fs4.writeFileSync(path7.join(projectPath, "index.html"), indexHtml, "utf-8");
3650
3661
  logger.success("Created index.html");
3651
- fs3.copyFileSync(path7.join(viteDir, "main.tsx"), path7.join(projectPath, "src", "main.tsx"));
3662
+ fs4.copyFileSync(path7.join(viteDir, "main.tsx"), path7.join(projectPath, "src", "main.tsx"));
3652
3663
  logger.success("Created src/main.tsx");
3653
- let viteConfig = fs3.readFileSync(path7.join(viteDir, "vite.config.ts"), "utf-8");
3664
+ let viteConfig = fs4.readFileSync(path7.join(viteDir, "vite.config.ts"), "utf-8");
3654
3665
  viteConfig = `import { defineConfig } from 'vite'
3655
3666
  import react from '@vitejs/plugin-react'
3656
3667
  import tailwindcss from '@tailwindcss/vite'
@@ -3662,16 +3673,16 @@ export default defineConfig({
3662
3673
  ],
3663
3674
  })
3664
3675
  `;
3665
- fs3.writeFileSync(path7.join(projectPath, "vite.config.ts"), viteConfig, "utf-8");
3676
+ fs4.writeFileSync(path7.join(projectPath, "vite.config.ts"), viteConfig, "utf-8");
3666
3677
  logger.success("Created vite.config.ts");
3667
- fs3.copyFileSync(path7.join(chatSourceDir, "tsconfig.json"), path7.join(projectPath, "tsconfig.json"));
3668
- const tsconfig = JSON.parse(fs3.readFileSync(path7.join(projectPath, "tsconfig.json"), "utf-8"));
3678
+ fs4.copyFileSync(path7.join(chatSourceDir, "tsconfig.json"), path7.join(projectPath, "tsconfig.json"));
3679
+ const tsconfig = JSON.parse(fs4.readFileSync(path7.join(projectPath, "tsconfig.json"), "utf-8"));
3669
3680
  tsconfig.include = ["src"];
3670
3681
  delete tsconfig.compilerOptions?.paths;
3671
- fs3.writeFileSync(path7.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3682
+ fs4.writeFileSync(path7.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3672
3683
  logger.success("Created tsconfig.json");
3673
- fs3.copyFileSync(path7.join(chatSourceDir, "package.json"), path7.join(projectPath, "package.json"));
3674
- const pkg = JSON.parse(fs3.readFileSync(path7.join(projectPath, "package.json"), "utf-8"));
3684
+ fs4.copyFileSync(path7.join(chatSourceDir, "package.json"), path7.join(projectPath, "package.json"));
3685
+ const pkg = JSON.parse(fs4.readFileSync(path7.join(projectPath, "package.json"), "utf-8"));
3675
3686
  pkg.name = projectName;
3676
3687
  pkg.scripts = {
3677
3688
  dev: "vite",
@@ -3685,23 +3696,23 @@ export default defineConfig({
3685
3696
  delete pkg.dependencies?.["next"];
3686
3697
  delete pkg.devDependencies?.["@tailwindcss/postcss"];
3687
3698
  delete pkg.devDependencies?.["postcss"];
3688
- fs3.writeFileSync(path7.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3699
+ fs4.writeFileSync(path7.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3689
3700
  logger.success("Created package.json");
3690
3701
  const envContent = `# Agentbuilder connection
3691
3702
  VITE_AGENTBUILDER_URL=${serverUrl}
3692
3703
  `;
3693
- fs3.writeFileSync(path7.join(projectPath, ".env"), envContent, "utf-8");
3704
+ fs4.writeFileSync(path7.join(projectPath, ".env"), envContent, "utf-8");
3694
3705
  logger.success("Created .env");
3695
- fs3.writeFileSync(path7.join(projectPath, ".gitignore"), `node_modules
3706
+ fs4.writeFileSync(path7.join(projectPath, ".gitignore"), `node_modules
3696
3707
  dist
3697
3708
  .env
3698
3709
  `, "utf-8");
3699
3710
  logger.success("Created .gitignore");
3700
- let mainTsx = fs3.readFileSync(path7.join(projectPath, "src", "main.tsx"), "utf-8");
3711
+ let mainTsx = fs4.readFileSync(path7.join(projectPath, "src", "main.tsx"), "utf-8");
3701
3712
  mainTsx = mainTsx.replace(/from '\.\.\/src\//g, "from './").replace(/import '\.\.\/src\//g, "import './");
3702
- fs3.writeFileSync(path7.join(projectPath, "src", "main.tsx"), mainTsx, "utf-8");
3703
- if (fs3.existsSync(path7.join(viteDir, "favicon.svg"))) {
3704
- fs3.copyFileSync(path7.join(viteDir, "favicon.svg"), path7.join(projectPath, "favicon.svg"));
3713
+ fs4.writeFileSync(path7.join(projectPath, "src", "main.tsx"), mainTsx, "utf-8");
3714
+ if (fs4.existsSync(path7.join(viteDir, "favicon.svg"))) {
3715
+ fs4.copyFileSync(path7.join(viteDir, "favicon.svg"), path7.join(projectPath, "favicon.svg"));
3705
3716
  logger.success("Created favicon.svg");
3706
3717
  }
3707
3718
  }
@@ -3711,9 +3722,9 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
3711
3722
  const nextDir = path7.join(chatSourceDir, "next");
3712
3723
  copyDir(path7.join(nextDir, "app"), path7.join(projectPath, "app"), []);
3713
3724
  logger.success("Copied app/");
3714
- fs3.copyFileSync(path7.join(nextDir, "next.config.ts"), path7.join(projectPath, "next.config.ts"));
3725
+ fs4.copyFileSync(path7.join(nextDir, "next.config.ts"), path7.join(projectPath, "next.config.ts"));
3715
3726
  logger.success("Created next.config.ts");
3716
- fs3.copyFileSync(path7.join(nextDir, "postcss.config.mjs"), path7.join(projectPath, "postcss.config.mjs"));
3727
+ fs4.copyFileSync(path7.join(nextDir, "postcss.config.mjs"), path7.join(projectPath, "postcss.config.mjs"));
3717
3728
  logger.success("Created postcss.config.mjs");
3718
3729
  const tsconfig = {
3719
3730
  compilerOptions: {
@@ -3738,9 +3749,9 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
3738
3749
  include: ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
3739
3750
  exclude: ["node_modules"]
3740
3751
  };
3741
- fs3.writeFileSync(path7.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3752
+ fs4.writeFileSync(path7.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3742
3753
  logger.success("Created tsconfig.json");
3743
- const pkg = JSON.parse(fs3.readFileSync(path7.join(chatSourceDir, "package.json"), "utf-8"));
3754
+ const pkg = JSON.parse(fs4.readFileSync(path7.join(chatSourceDir, "package.json"), "utf-8"));
3744
3755
  pkg.name = projectName;
3745
3756
  pkg.scripts = {
3746
3757
  dev: "next dev",
@@ -3754,25 +3765,25 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
3754
3765
  delete pkg.devDependencies?.["@tailwindcss/vite"];
3755
3766
  delete pkg.devDependencies?.["@vitejs/plugin-react"];
3756
3767
  delete pkg.devDependencies?.["vite"];
3757
- fs3.writeFileSync(path7.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3768
+ fs4.writeFileSync(path7.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3758
3769
  logger.success("Created package.json");
3759
3770
  const envContent = `# Agentbuilder connection
3760
3771
  NEXT_PUBLIC_AGENTBUILDER_URL=${serverUrl}
3761
3772
  `;
3762
- fs3.writeFileSync(path7.join(projectPath, ".env.local"), envContent, "utf-8");
3773
+ fs4.writeFileSync(path7.join(projectPath, ".env.local"), envContent, "utf-8");
3763
3774
  logger.success("Created .env.local");
3764
- fs3.writeFileSync(path7.join(projectPath, ".gitignore"), `node_modules
3775
+ fs4.writeFileSync(path7.join(projectPath, ".gitignore"), `node_modules
3765
3776
  .next
3766
3777
  out
3767
3778
  .env.local
3768
3779
  `, "utf-8");
3769
3780
  logger.success("Created .gitignore");
3770
- let layoutTsx = fs3.readFileSync(path7.join(projectPath, "app", "layout.tsx"), "utf-8");
3781
+ let layoutTsx = fs4.readFileSync(path7.join(projectPath, "app", "layout.tsx"), "utf-8");
3771
3782
  layoutTsx = layoutTsx.replace(/from '\.\.\/\.\.\/src\//g, "from '../src/");
3772
- fs3.writeFileSync(path7.join(projectPath, "app", "layout.tsx"), layoutTsx, "utf-8");
3773
- let pageTsx = fs3.readFileSync(path7.join(projectPath, "app", "page.tsx"), "utf-8");
3783
+ fs4.writeFileSync(path7.join(projectPath, "app", "layout.tsx"), layoutTsx, "utf-8");
3784
+ let pageTsx = fs4.readFileSync(path7.join(projectPath, "app", "page.tsx"), "utf-8");
3774
3785
  pageTsx = pageTsx.replace(/from '\.\.\/\.\.\/src\//g, "from '../src/");
3775
- fs3.writeFileSync(path7.join(projectPath, "app", "page.tsx"), pageTsx, "utf-8");
3786
+ fs4.writeFileSync(path7.join(projectPath, "app", "page.tsx"), pageTsx, "utf-8");
3776
3787
  }
3777
3788
  async function selectAgent(agents) {
3778
3789
  return new Promise((resolve) => {
@@ -3894,11 +3905,11 @@ async function selectItemModes(items, _agentName) {
3894
3905
  });
3895
3906
  }
3896
3907
  function isStandardAgentsProject() {
3897
- if (!fs3.existsSync("agents")) {
3908
+ if (!fs4.existsSync("agents")) {
3898
3909
  return false;
3899
3910
  }
3900
3911
  try {
3901
- const pkgJson = JSON.parse(fs3.readFileSync("package.json", "utf-8"));
3912
+ const pkgJson = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
3902
3913
  const deps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
3903
3914
  return "@standardagents/builder" in deps;
3904
3915
  } catch {
@@ -4072,11 +4083,11 @@ async function pack(agentName, options) {
4072
4083
  }
4073
4084
  }
4074
4085
  function isStandardAgentsProject2() {
4075
- if (!fs3.existsSync("agents")) {
4086
+ if (!fs4.existsSync("agents")) {
4076
4087
  return false;
4077
4088
  }
4078
4089
  try {
4079
- const pkgJson = JSON.parse(fs3.readFileSync("package.json", "utf-8"));
4090
+ const pkgJson = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
4080
4091
  const deps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
4081
4092
  return "@standardagents/builder" in deps;
4082
4093
  } catch {
@@ -4265,8 +4276,8 @@ var PROJECT_SIGNAL_PATHS = [
4265
4276
  "vite.config.mjs"
4266
4277
  ];
4267
4278
  function hasProjectSignals(cwd) {
4268
- const hits = PROJECT_SIGNAL_PATHS.filter((signal) => fs3.existsSync(path7.join(cwd, signal))).length;
4269
- return hits >= 2 || fs3.existsSync(path7.join(cwd, ".agents"));
4279
+ const hits = PROJECT_SIGNAL_PATHS.filter((signal) => fs4.existsSync(path7.join(cwd, signal))).length;
4280
+ return hits >= 2 || fs4.existsSync(path7.join(cwd, ".agents"));
4270
4281
  }
4271
4282
  function detectCliDirectoryContext(cwd = process.cwd()) {
4272
4283
  if (!hasProjectSignals(cwd)) {
@@ -4462,14 +4473,14 @@ function buildInstallTargets(options = {}, env = process.env, homeDir = os3.home
4462
4473
  id: "codex",
4463
4474
  label: "Codex",
4464
4475
  summary: "Install as a Codex skill folder",
4465
- detected: fs3.existsSync(codexHome),
4476
+ detected: fs4.existsSync(codexHome),
4466
4477
  installPath: customRoot ?? path7.join(codexHome, "skills")
4467
4478
  },
4468
4479
  {
4469
4480
  id: "claude",
4470
4481
  label: "Claude Code",
4471
4482
  summary: "Install as a Claude Code user subagent",
4472
- detected: fs3.existsSync(claudeHome),
4483
+ detected: fs4.existsSync(claudeHome),
4473
4484
  installPath: customRoot ?? path7.join(claudeHome, "agents")
4474
4485
  }
4475
4486
  ];
@@ -4559,7 +4570,7 @@ async function installBundledSkill(targetId, skillName = DEFAULT_SKILL_NAME, opt
4559
4570
  const target = resolveSelectedTarget(targetId, options);
4560
4571
  if (target.id === "codex") {
4561
4572
  const targetDir = path7.join(target.installPath, skillName);
4562
- if (fs3.existsSync(targetDir) && !options.force) {
4573
+ if (fs4.existsSync(targetDir) && !options.force) {
4563
4574
  throw new Error(
4564
4575
  `Skill already exists at ${targetDir}. Re-run with --force to overwrite it.`
4565
4576
  );
@@ -4569,7 +4580,7 @@ async function installBundledSkill(targetId, skillName = DEFAULT_SKILL_NAME, opt
4569
4580
  });
4570
4581
  }
4571
4582
  const targetFile = path7.join(target.installPath, `${skillName}.md`);
4572
- if (fs3.existsSync(targetFile) && !options.force) {
4583
+ if (fs4.existsSync(targetFile) && !options.force) {
4573
4584
  throw new Error(
4574
4585
  `Claude subagent already exists at ${targetFile}. Re-run with --force to overwrite it.`
4575
4586
  );
@@ -4580,8 +4591,8 @@ async function installBundledSkill(targetId, skillName = DEFAULT_SKILL_NAME, opt
4580
4591
  "Use for Standard Agents and AgentBuilder architecture, composition, subagent design, and implementation work.",
4581
4592
  skillBody
4582
4593
  );
4583
- fs3.mkdirSync(target.installPath, { recursive: true });
4584
- fs3.writeFileSync(targetFile, subagentMarkdown, "utf8");
4594
+ fs4.mkdirSync(target.installPath, { recursive: true });
4595
+ fs4.writeFileSync(targetFile, subagentMarkdown, "utf8");
4585
4596
  return targetFile;
4586
4597
  }
4587
4598
  function isInteractiveTerminal() {
@@ -4724,7 +4735,7 @@ function parseEnvFile(content) {
4724
4735
  function findProjectRoot(startDir = process.cwd()) {
4725
4736
  let currentDir = path7.resolve(startDir);
4726
4737
  while (true) {
4727
- if (fs3.existsSync(path7.join(currentDir, "package.json"))) {
4738
+ if (fs4.existsSync(path7.join(currentDir, "package.json"))) {
4728
4739
  return currentDir;
4729
4740
  }
4730
4741
  const parentDir = path7.dirname(currentDir);
@@ -4736,10 +4747,10 @@ function findProjectRoot(startDir = process.cwd()) {
4736
4747
  }
4737
4748
  function readProjectPackageJson(projectRoot) {
4738
4749
  const packagePath = path7.join(projectRoot, "package.json");
4739
- if (!fs3.existsSync(packagePath)) {
4750
+ if (!fs4.existsSync(packagePath)) {
4740
4751
  return {};
4741
4752
  }
4742
- return JSON.parse(fs3.readFileSync(packagePath, "utf8"));
4753
+ return JSON.parse(fs4.readFileSync(packagePath, "utf8"));
4743
4754
  }
4744
4755
  function getDeclaredProviderPackages(projectRoot) {
4745
4756
  const pkg = readProjectPackageJson(projectRoot);
@@ -4758,7 +4769,7 @@ function resolvePackageEntry(packageName, projectRoot) {
4758
4769
  }
4759
4770
  const packageJsonPath = path7.join(packageDir, "package.json");
4760
4771
  try {
4761
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf8"));
4772
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf8"));
4762
4773
  const exportPath = resolvePackageExportPath(packageJson.exports) || packageJson.main || "index.js";
4763
4774
  return path7.join(packageDir, exportPath);
4764
4775
  } catch {
@@ -4769,7 +4780,7 @@ function findInstalledPackageDir(packageName, projectRoot) {
4769
4780
  let currentDir = path7.resolve(projectRoot);
4770
4781
  while (true) {
4771
4782
  const candidate = path7.join(currentDir, "node_modules", ...packageName.split("/"));
4772
- if (fs3.existsSync(candidate)) {
4783
+ if (fs4.existsSync(candidate)) {
4773
4784
  return candidate;
4774
4785
  }
4775
4786
  const parentDir = path7.dirname(currentDir);
@@ -4805,8 +4816,8 @@ function loadProjectEnv(projectRoot, processEnv = process.env) {
4805
4816
  const envFiles = [".env", ".env.local", ".dev.vars", ".dev.vars.local"];
4806
4817
  for (const fileName of envFiles) {
4807
4818
  const filePath = path7.join(projectRoot, fileName);
4808
- if (!fs3.existsSync(filePath)) continue;
4809
- Object.assign(result, parseEnvFile(fs3.readFileSync(filePath, "utf8")));
4819
+ if (!fs4.existsSync(filePath)) continue;
4820
+ Object.assign(result, parseEnvFile(fs4.readFileSync(filePath, "utf8")));
4810
4821
  }
4811
4822
  for (const [key, value] of Object.entries(processEnv)) {
4812
4823
  if (typeof value === "string") {
@@ -5072,7 +5083,7 @@ function findDotDevVars(startDir = process.cwd()) {
5072
5083
  let current = path7.resolve(startDir);
5073
5084
  while (true) {
5074
5085
  const candidate = path7.join(current, ".dev.vars");
5075
- if (fs3.existsSync(candidate)) return candidate;
5086
+ if (fs4.existsSync(candidate)) return candidate;
5076
5087
  const parent = path7.dirname(current);
5077
5088
  if (parent === current) return null;
5078
5089
  current = parent;
@@ -5090,7 +5101,7 @@ function isStandardAgentsGitHost(host) {
5090
5101
  }
5091
5102
  function loadLocalConfig(options) {
5092
5103
  const envPath = findDotDevVars(options.startDir);
5093
- const fileVars = envPath ? parseKeyValueLines(fs3.readFileSync(envPath, "utf-8")) : {};
5104
+ const fileVars = envPath ? parseKeyValueLines(fs4.readFileSync(envPath, "utf-8")) : {};
5094
5105
  const endpoint = normalizeEndpoint(
5095
5106
  options.endpoint || process.env.STANDARD_AGENTS_API_URL || process.env.PLATFORM_ENDPOINT || fileVars.STANDARD_AGENTS_API_URL || fileVars.PLATFORM_ENDPOINT || ""
5096
5107
  );
@@ -5379,10 +5390,15 @@ function resolveDiagConfig(options, env = process.env, fetchImpl) {
5379
5390
  async function apiGet(config, path14) {
5380
5391
  return apiRequest(config, path14, "GET");
5381
5392
  }
5382
- async function apiRequest(config, path14, method) {
5393
+ async function apiRequest(config, path14, method, body) {
5383
5394
  const headers = { Accept: "application/json" };
5384
5395
  if (config.token) headers.Authorization = `Bearer ${config.token}`;
5385
- const response = await config.fetchImpl(`${config.endpoint}${path14}`, { method, headers });
5396
+ if (body !== void 0) headers["Content-Type"] = "application/json";
5397
+ const response = await config.fetchImpl(`${config.endpoint}${path14}`, {
5398
+ method,
5399
+ headers,
5400
+ body: body === void 0 ? void 0 : JSON.stringify(body)
5401
+ });
5386
5402
  const text = await response.text();
5387
5403
  if (!response.ok) {
5388
5404
  let detail = text.slice(0, 300);
@@ -5465,6 +5481,20 @@ function resolveThreadIdFromList(threads, idOrPrefix) {
5465
5481
  `Ambiguous thread prefix "${idOrPrefix}" \u2014 matches: ${matches.map((t) => t.id.slice(0, 8)).join(", ")}`
5466
5482
  );
5467
5483
  }
5484
+ async function mintDiagWebSocketUrl(config, pathname) {
5485
+ const wsBase = config.endpoint.replace(/^http/, "ws");
5486
+ if (!config.token) return `${wsBase}${pathname}`;
5487
+ const payload = await apiRequest(
5488
+ config,
5489
+ "/api/auth/websocket-ticket",
5490
+ "POST",
5491
+ { pathname }
5492
+ );
5493
+ if (typeof payload.ticket !== "string" || !payload.ticket) {
5494
+ throw new Error("POST /api/auth/websocket-ticket returned no ticket");
5495
+ }
5496
+ return `${wsBase}${pathname}?ticket=${encodeURIComponent(payload.ticket)}`;
5497
+ }
5468
5498
  async function resolveThreadId(config, idOrPrefix) {
5469
5499
  if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(idOrPrefix)) {
5470
5500
  return idOrPrefix;
@@ -5661,7 +5691,8 @@ async function diagRevive(idOrPrefix, options, fetchImpl) {
5661
5691
  async function diagTail(idOrPrefix, options, fetchImpl) {
5662
5692
  const config = resolveDiagConfig(options, process.env, fetchImpl ?? fetch);
5663
5693
  const threadId = await resolveThreadId(config, idOrPrefix);
5664
- const wsUrl = config.endpoint.replace(/^http/, "ws") + `/api/threads/${threadId}/logs` + (config.token ? `?token=${encodeURIComponent(config.token)}` : "");
5694
+ const pathname = `/api/threads/${threadId}/logs`;
5695
+ const wsUrl = await mintDiagWebSocketUrl(config, pathname);
5665
5696
  const WebSocketCtor = globalThis.WebSocket;
5666
5697
  if (!WebSocketCtor) {
5667
5698
  throw new Error("WebSocket is not available in this Node runtime (need Node 22+)");
@@ -5747,7 +5778,7 @@ async function settleStdinForInitHandoff(stdin = process.stdin) {
5747
5778
  }
5748
5779
  }
5749
5780
  var program = new Command();
5750
- program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version("0.38.0");
5781
+ program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version("0.38.2");
5751
5782
  program.command("init [project-name]").description("Create a new Standard Agents project").option("-y, --yes", "Skip prompts and use defaults").option("--local", "Use local project scaffolding instead of browser platform onboarding").option("--cli", "Use classic line-by-line CLI prompts instead of the TUI wizard").option("--api-url <url>", "Standard Agents platform API URL").option("--endpoint <url>", "Platform API endpoint for auth/bootstrap exchange").option("--package-manager <manager>", "Package manager for generated project: npm, pnpm, yarn, or bun").option("--template <template>", "Vite template to use", "vanilla-ts").option("--workspace", "Install @standardagents packages as workspace:* (local pnpm workspace development)").option("--no-dev", "Clone and configure the project without starting the dev server").addOption(new Option("--bootstrap <code>", "Exchange a web onboarding bootstrap code")).action(init);
5752
5783
  program.command("login").description("Authenticate this machine (or use --bootstrap for project bootstrap auth)").option("--bootstrap <code>", "Bootstrap code from web onboarding").option("--endpoint <url>", "Platform API endpoint (default: https://api.standardagents.ai)").option("--no-open", "Do not auto-open browser URL").action(login);
5753
5784
  program.command("logout").description("Clear stored StandardAgents auth and local org-scoped project auth").option("--org <org-id-or-slug>", "Org ID or slug to logout (defaults to active org)").option("--endpoint <url>", "Platform API endpoint (default: https://api.standardagents.ai)").action(logout);