@standardagents/cli 0.45.6 → 0.45.8
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/README.md +40 -2
- package/dist/index.js +641 -503
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, Option, CommanderError } from 'commander';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import path19 from 'path';
|
|
4
|
+
import fs14 from 'fs';
|
|
5
|
+
import { applyEdits, modify, parse as parse$1 } from 'jsonc-parser';
|
|
6
|
+
import { LOCKSTEP_FRAMEWORK_PACKAGES, STANDARD_AGENTS_NPM_SCOPE, FIRST_PARTY_PROVIDER_PACKAGES, AGENT_DOCS, BUILD_GUARD_SCRIPT, renderPnpmWorkspaceYaml, renderAgentBuilderSupportFiles, STANDARD_AGENTS_NPM_REGISTRY, ROOT_AGENTS_MD_UNLINKED, renderAgentSkill } from '@standardagents/agentbuilder-template';
|
|
5
7
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
8
|
import crypto2, { createHash } from 'crypto';
|
|
7
9
|
import childProcess, { spawn, spawnSync, execFileSync } from 'child_process';
|
|
8
10
|
import os5 from 'os';
|
|
9
11
|
import net from 'net';
|
|
10
|
-
import { STANDARD_AGENTS_NPM_SCOPE, FIRST_PARTY_PROVIDER_PACKAGES, AGENT_DOCS, BUILD_GUARD_SCRIPT, renderPnpmWorkspaceYaml, renderAgentBuilderSupportFiles, STANDARD_AGENTS_NPM_REGISTRY, ROOT_AGENTS_MD_UNLINKED } from '@standardagents/agentbuilder-template';
|
|
11
12
|
import chalk from 'chalk';
|
|
12
13
|
import { parse, parseDocument, visit, isScalar, isNode, isMap } from 'yaml';
|
|
13
|
-
import { parse as parse$1, applyEdits, modify } from 'jsonc-parser';
|
|
14
14
|
import { loadFile, writeFile, generateCode, builders } from 'magicast';
|
|
15
15
|
import { addVitePlugin, getDefaultExportOptions } from 'magicast/helpers';
|
|
16
16
|
import { useState, useMemo } from 'react';
|
|
@@ -20,47 +20,276 @@ import readline from 'readline';
|
|
|
20
20
|
import { createRequire } from 'module';
|
|
21
21
|
import { copySkill } from '@standardagents/skill';
|
|
22
22
|
|
|
23
|
+
// src/utils/platform-endpoint.ts
|
|
24
|
+
var DEFAULT_PLATFORM_ENDPOINT = "https://api.standardagents.ai";
|
|
25
|
+
var PLATFORM_ENDPOINT_ENV_KEYS = [
|
|
26
|
+
"STANDARD_AGENTS_API_URL",
|
|
27
|
+
"PLATFORM_ENDPOINT",
|
|
28
|
+
"STANDARD_AGENTS_PLATFORM_URL"
|
|
29
|
+
];
|
|
30
|
+
function normalizePlatformEndpoint(value) {
|
|
31
|
+
return value.trim().replace(/\/+$/, "");
|
|
32
|
+
}
|
|
33
|
+
var PlatformEndpointError = class extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "PlatformEndpointError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function displayEndpoint(value) {
|
|
40
|
+
const trimmed = value.trim();
|
|
41
|
+
try {
|
|
42
|
+
const url = new URL(trimmed);
|
|
43
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
44
|
+
url.username = "";
|
|
45
|
+
url.password = "";
|
|
46
|
+
url.search = "";
|
|
47
|
+
url.hash = "";
|
|
48
|
+
return url.toString().replace(/\/+$/, "");
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
return trimmed.replace(/^[^@/\s]*@/, "").replace(/[?#].*$/, "");
|
|
53
|
+
}
|
|
54
|
+
function isLoopbackHost(hostname) {
|
|
55
|
+
const host = hostname.toLowerCase();
|
|
56
|
+
return host === "localhost" || host.endsWith(".localhost") || host === "[::1]" || /^127(\.\d{1,3}){3}$/.test(host);
|
|
57
|
+
}
|
|
58
|
+
function platformEndpointProblem(value, noun = "platform endpoint") {
|
|
59
|
+
const shown = displayEndpoint(value);
|
|
60
|
+
let url;
|
|
61
|
+
try {
|
|
62
|
+
url = new URL(value.trim());
|
|
63
|
+
} catch {
|
|
64
|
+
return `The ${noun} "${shown}" is not a URL.
|
|
65
|
+
Use an https:// URL, for example ${DEFAULT_PLATFORM_ENDPOINT}`;
|
|
66
|
+
}
|
|
67
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
68
|
+
return `The ${noun} ${shown} is not an HTTPS URL.
|
|
69
|
+
Use an https:// URL, for example ${DEFAULT_PLATFORM_ENDPOINT}`;
|
|
70
|
+
}
|
|
71
|
+
if (url.username || url.password) {
|
|
72
|
+
return `The ${noun} ${shown} must not contain a user name or password.
|
|
73
|
+
Use ${shown}`;
|
|
74
|
+
}
|
|
75
|
+
if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
|
|
76
|
+
return `The ${noun} ${shown} is not HTTPS. The CLI sends a credential only to an HTTPS endpoint, or to plain HTTP on this machine (localhost, 127.0.0.1, [::1]).
|
|
77
|
+
Use ${shown.replace(/^http:/i, "https:")}`;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function assertSafePlatformEndpoint(endpoint) {
|
|
82
|
+
const problem = platformEndpointProblem(endpoint);
|
|
83
|
+
if (problem) throw new PlatformEndpointError(problem);
|
|
84
|
+
return endpoint;
|
|
85
|
+
}
|
|
86
|
+
function platformEndpointFrom(source) {
|
|
87
|
+
for (const key of PLATFORM_ENDPOINT_ENV_KEYS) {
|
|
88
|
+
const value = normalizePlatformEndpoint(source[key] ?? "");
|
|
89
|
+
if (value) return value;
|
|
90
|
+
}
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
function configuredPlatformEndpoint(flag, ...fallbackSources) {
|
|
94
|
+
const explicit = normalizePlatformEndpoint(flag ?? "");
|
|
95
|
+
if (explicit) return assertSafePlatformEndpoint(explicit);
|
|
96
|
+
for (const source of [process.env, ...fallbackSources]) {
|
|
97
|
+
const value = platformEndpointFrom(source);
|
|
98
|
+
if (value) return assertSafePlatformEndpoint(value);
|
|
99
|
+
}
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
function resolvePlatformEndpoint(flag) {
|
|
103
|
+
return configuredPlatformEndpoint(flag) ?? DEFAULT_PLATFORM_ENDPOINT;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/utils/platform-request.ts
|
|
107
|
+
var REQUEST_TIMEOUT_MS = 3e4;
|
|
108
|
+
function requestHost(url) {
|
|
109
|
+
try {
|
|
110
|
+
return new URL(url).host;
|
|
111
|
+
} catch {
|
|
112
|
+
return "the server";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
var RequestTimeoutError = class extends Error {
|
|
116
|
+
constructor(host, timeoutMs, next) {
|
|
117
|
+
super(`${host} did not answer within ${Math.round(timeoutMs / 1e3)} seconds.
|
|
118
|
+
${next}`);
|
|
119
|
+
this.host = host;
|
|
120
|
+
this.timeoutMs = timeoutMs;
|
|
121
|
+
this.name = "RequestTimeoutError";
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var RedirectRefusedError = class extends Error {
|
|
125
|
+
constructor(host, status2, next) {
|
|
126
|
+
super(
|
|
127
|
+
`${host} answered with a redirect (HTTP ${status2}). The CLI does not follow a redirect with your sign-in.
|
|
128
|
+
${next}`
|
|
129
|
+
);
|
|
130
|
+
this.host = host;
|
|
131
|
+
this.status = status2;
|
|
132
|
+
this.name = "RedirectRefusedError";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var BODILESS_STATUSES = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
136
|
+
async function fetchWithDeadline(url, init2 = {}, options) {
|
|
137
|
+
const timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
138
|
+
const deadlineController = new AbortController();
|
|
139
|
+
const timer = setTimeout(() => deadlineController.abort(), timeoutMs);
|
|
140
|
+
const deadline = deadlineController.signal;
|
|
141
|
+
const signal = init2.signal ? AbortSignal.any([init2.signal, deadline]) : deadline;
|
|
142
|
+
try {
|
|
143
|
+
const response = await (options.fetchImpl ?? fetch)(url, { ...init2, signal });
|
|
144
|
+
if (!(response instanceof Response)) return response;
|
|
145
|
+
const body = await response.arrayBuffer();
|
|
146
|
+
return new Response(BODILESS_STATUSES.has(response.status) ? null : body, {
|
|
147
|
+
status: response.status,
|
|
148
|
+
statusText: response.statusText,
|
|
149
|
+
headers: response.headers
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (deadline.aborted && !init2.signal?.aborted) {
|
|
153
|
+
throw new RequestTimeoutError(requestHost(url), timeoutMs, options.next);
|
|
154
|
+
}
|
|
155
|
+
throw error;
|
|
156
|
+
} finally {
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function credentialFetch(url, init2, options) {
|
|
161
|
+
const response = await fetchWithDeadline(url, { redirect: "manual", ...init2 }, options);
|
|
162
|
+
if (response.status >= 300 && response.status < 400) {
|
|
163
|
+
throw new RedirectRefusedError(requestHost(url), response.status, options.next);
|
|
164
|
+
}
|
|
165
|
+
return response;
|
|
166
|
+
}
|
|
167
|
+
async function platformFetch(endpoint, pathname, init2, options) {
|
|
168
|
+
assertSafePlatformEndpoint(endpoint);
|
|
169
|
+
return credentialFetch(`${endpoint}${pathname}`, init2, options);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/utils/framework-versions.ts
|
|
173
|
+
var PUBLIC_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
174
|
+
var SCOPE_REGISTRY_ENV = "npm_config_@standardagents:registry";
|
|
175
|
+
var BUILDER_PACKUMENT_PATH = "/@standardagents%2Fbuilder";
|
|
176
|
+
var LATEST_LOOKUP_TIMEOUT_MS = 1e4;
|
|
177
|
+
var EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
178
|
+
var DEPENDENCY_SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
179
|
+
var FRAMEWORK_PACKAGES = new Set(LOCKSTEP_FRAMEWORK_PACKAGES);
|
|
180
|
+
function isExactVersion(specifier) {
|
|
181
|
+
return EXACT_VERSION.test(specifier);
|
|
182
|
+
}
|
|
183
|
+
function isPrereleaseVersion(specifier) {
|
|
184
|
+
return isExactVersion(specifier) && specifier.includes("-");
|
|
185
|
+
}
|
|
186
|
+
function frameworkRegistry(env = process.env) {
|
|
187
|
+
const key = Object.keys(env).find((name) => name.toLowerCase() === SCOPE_REGISTRY_ENV);
|
|
188
|
+
const override = key ? env[key]?.trim() : void 0;
|
|
189
|
+
if (override && /^https?:\/\//i.test(override)) return override.replace(/\/+$/, "");
|
|
190
|
+
return PUBLIC_NPM_REGISTRY;
|
|
191
|
+
}
|
|
192
|
+
function hasLatestTag(value) {
|
|
193
|
+
if (typeof value !== "object" || value === null || !("dist-tags" in value)) return false;
|
|
194
|
+
const tags = value["dist-tags"];
|
|
195
|
+
return typeof tags === "object" && tags !== null && "latest" in tags;
|
|
196
|
+
}
|
|
197
|
+
async function resolveLatestFrameworkVersion(options = {}) {
|
|
198
|
+
const url = `${frameworkRegistry(options.env)}${BUILDER_PACKUMENT_PATH}`;
|
|
199
|
+
const host = requestHost(url);
|
|
200
|
+
try {
|
|
201
|
+
const response = await fetchWithDeadline(
|
|
202
|
+
url,
|
|
203
|
+
{ headers: { Accept: "application/vnd.npm.install-v1+json, application/json" } },
|
|
204
|
+
{
|
|
205
|
+
fetchImpl: options.fetchImpl,
|
|
206
|
+
timeoutMs: options.timeoutMs ?? LATEST_LOOKUP_TIMEOUT_MS,
|
|
207
|
+
next: "Check your network connection."
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
if (!response.ok) return { version: null, reason: `${host} answered HTTP ${response.status}.` };
|
|
211
|
+
const body = await response.json();
|
|
212
|
+
const latest = hasLatestTag(body) ? body["dist-tags"].latest : void 0;
|
|
213
|
+
if (typeof latest !== "string" || !isExactVersion(latest)) {
|
|
214
|
+
return { version: null, reason: `${host} did not name a latest release.` };
|
|
215
|
+
}
|
|
216
|
+
return { version: latest };
|
|
217
|
+
} catch (error) {
|
|
218
|
+
const detail = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
219
|
+
return { version: null, reason: detail.includes(host) ? detail : `${host} could not be reached (${detail}).` };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function isRegistrySpecifier(specifier) {
|
|
223
|
+
return typeof specifier === "string" && !specifier.includes(":") && !specifier.includes("/");
|
|
224
|
+
}
|
|
225
|
+
function pinFrameworkDependencies(projectPath, version) {
|
|
226
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
227
|
+
const original = fs14.readFileSync(packageJsonPath, "utf-8");
|
|
228
|
+
const manifest = JSON.parse(original);
|
|
229
|
+
if (typeof manifest !== "object" || manifest === null) return [];
|
|
230
|
+
let text2 = original;
|
|
231
|
+
const pinned = [];
|
|
232
|
+
for (const section of DEPENDENCY_SECTIONS) {
|
|
233
|
+
const dependencies = section in manifest ? Reflect.get(manifest, section) : void 0;
|
|
234
|
+
if (typeof dependencies !== "object" || dependencies === null) continue;
|
|
235
|
+
for (const [name, specifier] of Object.entries(dependencies)) {
|
|
236
|
+
if (!FRAMEWORK_PACKAGES.has(name) || !isRegistrySpecifier(specifier)) continue;
|
|
237
|
+
pinned.push(name);
|
|
238
|
+
if (specifier === version) continue;
|
|
239
|
+
text2 = applyEdits(text2, modify(text2, [section, name], version, {
|
|
240
|
+
formattingOptions: { insertSpaces: true, tabSize: 2 }
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (text2 !== original) fs14.writeFileSync(packageJsonPath, text2, "utf-8");
|
|
245
|
+
return pinned;
|
|
246
|
+
}
|
|
247
|
+
function freshInstallOptions(packageManager) {
|
|
248
|
+
if (packageManager === "pnpm") return { args: ["--no-frozen-lockfile"], env: {} };
|
|
249
|
+
if (packageManager === "yarn") return { args: [], env: { YARN_ENABLE_IMMUTABLE_INSTALLS: "false" } };
|
|
250
|
+
return { args: [], env: {} };
|
|
251
|
+
}
|
|
23
252
|
function findPnpmWorkspaceRoot(startDir) {
|
|
24
253
|
let currentDir = startDir;
|
|
25
254
|
while (true) {
|
|
26
|
-
if (
|
|
255
|
+
if (fs14.existsSync(path19.join(currentDir, "pnpm-workspace.yaml"))) {
|
|
27
256
|
return currentDir;
|
|
28
257
|
}
|
|
29
|
-
const parentDir =
|
|
258
|
+
const parentDir = path19.dirname(currentDir);
|
|
30
259
|
if (parentDir === currentDir) {
|
|
31
260
|
return null;
|
|
32
261
|
}
|
|
33
262
|
currentDir = parentDir;
|
|
34
263
|
}
|
|
35
264
|
}
|
|
36
|
-
function findStandardAgentsWorkspaceRoot(startDir =
|
|
265
|
+
function findStandardAgentsWorkspaceRoot(startDir = path19.dirname(fileURLToPath(import.meta.url))) {
|
|
37
266
|
let currentDir = startDir;
|
|
38
267
|
for (; ; ) {
|
|
39
268
|
const workspaceRoot = findPnpmWorkspaceRoot(currentDir);
|
|
40
269
|
if (!workspaceRoot) return null;
|
|
41
|
-
const manifestPath =
|
|
270
|
+
const manifestPath = path19.join(workspaceRoot, "package.json");
|
|
42
271
|
try {
|
|
43
|
-
const manifest = JSON.parse(
|
|
272
|
+
const manifest = JSON.parse(fs14.readFileSync(manifestPath, "utf8"));
|
|
44
273
|
if (manifest && typeof manifest === "object" && "name" in manifest && manifest.name === "standardagents") {
|
|
45
274
|
return workspaceRoot;
|
|
46
275
|
}
|
|
47
276
|
} catch {
|
|
48
277
|
}
|
|
49
|
-
const parent =
|
|
278
|
+
const parent = path19.dirname(workspaceRoot);
|
|
50
279
|
if (parent === workspaceRoot) return null;
|
|
51
280
|
currentDir = parent;
|
|
52
281
|
}
|
|
53
282
|
}
|
|
54
283
|
function resolveStandardAgentsWorkspaceRoot(startDirs = [
|
|
55
|
-
|
|
284
|
+
path19.dirname(fileURLToPath(import.meta.url)),
|
|
56
285
|
process.cwd()
|
|
57
286
|
]) {
|
|
58
287
|
const explicitRoot = process.env.STANDARDAGENTS_WORKSPACE_ROOT?.trim();
|
|
59
288
|
if (explicitRoot) {
|
|
60
|
-
const workspaceRoot = findStandardAgentsWorkspaceRoot(
|
|
289
|
+
const workspaceRoot = findStandardAgentsWorkspaceRoot(path19.resolve(explicitRoot));
|
|
61
290
|
if (workspaceRoot) return workspaceRoot;
|
|
62
291
|
throw new Error(
|
|
63
|
-
`STANDARDAGENTS_WORKSPACE_ROOT=${
|
|
292
|
+
`STANDARDAGENTS_WORKSPACE_ROOT=${path19.resolve(explicitRoot)} is not a Standard Agents workspace root`
|
|
64
293
|
);
|
|
65
294
|
}
|
|
66
295
|
for (const startDir of startDirs) {
|
|
@@ -70,14 +299,14 @@ function resolveStandardAgentsWorkspaceRoot(startDirs = [
|
|
|
70
299
|
return null;
|
|
71
300
|
}
|
|
72
301
|
function workspacePackageDir(workspaceRoot, packageName) {
|
|
73
|
-
return
|
|
302
|
+
return path19.join(workspaceRoot, "packages", packageName.replace("@standardagents/", ""));
|
|
74
303
|
}
|
|
75
304
|
function validateWorkspacePackageDir(packageName, packageDir) {
|
|
76
|
-
const dependencyPackageJsonPath =
|
|
77
|
-
if (!
|
|
305
|
+
const dependencyPackageJsonPath = path19.join(packageDir, "package.json");
|
|
306
|
+
if (!fs14.existsSync(dependencyPackageJsonPath)) {
|
|
78
307
|
throw new Error(`Could not find workspace package for ${packageName} at ${packageDir}`);
|
|
79
308
|
}
|
|
80
|
-
const manifest = JSON.parse(
|
|
309
|
+
const manifest = JSON.parse(fs14.readFileSync(dependencyPackageJsonPath, "utf8"));
|
|
81
310
|
const name = manifest && typeof manifest === "object" && "name" in manifest ? manifest.name : void 0;
|
|
82
311
|
if (name !== packageName) {
|
|
83
312
|
throw new Error(`Expected ${packageDir} to contain ${packageName}, found ${String(name ?? "unknown package")}`);
|
|
@@ -150,8 +379,8 @@ function ignoredByGit(projectPath) {
|
|
|
150
379
|
return new Set(result.lines);
|
|
151
380
|
}
|
|
152
381
|
function coveredByGitignoreText(projectPath) {
|
|
153
|
-
const gitignorePath =
|
|
154
|
-
const lines =
|
|
382
|
+
const gitignorePath = path19.join(projectPath, ".gitignore");
|
|
383
|
+
const lines = fs14.existsSync(gitignorePath) ? fs14.readFileSync(gitignorePath, "utf8").split(/\r?\n/) : [];
|
|
155
384
|
const lastNegation = lines.map((line) => line.startsWith("!")).lastIndexOf(true);
|
|
156
385
|
const finalRules = new Set(lines.slice(lastNegation + 1));
|
|
157
386
|
return new Set(
|
|
@@ -159,7 +388,7 @@ function coveredByGitignoreText(projectPath) {
|
|
|
159
388
|
);
|
|
160
389
|
}
|
|
161
390
|
function isSymbolicLink(filePath) {
|
|
162
|
-
return
|
|
391
|
+
return fs14.lstatSync(filePath, { throwIfNoEntry: false })?.isSymbolicLink() ?? false;
|
|
163
392
|
}
|
|
164
393
|
function notIgnoredError(paths, reason) {
|
|
165
394
|
return new Error([
|
|
@@ -168,10 +397,10 @@ function notIgnoredError(paths, reason) {
|
|
|
168
397
|
].join("\n"));
|
|
169
398
|
}
|
|
170
399
|
function appendGitignoreEntries(projectPath, entries) {
|
|
171
|
-
const gitignorePath =
|
|
172
|
-
const existing =
|
|
400
|
+
const gitignorePath = path19.join(projectPath, ".gitignore");
|
|
401
|
+
const existing = fs14.existsSync(gitignorePath) ? fs14.readFileSync(gitignorePath, "utf8") : "";
|
|
173
402
|
const separator = existing.length === 0 ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
174
|
-
|
|
403
|
+
fs14.appendFileSync(gitignorePath, `${separator}${GITIGNORE_HEADING}
|
|
175
404
|
${entries.join("\n")}
|
|
176
405
|
`);
|
|
177
406
|
}
|
|
@@ -189,7 +418,7 @@ function protectProjectCredentialFiles(projectPath) {
|
|
|
189
418
|
].join("\n"));
|
|
190
419
|
}
|
|
191
420
|
}
|
|
192
|
-
const linkedGitignore = isSymbolicLink(
|
|
421
|
+
const linkedGitignore = isSymbolicLink(path19.join(projectPath, ".gitignore"));
|
|
193
422
|
const covered = insideGit ? ignoredByGit(projectPath) : linkedGitignore ? /* @__PURE__ */ new Set() : coveredByGitignoreText(projectPath);
|
|
194
423
|
const missing = CREDENTIAL_FILES.filter((file) => !covered.has(file.path));
|
|
195
424
|
if (missing.length === 0) return { ignored: [] };
|
|
@@ -214,12 +443,12 @@ function protectProjectCredentialFiles(projectPath) {
|
|
|
214
443
|
return { ignored: entries };
|
|
215
444
|
}
|
|
216
445
|
function writePrivateFileSync(filePath, content) {
|
|
217
|
-
const descriptor =
|
|
446
|
+
const descriptor = fs14.openSync(filePath, "w", 384);
|
|
218
447
|
try {
|
|
219
|
-
|
|
220
|
-
|
|
448
|
+
fs14.fchmodSync(descriptor, 384);
|
|
449
|
+
fs14.writeFileSync(descriptor, content, "utf8");
|
|
221
450
|
} finally {
|
|
222
|
-
|
|
451
|
+
fs14.closeSync(descriptor);
|
|
223
452
|
}
|
|
224
453
|
}
|
|
225
454
|
|
|
@@ -304,12 +533,12 @@ function collapseBlankLines(content) {
|
|
|
304
533
|
return (result + outside(content.slice(cursor))).replace(/^\n+/, "");
|
|
305
534
|
}
|
|
306
535
|
function readDevVarsFile(projectPath) {
|
|
307
|
-
const filePath =
|
|
308
|
-
return
|
|
536
|
+
const filePath = path19.join(projectPath, DEV_VARS_FILENAME);
|
|
537
|
+
return fs14.existsSync(filePath) ? fs14.readFileSync(filePath, "utf-8") : "";
|
|
309
538
|
}
|
|
310
539
|
function writeDevVarsFile(projectPath, content, options = {}) {
|
|
311
540
|
if (!options.removesCredentials) protectProjectCredentialFiles(projectPath);
|
|
312
|
-
const filePath =
|
|
541
|
+
const filePath = path19.join(projectPath, DEV_VARS_FILENAME);
|
|
313
542
|
writePrivateFileSync(filePath, content === "" || content.endsWith("\n") ? content : `${content}
|
|
314
543
|
`);
|
|
315
544
|
return filePath;
|
|
@@ -505,7 +734,7 @@ function isPackageManager(name) {
|
|
|
505
734
|
}
|
|
506
735
|
function declaredPackageManager(projectPath) {
|
|
507
736
|
try {
|
|
508
|
-
const manifest = JSON.parse(
|
|
737
|
+
const manifest = JSON.parse(fs14.readFileSync(path19.join(projectPath, "package.json"), "utf-8"));
|
|
509
738
|
if (!manifest || typeof manifest !== "object" || !("packageManager" in manifest)) return null;
|
|
510
739
|
const declared = /^([a-z]+)@(\d+)/.exec(String(manifest.packageManager));
|
|
511
740
|
return declared && isPackageManager(declared[1]) ? { name: declared[1], major: Number(declared[2]) } : null;
|
|
@@ -525,12 +754,12 @@ function globToRegExp(glob) {
|
|
|
525
754
|
return new RegExp(`^${pattern}$`);
|
|
526
755
|
}
|
|
527
756
|
function isPnpmWorkspaceMember(workspaceRoot, projectPath) {
|
|
528
|
-
const relative =
|
|
757
|
+
const relative = path19.relative(workspaceRoot, projectPath).split(path19.sep).join("/");
|
|
529
758
|
if (relative === "") return true;
|
|
530
759
|
if (relative.startsWith("..")) return false;
|
|
531
760
|
let packages;
|
|
532
761
|
try {
|
|
533
|
-
const workspace = parse(
|
|
762
|
+
const workspace = parse(fs14.readFileSync(path19.join(workspaceRoot, "pnpm-workspace.yaml"), "utf-8"));
|
|
534
763
|
packages = workspace && typeof workspace === "object" && "packages" in workspace ? workspace.packages : void 0;
|
|
535
764
|
} catch {
|
|
536
765
|
return false;
|
|
@@ -546,7 +775,7 @@ function inferProjectPackageManager(projectPath) {
|
|
|
546
775
|
const declared = declaredPackageManager(projectPath);
|
|
547
776
|
if (declared) return declared.name;
|
|
548
777
|
for (const [lockfile, packageManager] of LOCKFILES) {
|
|
549
|
-
if (
|
|
778
|
+
if (fs14.existsSync(path19.join(projectPath, lockfile))) return packageManager;
|
|
550
779
|
}
|
|
551
780
|
const workspaceRoot = findPnpmWorkspaceRoot(projectPath);
|
|
552
781
|
return workspaceRoot && isPnpmWorkspaceMember(workspaceRoot, projectPath) ? "pnpm" : void 0;
|
|
@@ -772,11 +1001,11 @@ function isPrivateRegistry(value) {
|
|
|
772
1001
|
}
|
|
773
1002
|
function yarnrcFiles(projectPath) {
|
|
774
1003
|
const files = [];
|
|
775
|
-
for (let directory =
|
|
776
|
-
files.push(
|
|
777
|
-
if (
|
|
1004
|
+
for (let directory = path19.resolve(projectPath); ; directory = path19.dirname(directory)) {
|
|
1005
|
+
files.push(path19.join(directory, ".yarnrc.yml"));
|
|
1006
|
+
if (path19.dirname(directory) === directory) break;
|
|
778
1007
|
}
|
|
779
|
-
const homeFile =
|
|
1008
|
+
const homeFile = path19.join(os5.homedir(), ".yarnrc.yml");
|
|
780
1009
|
return files.includes(homeFile) ? files : [...files, homeFile];
|
|
781
1010
|
}
|
|
782
1011
|
function yarnCredentialsBoundToScope(projectPath, env = process.env) {
|
|
@@ -784,10 +1013,10 @@ function yarnCredentialsBoundToScope(projectPath, env = process.env) {
|
|
|
784
1013
|
const topLevelSources = AUTH_ENVIRONMENT.filter((name) => isSet(env[name]));
|
|
785
1014
|
let privateDefaultRegistry = isPrivateRegistry(env.YARN_NPM_REGISTRY_SERVER);
|
|
786
1015
|
for (const file of yarnrcFiles(projectPath)) {
|
|
787
|
-
if (!
|
|
1016
|
+
if (!fs14.existsSync(file)) continue;
|
|
788
1017
|
let config;
|
|
789
1018
|
try {
|
|
790
|
-
config = parse(
|
|
1019
|
+
config = parse(fs14.readFileSync(file, "utf-8"), { merge: true });
|
|
791
1020
|
} catch {
|
|
792
1021
|
scopeSources.push(`${file} (unreadable)`);
|
|
793
1022
|
continue;
|
|
@@ -810,14 +1039,14 @@ function refuse(plan, step, required) {
|
|
|
810
1039
|
if (required) plan.blocked = true;
|
|
811
1040
|
}
|
|
812
1041
|
function planNpmrc(npmrcPath, plan) {
|
|
813
|
-
const stat =
|
|
1042
|
+
const stat = fs14.lstatSync(npmrcPath, { throwIfNoEntry: false });
|
|
814
1043
|
if (!stat) {
|
|
815
1044
|
plan.writes.push({ filePath: npmrcPath, text: `${SCOPE_REGISTRY_PIN}
|
|
816
1045
|
` });
|
|
817
1046
|
return;
|
|
818
1047
|
}
|
|
819
1048
|
if (stat.isSymbolicLink()) {
|
|
820
|
-
const target =
|
|
1049
|
+
const target = fs14.existsSync(npmrcPath) ? fs14.readFileSync(npmrcPath, "utf-8") : "";
|
|
821
1050
|
if (!pinScopeRegistryInNpmrc(target).changed) return;
|
|
822
1051
|
if (hasOtherNpmrcSettings(target)) {
|
|
823
1052
|
refuse(plan, `${npmrcPath} is a symbolic link, so it is unchanged. Add this line to a project-owned .npmrc: ${SCOPE_REGISTRY_PIN}`, true);
|
|
@@ -827,17 +1056,17 @@ function planNpmrc(npmrcPath, plan) {
|
|
|
827
1056
|
`, replacesLink: true });
|
|
828
1057
|
return;
|
|
829
1058
|
}
|
|
830
|
-
const pinned = pinScopeRegistryInNpmrc(
|
|
1059
|
+
const pinned = pinScopeRegistryInNpmrc(fs14.readFileSync(npmrcPath, "utf-8"));
|
|
831
1060
|
if (pinned.changed) plan.writes.push({ filePath: npmrcPath, text: pinned.text });
|
|
832
1061
|
}
|
|
833
1062
|
function planYaml(filePath, pin, keyPath, required, plan) {
|
|
834
1063
|
const step = `Set ${keyPath.join(".")} to https://registry.npmjs.org/ in ${filePath}.`;
|
|
835
|
-
const stat =
|
|
1064
|
+
const stat = fs14.lstatSync(filePath, { throwIfNoEntry: false });
|
|
836
1065
|
if (stat?.isSymbolicLink()) {
|
|
837
1066
|
refuse(plan, `${filePath} is a symbolic link, so it is unchanged. ${step}`, required);
|
|
838
1067
|
return;
|
|
839
1068
|
}
|
|
840
|
-
const pinned = pin(stat ?
|
|
1069
|
+
const pinned = pin(stat ? fs14.readFileSync(filePath, "utf-8") : "");
|
|
841
1070
|
if (pinned === null) {
|
|
842
1071
|
refuse(plan, `The CLI cannot edit ${filePath} safely, so it is unchanged. ${step}`, required);
|
|
843
1072
|
return;
|
|
@@ -845,9 +1074,9 @@ function planYaml(filePath, pin, keyPath, required, plan) {
|
|
|
845
1074
|
if (pinned.changed) plan.writes.push({ filePath, text: pinned.text });
|
|
846
1075
|
}
|
|
847
1076
|
function planYarnrc(projectPath, required, plan) {
|
|
848
|
-
const filePath =
|
|
849
|
-
const stat =
|
|
850
|
-
const current = stat && !stat.isSymbolicLink() ?
|
|
1077
|
+
const filePath = path19.join(projectPath, ".yarnrc.yml");
|
|
1078
|
+
const stat = fs14.lstatSync(filePath, { throwIfNoEntry: false });
|
|
1079
|
+
const current = stat && !stat.isSymbolicLink() ? fs14.readFileSync(filePath, "utf-8") : "";
|
|
851
1080
|
const credentials = pinScopeRegistryInYarnrc(current)?.changed ? yarnCredentialsBoundToScope(projectPath) : [];
|
|
852
1081
|
if (credentials.length > 0) {
|
|
853
1082
|
refuse(
|
|
@@ -860,7 +1089,7 @@ function planYarnrc(projectPath, required, plan) {
|
|
|
860
1089
|
planYaml(filePath, pinScopeRegistryInYarnrc, YARNRC_REGISTRY_PATH, required, plan);
|
|
861
1090
|
}
|
|
862
1091
|
function needsYarnrc(projectPath, packageManager, options) {
|
|
863
|
-
if (
|
|
1092
|
+
if (fs14.lstatSync(path19.join(projectPath, ".yarnrc.yml"), { throwIfNoEntry: false })) return true;
|
|
864
1093
|
if (packageManager !== "yarn") return false;
|
|
865
1094
|
const declared = declaredPackageManager(projectPath);
|
|
866
1095
|
if (declared?.name === "yarn") return declared.major >= 2;
|
|
@@ -869,13 +1098,13 @@ function needsYarnrc(projectPath, packageManager, options) {
|
|
|
869
1098
|
}
|
|
870
1099
|
function migrateLockfiles(projectPath, changed) {
|
|
871
1100
|
for (const [name, migrate] of Object.entries(LOCKFILE_MIGRATIONS)) {
|
|
872
|
-
const lockfilePath =
|
|
873
|
-
const stat =
|
|
1101
|
+
const lockfilePath = path19.join(projectPath, name);
|
|
1102
|
+
const stat = fs14.lstatSync(lockfilePath, { throwIfNoEntry: false });
|
|
874
1103
|
if (!stat?.isFile()) continue;
|
|
875
|
-
const text2 =
|
|
1104
|
+
const text2 = fs14.readFileSync(lockfilePath, "utf-8");
|
|
876
1105
|
const migrated = migrate(text2);
|
|
877
1106
|
if (migrated === text2) continue;
|
|
878
|
-
|
|
1107
|
+
fs14.writeFileSync(lockfilePath, migrated, "utf-8");
|
|
879
1108
|
changed.push(lockfilePath);
|
|
880
1109
|
}
|
|
881
1110
|
}
|
|
@@ -883,9 +1112,9 @@ function pinStandardAgentsScopeRegistry(projectPath, options = {}) {
|
|
|
883
1112
|
const packageManager = options.packageManager ?? inferProjectPackageManager(projectPath);
|
|
884
1113
|
const configRoot = registryConfigRoot(projectPath, packageManager, options.isolateFromParent ?? false);
|
|
885
1114
|
const plan = { writes: [], manual: [], blocked: false };
|
|
886
|
-
planNpmrc(
|
|
887
|
-
const workspaceFile =
|
|
888
|
-
if (
|
|
1115
|
+
planNpmrc(path19.join(configRoot, ".npmrc"), plan);
|
|
1116
|
+
const workspaceFile = path19.join(configRoot, "pnpm-workspace.yaml");
|
|
1117
|
+
if (fs14.lstatSync(workspaceFile, { throwIfNoEntry: false })) {
|
|
889
1118
|
planYaml(workspaceFile, pinScopeRegistryInPnpmWorkspace, PNPM_WORKSPACE_REGISTRY_PATH, packageManager === "pnpm", plan);
|
|
890
1119
|
}
|
|
891
1120
|
if (needsYarnrc(projectPath, packageManager, options)) {
|
|
@@ -894,8 +1123,8 @@ function pinStandardAgentsScopeRegistry(projectPath, options = {}) {
|
|
|
894
1123
|
if (plan.blocked) return { changed: [], manual: plan.manual, blocked: true };
|
|
895
1124
|
const changed = [];
|
|
896
1125
|
for (const write of plan.writes) {
|
|
897
|
-
if (write.replacesLink)
|
|
898
|
-
|
|
1126
|
+
if (write.replacesLink) fs14.unlinkSync(write.filePath);
|
|
1127
|
+
fs14.writeFileSync(write.filePath, write.text, "utf-8");
|
|
899
1128
|
changed.push(write.filePath);
|
|
900
1129
|
}
|
|
901
1130
|
migrateLockfiles(projectPath, changed);
|
|
@@ -904,7 +1133,7 @@ function pinStandardAgentsScopeRegistry(projectPath, options = {}) {
|
|
|
904
1133
|
function pinProjectScopeRegistry(projectPath, options, log) {
|
|
905
1134
|
const result = pinStandardAgentsScopeRegistry(projectPath, options);
|
|
906
1135
|
if (result.changed.length > 0) {
|
|
907
|
-
const files = result.changed.map((file) =>
|
|
1136
|
+
const files = result.changed.map((file) => path19.relative(projectPath, file)).join(", ");
|
|
908
1137
|
log.info(`Your project now installs @standardagents packages from npm (updated ${files}).`);
|
|
909
1138
|
}
|
|
910
1139
|
for (const step of result.manual) log.warning(step);
|
|
@@ -923,155 +1152,6 @@ function cliCommand(args = "") {
|
|
|
923
1152
|
}
|
|
924
1153
|
var SIGN_IN_UNREADABLE_MESSAGE = `The Keychain did not return the saved sign-in. It is locked in this session (for example over SSH): unlock it with \`security unlock-keychain\`, or sign in again with: ${cliCommand("login")}`;
|
|
925
1154
|
|
|
926
|
-
// src/utils/platform-endpoint.ts
|
|
927
|
-
var DEFAULT_PLATFORM_ENDPOINT = "https://api.standardagents.ai";
|
|
928
|
-
var PLATFORM_ENDPOINT_ENV_KEYS = [
|
|
929
|
-
"STANDARD_AGENTS_API_URL",
|
|
930
|
-
"PLATFORM_ENDPOINT",
|
|
931
|
-
"STANDARD_AGENTS_PLATFORM_URL"
|
|
932
|
-
];
|
|
933
|
-
function normalizePlatformEndpoint(value) {
|
|
934
|
-
return value.trim().replace(/\/+$/, "");
|
|
935
|
-
}
|
|
936
|
-
var PlatformEndpointError = class extends Error {
|
|
937
|
-
constructor(message) {
|
|
938
|
-
super(message);
|
|
939
|
-
this.name = "PlatformEndpointError";
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
function displayEndpoint(value) {
|
|
943
|
-
const trimmed = value.trim();
|
|
944
|
-
try {
|
|
945
|
-
const url = new URL(trimmed);
|
|
946
|
-
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
947
|
-
url.username = "";
|
|
948
|
-
url.password = "";
|
|
949
|
-
url.search = "";
|
|
950
|
-
url.hash = "";
|
|
951
|
-
return url.toString().replace(/\/+$/, "");
|
|
952
|
-
}
|
|
953
|
-
} catch {
|
|
954
|
-
}
|
|
955
|
-
return trimmed.replace(/^[^@/\s]*@/, "").replace(/[?#].*$/, "");
|
|
956
|
-
}
|
|
957
|
-
function isLoopbackHost(hostname) {
|
|
958
|
-
const host = hostname.toLowerCase();
|
|
959
|
-
return host === "localhost" || host.endsWith(".localhost") || host === "[::1]" || /^127(\.\d{1,3}){3}$/.test(host);
|
|
960
|
-
}
|
|
961
|
-
function platformEndpointProblem(value, noun = "platform endpoint") {
|
|
962
|
-
const shown = displayEndpoint(value);
|
|
963
|
-
let url;
|
|
964
|
-
try {
|
|
965
|
-
url = new URL(value.trim());
|
|
966
|
-
} catch {
|
|
967
|
-
return `The ${noun} "${shown}" is not a URL.
|
|
968
|
-
Use an https:// URL, for example ${DEFAULT_PLATFORM_ENDPOINT}`;
|
|
969
|
-
}
|
|
970
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
971
|
-
return `The ${noun} ${shown} is not an HTTPS URL.
|
|
972
|
-
Use an https:// URL, for example ${DEFAULT_PLATFORM_ENDPOINT}`;
|
|
973
|
-
}
|
|
974
|
-
if (url.username || url.password) {
|
|
975
|
-
return `The ${noun} ${shown} must not contain a user name or password.
|
|
976
|
-
Use ${shown}`;
|
|
977
|
-
}
|
|
978
|
-
if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
|
|
979
|
-
return `The ${noun} ${shown} is not HTTPS. The CLI sends a credential only to an HTTPS endpoint, or to plain HTTP on this machine (localhost, 127.0.0.1, [::1]).
|
|
980
|
-
Use ${shown.replace(/^http:/i, "https:")}`;
|
|
981
|
-
}
|
|
982
|
-
return null;
|
|
983
|
-
}
|
|
984
|
-
function assertSafePlatformEndpoint(endpoint) {
|
|
985
|
-
const problem = platformEndpointProblem(endpoint);
|
|
986
|
-
if (problem) throw new PlatformEndpointError(problem);
|
|
987
|
-
return endpoint;
|
|
988
|
-
}
|
|
989
|
-
function platformEndpointFrom(source) {
|
|
990
|
-
for (const key of PLATFORM_ENDPOINT_ENV_KEYS) {
|
|
991
|
-
const value = normalizePlatformEndpoint(source[key] ?? "");
|
|
992
|
-
if (value) return value;
|
|
993
|
-
}
|
|
994
|
-
return void 0;
|
|
995
|
-
}
|
|
996
|
-
function configuredPlatformEndpoint(flag, ...fallbackSources) {
|
|
997
|
-
const explicit = normalizePlatformEndpoint(flag ?? "");
|
|
998
|
-
if (explicit) return assertSafePlatformEndpoint(explicit);
|
|
999
|
-
for (const source of [process.env, ...fallbackSources]) {
|
|
1000
|
-
const value = platformEndpointFrom(source);
|
|
1001
|
-
if (value) return assertSafePlatformEndpoint(value);
|
|
1002
|
-
}
|
|
1003
|
-
return void 0;
|
|
1004
|
-
}
|
|
1005
|
-
function resolvePlatformEndpoint(flag) {
|
|
1006
|
-
return configuredPlatformEndpoint(flag) ?? DEFAULT_PLATFORM_ENDPOINT;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
// src/utils/platform-request.ts
|
|
1010
|
-
var REQUEST_TIMEOUT_MS = 3e4;
|
|
1011
|
-
function requestHost(url) {
|
|
1012
|
-
try {
|
|
1013
|
-
return new URL(url).host;
|
|
1014
|
-
} catch {
|
|
1015
|
-
return "the server";
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
var RequestTimeoutError = class extends Error {
|
|
1019
|
-
constructor(host, timeoutMs, next) {
|
|
1020
|
-
super(`${host} did not answer within ${Math.round(timeoutMs / 1e3)} seconds.
|
|
1021
|
-
${next}`);
|
|
1022
|
-
this.host = host;
|
|
1023
|
-
this.timeoutMs = timeoutMs;
|
|
1024
|
-
this.name = "RequestTimeoutError";
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
var RedirectRefusedError = class extends Error {
|
|
1028
|
-
constructor(host, status2, next) {
|
|
1029
|
-
super(
|
|
1030
|
-
`${host} answered with a redirect (HTTP ${status2}). The CLI does not follow a redirect with your sign-in.
|
|
1031
|
-
${next}`
|
|
1032
|
-
);
|
|
1033
|
-
this.host = host;
|
|
1034
|
-
this.status = status2;
|
|
1035
|
-
this.name = "RedirectRefusedError";
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
var BODILESS_STATUSES = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
1039
|
-
async function fetchWithDeadline(url, init2 = {}, options) {
|
|
1040
|
-
const timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
1041
|
-
const deadlineController = new AbortController();
|
|
1042
|
-
const timer = setTimeout(() => deadlineController.abort(), timeoutMs);
|
|
1043
|
-
const deadline = deadlineController.signal;
|
|
1044
|
-
const signal = init2.signal ? AbortSignal.any([init2.signal, deadline]) : deadline;
|
|
1045
|
-
try {
|
|
1046
|
-
const response = await (options.fetchImpl ?? fetch)(url, { ...init2, signal });
|
|
1047
|
-
if (!(response instanceof Response)) return response;
|
|
1048
|
-
const body = await response.arrayBuffer();
|
|
1049
|
-
return new Response(BODILESS_STATUSES.has(response.status) ? null : body, {
|
|
1050
|
-
status: response.status,
|
|
1051
|
-
statusText: response.statusText,
|
|
1052
|
-
headers: response.headers
|
|
1053
|
-
});
|
|
1054
|
-
} catch (error) {
|
|
1055
|
-
if (deadline.aborted && !init2.signal?.aborted) {
|
|
1056
|
-
throw new RequestTimeoutError(requestHost(url), timeoutMs, options.next);
|
|
1057
|
-
}
|
|
1058
|
-
throw error;
|
|
1059
|
-
} finally {
|
|
1060
|
-
clearTimeout(timer);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
async function credentialFetch(url, init2, options) {
|
|
1064
|
-
const response = await fetchWithDeadline(url, { redirect: "manual", ...init2 }, options);
|
|
1065
|
-
if (response.status >= 300 && response.status < 400) {
|
|
1066
|
-
throw new RedirectRefusedError(requestHost(url), response.status, options.next);
|
|
1067
|
-
}
|
|
1068
|
-
return response;
|
|
1069
|
-
}
|
|
1070
|
-
async function platformFetch(endpoint, pathname, init2, options) {
|
|
1071
|
-
assertSafePlatformEndpoint(endpoint);
|
|
1072
|
-
return credentialFetch(`${endpoint}${pathname}`, init2, options);
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
1155
|
// src/utils/cli-auth-api.ts
|
|
1076
1156
|
var CliAuthWsTransportError = class extends Error {
|
|
1077
1157
|
};
|
|
@@ -1446,6 +1526,9 @@ function parkUntilExit() {
|
|
|
1446
1526
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1447
1527
|
var CLEAR_LINE = "\r\x1B[2K";
|
|
1448
1528
|
var CANCEL_HINT = "Press Ctrl-C to cancel.";
|
|
1529
|
+
var SHORT_CANCEL_HINT = "Ctrl-C to cancel";
|
|
1530
|
+
var FRAME_MS = 100;
|
|
1531
|
+
var DEFAULT_COLUMNS = 80;
|
|
1449
1532
|
function formatDuration(ms) {
|
|
1450
1533
|
const totalSeconds = Math.max(0, Math.floor(ms / 1e3));
|
|
1451
1534
|
const minutes = Math.floor(totalSeconds / 60);
|
|
@@ -1464,17 +1547,23 @@ function startWaitIndicator(options) {
|
|
|
1464
1547
|
return { note: log, stop: () => {
|
|
1465
1548
|
} };
|
|
1466
1549
|
}
|
|
1550
|
+
const useColor = !process.env.NO_COLOR;
|
|
1551
|
+
const dim = (text2) => useColor ? `\x1B[2m${text2}\x1B[22m` : text2;
|
|
1552
|
+
const accent = (text2) => useColor ? `\x1B[36m${text2}\x1B[39m` : text2;
|
|
1467
1553
|
let frame = 0;
|
|
1468
1554
|
let stopped = false;
|
|
1469
1555
|
const render3 = () => {
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1556
|
+
const width = Math.max(1, (stream.columns || DEFAULT_COLUMNS) - 1);
|
|
1557
|
+
const left = `${formatDuration(options.expiresAt - Date.now())} left`;
|
|
1558
|
+
const tails = [` \xB7 ${left} \xB7 ${SHORT_CANCEL_HINT}`, ` \xB7 ${left}`, ""];
|
|
1559
|
+
const room = width - 2;
|
|
1560
|
+
const label = options.label.length > room ? `${options.label.slice(0, Math.max(0, room - 1)).trimEnd()}\u2026` : options.label;
|
|
1561
|
+
const tail = tails.find((candidate) => label.length + candidate.length <= room) ?? "";
|
|
1562
|
+
stream.write(`${CLEAR_LINE}${accent(SPINNER_FRAMES[frame])} ${label}${dim(tail)}`);
|
|
1474
1563
|
frame = (frame + 1) % SPINNER_FRAMES.length;
|
|
1475
1564
|
};
|
|
1476
1565
|
render3();
|
|
1477
|
-
const timer = setInterval(render3,
|
|
1566
|
+
const timer = setInterval(render3, FRAME_MS);
|
|
1478
1567
|
return {
|
|
1479
1568
|
note(message) {
|
|
1480
1569
|
if (stopped) {
|
|
@@ -1666,13 +1755,13 @@ function getScaffoldStandardAgentsVersion() {
|
|
|
1666
1755
|
if (process.env.STANDARDAGENTS_WORKSPACE === "1") {
|
|
1667
1756
|
return workspacePackageLink("@standardagents/builder");
|
|
1668
1757
|
}
|
|
1669
|
-
return "0.45.
|
|
1758
|
+
return "0.45.8";
|
|
1670
1759
|
}
|
|
1671
1760
|
function findViteConfig(cwd) {
|
|
1672
1761
|
const candidates = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs"];
|
|
1673
1762
|
for (const candidate of candidates) {
|
|
1674
|
-
const configPath =
|
|
1675
|
-
if (
|
|
1763
|
+
const configPath = path19.join(cwd, candidate);
|
|
1764
|
+
if (fs14.existsSync(configPath)) {
|
|
1676
1765
|
return configPath;
|
|
1677
1766
|
}
|
|
1678
1767
|
}
|
|
@@ -1690,27 +1779,27 @@ function setPackageDependency(packageJsonText, section, packageName, version) {
|
|
|
1690
1779
|
return applyEdits(packageJsonText, edits);
|
|
1691
1780
|
}
|
|
1692
1781
|
function updatePackageDependencies(cwd, versions = {}) {
|
|
1693
|
-
const packageJsonPath =
|
|
1694
|
-
if (!
|
|
1782
|
+
const packageJsonPath = path19.join(cwd, "package.json");
|
|
1783
|
+
if (!fs14.existsSync(packageJsonPath)) {
|
|
1695
1784
|
return stageResult("package-json", "failed", "No package.json found. Create one (for example with `npm init -y`).");
|
|
1696
1785
|
}
|
|
1697
1786
|
let text2;
|
|
1698
1787
|
let pkg;
|
|
1699
1788
|
try {
|
|
1700
|
-
text2 =
|
|
1789
|
+
text2 = fs14.readFileSync(packageJsonPath, "utf-8");
|
|
1701
1790
|
pkg = JSON.parse(text2);
|
|
1702
1791
|
} catch (error) {
|
|
1703
1792
|
return stageResult("package-json", "failed", `package.json is not valid JSON, so it is unchanged: ${error instanceof Error ? error.message : error}`);
|
|
1704
1793
|
}
|
|
1705
1794
|
const desiredBuilderVersion = versions.standardAgents ?? getScaffoldStandardAgentsVersion();
|
|
1706
1795
|
const builderSection = dependencySectionFor(pkg, "@standardagents/builder", "dependencies");
|
|
1707
|
-
if (pkg[builderSection]?.["@standardagents/builder"]
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
const result = setPackageDependency(text2, builderSection, "@standardagents/builder", desiredBuilderVersion);
|
|
1711
|
-
fs13.writeFileSync(packageJsonPath, `${result.trimEnd()}
|
|
1796
|
+
if (pkg[builderSection]?.["@standardagents/builder"] !== desiredBuilderVersion) {
|
|
1797
|
+
const result = setPackageDependency(text2, builderSection, "@standardagents/builder", desiredBuilderVersion);
|
|
1798
|
+
fs14.writeFileSync(packageJsonPath, `${result.trimEnd()}
|
|
1712
1799
|
`, "utf-8");
|
|
1713
|
-
|
|
1800
|
+
}
|
|
1801
|
+
if (isExactVersion(desiredBuilderVersion)) pinFrameworkDependencies(cwd, desiredBuilderVersion);
|
|
1802
|
+
return fs14.readFileSync(packageJsonPath, "utf-8") === text2 ? stageResult("package-json", "ok", "package.json already has current Standard Agents dependencies") : stageResult("package-json", "ok", "Updated package.json with current Standard Agents dependencies");
|
|
1714
1803
|
}
|
|
1715
1804
|
var BUILDER_PACKAGE = "@standardagents/builder";
|
|
1716
1805
|
var BUILDER_PLUGIN_EXPORTS = ["builder", "agentbuilder"];
|
|
@@ -1737,10 +1826,10 @@ async function modifyViteConfig(cwd, force, log) {
|
|
|
1737
1826
|
if (!configPath) {
|
|
1738
1827
|
return stageResult("vite-config", "failed", `No vite.config found. Create vite.config.ts first. ${VITE_CONFIG_MANUAL_EDIT}`);
|
|
1739
1828
|
}
|
|
1740
|
-
const configName =
|
|
1829
|
+
const configName = path19.basename(configPath);
|
|
1741
1830
|
try {
|
|
1742
1831
|
const mod = await loadFile(configPath);
|
|
1743
|
-
const code =
|
|
1832
|
+
const code = fs14.readFileSync(configPath, "utf-8");
|
|
1744
1833
|
const hasAgentBuilder = code.includes("@standardagents/builder") || code.includes("builder()") || code.includes("agentbuilder()");
|
|
1745
1834
|
if (!hasAgentBuilder) {
|
|
1746
1835
|
addVitePlugin(mod, {
|
|
@@ -1789,40 +1878,53 @@ function projectGuides(cwd) {
|
|
|
1789
1878
|
}
|
|
1790
1879
|
function outdatedGuides(cwd) {
|
|
1791
1880
|
return projectGuides(cwd).filter((doc) => {
|
|
1792
|
-
const filePath =
|
|
1793
|
-
return
|
|
1881
|
+
const filePath = path19.join(cwd, guidePath(doc.directory));
|
|
1882
|
+
return fs14.existsSync(filePath) && fs14.readFileSync(filePath, "utf-8") !== doc.content;
|
|
1794
1883
|
}).map((doc) => guidePath(doc.directory));
|
|
1795
1884
|
}
|
|
1796
1885
|
function writeGuides(cwd, replace, log) {
|
|
1797
1886
|
for (const doc of projectGuides(cwd)) {
|
|
1798
|
-
const dirPath =
|
|
1799
|
-
if (!
|
|
1800
|
-
|
|
1887
|
+
const dirPath = path19.join(cwd, doc.directory);
|
|
1888
|
+
if (!fs14.existsSync(dirPath)) {
|
|
1889
|
+
fs14.mkdirSync(dirPath, { recursive: true });
|
|
1801
1890
|
log.success(`Created ${doc.directory}`);
|
|
1802
1891
|
}
|
|
1803
1892
|
const guide = guidePath(doc.directory);
|
|
1804
|
-
const agentsDocPath =
|
|
1805
|
-
if (!
|
|
1806
|
-
|
|
1893
|
+
const agentsDocPath = path19.join(cwd, guide);
|
|
1894
|
+
if (!fs14.existsSync(agentsDocPath)) {
|
|
1895
|
+
fs14.writeFileSync(agentsDocPath, doc.content, "utf-8");
|
|
1807
1896
|
log.success(`Created ${guide}`);
|
|
1808
1897
|
} else if (replace.has(guide)) {
|
|
1809
|
-
|
|
1898
|
+
fs14.writeFileSync(agentsDocPath, doc.content, "utf-8");
|
|
1810
1899
|
log.success(`Replaced ${guide}`);
|
|
1811
1900
|
}
|
|
1812
|
-
const claudeDocPath =
|
|
1813
|
-
if (!
|
|
1814
|
-
|
|
1901
|
+
const claudeDocPath = path19.join(dirPath, "CLAUDE.md");
|
|
1902
|
+
if (!fs14.lstatSync(claudeDocPath, { throwIfNoEntry: false })) {
|
|
1903
|
+
fs14.symlinkSync("AGENTS.md", claudeDocPath);
|
|
1815
1904
|
log.success(`Created ${guide.replace(/AGENTS\.md$/, "CLAUDE.md")} symlink`);
|
|
1816
1905
|
}
|
|
1817
1906
|
}
|
|
1907
|
+
for (const skillFile of renderAgentSkill()) {
|
|
1908
|
+
const target = path19.join(cwd, skillFile.path);
|
|
1909
|
+
if (fs14.lstatSync(target, { throwIfNoEntry: false })) {
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
fs14.mkdirSync(path19.dirname(target), { recursive: true });
|
|
1913
|
+
if (skillFile.kind === "symlink") {
|
|
1914
|
+
fs14.symlinkSync(skillFile.content, target);
|
|
1915
|
+
} else {
|
|
1916
|
+
fs14.writeFileSync(target, skillFile.content, "utf-8");
|
|
1917
|
+
}
|
|
1918
|
+
log.success(`Created ${skillFile.path}`);
|
|
1919
|
+
}
|
|
1818
1920
|
return stageResult("guides", "ok", "Agent directories and AGENTS.md guides are in place");
|
|
1819
1921
|
}
|
|
1820
1922
|
function updateTsConfig(cwd) {
|
|
1821
|
-
const tsconfigPath =
|
|
1822
|
-
if (!
|
|
1923
|
+
const tsconfigPath = path19.join(cwd, "tsconfig.json");
|
|
1924
|
+
if (!fs14.existsSync(tsconfigPath)) {
|
|
1823
1925
|
return stageResult("tsconfig", "skipped", "No tsconfig.json found, so there is no TypeScript configuration to update");
|
|
1824
1926
|
}
|
|
1825
|
-
const text2 =
|
|
1927
|
+
const text2 = fs14.readFileSync(tsconfigPath, "utf-8");
|
|
1826
1928
|
const config = parse$1(text2);
|
|
1827
1929
|
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
1828
1930
|
return stageResult(
|
|
@@ -1849,7 +1951,7 @@ function updateTsConfig(cwd) {
|
|
|
1849
1951
|
if (newTypes.length === 0 && newIncludes.length === 0) {
|
|
1850
1952
|
return stageResult("tsconfig", "ok", "tsconfig.json already configured");
|
|
1851
1953
|
}
|
|
1852
|
-
|
|
1954
|
+
fs14.writeFileSync(tsconfigPath, result, "utf-8");
|
|
1853
1955
|
return stageResult("tsconfig", "ok", "Updated tsconfig.json with Standard Agents types");
|
|
1854
1956
|
}
|
|
1855
1957
|
function pinScopeRegistry(cwd, options, log) {
|
|
@@ -1883,21 +1985,21 @@ function cleanupViteDefaults(cwd) {
|
|
|
1883
1985
|
];
|
|
1884
1986
|
const dirsToRemove = ["src", "public", "worker"];
|
|
1885
1987
|
for (const file of filesToRemove) {
|
|
1886
|
-
const filePath =
|
|
1887
|
-
if (
|
|
1988
|
+
const filePath = path19.join(cwd, file);
|
|
1989
|
+
if (fs14.existsSync(filePath)) {
|
|
1888
1990
|
try {
|
|
1889
|
-
|
|
1991
|
+
fs14.unlinkSync(filePath);
|
|
1890
1992
|
} catch {
|
|
1891
1993
|
}
|
|
1892
1994
|
}
|
|
1893
1995
|
}
|
|
1894
1996
|
for (const dir of dirsToRemove) {
|
|
1895
|
-
const dirPath =
|
|
1896
|
-
if (
|
|
1997
|
+
const dirPath = path19.join(cwd, dir);
|
|
1998
|
+
if (fs14.existsSync(dirPath)) {
|
|
1897
1999
|
try {
|
|
1898
|
-
const files =
|
|
2000
|
+
const files = fs14.readdirSync(dirPath);
|
|
1899
2001
|
if (files.length === 0) {
|
|
1900
|
-
|
|
2002
|
+
fs14.rmdirSync(dirPath);
|
|
1901
2003
|
}
|
|
1902
2004
|
} catch {
|
|
1903
2005
|
}
|
|
@@ -1976,25 +2078,25 @@ async function scaffoldCommand(options = {}) {
|
|
|
1976
2078
|
const directories = AGENT_DOCS.filter((doc) => doc.directory !== ".");
|
|
1977
2079
|
directories.forEach((doc, index) => {
|
|
1978
2080
|
const branch = index === directories.length - 1 ? "\u2514\u2500\u2500" : "\u251C\u2500\u2500";
|
|
1979
|
-
const name = `${
|
|
2081
|
+
const name = `${path19.basename(doc.directory)}/`;
|
|
1980
2082
|
log.log(` ${branch} ${name.padEnd(20)}# ${doc.label[0].toUpperCase()}${doc.label.slice(1)} definitions`);
|
|
1981
2083
|
});
|
|
1982
2084
|
log.log("");
|
|
1983
2085
|
}
|
|
1984
2086
|
function writeBuildGuardScript(projectPath) {
|
|
1985
|
-
const manifestPath =
|
|
1986
|
-
if (!
|
|
1987
|
-
const manifest = JSON.parse(
|
|
2087
|
+
const manifestPath = path19.join(projectPath, "package.json");
|
|
2088
|
+
if (!fs14.existsSync(manifestPath)) return false;
|
|
2089
|
+
const manifest = JSON.parse(fs14.readFileSync(manifestPath, "utf-8"));
|
|
1988
2090
|
if (manifest.scripts?.build === BUILD_GUARD_SCRIPT) return false;
|
|
1989
2091
|
manifest.scripts = { ...manifest.scripts, build: BUILD_GUARD_SCRIPT };
|
|
1990
|
-
|
|
2092
|
+
fs14.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
1991
2093
|
`, "utf-8");
|
|
1992
2094
|
return true;
|
|
1993
2095
|
}
|
|
1994
2096
|
|
|
1995
2097
|
// src/utils/git-helper-command.ts
|
|
1996
2098
|
function cliVersion() {
|
|
1997
|
-
return "0.45.
|
|
2099
|
+
return "0.45.8";
|
|
1998
2100
|
}
|
|
1999
2101
|
function defaultGitCredentialHelperCommand(version = cliVersion()) {
|
|
2000
2102
|
return `!npx -y @standardagents/cli@${version} git-credential`;
|
|
@@ -2028,7 +2130,7 @@ async function resolveSetupCode(options, readStdin2 = readStandardInput) {
|
|
|
2028
2130
|
if (file) {
|
|
2029
2131
|
source = `The file ${file}`;
|
|
2030
2132
|
try {
|
|
2031
|
-
code =
|
|
2133
|
+
code = fs14.readFileSync(file, "utf8");
|
|
2032
2134
|
} catch (error) {
|
|
2033
2135
|
const reason = error instanceof Error && "code" in error ? String(error.code) : "it could not be read";
|
|
2034
2136
|
throw new Error(`Cannot read the setup code file ${file} (${reason}).`);
|
|
@@ -2068,7 +2170,7 @@ function signalAll(pids, signal) {
|
|
|
2068
2170
|
function readProcfsTable() {
|
|
2069
2171
|
let entries;
|
|
2070
2172
|
try {
|
|
2071
|
-
entries =
|
|
2173
|
+
entries = fs14.readdirSync("/proc");
|
|
2072
2174
|
} catch {
|
|
2073
2175
|
return null;
|
|
2074
2176
|
}
|
|
@@ -2076,7 +2178,7 @@ function readProcfsTable() {
|
|
|
2076
2178
|
for (const entry of entries) {
|
|
2077
2179
|
if (!/^\d+$/.test(entry)) continue;
|
|
2078
2180
|
try {
|
|
2079
|
-
const stat =
|
|
2181
|
+
const stat = fs14.readFileSync(`/proc/${entry}/stat`, "utf8");
|
|
2080
2182
|
const parent = Number.parseInt(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1], 10);
|
|
2081
2183
|
if (Number.isInteger(parent)) parents.set(Number(entry), parent);
|
|
2082
2184
|
} catch {
|
|
@@ -2248,10 +2350,10 @@ function directoryExistsFailure(name) {
|
|
|
2248
2350
|
};
|
|
2249
2351
|
}
|
|
2250
2352
|
function resolveFreeDirectoryName(cwd, name) {
|
|
2251
|
-
if (!
|
|
2353
|
+
if (!fs14.existsSync(path19.join(cwd, name))) return name;
|
|
2252
2354
|
for (let suffix = 2; ; suffix += 1) {
|
|
2253
2355
|
const candidate = `${name}-${suffix}`;
|
|
2254
|
-
if (!
|
|
2356
|
+
if (!fs14.existsSync(path19.join(cwd, candidate))) return candidate;
|
|
2255
2357
|
}
|
|
2256
2358
|
}
|
|
2257
2359
|
function commandFailureCause(label, error) {
|
|
@@ -2832,16 +2934,16 @@ function normalizeProjectName(raw) {
|
|
|
2832
2934
|
return toKebabCase(raw.trim());
|
|
2833
2935
|
}
|
|
2834
2936
|
function isNonEmptyDirectory(targetPath) {
|
|
2835
|
-
if (!
|
|
2836
|
-
const stat =
|
|
2937
|
+
if (!fs14.existsSync(targetPath)) return false;
|
|
2938
|
+
const stat = fs14.statSync(targetPath);
|
|
2837
2939
|
if (!stat.isDirectory()) return false;
|
|
2838
|
-
return
|
|
2940
|
+
return fs14.readdirSync(targetPath).length > 0;
|
|
2839
2941
|
}
|
|
2840
2942
|
function hasBuilderDependency(targetPath) {
|
|
2841
|
-
const packageJsonPath =
|
|
2842
|
-
if (!
|
|
2943
|
+
const packageJsonPath = path19.join(targetPath, "package.json");
|
|
2944
|
+
if (!fs14.existsSync(packageJsonPath)) return false;
|
|
2843
2945
|
try {
|
|
2844
|
-
const pkg = JSON.parse(
|
|
2946
|
+
const pkg = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
2845
2947
|
if (pkg === null || typeof pkg !== "object") return false;
|
|
2846
2948
|
const dependencies = "dependencies" in pkg ? pkg.dependencies : void 0;
|
|
2847
2949
|
const devDependencies = "devDependencies" in pkg ? pkg.devDependencies : void 0;
|
|
@@ -2853,12 +2955,12 @@ function hasBuilderDependency(targetPath) {
|
|
|
2853
2955
|
}
|
|
2854
2956
|
}
|
|
2855
2957
|
function isStandardAgentsProjectDir(targetPath) {
|
|
2856
|
-
const agentsDir =
|
|
2857
|
-
if (!
|
|
2958
|
+
const agentsDir = path19.join(targetPath, "agents");
|
|
2959
|
+
if (!fs14.existsSync(agentsDir) || !fs14.statSync(agentsDir).isDirectory()) {
|
|
2858
2960
|
return false;
|
|
2859
2961
|
}
|
|
2860
2962
|
if (hasBuilderDependency(targetPath)) return true;
|
|
2861
|
-
return
|
|
2963
|
+
return fs14.existsSync(path19.join(targetPath, "vite.config.ts")) && fs14.existsSync(path19.join(targetPath, "tsconfig.json"));
|
|
2862
2964
|
}
|
|
2863
2965
|
function initScaffoldOptions(useExistingProject, standardAgents) {
|
|
2864
2966
|
return { freshProject: !useExistingProject, scopeRegistryPinned: true, standardAgents };
|
|
@@ -2869,7 +2971,7 @@ function resolveProjectTarget(cwd, candidate) {
|
|
|
2869
2971
|
if (!isStandardAgentsProjectDir(cwd)) {
|
|
2870
2972
|
return { ok: false, message: "Project name is required" };
|
|
2871
2973
|
}
|
|
2872
|
-
const dirName =
|
|
2974
|
+
const dirName = path19.basename(cwd) || "standard-agents";
|
|
2873
2975
|
return {
|
|
2874
2976
|
ok: true,
|
|
2875
2977
|
target: {
|
|
@@ -2883,9 +2985,9 @@ function resolveProjectTarget(cwd, candidate) {
|
|
|
2883
2985
|
if (!projectName) {
|
|
2884
2986
|
return { ok: false, message: "Project name must include at least one letter or number" };
|
|
2885
2987
|
}
|
|
2886
|
-
const projectPath =
|
|
2887
|
-
const exists =
|
|
2888
|
-
if (exists && !
|
|
2988
|
+
const projectPath = path19.join(cwd, projectName);
|
|
2989
|
+
const exists = fs14.existsSync(projectPath);
|
|
2990
|
+
if (exists && !fs14.statSync(projectPath).isDirectory()) {
|
|
2889
2991
|
return { ok: false, message: `Path "${projectName}" already exists and is not a directory` };
|
|
2890
2992
|
}
|
|
2891
2993
|
const existingStandardAgentsProject = exists && isStandardAgentsProjectDir(projectPath);
|
|
@@ -2902,7 +3004,7 @@ function resolveProjectTarget(cwd, candidate) {
|
|
|
2902
3004
|
};
|
|
2903
3005
|
}
|
|
2904
3006
|
function detectLockfilePackageManager(projectPath) {
|
|
2905
|
-
const has = (file) =>
|
|
3007
|
+
const has = (file) => fs14.existsSync(path19.join(projectPath, file));
|
|
2906
3008
|
if (has("pnpm-lock.yaml")) return "pnpm";
|
|
2907
3009
|
if (has("yarn.lock")) return "yarn";
|
|
2908
3010
|
if (has("bun.lockb") || has("bun.lock")) return "bun";
|
|
@@ -2982,7 +3084,7 @@ function renderInitStepHeader(stage, title, subtitle, options) {
|
|
|
2982
3084
|
logger.log("");
|
|
2983
3085
|
}
|
|
2984
3086
|
function getCliVersion() {
|
|
2985
|
-
return "0.45.
|
|
3087
|
+
return "0.45.8";
|
|
2986
3088
|
}
|
|
2987
3089
|
function getSipVersion() {
|
|
2988
3090
|
return "1.0.1";
|
|
@@ -3011,8 +3113,8 @@ function resolveStandardAgentsPackageSpecifier(packageName, packageSpecifier) {
|
|
|
3011
3113
|
return packageSpecifier;
|
|
3012
3114
|
}
|
|
3013
3115
|
function rewriteStandardAgentsDependenciesForWorkspace(projectPath, workspaceRoot) {
|
|
3014
|
-
const packageJsonPath =
|
|
3015
|
-
const packageJson = JSON.parse(
|
|
3116
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
3117
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
3016
3118
|
const dependencies = packageJson.dependencies ?? {};
|
|
3017
3119
|
const linkedPackages = [];
|
|
3018
3120
|
for (const packageName of GENERATED_STANDARD_AGENTS_PACKAGES) {
|
|
@@ -3024,7 +3126,7 @@ function rewriteStandardAgentsDependenciesForWorkspace(projectPath, workspaceRoo
|
|
|
3024
3126
|
}
|
|
3025
3127
|
if (linkedPackages.length > 0) {
|
|
3026
3128
|
packageJson.dependencies = dependencies;
|
|
3027
|
-
|
|
3129
|
+
fs14.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
3028
3130
|
`, "utf-8");
|
|
3029
3131
|
}
|
|
3030
3132
|
return linkedPackages;
|
|
@@ -3045,7 +3147,7 @@ function preparePlatformProjectDependencies(projectPath, packageManager, options
|
|
|
3045
3147
|
return linkedPackages;
|
|
3046
3148
|
}
|
|
3047
3149
|
function getPnpmWorkspaceCompatibilityArgs(packageManager, projectPath) {
|
|
3048
|
-
if (packageManager !== "pnpm" || !
|
|
3150
|
+
if (packageManager !== "pnpm" || !fs14.existsSync(path19.join(projectPath, "pnpm-workspace.yaml"))) return [];
|
|
3049
3151
|
try {
|
|
3050
3152
|
childProcess.execFileSync("pnpm", ["config", "get", "registry"], {
|
|
3051
3153
|
cwd: projectPath,
|
|
@@ -3063,33 +3165,55 @@ function getPnpmWorkspaceCompatibilityArgs(packageManager, projectPath) {
|
|
|
3063
3165
|
}
|
|
3064
3166
|
}
|
|
3065
3167
|
function projectInstallArgs(packageManager, projectPath, command = "install", dependencies = [], options = {}) {
|
|
3066
|
-
const hasProjectWorkspace = projectPath !== void 0 &&
|
|
3067
|
-
const inheritsWorkspace = !options.isolateFromParent && projectPath !== void 0 && findPnpmWorkspaceRoot(
|
|
3168
|
+
const hasProjectWorkspace = projectPath !== void 0 && fs14.existsSync(path19.join(projectPath, "pnpm-workspace.yaml"));
|
|
3169
|
+
const inheritsWorkspace = !options.isolateFromParent && projectPath !== void 0 && findPnpmWorkspaceRoot(path19.dirname(projectPath)) !== null;
|
|
3068
3170
|
const prefix = [];
|
|
3069
3171
|
if (packageManager === "pnpm") {
|
|
3070
3172
|
if (options.ignoreProjectWorkspace) prefix.push("--ignore-workspace");
|
|
3071
3173
|
else if (hasProjectWorkspace && command === "add") prefix.push("--workspace-root");
|
|
3072
3174
|
else if (!hasProjectWorkspace && !inheritsWorkspace) prefix.push("--ignore-workspace");
|
|
3073
3175
|
}
|
|
3074
|
-
|
|
3176
|
+
const saveExact = packageManager === "npm" && dependencies.length > 0 ? ["--save-exact"] : [];
|
|
3177
|
+
return [...prefix, command, ...saveExact, ...dependencies];
|
|
3178
|
+
}
|
|
3179
|
+
async function pinLatestFrameworkRelease(projectPath) {
|
|
3180
|
+
const cliVersion2 = getCliVersion();
|
|
3181
|
+
if (isPrereleaseVersion(cliVersion2)) {
|
|
3182
|
+
const pinned2 = pinFrameworkDependencies(projectPath, cliVersion2);
|
|
3183
|
+
if (pinned2.length > 0) {
|
|
3184
|
+
logger.info(`Pinned ${pinned2.length} Standard Agents packages to ${cliVersion2}, the release of this prerelease CLI.`);
|
|
3185
|
+
}
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
const latest = await resolveLatestFrameworkVersion();
|
|
3189
|
+
if (latest.version === null) {
|
|
3190
|
+
logger.warning(
|
|
3191
|
+
`Could not read the latest Standard Agents Builder release: ${latest.reason} Keeping the versions in package.json.`
|
|
3192
|
+
);
|
|
3193
|
+
return;
|
|
3194
|
+
}
|
|
3195
|
+
const pinned = pinFrameworkDependencies(projectPath, latest.version);
|
|
3196
|
+
if (pinned.length > 0) {
|
|
3197
|
+
logger.info(`Pinned ${pinned.length} Standard Agents packages to ${latest.version}, the latest release.`);
|
|
3198
|
+
}
|
|
3075
3199
|
}
|
|
3076
3200
|
function shellQuote(value) {
|
|
3077
3201
|
return `"${value.replace(/(["\\$`])/g, "\\$1")}"`;
|
|
3078
3202
|
}
|
|
3079
3203
|
function findWorkspaceCommandRoot(projectPath) {
|
|
3080
|
-
let current =
|
|
3204
|
+
let current = path19.dirname(projectPath);
|
|
3081
3205
|
while (true) {
|
|
3082
|
-
const packageJsonPath =
|
|
3083
|
-
if (
|
|
3206
|
+
const packageJsonPath = path19.join(current, "package.json");
|
|
3207
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
3084
3208
|
try {
|
|
3085
|
-
const packageJson = JSON.parse(
|
|
3209
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
3086
3210
|
if (packageJson?.scripts && typeof packageJson.scripts["sandbox:hmr"] === "string") {
|
|
3087
3211
|
return current;
|
|
3088
3212
|
}
|
|
3089
3213
|
} catch {
|
|
3090
3214
|
}
|
|
3091
3215
|
}
|
|
3092
|
-
const parent =
|
|
3216
|
+
const parent = path19.dirname(current);
|
|
3093
3217
|
if (parent === current) {
|
|
3094
3218
|
return null;
|
|
3095
3219
|
}
|
|
@@ -3097,47 +3221,47 @@ function findWorkspaceCommandRoot(projectPath) {
|
|
|
3097
3221
|
}
|
|
3098
3222
|
}
|
|
3099
3223
|
function linkWorkspaceProjectToolchain(projectPath, workspaceRoot) {
|
|
3100
|
-
const packageJsonPath =
|
|
3101
|
-
const manifest = JSON.parse(
|
|
3224
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
3225
|
+
const manifest = JSON.parse(fs14.readFileSync(packageJsonPath, "utf8"));
|
|
3102
3226
|
for (const section of [manifest.dependencies, manifest.devDependencies]) {
|
|
3103
3227
|
if (!section) continue;
|
|
3104
3228
|
for (const name of ["vite", "typescript"]) {
|
|
3105
3229
|
if (!(name in section)) continue;
|
|
3106
|
-
const installedPath =
|
|
3107
|
-
if (!
|
|
3230
|
+
const installedPath = path19.join(workspaceRoot, "node_modules", name);
|
|
3231
|
+
if (!fs14.existsSync(path19.join(installedPath, "package.json"))) {
|
|
3108
3232
|
throw new Error(`Install the contributor workspace before linking ${name}`);
|
|
3109
3233
|
}
|
|
3110
3234
|
section[name] = `link:${installedPath}`;
|
|
3111
3235
|
}
|
|
3112
3236
|
}
|
|
3113
|
-
|
|
3237
|
+
fs14.writeFileSync(packageJsonPath, `${JSON.stringify(manifest, null, 2)}
|
|
3114
3238
|
`);
|
|
3115
3239
|
}
|
|
3116
3240
|
function configureWorkspaceProjectScripts(projectPath, projectName) {
|
|
3117
|
-
const packageJsonPath =
|
|
3118
|
-
if (!
|
|
3241
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
3242
|
+
if (!fs14.existsSync(packageJsonPath)) return false;
|
|
3119
3243
|
const workspaceRoot = findWorkspaceCommandRoot(projectPath);
|
|
3120
3244
|
if (!workspaceRoot) return false;
|
|
3121
|
-
const workspacePackageJsonPath =
|
|
3122
|
-
const workspacePackageJson = JSON.parse(
|
|
3123
|
-
const packageJson = JSON.parse(
|
|
3245
|
+
const workspacePackageJsonPath = path19.join(workspaceRoot, "package.json");
|
|
3246
|
+
const workspacePackageJson = JSON.parse(fs14.readFileSync(workspacePackageJsonPath, "utf-8"));
|
|
3247
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
3124
3248
|
const scripts = packageJson.scripts && typeof packageJson.scripts === "object" ? packageJson.scripts : {};
|
|
3125
|
-
const relativeRoot =
|
|
3249
|
+
const relativeRoot = path19.relative(projectPath, workspaceRoot) || ".";
|
|
3126
3250
|
scripts["sandbox:hmr"] = `pnpm -C ${shellQuote(relativeRoot)} sandbox:hmr -- ${shellQuote(projectName)}`;
|
|
3127
3251
|
if (workspacePackageJson?.scripts && typeof workspacePackageJson.scripts["cli:login:workspace"] === "string") {
|
|
3128
3252
|
scripts["cli:login:workspace"] = `pnpm -C ${shellQuote(relativeRoot)} cli:login:workspace -- ${shellQuote(projectName)}`;
|
|
3129
3253
|
}
|
|
3130
3254
|
packageJson.scripts = scripts;
|
|
3131
|
-
|
|
3255
|
+
fs14.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
|
|
3132
3256
|
return true;
|
|
3133
3257
|
}
|
|
3134
3258
|
function resolvePostInitRunCommand(packageManager, projectPath, workspacePackages, pnpmCompatibilityArgs = []) {
|
|
3135
3259
|
const command = packageManager === "pnpm" ? [packageManager, ...pnpmCompatibilityArgs].join(" ") : packageManager;
|
|
3136
3260
|
if (workspacePackages) {
|
|
3137
|
-
const packageJsonPath =
|
|
3138
|
-
if (
|
|
3261
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
3262
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
3139
3263
|
try {
|
|
3140
|
-
const packageJson = JSON.parse(
|
|
3264
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
3141
3265
|
if (packageJson?.scripts && typeof packageJson.scripts["sandbox:hmr"] === "string") {
|
|
3142
3266
|
return packageManager === "npm" ? "npm run sandbox:hmr" : `${command} sandbox:hmr`;
|
|
3143
3267
|
}
|
|
@@ -3285,8 +3409,8 @@ function gitSupportsEnvironmentConfig(versionLine) {
|
|
|
3285
3409
|
return major > 2 || major === 2 && minor >= 31;
|
|
3286
3410
|
}
|
|
3287
3411
|
function platformGitCredentialHelperCommand(cliEntry = process.argv[1] ?? "") {
|
|
3288
|
-
if (process.env.STANDARDAGENTS_WORKSPACE === "1" && cliEntry &&
|
|
3289
|
-
return `!node ${shellQuote(
|
|
3412
|
+
if (process.env.STANDARDAGENTS_WORKSPACE === "1" && cliEntry && fs14.existsSync(cliEntry)) {
|
|
3413
|
+
return `!node ${shellQuote(path19.resolve(cliEntry))} git-credential`;
|
|
3290
3414
|
}
|
|
3291
3415
|
if (process.env.STANDARD_AGENTS_GIT_HELPER?.trim()) {
|
|
3292
3416
|
return process.env.STANDARD_AGENTS_GIT_HELPER.trim();
|
|
@@ -3310,20 +3434,20 @@ function waitForPlatformProject(session, onProgress, signal) {
|
|
|
3310
3434
|
return waitForCliAuthCompletion(session, PLATFORM_PROJECT_READER, { onProgress, signal });
|
|
3311
3435
|
}
|
|
3312
3436
|
function appendGitignoreEntries2(projectPath, heading, entries) {
|
|
3313
|
-
const gitignorePath =
|
|
3314
|
-
const gitignoreContent =
|
|
3437
|
+
const gitignorePath = path19.join(projectPath, ".gitignore");
|
|
3438
|
+
const gitignoreContent = fs14.existsSync(gitignorePath) ? fs14.readFileSync(gitignorePath, "utf-8") : "";
|
|
3315
3439
|
const existingEntries = new Set(gitignoreContent.split(/\r?\n/));
|
|
3316
3440
|
const missingEntries = entries.filter((entry) => !existingEntries.has(entry));
|
|
3317
3441
|
if (missingEntries.length === 0) return;
|
|
3318
3442
|
const prefix = gitignoreContent.length === 0 ? "" : gitignoreContent.endsWith("\n") ? "\n" : "\n\n";
|
|
3319
|
-
|
|
3443
|
+
fs14.appendFileSync(gitignorePath, `${prefix}${heading}
|
|
3320
3444
|
${missingEntries.join("\n")}
|
|
3321
3445
|
`);
|
|
3322
3446
|
}
|
|
3323
3447
|
function writeLocalPnpmBuildPolicy(projectPath, packageManager, options = {}) {
|
|
3324
3448
|
if (packageManager !== "pnpm") return false;
|
|
3325
|
-
const policyPath =
|
|
3326
|
-
if (
|
|
3449
|
+
const policyPath = path19.join(projectPath, "pnpm-workspace.yaml");
|
|
3450
|
+
if (fs14.existsSync(policyPath)) return false;
|
|
3327
3451
|
const buildPolicySettings = [
|
|
3328
3452
|
"onlyBuiltDependencies",
|
|
3329
3453
|
"onlyBuiltDependenciesFile",
|
|
@@ -3334,20 +3458,20 @@ function writeLocalPnpmBuildPolicy(projectPath, packageManager, options = {}) {
|
|
|
3334
3458
|
"ignoreDepScripts",
|
|
3335
3459
|
"ignoreScripts"
|
|
3336
3460
|
];
|
|
3337
|
-
const npmrcPath =
|
|
3338
|
-
if (
|
|
3339
|
-
const hasBuildPolicy =
|
|
3461
|
+
const npmrcPath = path19.join(projectPath, ".npmrc");
|
|
3462
|
+
if (fs14.existsSync(npmrcPath)) {
|
|
3463
|
+
const hasBuildPolicy = fs14.readFileSync(npmrcPath, "utf8").split(/\r?\n/).some((line) => {
|
|
3340
3464
|
const separator = line.indexOf("=");
|
|
3341
3465
|
const name = (separator < 0 ? line : line.slice(0, separator)).trim().replace(/[-_[\]]/g, "").toLowerCase();
|
|
3342
3466
|
return buildPolicySettings.some((setting) => setting.toLowerCase() === name);
|
|
3343
3467
|
});
|
|
3344
3468
|
if (hasBuildPolicy) return false;
|
|
3345
3469
|
}
|
|
3346
|
-
if (!options.isolateFromParent && findPnpmWorkspaceRoot(
|
|
3470
|
+
if (!options.isolateFromParent && findPnpmWorkspaceRoot(path19.dirname(projectPath))) return false;
|
|
3347
3471
|
const ignoredBuildScripts = options.ignoredBuildScripts ?? [];
|
|
3348
3472
|
const approvedBuildScripts = ["esbuild", "workerd"].filter((name) => !ignoredBuildScripts.includes(name));
|
|
3349
|
-
const manifestPath =
|
|
3350
|
-
const manifest = JSON.parse(
|
|
3473
|
+
const manifestPath = path19.join(projectPath, "package.json");
|
|
3474
|
+
const manifest = JSON.parse(fs14.readFileSync(manifestPath, "utf8"));
|
|
3351
3475
|
const existingPnpm = manifest.pnpm ?? {};
|
|
3352
3476
|
if (buildPolicySettings.some((name) => Object.hasOwn(existingPnpm, name))) return false;
|
|
3353
3477
|
manifest.pnpm = {
|
|
@@ -3355,9 +3479,9 @@ function writeLocalPnpmBuildPolicy(projectPath, packageManager, options = {}) {
|
|
|
3355
3479
|
onlyBuiltDependencies: approvedBuildScripts,
|
|
3356
3480
|
...ignoredBuildScripts.length > 0 ? { ignoredBuiltDependencies: ignoredBuildScripts } : {}
|
|
3357
3481
|
};
|
|
3358
|
-
|
|
3482
|
+
fs14.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
3359
3483
|
`);
|
|
3360
|
-
|
|
3484
|
+
fs14.writeFileSync(policyPath, renderPnpmWorkspaceYaml(approvedBuildScripts, ignoredBuildScripts));
|
|
3361
3485
|
return true;
|
|
3362
3486
|
}
|
|
3363
3487
|
function writeStandardAgentsSupportFiles(projectPath, params) {
|
|
@@ -3370,15 +3494,17 @@ function writeStandardAgentsSupportFiles(projectPath, params) {
|
|
|
3370
3494
|
sip: getSipVersion()
|
|
3371
3495
|
}
|
|
3372
3496
|
})) {
|
|
3373
|
-
const targetPath =
|
|
3374
|
-
if (
|
|
3375
|
-
|
|
3376
|
-
|
|
3497
|
+
const targetPath = path19.join(projectPath, supportFile.path);
|
|
3498
|
+
if (fs14.existsSync(targetPath)) continue;
|
|
3499
|
+
fs14.mkdirSync(path19.dirname(targetPath), { recursive: true });
|
|
3500
|
+
fs14.writeFileSync(targetPath, supportFile.content, "utf-8");
|
|
3377
3501
|
written.push(supportFile.path);
|
|
3378
3502
|
}
|
|
3379
3503
|
appendGitignoreEntries2(projectPath, "# Standard Agents local dev state", [
|
|
3380
3504
|
"node_modules",
|
|
3381
|
-
|
|
3505
|
+
// Generated files are ignored; the committed coding-agent skill is kept.
|
|
3506
|
+
".agents/*",
|
|
3507
|
+
"!.agents/skills/",
|
|
3382
3508
|
".wrangler",
|
|
3383
3509
|
"dist",
|
|
3384
3510
|
".agentbuilder-dev.log"
|
|
@@ -3404,7 +3530,7 @@ async function writeSupportFilesStages(options = {}, log = logger) {
|
|
|
3404
3530
|
], resume);
|
|
3405
3531
|
}
|
|
3406
3532
|
const cwd = process.cwd();
|
|
3407
|
-
const projectName = normalizeProjectName(options.projectName ??
|
|
3533
|
+
const projectName = normalizeProjectName(options.projectName ?? path19.basename(cwd)) || "standard-agents";
|
|
3408
3534
|
const stages = [
|
|
3409
3535
|
await runStage("support-files", () => {
|
|
3410
3536
|
const written = writeStandardAgentsSupportFiles(cwd, { projectName, packageManager });
|
|
@@ -3568,7 +3694,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3568
3694
|
process.exit(1);
|
|
3569
3695
|
}
|
|
3570
3696
|
const requestedProjectName = projectNameArg?.trim() || void 0;
|
|
3571
|
-
if (requestedProjectName &&
|
|
3697
|
+
if (requestedProjectName && fs14.existsSync(path19.join(cwd, requestedProjectName))) {
|
|
3572
3698
|
exitWithInitFailure(directoryExistsFailure(requestedProjectName));
|
|
3573
3699
|
}
|
|
3574
3700
|
const endpoint = platformEndpoint(options);
|
|
@@ -3613,7 +3739,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3613
3739
|
exitWithInitFailure({ cause: error instanceof Error ? error.message : String(error), next: [] });
|
|
3614
3740
|
}
|
|
3615
3741
|
const projectName = resolveFreeDirectoryName(cwd, platformName);
|
|
3616
|
-
const projectPath =
|
|
3742
|
+
const projectPath = path19.join(cwd, projectName);
|
|
3617
3743
|
const projectLabel = project.name || projectName;
|
|
3618
3744
|
logger.success("Browser setup complete.");
|
|
3619
3745
|
if (projectName !== platformName) {
|
|
@@ -3621,7 +3747,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3621
3747
|
}
|
|
3622
3748
|
logger.info(`Cloning ${cloneDisplayUrl(project)}...`);
|
|
3623
3749
|
const stopRemoveOnInterrupt = interrupts.onInterrupt(() => {
|
|
3624
|
-
|
|
3750
|
+
fs14.rmSync(projectPath, { recursive: true, force: true });
|
|
3625
3751
|
logger.log("");
|
|
3626
3752
|
logger.info(`Setup interrupted. Removed the partial "${projectName}" directory.`);
|
|
3627
3753
|
for (const line of finishExistingProjectSteps(projectLabel, dashboardUrl)) {
|
|
@@ -3654,7 +3780,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3654
3780
|
apiKey: project.api_key,
|
|
3655
3781
|
platformEndpoint: endpoint
|
|
3656
3782
|
});
|
|
3657
|
-
logger.success(`Wrote Standard Agents credentials to ${
|
|
3783
|
+
logger.success(`Wrote Standard Agents credentials to ${path19.relative(cwd, envPath)}.`);
|
|
3658
3784
|
if (project.git_extra_header) {
|
|
3659
3785
|
await configurePlatformGitCredentialHelper(projectPath);
|
|
3660
3786
|
logger.success("Configured git credentials for the platform repository.");
|
|
@@ -3663,6 +3789,9 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3663
3789
|
if (linkedPackages.length > 0) {
|
|
3664
3790
|
logger.info(`Workspace mode detected: linked ${linkedPackages.length} Standard Agents packages locally.`);
|
|
3665
3791
|
}
|
|
3792
|
+
if (!shouldUseWorkspacePackages(options)) {
|
|
3793
|
+
await pinLatestFrameworkRelease(projectPath);
|
|
3794
|
+
}
|
|
3666
3795
|
} catch (error) {
|
|
3667
3796
|
stopRemoveOnInterrupt();
|
|
3668
3797
|
exitWithInitFailure(configureFailure({
|
|
@@ -3676,10 +3805,14 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3676
3805
|
logger.info(`Installing dependencies with ${projectPackageManager}...`);
|
|
3677
3806
|
const pnpmCompatibilityArgs = getPnpmWorkspaceCompatibilityArgs(projectPackageManager, projectPath);
|
|
3678
3807
|
const devHint = pnpmCompatibilityArgs.length > 0 ? resolvePostInitRunCommand(projectPackageManager, projectPath, false, pnpmCompatibilityArgs) : devCommandHint(projectPackageManager);
|
|
3679
|
-
const
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3808
|
+
const freshInstall = freshInstallOptions(projectPackageManager);
|
|
3809
|
+
const installArgs = [
|
|
3810
|
+
...projectInstallArgs(projectPackageManager, projectPath, "install", [], {
|
|
3811
|
+
isolateFromParent: true,
|
|
3812
|
+
ignoreProjectWorkspace: pnpmCompatibilityArgs.length > 0
|
|
3813
|
+
}),
|
|
3814
|
+
...freshInstall.args
|
|
3815
|
+
];
|
|
3683
3816
|
const installCommand = [projectPackageManager, ...installArgs].join(" ");
|
|
3684
3817
|
if (pinProjectScopeRegistry(projectPath, { packageManager: projectPackageManager, isolateFromParent: true }, logger).blocked) {
|
|
3685
3818
|
exitWithInitFailure(installFailure({
|
|
@@ -3697,7 +3830,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3697
3830
|
}
|
|
3698
3831
|
});
|
|
3699
3832
|
try {
|
|
3700
|
-
await runCommand(projectPackageManager, installArgs, projectPath);
|
|
3833
|
+
await runCommand(projectPackageManager, installArgs, projectPath, { env: freshInstall.env });
|
|
3701
3834
|
} catch (error) {
|
|
3702
3835
|
stopResumeHintOnInterrupt();
|
|
3703
3836
|
exitWithInitFailure(installFailure({
|
|
@@ -3709,7 +3842,7 @@ async function runPlatformInit(projectNameArg, options) {
|
|
|
3709
3842
|
}
|
|
3710
3843
|
stopResumeHintOnInterrupt();
|
|
3711
3844
|
const repoUrl = project.repo_html_url ?? project.repo_clone_url;
|
|
3712
|
-
const tokenLocation =
|
|
3845
|
+
const tokenLocation = path19.relative(cwd, envPath);
|
|
3713
3846
|
if (options.dev === false) {
|
|
3714
3847
|
logger.success("Your Standard Agents instance is ready.");
|
|
3715
3848
|
logger.log(`Repository: ${repoUrl}`);
|
|
@@ -3809,8 +3942,8 @@ var MANAGED_PROVIDER_KEY_HINTS = [
|
|
|
3809
3942
|
""
|
|
3810
3943
|
].join("\n");
|
|
3811
3944
|
function writeLocalDevVars(projectPath, input) {
|
|
3812
|
-
const devVarsPath =
|
|
3813
|
-
const existed =
|
|
3945
|
+
const devVarsPath = path19.join(projectPath, DEV_VARS_FILENAME);
|
|
3946
|
+
const existed = fs14.existsSync(devVarsPath);
|
|
3814
3947
|
const existing = readDevVarsFile(projectPath);
|
|
3815
3948
|
const wanted = [
|
|
3816
3949
|
{
|
|
@@ -3841,7 +3974,7 @@ function writeLocalDevVars(projectPath, input) {
|
|
|
3841
3974
|
}
|
|
3842
3975
|
const missing = wanted.filter(({ key }) => !readDevVar(existing, key));
|
|
3843
3976
|
if (existed && missing.length === 0) {
|
|
3844
|
-
|
|
3977
|
+
fs14.chmodSync(devVarsPath, 384);
|
|
3845
3978
|
} else {
|
|
3846
3979
|
let devVars = existed ? existing : LOCAL_DEV_VARS_HEADER;
|
|
3847
3980
|
for (const { heading, key, value } of missing) {
|
|
@@ -3900,7 +4033,7 @@ async function init(projectNameArg, initOptions = {}) {
|
|
|
3900
4033
|
}
|
|
3901
4034
|
}
|
|
3902
4035
|
const providedBootstrap = options.bootstrap?.trim() ?? "";
|
|
3903
|
-
const needsLocalEnv = (candidate) => !providedBootstrap && !
|
|
4036
|
+
const needsLocalEnv = (candidate) => !providedBootstrap && !fs14.existsSync(path19.join(candidate.projectPath, ".dev.vars"));
|
|
3904
4037
|
const existingProjectPackageManager = (candidate) => candidate.useExistingProject ? detectLockfilePackageManager(candidate.projectPath) : void 0;
|
|
3905
4038
|
const initialTarget = resolveProjectTarget(cwd, projectNameArg);
|
|
3906
4039
|
let target;
|
|
@@ -3974,8 +4107,8 @@ async function init(projectNameArg, initOptions = {}) {
|
|
|
3974
4107
|
"Installing dependencies and applying Standard Agents project structure.",
|
|
3975
4108
|
headerOptions
|
|
3976
4109
|
);
|
|
3977
|
-
const stopRemoveOnInterrupt = !useExistingProject && !
|
|
3978
|
-
|
|
4110
|
+
const stopRemoveOnInterrupt = !useExistingProject && !fs14.existsSync(projectPath) ? interrupts.onInterrupt(() => {
|
|
4111
|
+
fs14.rmSync(projectPath, { recursive: true, force: true });
|
|
3979
4112
|
logger.log("");
|
|
3980
4113
|
logger.info(`Setup interrupted. Removed the partial "${projectName}" directory.`);
|
|
3981
4114
|
}) : () => {
|
|
@@ -4011,28 +4144,28 @@ async function init(projectNameArg, initOptions = {}) {
|
|
|
4011
4144
|
);
|
|
4012
4145
|
process.exit(1);
|
|
4013
4146
|
}
|
|
4014
|
-
const viteConfigPath =
|
|
4015
|
-
if (!
|
|
4147
|
+
const viteConfigPath = path19.join(projectPath, "vite.config.ts");
|
|
4148
|
+
if (!fs14.existsSync(viteConfigPath)) {
|
|
4016
4149
|
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
4017
4150
|
|
|
4018
4151
|
export default defineConfig({
|
|
4019
4152
|
plugins: [],
|
|
4020
4153
|
})
|
|
4021
4154
|
`;
|
|
4022
|
-
|
|
4155
|
+
fs14.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
4023
4156
|
logSuccess("Created vite.config.ts");
|
|
4024
4157
|
}
|
|
4025
4158
|
writeBuildGuardScript(projectPath);
|
|
4026
4159
|
} else {
|
|
4027
4160
|
logInfo(`Detected existing Standard Agents project in "${projectName}".`);
|
|
4028
4161
|
}
|
|
4029
|
-
const packageJsonPath =
|
|
4030
|
-
if (
|
|
4031
|
-
const packageJson = JSON.parse(
|
|
4162
|
+
const packageJsonPath = path19.join(projectPath, "package.json");
|
|
4163
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
4164
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
4032
4165
|
const kebabName = toKebabCase(projectName);
|
|
4033
4166
|
if (packageJson.name !== kebabName) {
|
|
4034
4167
|
packageJson.name = kebabName;
|
|
4035
|
-
|
|
4168
|
+
fs14.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
|
|
4036
4169
|
}
|
|
4037
4170
|
if (packageSpecifier === "workspace:*") {
|
|
4038
4171
|
const workspaceRoot = resolveStandardAgentsWorkspaceRoot();
|
|
@@ -4057,7 +4190,7 @@ export default defineConfig({
|
|
|
4057
4190
|
let projectPnpmCompatibilityArgs = [];
|
|
4058
4191
|
try {
|
|
4059
4192
|
const installBoundary = { isolateFromParent: packageSpecifier === "workspace:*" };
|
|
4060
|
-
if (pm === "pnpm" && !installBoundary.isolateFromParent && !
|
|
4193
|
+
if (pm === "pnpm" && !installBoundary.isolateFromParent && !fs14.existsSync(path19.join(projectPath, "pnpm-workspace.yaml")) && findPnpmWorkspaceRoot(path19.dirname(projectPath))) {
|
|
4061
4194
|
logInfo("The enclosing pnpm workspace controls esbuild and workerd build approvals.");
|
|
4062
4195
|
}
|
|
4063
4196
|
writeLocalPnpmBuildPolicy(projectPath, pm, {
|
|
@@ -4272,20 +4405,20 @@ var KEYCHAIN_SERVICE2 = "standardagents-cli";
|
|
|
4272
4405
|
function configDir() {
|
|
4273
4406
|
if (process.platform === "win32") {
|
|
4274
4407
|
const appData = process.env.APPDATA;
|
|
4275
|
-
if (appData) return
|
|
4408
|
+
if (appData) return path19.join(appData, "standardagents");
|
|
4276
4409
|
}
|
|
4277
4410
|
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
4278
|
-
if (xdgConfig) return
|
|
4279
|
-
return
|
|
4411
|
+
if (xdgConfig) return path19.join(xdgConfig, "standardagents");
|
|
4412
|
+
return path19.join(os5.homedir(), ".config", "standardagents");
|
|
4280
4413
|
}
|
|
4281
4414
|
function stateFilePath() {
|
|
4282
|
-
return
|
|
4415
|
+
return path19.join(configDir(), "auth-state.json");
|
|
4283
4416
|
}
|
|
4284
4417
|
function cliAuthStatePath() {
|
|
4285
4418
|
return stateFilePath();
|
|
4286
4419
|
}
|
|
4287
4420
|
function ensureStateDir() {
|
|
4288
|
-
|
|
4421
|
+
fs14.mkdirSync(path19.dirname(stateFilePath()), { recursive: true });
|
|
4289
4422
|
}
|
|
4290
4423
|
function securityCommand(args) {
|
|
4291
4424
|
const result = spawnSync("security", args, { encoding: "utf8" });
|
|
@@ -4314,11 +4447,11 @@ function deleteFromKeychain(orgId) {
|
|
|
4314
4447
|
}
|
|
4315
4448
|
function readCliAuthState() {
|
|
4316
4449
|
const file = stateFilePath();
|
|
4317
|
-
if (!
|
|
4450
|
+
if (!fs14.existsSync(file)) {
|
|
4318
4451
|
return { active_org_id: null, orgs: {} };
|
|
4319
4452
|
}
|
|
4320
4453
|
try {
|
|
4321
|
-
const parsed = JSON.parse(
|
|
4454
|
+
const parsed = JSON.parse(fs14.readFileSync(file, "utf8"));
|
|
4322
4455
|
return {
|
|
4323
4456
|
active_org_id: parsed.active_org_id ?? null,
|
|
4324
4457
|
orgs: parsed.orgs ?? {},
|
|
@@ -4372,7 +4505,7 @@ function hasStoredCliAuth() {
|
|
|
4372
4505
|
return Object.keys(state.orgs).length > 0;
|
|
4373
4506
|
}
|
|
4374
4507
|
function gitAuthKeychainAccount(endpoint) {
|
|
4375
|
-
const owner = `${
|
|
4508
|
+
const owner = `${path19.resolve(stateFilePath())}\0${endpoint}`;
|
|
4376
4509
|
return `git-auth-${createHash("sha256").update(owner).digest("hex").slice(0, 32)}`;
|
|
4377
4510
|
}
|
|
4378
4511
|
function parseGitAuthSecrets(text2) {
|
|
@@ -4714,11 +4847,11 @@ function wasReplacedByRetry(build) {
|
|
|
4714
4847
|
return build.error_code === LEGAL_ACCEPTANCE_RETRIED;
|
|
4715
4848
|
}
|
|
4716
4849
|
function findDevVars(startDir) {
|
|
4717
|
-
let current =
|
|
4850
|
+
let current = path19.resolve(startDir);
|
|
4718
4851
|
while (true) {
|
|
4719
|
-
const candidate =
|
|
4720
|
-
if (
|
|
4721
|
-
const parent =
|
|
4852
|
+
const candidate = path19.join(current, DEV_VARS_FILENAME);
|
|
4853
|
+
if (fs14.existsSync(candidate)) return fs14.readFileSync(candidate, "utf-8");
|
|
4854
|
+
const parent = path19.dirname(current);
|
|
4722
4855
|
if (parent === current) return "";
|
|
4723
4856
|
current = parent;
|
|
4724
4857
|
}
|
|
@@ -5061,19 +5194,19 @@ function standardAgentsRemote(dir) {
|
|
|
5061
5194
|
return remote && isStandardAgentsGitRemote(remote) ? remote : null;
|
|
5062
5195
|
}
|
|
5063
5196
|
function findProjectDir(cwd) {
|
|
5064
|
-
let start =
|
|
5197
|
+
let start = path19.resolve(cwd);
|
|
5065
5198
|
try {
|
|
5066
|
-
start =
|
|
5199
|
+
start = fs14.realpathSync(start);
|
|
5067
5200
|
} catch {
|
|
5068
5201
|
return null;
|
|
5069
5202
|
}
|
|
5070
5203
|
const toplevel = gitOutput(start, ["rev-parse", "--show-toplevel"]);
|
|
5071
|
-
const root = toplevel ?
|
|
5072
|
-
for (let current = start; ; current =
|
|
5073
|
-
if (
|
|
5204
|
+
const root = toplevel ? path19.resolve(toplevel) : null;
|
|
5205
|
+
for (let current = start; ; current = path19.dirname(current)) {
|
|
5206
|
+
if (fs14.existsSync(path19.join(current, DEV_VARS_FILENAME)) || isStandardAgentsProjectDir(current)) {
|
|
5074
5207
|
return current;
|
|
5075
5208
|
}
|
|
5076
|
-
if (!root || current === root ||
|
|
5209
|
+
if (!root || current === root || path19.dirname(current) === current) break;
|
|
5077
5210
|
}
|
|
5078
5211
|
return root && standardAgentsRemote(root) ? root : null;
|
|
5079
5212
|
}
|
|
@@ -5193,7 +5326,7 @@ async function performLogin(options = {}) {
|
|
|
5193
5326
|
return { record, keyReused: accessKey?.reused === true, store, helper, ...helperError ? { helperError } : {}, project };
|
|
5194
5327
|
}
|
|
5195
5328
|
function reportProject(project) {
|
|
5196
|
-
const devVars =
|
|
5329
|
+
const devVars = path19.join(path19.relative(process.cwd(), project.dir), DEV_VARS_FILENAME);
|
|
5197
5330
|
if (project.status === "key_saved") {
|
|
5198
5331
|
logger.log(`Project: saved a project API key in ${devVars}. Local sign-in uses your Standard Agents account.`);
|
|
5199
5332
|
return;
|
|
@@ -5327,7 +5460,7 @@ function registerLoginCommands(program2) {
|
|
|
5327
5460
|
}
|
|
5328
5461
|
function readSession(statePath) {
|
|
5329
5462
|
try {
|
|
5330
|
-
const parsed = JSON.parse(
|
|
5463
|
+
const parsed = JSON.parse(fs14.readFileSync(statePath, "utf-8"));
|
|
5331
5464
|
if (!parsed || typeof parsed !== "object") return null;
|
|
5332
5465
|
const { endpoint, session_cookie: cookie } = parsed;
|
|
5333
5466
|
return typeof endpoint === "string" && endpoint && typeof cookie === "string" && cookie ? { endpoint, cookie } : null;
|
|
@@ -5336,10 +5469,10 @@ function readSession(statePath) {
|
|
|
5336
5469
|
}
|
|
5337
5470
|
}
|
|
5338
5471
|
function removeLegacyProjectSession(projectPath) {
|
|
5339
|
-
const statePath =
|
|
5340
|
-
if (!
|
|
5472
|
+
const statePath = path19.join(projectPath, BOOTSTRAP_STATE_RELATIVE_PATH);
|
|
5473
|
+
if (!fs14.existsSync(statePath)) return null;
|
|
5341
5474
|
const session = readSession(statePath);
|
|
5342
|
-
|
|
5475
|
+
fs14.unlinkSync(statePath);
|
|
5343
5476
|
return { file: BOOTSTRAP_STATE_RELATIVE_PATH, session };
|
|
5344
5477
|
}
|
|
5345
5478
|
var GIT_TOKEN_SCOPE_ENV = "STANDARD_AGENTS_GIT_TOKEN_SCOPE";
|
|
@@ -5368,7 +5501,7 @@ function gitSubcommand(args) {
|
|
|
5368
5501
|
}
|
|
5369
5502
|
function gitTokenScopeFor(ancestors) {
|
|
5370
5503
|
for (const { argv, exact } of ancestors) {
|
|
5371
|
-
const program2 =
|
|
5504
|
+
const program2 = path19.basename(argv[0] ?? "").toLowerCase().replace(/\.exe$/, "");
|
|
5372
5505
|
if (program2 !== "git") continue;
|
|
5373
5506
|
const command = gitSubcommand(argv.slice(1));
|
|
5374
5507
|
if (command?.startsWith("remote-http")) continue;
|
|
@@ -5380,8 +5513,8 @@ function gitTokenScopeFor(ancestors) {
|
|
|
5380
5513
|
}
|
|
5381
5514
|
function procfsProcess(pid) {
|
|
5382
5515
|
try {
|
|
5383
|
-
const argv =
|
|
5384
|
-
const stat =
|
|
5516
|
+
const argv = fs14.readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter(Boolean);
|
|
5517
|
+
const stat = fs14.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
5385
5518
|
const parent = Number.parseInt(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1], 10);
|
|
5386
5519
|
return Number.isInteger(parent) ? { argv, parent } : null;
|
|
5387
5520
|
} catch {
|
|
@@ -5396,7 +5529,7 @@ function psProcess(pid) {
|
|
|
5396
5529
|
}
|
|
5397
5530
|
function* readAncestorCommands(startPid = process.ppid) {
|
|
5398
5531
|
if (process.platform === "win32") return;
|
|
5399
|
-
const exact =
|
|
5532
|
+
const exact = fs14.existsSync("/proc/self/stat");
|
|
5400
5533
|
let pid = startPid;
|
|
5401
5534
|
for (let depth = 0; pid > 1 && depth < MAX_ANCESTORS; depth += 1) {
|
|
5402
5535
|
const entry = exact ? procfsProcess(pid) : psProcess(pid);
|
|
@@ -5428,11 +5561,11 @@ function parseCredentialRequest(input) {
|
|
|
5428
5561
|
return result;
|
|
5429
5562
|
}
|
|
5430
5563
|
function findDotDevVars(startDir = process.cwd()) {
|
|
5431
|
-
let current =
|
|
5564
|
+
let current = path19.resolve(startDir);
|
|
5432
5565
|
while (true) {
|
|
5433
|
-
const candidate =
|
|
5434
|
-
if (
|
|
5435
|
-
const parent =
|
|
5566
|
+
const candidate = path19.join(current, DEV_VARS_FILENAME);
|
|
5567
|
+
if (fs14.existsSync(candidate)) return candidate;
|
|
5568
|
+
const parent = path19.dirname(current);
|
|
5436
5569
|
if (parent === current) return null;
|
|
5437
5570
|
current = parent;
|
|
5438
5571
|
}
|
|
@@ -5440,7 +5573,7 @@ function findDotDevVars(startDir = process.cwd()) {
|
|
|
5440
5573
|
var PROJECT_API_KEY = "STANDARD_AGENTS_API_KEY";
|
|
5441
5574
|
function credentialSources(options) {
|
|
5442
5575
|
const envPath = findDotDevVars(options.startDir);
|
|
5443
|
-
const devVars = envPath ? readDevVarsFile(
|
|
5576
|
+
const devVars = envPath ? readDevVarsFile(path19.dirname(envPath)) : "";
|
|
5444
5577
|
const fileVar = (key) => readDevVar(devVars, key)?.trim() ?? "";
|
|
5445
5578
|
const endpoint = configuredPlatformEndpoint(
|
|
5446
5579
|
options.endpoint,
|
|
@@ -5591,7 +5724,7 @@ var ENVIRONMENT_CREDENTIAL_KEYS = [
|
|
|
5591
5724
|
];
|
|
5592
5725
|
function resolveProjectDir(startDir) {
|
|
5593
5726
|
const devVarsPath = findDotDevVars(startDir);
|
|
5594
|
-
return devVarsPath ?
|
|
5727
|
+
return devVarsPath ? path19.dirname(devVarsPath) : path19.resolve(startDir);
|
|
5595
5728
|
}
|
|
5596
5729
|
function recordRevocation(report, outcome, labels) {
|
|
5597
5730
|
if (outcome.status === "revoked") {
|
|
@@ -5948,9 +6081,9 @@ export default defineConfig(({ mode }) => {
|
|
|
5948
6081
|
}
|
|
5949
6082
|
function getReactPackageVersion() {
|
|
5950
6083
|
try {
|
|
5951
|
-
const __dirname =
|
|
5952
|
-
const pkgPath =
|
|
5953
|
-
const pkg = JSON.parse(
|
|
6084
|
+
const __dirname = path19.dirname(fileURLToPath(import.meta.url));
|
|
6085
|
+
const pkgPath = path19.resolve(__dirname, "../package.json");
|
|
6086
|
+
const pkg = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
5954
6087
|
const version = pkg.version;
|
|
5955
6088
|
const prereleaseMatch = version.match(/-([a-z]+)\./i);
|
|
5956
6089
|
if (prereleaseMatch) {
|
|
@@ -5962,9 +6095,9 @@ function getReactPackageVersion() {
|
|
|
5962
6095
|
}
|
|
5963
6096
|
}
|
|
5964
6097
|
function getChatSourceDir() {
|
|
5965
|
-
const __dirname =
|
|
5966
|
-
const bundled =
|
|
5967
|
-
return
|
|
6098
|
+
const __dirname = path19.dirname(fileURLToPath(import.meta.url));
|
|
6099
|
+
const bundled = path19.resolve(__dirname, "../chat");
|
|
6100
|
+
return fs14.existsSync(bundled) ? bundled : path19.resolve(__dirname, "../../chat");
|
|
5968
6101
|
}
|
|
5969
6102
|
async function prompt(question) {
|
|
5970
6103
|
const rl = readline.createInterface({
|
|
@@ -5985,10 +6118,10 @@ function detectPackageManager2() {
|
|
|
5985
6118
|
if (userAgent.includes("yarn")) return "yarn";
|
|
5986
6119
|
if (userAgent.includes("bun")) return "bun";
|
|
5987
6120
|
}
|
|
5988
|
-
if (
|
|
5989
|
-
if (
|
|
5990
|
-
if (
|
|
5991
|
-
if (
|
|
6121
|
+
if (fs14.existsSync("pnpm-lock.yaml")) return "pnpm";
|
|
6122
|
+
if (fs14.existsSync("yarn.lock")) return "yarn";
|
|
6123
|
+
if (fs14.existsSync("bun.lockb")) return "bun";
|
|
6124
|
+
if (fs14.existsSync("package-lock.json")) return "npm";
|
|
5992
6125
|
return "npm";
|
|
5993
6126
|
}
|
|
5994
6127
|
async function selectPackageManager(detected) {
|
|
@@ -6217,25 +6350,25 @@ minimumReleaseAgeExclude:
|
|
|
6217
6350
|
`;
|
|
6218
6351
|
}
|
|
6219
6352
|
function copyDir(src, dest, skip = []) {
|
|
6220
|
-
if (!
|
|
6221
|
-
|
|
6353
|
+
if (!fs14.existsSync(dest)) {
|
|
6354
|
+
fs14.mkdirSync(dest, { recursive: true });
|
|
6222
6355
|
}
|
|
6223
|
-
const entries =
|
|
6356
|
+
const entries = fs14.readdirSync(src, { withFileTypes: true });
|
|
6224
6357
|
for (const entry of entries) {
|
|
6225
6358
|
if (skip.includes(entry.name) || /\.test\.tsx?$/.test(entry.name)) continue;
|
|
6226
|
-
const srcPath =
|
|
6227
|
-
const destPath =
|
|
6359
|
+
const srcPath = path19.join(src, entry.name);
|
|
6360
|
+
const destPath = path19.join(dest, entry.name);
|
|
6228
6361
|
if (entry.isDirectory()) {
|
|
6229
6362
|
copyDir(srcPath, destPath, skip);
|
|
6230
6363
|
} else {
|
|
6231
|
-
|
|
6364
|
+
fs14.copyFileSync(srcPath, destPath);
|
|
6232
6365
|
}
|
|
6233
6366
|
}
|
|
6234
6367
|
}
|
|
6235
6368
|
async function initChat(projectNameArg, options = {}) {
|
|
6236
6369
|
const cwd = process.cwd();
|
|
6237
6370
|
const chatSourceDir = getChatSourceDir();
|
|
6238
|
-
if (!
|
|
6371
|
+
if (!fs14.existsSync(chatSourceDir)) {
|
|
6239
6372
|
logger.error("Chat source files not found. This CLI installation may be corrupted.");
|
|
6240
6373
|
process.exit(1);
|
|
6241
6374
|
}
|
|
@@ -6255,8 +6388,8 @@ async function initChat(projectNameArg, options = {}) {
|
|
|
6255
6388
|
logger.error("Project name is required");
|
|
6256
6389
|
process.exit(1);
|
|
6257
6390
|
}
|
|
6258
|
-
const projectPath =
|
|
6259
|
-
if (
|
|
6391
|
+
const projectPath = path19.join(cwd, projectName);
|
|
6392
|
+
if (fs14.existsSync(projectPath)) {
|
|
6260
6393
|
logger.error(`Directory "${projectName}" already exists`);
|
|
6261
6394
|
process.exit(1);
|
|
6262
6395
|
}
|
|
@@ -6290,7 +6423,7 @@ async function initChat(projectNameArg, options = {}) {
|
|
|
6290
6423
|
logger.log("");
|
|
6291
6424
|
logger.info(`Creating ${framework === "vite" ? "Vite" : "Next.js"} project...`);
|
|
6292
6425
|
logger.log("");
|
|
6293
|
-
|
|
6426
|
+
fs14.mkdirSync(projectPath, { recursive: true });
|
|
6294
6427
|
const reactVersion = getReactPackageVersion();
|
|
6295
6428
|
if (framework === "vite") {
|
|
6296
6429
|
await scaffoldVite(projectPath, chatSourceDir, projectName, serverUrl, reactVersion);
|
|
@@ -6353,25 +6486,25 @@ async function initChat(projectNameArg, options = {}) {
|
|
|
6353
6486
|
}
|
|
6354
6487
|
}
|
|
6355
6488
|
async function scaffoldVite(projectPath, chatSourceDir, projectName, serverUrl, reactVersion) {
|
|
6356
|
-
copyDir(
|
|
6489
|
+
copyDir(path19.join(chatSourceDir, "src"), path19.join(projectPath, "src"), []);
|
|
6357
6490
|
logger.success("Copied src/");
|
|
6358
|
-
const viteDir =
|
|
6359
|
-
let indexHtml =
|
|
6491
|
+
const viteDir = path19.join(chatSourceDir, "vite");
|
|
6492
|
+
let indexHtml = fs14.readFileSync(path19.join(viteDir, "index.html"), "utf-8");
|
|
6360
6493
|
indexHtml = indexHtml.replace('src="/main.tsx"', 'src="/src/main.tsx"');
|
|
6361
|
-
|
|
6494
|
+
fs14.writeFileSync(path19.join(projectPath, "index.html"), indexHtml, "utf-8");
|
|
6362
6495
|
logger.success("Created index.html");
|
|
6363
|
-
|
|
6496
|
+
fs14.copyFileSync(path19.join(viteDir, "main.tsx"), path19.join(projectPath, "src", "main.tsx"));
|
|
6364
6497
|
logger.success("Created src/main.tsx");
|
|
6365
|
-
|
|
6498
|
+
fs14.writeFileSync(path19.join(projectPath, "vite.config.ts"), renderChatViteConfig(), "utf-8");
|
|
6366
6499
|
logger.success("Created vite.config.ts");
|
|
6367
|
-
|
|
6368
|
-
const tsconfig = JSON.parse(
|
|
6500
|
+
fs14.copyFileSync(path19.join(chatSourceDir, "tsconfig.json"), path19.join(projectPath, "tsconfig.json"));
|
|
6501
|
+
const tsconfig = JSON.parse(fs14.readFileSync(path19.join(projectPath, "tsconfig.json"), "utf-8"));
|
|
6369
6502
|
tsconfig.include = ["src"];
|
|
6370
6503
|
delete tsconfig.compilerOptions?.paths;
|
|
6371
|
-
|
|
6504
|
+
fs14.writeFileSync(path19.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
|
|
6372
6505
|
logger.success("Created tsconfig.json");
|
|
6373
|
-
|
|
6374
|
-
const pkg = JSON.parse(
|
|
6506
|
+
fs14.copyFileSync(path19.join(chatSourceDir, "package.json"), path19.join(projectPath, "package.json"));
|
|
6507
|
+
const pkg = JSON.parse(fs14.readFileSync(path19.join(projectPath, "package.json"), "utf-8"));
|
|
6375
6508
|
pkg.name = projectName;
|
|
6376
6509
|
pkg.scripts = { ...CHAT_SCRIPTS.vite };
|
|
6377
6510
|
delete pkg.private;
|
|
@@ -6382,36 +6515,36 @@ async function scaffoldVite(projectPath, chatSourceDir, projectName, serverUrl,
|
|
|
6382
6515
|
delete pkg.devDependencies?.["@tailwindcss/postcss"];
|
|
6383
6516
|
delete pkg.devDependencies?.["postcss"];
|
|
6384
6517
|
delete pkg.devDependencies?.["vitest"];
|
|
6385
|
-
|
|
6386
|
-
|
|
6518
|
+
fs14.writeFileSync(path19.join(projectPath, "package.json"), JSON.stringify(applyChatBuildApprovals(pkg), null, 2) + "\n", "utf-8");
|
|
6519
|
+
fs14.writeFileSync(path19.join(projectPath, "pnpm-workspace.yaml"), renderChatPnpmWorkspaceYaml(), "utf-8");
|
|
6387
6520
|
logger.success("Created package.json");
|
|
6388
6521
|
const envContent = `# Standard Agents Builder connection
|
|
6389
6522
|
VITE_AGENTBUILDER_URL=${serverUrl}
|
|
6390
6523
|
`;
|
|
6391
|
-
|
|
6524
|
+
fs14.writeFileSync(path19.join(projectPath, ".env"), envContent, "utf-8");
|
|
6392
6525
|
logger.success("Created .env");
|
|
6393
|
-
|
|
6526
|
+
fs14.writeFileSync(path19.join(projectPath, ".gitignore"), `node_modules
|
|
6394
6527
|
dist
|
|
6395
6528
|
.env
|
|
6396
6529
|
`, "utf-8");
|
|
6397
6530
|
logger.success("Created .gitignore");
|
|
6398
|
-
let mainTsx =
|
|
6531
|
+
let mainTsx = fs14.readFileSync(path19.join(projectPath, "src", "main.tsx"), "utf-8");
|
|
6399
6532
|
mainTsx = mainTsx.replace(/from '\.\.\/src\//g, "from './").replace(/import '\.\.\/src\//g, "import './");
|
|
6400
|
-
|
|
6401
|
-
if (
|
|
6402
|
-
|
|
6533
|
+
fs14.writeFileSync(path19.join(projectPath, "src", "main.tsx"), mainTsx, "utf-8");
|
|
6534
|
+
if (fs14.existsSync(path19.join(viteDir, "favicon.svg"))) {
|
|
6535
|
+
fs14.copyFileSync(path19.join(viteDir, "favicon.svg"), path19.join(projectPath, "favicon.svg"));
|
|
6403
6536
|
logger.success("Created favicon.svg");
|
|
6404
6537
|
}
|
|
6405
6538
|
}
|
|
6406
6539
|
async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl, reactVersion) {
|
|
6407
|
-
copyDir(
|
|
6540
|
+
copyDir(path19.join(chatSourceDir, "src"), path19.join(projectPath, "src"), []);
|
|
6408
6541
|
logger.success("Copied src/");
|
|
6409
|
-
const nextDir =
|
|
6410
|
-
copyDir(
|
|
6542
|
+
const nextDir = path19.join(chatSourceDir, "next");
|
|
6543
|
+
copyDir(path19.join(nextDir, "app"), path19.join(projectPath, "app"), []);
|
|
6411
6544
|
logger.success("Copied app/");
|
|
6412
|
-
|
|
6545
|
+
fs14.copyFileSync(path19.join(nextDir, "next.config.ts"), path19.join(projectPath, "next.config.ts"));
|
|
6413
6546
|
logger.success("Created next.config.ts");
|
|
6414
|
-
|
|
6547
|
+
fs14.copyFileSync(path19.join(nextDir, "postcss.config.mjs"), path19.join(projectPath, "postcss.config.mjs"));
|
|
6415
6548
|
logger.success("Created postcss.config.mjs");
|
|
6416
6549
|
const tsconfig = {
|
|
6417
6550
|
compilerOptions: {
|
|
@@ -6436,9 +6569,9 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
|
|
|
6436
6569
|
include: ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
6437
6570
|
exclude: ["node_modules"]
|
|
6438
6571
|
};
|
|
6439
|
-
|
|
6572
|
+
fs14.writeFileSync(path19.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
|
|
6440
6573
|
logger.success("Created tsconfig.json");
|
|
6441
|
-
const pkg = JSON.parse(
|
|
6574
|
+
const pkg = JSON.parse(fs14.readFileSync(path19.join(chatSourceDir, "package.json"), "utf-8"));
|
|
6442
6575
|
pkg.name = projectName;
|
|
6443
6576
|
pkg.scripts = { ...CHAT_SCRIPTS.nextjs };
|
|
6444
6577
|
delete pkg.private;
|
|
@@ -6449,26 +6582,26 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
|
|
|
6449
6582
|
delete pkg.devDependencies?.["@vitejs/plugin-react"];
|
|
6450
6583
|
delete pkg.devDependencies?.["vite"];
|
|
6451
6584
|
delete pkg.devDependencies?.["vitest"];
|
|
6452
|
-
|
|
6453
|
-
|
|
6585
|
+
fs14.writeFileSync(path19.join(projectPath, "package.json"), JSON.stringify(applyChatBuildApprovals(pkg), null, 2) + "\n", "utf-8");
|
|
6586
|
+
fs14.writeFileSync(path19.join(projectPath, "pnpm-workspace.yaml"), renderChatPnpmWorkspaceYaml(), "utf-8");
|
|
6454
6587
|
logger.success("Created package.json");
|
|
6455
6588
|
const envContent = `# Standard Agents Builder connection
|
|
6456
6589
|
NEXT_PUBLIC_AGENTBUILDER_URL=${serverUrl}
|
|
6457
6590
|
`;
|
|
6458
|
-
|
|
6591
|
+
fs14.writeFileSync(path19.join(projectPath, ".env.local"), envContent, "utf-8");
|
|
6459
6592
|
logger.success("Created .env.local");
|
|
6460
|
-
|
|
6593
|
+
fs14.writeFileSync(path19.join(projectPath, ".gitignore"), `node_modules
|
|
6461
6594
|
.next
|
|
6462
6595
|
out
|
|
6463
6596
|
.env.local
|
|
6464
6597
|
`, "utf-8");
|
|
6465
6598
|
logger.success("Created .gitignore");
|
|
6466
|
-
let layoutTsx =
|
|
6599
|
+
let layoutTsx = fs14.readFileSync(path19.join(projectPath, "app", "layout.tsx"), "utf-8");
|
|
6467
6600
|
layoutTsx = layoutTsx.replace(/from '\.\.\/\.\.\/src\//g, "from '../src/");
|
|
6468
|
-
|
|
6469
|
-
let pageTsx =
|
|
6601
|
+
fs14.writeFileSync(path19.join(projectPath, "app", "layout.tsx"), layoutTsx, "utf-8");
|
|
6602
|
+
let pageTsx = fs14.readFileSync(path19.join(projectPath, "app", "page.tsx"), "utf-8");
|
|
6470
6603
|
pageTsx = pageTsx.replace(/from '\.\.\/\.\.\/src\//g, "from '../src/");
|
|
6471
|
-
|
|
6604
|
+
fs14.writeFileSync(path19.join(projectPath, "app", "page.tsx"), pageTsx, "utf-8");
|
|
6472
6605
|
}
|
|
6473
6606
|
|
|
6474
6607
|
// src/commands/init-chat-command.ts
|
|
@@ -6505,7 +6638,7 @@ function packageManagerFor(rootDir) {
|
|
|
6505
6638
|
}
|
|
6506
6639
|
function declaresBuilder(rootDir) {
|
|
6507
6640
|
try {
|
|
6508
|
-
const manifest = JSON.parse(
|
|
6641
|
+
const manifest = JSON.parse(fs14.readFileSync(path19.join(rootDir, "package.json"), "utf-8"));
|
|
6509
6642
|
if (!manifest || typeof manifest !== "object") return false;
|
|
6510
6643
|
return ["dependencies", "devDependencies"].some((field2) => {
|
|
6511
6644
|
const dependencies = Reflect.get(manifest, field2);
|
|
@@ -6521,15 +6654,15 @@ function builderInstallCommand(rootDir) {
|
|
|
6521
6654
|
return packageManager === "npm" ? `npm install ${BUILDER}` : `${packageManager} add ${BUILDER}`;
|
|
6522
6655
|
}
|
|
6523
6656
|
function findInstalledBuilder(rootDir) {
|
|
6524
|
-
for (let dir =
|
|
6525
|
-
const candidate =
|
|
6526
|
-
if (
|
|
6527
|
-
if (
|
|
6657
|
+
for (let dir = path19.resolve(rootDir); ; dir = path19.dirname(dir)) {
|
|
6658
|
+
const candidate = path19.join(dir, "node_modules", BUILDER);
|
|
6659
|
+
if (fs14.existsSync(path19.join(candidate, "package.json"))) return candidate;
|
|
6660
|
+
if (path19.dirname(dir) === dir) return void 0;
|
|
6528
6661
|
}
|
|
6529
6662
|
}
|
|
6530
6663
|
function installedVersion(builderDir) {
|
|
6531
6664
|
try {
|
|
6532
|
-
const manifest = JSON.parse(
|
|
6665
|
+
const manifest = JSON.parse(fs14.readFileSync(path19.join(builderDir, "package.json"), "utf-8"));
|
|
6533
6666
|
const version = manifest && typeof manifest === "object" ? Reflect.get(manifest, "version") : void 0;
|
|
6534
6667
|
return typeof version === "string" ? version : "unknown version";
|
|
6535
6668
|
} catch {
|
|
@@ -6546,7 +6679,7 @@ async function loadProjectPacking(rootDir) {
|
|
|
6546
6679
|
}
|
|
6547
6680
|
let entry;
|
|
6548
6681
|
try {
|
|
6549
|
-
entry = createRequire(
|
|
6682
|
+
entry = createRequire(path19.join(rootDir, "package.json")).resolve(PACKING_ENTRY);
|
|
6550
6683
|
} catch (error) {
|
|
6551
6684
|
const installed = `${BUILDER} ${installedVersion(builderDir)} at ${builderDir}`;
|
|
6552
6685
|
if (errorCode(error) === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
@@ -6571,7 +6704,7 @@ async function loadProjectPacking(rootDir) {
|
|
|
6571
6704
|
}
|
|
6572
6705
|
}
|
|
6573
6706
|
async function requireProjectPacking(rootDir) {
|
|
6574
|
-
if (!
|
|
6707
|
+
if (!fs14.existsSync(path19.join(rootDir, "agents"))) {
|
|
6575
6708
|
throw new PackingUnavailableError(
|
|
6576
6709
|
`No agents/ directory in ${rootDir}.`,
|
|
6577
6710
|
"Run this command from the root of a Standard Agents project.",
|
|
@@ -6844,12 +6977,12 @@ async function pack(agentName, options) {
|
|
|
6844
6977
|
if (removed.length > 0) {
|
|
6845
6978
|
logger.warning("Packing removes these original files from the project. The package keeps a copy of each. Pass --no-remove to keep them:");
|
|
6846
6979
|
for (const item of removed) {
|
|
6847
|
-
logger.detail(` - ${
|
|
6980
|
+
logger.detail(` - ${path19.relative(rootDir, item.filePath)}`);
|
|
6848
6981
|
}
|
|
6849
6982
|
} else {
|
|
6850
6983
|
logger.info("Original files are kept. Packing removes nothing from the project.");
|
|
6851
6984
|
}
|
|
6852
|
-
const outputDir = options.output ||
|
|
6985
|
+
const outputDir = options.output || path19.join(rootDir, "agents", "packed");
|
|
6853
6986
|
logger.info(`Packing to: ${outputDir}`);
|
|
6854
6987
|
const result = await packingService.pack({
|
|
6855
6988
|
agentName: selectedAgent,
|
|
@@ -6948,7 +7081,7 @@ async function unpack(pkgIdentifier) {
|
|
|
6948
7081
|
console.log("");
|
|
6949
7082
|
logger.info("Created files:");
|
|
6950
7083
|
for (const file of result.filesGenerated) {
|
|
6951
|
-
const relPath =
|
|
7084
|
+
const relPath = path19.relative(rootDir, file);
|
|
6952
7085
|
console.log(` - ${relPath}`);
|
|
6953
7086
|
}
|
|
6954
7087
|
}
|
|
@@ -7868,8 +8001,8 @@ var PROJECT_SIGNAL_PATHS = [
|
|
|
7868
8001
|
"vite.config.mjs"
|
|
7869
8002
|
];
|
|
7870
8003
|
function hasProjectSignals(cwd) {
|
|
7871
|
-
const hits = PROJECT_SIGNAL_PATHS.filter((signal) =>
|
|
7872
|
-
return hits >= 2 ||
|
|
8004
|
+
const hits = PROJECT_SIGNAL_PATHS.filter((signal) => fs14.existsSync(path19.join(cwd, signal))).length;
|
|
8005
|
+
return hits >= 2 || fs14.existsSync(path19.join(cwd, ".agents"));
|
|
7873
8006
|
}
|
|
7874
8007
|
function detectCliDirectoryContext(cwd = process.cwd()) {
|
|
7875
8008
|
if (!hasProjectSignals(cwd)) {
|
|
@@ -8038,13 +8171,13 @@ async function runHomeTui(cwd = process.cwd()) {
|
|
|
8038
8171
|
}
|
|
8039
8172
|
var DEFAULT_SKILL_NAME = "agentbuilder";
|
|
8040
8173
|
function resolveCodexHome(env = process.env, homeDir = os5.homedir()) {
|
|
8041
|
-
return env.CODEX_HOME ||
|
|
8174
|
+
return env.CODEX_HOME || path19.join(homeDir, ".codex");
|
|
8042
8175
|
}
|
|
8043
8176
|
function resolveClaudeHome(homeDir = os5.homedir()) {
|
|
8044
|
-
return
|
|
8177
|
+
return path19.join(homeDir, ".claude");
|
|
8045
8178
|
}
|
|
8046
8179
|
function resolveAgentsHome(homeDir = os5.homedir()) {
|
|
8047
|
-
return
|
|
8180
|
+
return path19.join(homeDir, ".agents");
|
|
8048
8181
|
}
|
|
8049
8182
|
function normalizeTargetId(target) {
|
|
8050
8183
|
if (target === "codex" || target === "agents") {
|
|
@@ -8057,12 +8190,12 @@ function expandHomePath(inputPath, homeDir = os5.homedir()) {
|
|
|
8057
8190
|
return homeDir;
|
|
8058
8191
|
}
|
|
8059
8192
|
if (inputPath.startsWith("~/")) {
|
|
8060
|
-
return
|
|
8193
|
+
return path19.join(homeDir, inputPath.slice(2));
|
|
8061
8194
|
}
|
|
8062
8195
|
return inputPath;
|
|
8063
8196
|
}
|
|
8064
8197
|
function buildInstallTargets(options = {}, env = process.env, homeDir = os5.homedir()) {
|
|
8065
|
-
const customRoot = options.dir ?
|
|
8198
|
+
const customRoot = options.dir ? path19.resolve(expandHomePath(options.dir, homeDir)) : null;
|
|
8066
8199
|
const agentsHome = resolveAgentsHome(homeDir);
|
|
8067
8200
|
const claudeHome = resolveClaudeHome(homeDir);
|
|
8068
8201
|
return [
|
|
@@ -8070,15 +8203,15 @@ function buildInstallTargets(options = {}, env = process.env, homeDir = os5.home
|
|
|
8070
8203
|
id: "agents",
|
|
8071
8204
|
label: "Codex and other coding agents",
|
|
8072
8205
|
summary: "Agent Skills folder read by Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, and others",
|
|
8073
|
-
detected:
|
|
8074
|
-
installPath: customRoot ??
|
|
8206
|
+
detected: fs14.existsSync(agentsHome) || fs14.existsSync(resolveCodexHome(env, homeDir)),
|
|
8207
|
+
installPath: customRoot ?? path19.join(agentsHome, "skills")
|
|
8075
8208
|
},
|
|
8076
8209
|
{
|
|
8077
8210
|
id: "claude",
|
|
8078
8211
|
label: "Claude Code",
|
|
8079
8212
|
summary: "Agent Skills folder read by Claude Code",
|
|
8080
|
-
detected:
|
|
8081
|
-
installPath: customRoot ??
|
|
8213
|
+
detected: fs14.existsSync(claudeHome),
|
|
8214
|
+
installPath: customRoot ?? path19.join(claudeHome, "skills")
|
|
8082
8215
|
}
|
|
8083
8216
|
];
|
|
8084
8217
|
}
|
|
@@ -8098,8 +8231,8 @@ function findSupersededInstalls(targetId, skillName = DEFAULT_SKILL_NAME, option
|
|
|
8098
8231
|
if (options.dir) {
|
|
8099
8232
|
return [];
|
|
8100
8233
|
}
|
|
8101
|
-
const superseded = normalizeTargetId(targetId) === "claude" ?
|
|
8102
|
-
return
|
|
8234
|
+
const superseded = normalizeTargetId(targetId) === "claude" ? path19.join(resolveClaudeHome(homeDir), "agents", `${skillName}.md`) : path19.join(resolveCodexHome(env, homeDir), "skills", skillName);
|
|
8235
|
+
return fs14.existsSync(superseded) ? [superseded] : [];
|
|
8103
8236
|
}
|
|
8104
8237
|
async function selectInstallTarget(targets) {
|
|
8105
8238
|
return new Promise((resolve) => {
|
|
@@ -8163,8 +8296,8 @@ async function selectInstallTarget(targets) {
|
|
|
8163
8296
|
}
|
|
8164
8297
|
async function installBundledSkill(targetId, skillName = DEFAULT_SKILL_NAME, options = {}) {
|
|
8165
8298
|
const target = resolveSelectedTarget(targetId, options);
|
|
8166
|
-
const targetDir =
|
|
8167
|
-
if (
|
|
8299
|
+
const targetDir = path19.join(target.installPath, skillName);
|
|
8300
|
+
if (fs14.existsSync(targetDir) && !options.force) {
|
|
8168
8301
|
throw new Error(
|
|
8169
8302
|
`Skill already exists at ${targetDir}. Re-run with --force to overwrite it.`
|
|
8170
8303
|
);
|
|
@@ -8192,7 +8325,7 @@ async function skill(options = {}) {
|
|
|
8192
8325
|
logger.log("");
|
|
8193
8326
|
logger.log("Next steps:");
|
|
8194
8327
|
logger.log(` Restart ${selectedTarget.id === "claude" ? "Claude Code" : "your coding agent"} if it is already running`);
|
|
8195
|
-
logger.log(` Edit ${
|
|
8328
|
+
logger.log(` Edit ${path19.join(installedPath, "SKILL.md")} to continue customizing the skill`);
|
|
8196
8329
|
for (const superseded of findSupersededInstalls(
|
|
8197
8330
|
selectedTarget.id,
|
|
8198
8331
|
DEFAULT_SKILL_NAME,
|
|
@@ -8355,24 +8488,24 @@ function parseEnvFile(content) {
|
|
|
8355
8488
|
return result;
|
|
8356
8489
|
}
|
|
8357
8490
|
function findProjectRoot(startDir = process.cwd()) {
|
|
8358
|
-
let currentDir =
|
|
8491
|
+
let currentDir = path19.resolve(startDir);
|
|
8359
8492
|
while (true) {
|
|
8360
|
-
if (
|
|
8493
|
+
if (fs14.existsSync(path19.join(currentDir, "package.json"))) {
|
|
8361
8494
|
return currentDir;
|
|
8362
8495
|
}
|
|
8363
|
-
const parentDir =
|
|
8496
|
+
const parentDir = path19.dirname(currentDir);
|
|
8364
8497
|
if (parentDir === currentDir) {
|
|
8365
|
-
return
|
|
8498
|
+
return path19.resolve(startDir);
|
|
8366
8499
|
}
|
|
8367
8500
|
currentDir = parentDir;
|
|
8368
8501
|
}
|
|
8369
8502
|
}
|
|
8370
8503
|
function readProjectPackageJson(projectRoot) {
|
|
8371
|
-
const packagePath =
|
|
8372
|
-
if (!
|
|
8504
|
+
const packagePath = path19.join(projectRoot, "package.json");
|
|
8505
|
+
if (!fs14.existsSync(packagePath)) {
|
|
8373
8506
|
return {};
|
|
8374
8507
|
}
|
|
8375
|
-
return JSON.parse(
|
|
8508
|
+
return JSON.parse(fs14.readFileSync(packagePath, "utf8"));
|
|
8376
8509
|
}
|
|
8377
8510
|
function getDeclaredProviderPackages(projectRoot) {
|
|
8378
8511
|
const pkg = readProjectPackageJson(projectRoot);
|
|
@@ -8389,23 +8522,23 @@ function resolvePackageEntry(packageName, projectRoot) {
|
|
|
8389
8522
|
if (!packageDir) {
|
|
8390
8523
|
return null;
|
|
8391
8524
|
}
|
|
8392
|
-
const packageJsonPath =
|
|
8525
|
+
const packageJsonPath = path19.join(packageDir, "package.json");
|
|
8393
8526
|
try {
|
|
8394
|
-
const packageJson = JSON.parse(
|
|
8527
|
+
const packageJson = JSON.parse(fs14.readFileSync(packageJsonPath, "utf8"));
|
|
8395
8528
|
const exportPath = resolvePackageExportPath(packageJson.exports) || packageJson.main || "index.js";
|
|
8396
|
-
return
|
|
8529
|
+
return path19.join(packageDir, exportPath);
|
|
8397
8530
|
} catch {
|
|
8398
8531
|
return null;
|
|
8399
8532
|
}
|
|
8400
8533
|
}
|
|
8401
8534
|
function findInstalledPackageDir(packageName, projectRoot) {
|
|
8402
|
-
let currentDir =
|
|
8535
|
+
let currentDir = path19.resolve(projectRoot);
|
|
8403
8536
|
while (true) {
|
|
8404
|
-
const candidate =
|
|
8405
|
-
if (
|
|
8537
|
+
const candidate = path19.join(currentDir, "node_modules", ...packageName.split("/"));
|
|
8538
|
+
if (fs14.existsSync(candidate)) {
|
|
8406
8539
|
return candidate;
|
|
8407
8540
|
}
|
|
8408
|
-
const parentDir =
|
|
8541
|
+
const parentDir = path19.dirname(currentDir);
|
|
8409
8542
|
if (parentDir === currentDir) {
|
|
8410
8543
|
return null;
|
|
8411
8544
|
}
|
|
@@ -8437,9 +8570,9 @@ function loadProjectEnv(projectRoot, processEnv = process.env) {
|
|
|
8437
8570
|
const result = {};
|
|
8438
8571
|
const envFiles = [".env", ".env.local", ".dev.vars", ".dev.vars.local"];
|
|
8439
8572
|
for (const fileName of envFiles) {
|
|
8440
|
-
const filePath =
|
|
8441
|
-
if (!
|
|
8442
|
-
Object.assign(result, parseEnvFile(
|
|
8573
|
+
const filePath = path19.join(projectRoot, fileName);
|
|
8574
|
+
if (!fs14.existsSync(filePath)) continue;
|
|
8575
|
+
Object.assign(result, parseEnvFile(fs14.readFileSync(filePath, "utf8")));
|
|
8443
8576
|
}
|
|
8444
8577
|
for (const [key, value] of Object.entries(processEnv)) {
|
|
8445
8578
|
if (typeof value === "string") {
|
|
@@ -8629,23 +8762,23 @@ async function currentModels(options = {}) {
|
|
|
8629
8762
|
process.exit(1);
|
|
8630
8763
|
}
|
|
8631
8764
|
}
|
|
8632
|
-
var PROJECT_PROVIDERS_DIR =
|
|
8765
|
+
var PROJECT_PROVIDERS_DIR = path19.join("agents", "providers");
|
|
8633
8766
|
function isLoadedProjectProvider(provider) {
|
|
8634
8767
|
return !("loadError" in provider);
|
|
8635
8768
|
}
|
|
8636
8769
|
function projectProviderPath(projectRoot, provider) {
|
|
8637
|
-
return
|
|
8770
|
+
return path19.relative(projectRoot, provider.filePath).split(path19.sep).join("/");
|
|
8638
8771
|
}
|
|
8639
8772
|
function scanProjectProviders(projectRoot) {
|
|
8640
|
-
const dir =
|
|
8641
|
-
if (!
|
|
8773
|
+
const dir = path19.join(projectRoot, PROJECT_PROVIDERS_DIR);
|
|
8774
|
+
if (!fs14.existsSync(dir)) return [];
|
|
8642
8775
|
const providers = [];
|
|
8643
|
-
for (const entry of
|
|
8776
|
+
for (const entry of fs14.readdirSync(dir, { withFileTypes: true })) {
|
|
8644
8777
|
if (!entry.isFile() || !entry.name.endsWith(".ts")) continue;
|
|
8645
|
-
const filePath =
|
|
8778
|
+
const filePath = path19.join(dir, entry.name);
|
|
8646
8779
|
let content;
|
|
8647
8780
|
try {
|
|
8648
|
-
content =
|
|
8781
|
+
content = fs14.readFileSync(filePath, "utf8");
|
|
8649
8782
|
} catch {
|
|
8650
8783
|
continue;
|
|
8651
8784
|
}
|
|
@@ -8756,7 +8889,7 @@ async function createProjectModuleServer(projectRoot) {
|
|
|
8756
8889
|
if (!entryPath) {
|
|
8757
8890
|
throw new Error(
|
|
8758
8891
|
[
|
|
8759
|
-
`Reading ${PROJECT_PROVIDERS_DIR.split(
|
|
8892
|
+
`Reading ${PROJECT_PROVIDERS_DIR.split(path19.sep).join("/")}/ needs the project's Vite installation, which was not found from ${projectRoot}.`,
|
|
8760
8893
|
"Install the project dependencies, then run this command again."
|
|
8761
8894
|
].join("\n")
|
|
8762
8895
|
);
|
|
@@ -9069,7 +9202,7 @@ function stringField(value, key) {
|
|
|
9069
9202
|
const field2 = Reflect.get(value, key);
|
|
9070
9203
|
return typeof field2 === "string" && field2 ? field2 : null;
|
|
9071
9204
|
}
|
|
9072
|
-
function describeFailedResponse(method,
|
|
9205
|
+
function describeFailedResponse(method, path27, status2, text2) {
|
|
9073
9206
|
let detail = text2.slice(0, 300);
|
|
9074
9207
|
let code = null;
|
|
9075
9208
|
let requestId = null;
|
|
@@ -9087,7 +9220,7 @@ function describeFailedResponse(method, path26, status2, text2) {
|
|
|
9087
9220
|
}
|
|
9088
9221
|
const context = [code ? `code: ${code}` : null, requestId ? `request ID: ${requestId}` : null].filter(Boolean);
|
|
9089
9222
|
const suffix = context.length > 0 ? ` (${context.join(", ")})` : "";
|
|
9090
|
-
return new DiagRequestError(`${method} ${
|
|
9223
|
+
return new DiagRequestError(`${method} ${path27} \u2192 HTTP ${status2}: ${detail}${suffix}`, status2, code, requestId);
|
|
9091
9224
|
}
|
|
9092
9225
|
function diagJsonError(error) {
|
|
9093
9226
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -9099,40 +9232,40 @@ function diagJsonError(error) {
|
|
|
9099
9232
|
...error.requestId ? { request_id: error.requestId } : {}
|
|
9100
9233
|
};
|
|
9101
9234
|
}
|
|
9102
|
-
async function apiGet(config,
|
|
9103
|
-
return apiRequest(config,
|
|
9235
|
+
async function apiGet(config, path27) {
|
|
9236
|
+
return apiRequest(config, path27, "GET");
|
|
9104
9237
|
}
|
|
9105
|
-
async function apiRequest(config,
|
|
9238
|
+
async function apiRequest(config, path27, method, body) {
|
|
9106
9239
|
const headers = { Accept: "application/json" };
|
|
9107
9240
|
if (config.token) headers.Authorization = `Bearer ${config.token}`;
|
|
9108
9241
|
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
9109
9242
|
let response;
|
|
9110
9243
|
try {
|
|
9111
|
-
response = await (config.token ? credentialFetch : fetchWithDeadline)(`${config.endpoint}${
|
|
9244
|
+
response = await (config.token ? credentialFetch : fetchWithDeadline)(`${config.endpoint}${path27}`, {
|
|
9112
9245
|
method,
|
|
9113
9246
|
headers,
|
|
9114
9247
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
9115
9248
|
}, { fetchImpl: config.fetchImpl, next: "Check the instance URL (--endpoint), then run the command again." });
|
|
9116
9249
|
} catch (error) {
|
|
9117
9250
|
if (error instanceof RequestTimeoutError) {
|
|
9118
|
-
throw new DiagRequestError(`${method} ${
|
|
9251
|
+
throw new DiagRequestError(`${method} ${path27}: ${error.message.replace("\n", " ")}`, null, "timeout", null);
|
|
9119
9252
|
}
|
|
9120
9253
|
if (error instanceof RedirectRefusedError) {
|
|
9121
|
-
throw new DiagRequestError(`${method} ${
|
|
9254
|
+
throw new DiagRequestError(`${method} ${path27}: ${error.message.replace("\n", " ")}`, error.status, "redirect_refused", null);
|
|
9122
9255
|
}
|
|
9123
9256
|
const cause = error instanceof Error && error.cause instanceof Error ? error.cause.message : null;
|
|
9124
9257
|
const detail = cause ?? (error instanceof Error ? error.message : String(error));
|
|
9125
|
-
throw new DiagRequestError(`${method} ${
|
|
9258
|
+
throw new DiagRequestError(`${method} ${path27} could not reach ${config.endpoint}: ${detail}`, null, "unreachable", null);
|
|
9126
9259
|
}
|
|
9127
9260
|
const text2 = await response.text();
|
|
9128
9261
|
if (!response.ok) {
|
|
9129
|
-
throw describeFailedResponse(method,
|
|
9262
|
+
throw describeFailedResponse(method, path27, response.status, text2);
|
|
9130
9263
|
}
|
|
9131
9264
|
try {
|
|
9132
9265
|
return JSON.parse(text2);
|
|
9133
9266
|
} catch {
|
|
9134
9267
|
throw new Error(
|
|
9135
|
-
`${method} ${
|
|
9268
|
+
`${method} ${path27} returned non-JSON (is this a Standard Agents Builder instance URL?): ${text2.slice(0, 120)}`
|
|
9136
9269
|
);
|
|
9137
9270
|
}
|
|
9138
9271
|
}
|
|
@@ -9248,6 +9381,11 @@ async function diagInstance(options, fetchImpl) {
|
|
|
9248
9381
|
console.log(" builder version pre-0.26 (no runtime block in /api/diagnostics)");
|
|
9249
9382
|
console.log(` config warnings ${data.warnings?.length ?? 0}`);
|
|
9250
9383
|
}
|
|
9384
|
+
for (const warning of data.warnings ?? []) {
|
|
9385
|
+
if (warning && typeof warning === "object" && "message" in warning && typeof warning.message === "string") {
|
|
9386
|
+
console.log(` warning: ${warning.message}`);
|
|
9387
|
+
}
|
|
9388
|
+
}
|
|
9251
9389
|
}
|
|
9252
9390
|
async function diagThreads(options, fetchImpl) {
|
|
9253
9391
|
const config = resolveDiagConfig(options, process.env, fetchImpl ?? fetch);
|
|
@@ -9632,7 +9770,7 @@ function parsePlatformError(body) {
|
|
|
9632
9770
|
reason: details ? stringField2(details, "reason") : null
|
|
9633
9771
|
};
|
|
9634
9772
|
}
|
|
9635
|
-
async function requestLegal(config,
|
|
9773
|
+
async function requestLegal(config, path27, init2) {
|
|
9636
9774
|
const fetchImpl = config.fetchImpl ?? fetch;
|
|
9637
9775
|
const headers = {
|
|
9638
9776
|
Accept: "application/json",
|
|
@@ -9642,7 +9780,7 @@ async function requestLegal(config, path26, init2) {
|
|
|
9642
9780
|
if (init2.body !== void 0) headers["Content-Type"] = "application/json";
|
|
9643
9781
|
let response;
|
|
9644
9782
|
try {
|
|
9645
|
-
response = await platformFetch(config.endpoint,
|
|
9783
|
+
response = await platformFetch(config.endpoint, path27, {
|
|
9646
9784
|
method: init2.method,
|
|
9647
9785
|
headers,
|
|
9648
9786
|
// The cookie belongs to this endpoint only; never follow it elsewhere.
|
|
@@ -10149,7 +10287,7 @@ async function settleStdinForInitHandoff(stdin = process.stdin) {
|
|
|
10149
10287
|
}
|
|
10150
10288
|
}
|
|
10151
10289
|
var program = new Command();
|
|
10152
|
-
program.name("agents").description("CLI tool for Standard Agents Builder").version("0.45.
|
|
10290
|
+
program.name("agents").description("CLI tool for Standard Agents Builder").version("0.45.8").exitOverride();
|
|
10153
10291
|
registerInitCommand(program);
|
|
10154
10292
|
registerLoginCommands(program);
|
|
10155
10293
|
addPlatformEndpointOption(
|
|
@@ -10174,7 +10312,7 @@ program.command("skill").description("Install the bundled Standard Agents Builde
|
|
|
10174
10312
|
program.command("current-models").description("Print the live curated model guide from standardagentspec.org (standardagentspec.com when that request fails)").option("--url <url>", "Request this models markdown URL instead").action(currentModels);
|
|
10175
10313
|
program.command("available-models").description("List the model IDs of one provider in the current project, using its own key or the project's Standard Agents account key").option("--provider <provider>", "Provider to query: an installed provider package such as openai, or a provider defined in agents/providers/").option("--json", "Print the provider and its models as one JSON document on stdout").action(availableModels);
|
|
10176
10314
|
registerDiagCommand(program);
|
|
10177
|
-
registerTermsCommand(program, "0.45.
|
|
10315
|
+
registerTermsCommand(program, "0.45.8");
|
|
10178
10316
|
async function run() {
|
|
10179
10317
|
const userArgs = process.argv.slice(2);
|
|
10180
10318
|
if (userArgs[0] !== "git-credential") {
|