@yansirplus/cli 0.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PUBLIC_API.md +22 -0
- package/README.md +34 -0
- package/dist/build/agent-authoring/config.d.ts +177 -0
- package/dist/build/agent-authoring/config.js +607 -0
- package/dist/build/agent-authoring/manifest-compiler.d.ts +159 -0
- package/dist/build/agent-authoring/manifest-compiler.js +737 -0
- package/dist/build/agent-authoring/shared.d.ts +10 -0
- package/dist/build/agent-authoring/shared.js +57 -0
- package/dist/build/agent-authoring/static-target.d.ts +59 -0
- package/dist/build/agent-authoring/static-target.js +1857 -0
- package/dist/build/agent-authoring.d.ts +9 -0
- package/dist/build/agent-authoring.js +5 -0
- package/dist/build/build-cli.d.ts +2 -0
- package/dist/build/build-cli.js +264 -0
- package/dist/check/algorithmic/architecture-checks.mjs +971 -0
- package/dist/check/algorithmic/client-boundary-checks.mjs +337 -0
- package/dist/check/algorithmic/convergence-smoke-checks.mjs +608 -0
- package/dist/check/algorithmic/distribution-checks.mjs +919 -0
- package/dist/check/algorithmic/owner-checks.mjs +647 -0
- package/dist/check/algorithmic/package-boundary-checks.mjs +985 -0
- package/dist/check/algorithmic/projection-boundary-checks.mjs +302 -0
- package/dist/check/algorithmic/repo-surface-checks.mjs +267 -0
- package/dist/check/algorithmic/runtime-structural-checks.mjs +264 -0
- package/dist/check/algorithmic/source-alias-checks.mjs +106 -0
- package/dist/check/algorithmic/static-target-checks.mjs +447 -0
- package/dist/check/algorithmic-checks.mjs +482 -0
- package/dist/check/check-coverage.mjs +231 -0
- package/dist/check/command-runner.mjs +22 -0
- package/dist/check/default-gate.mjs +51 -0
- package/dist/check/gate-selector.mjs +305 -0
- package/dist/check/manifest-rules.mjs +223 -0
- package/dist/check/package-graph.mjs +464 -0
- package/dist/generate/generate-agent-docs.mjs +435 -0
- package/dist/generate/generate-carrier-reference.mjs +514 -0
- package/dist/generate/generate-docs.mjs +345 -0
- package/dist/generate/generate-effect-skill-manifests.mjs +193 -0
- package/dist/generate/project-docs-site.mjs +190 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -0
- package/dist/lib/agent-docs-model.mjs +888 -0
- package/dist/lib/boundary-rules.mjs +63 -0
- package/dist/lib/capability-routes.mjs +354 -0
- package/dist/lib/projection-sink.mjs +113 -0
- package/dist/lib/public-api-model.mjs +306 -0
- package/dist/main.mjs +233 -0
- package/dist/runner.mjs +127 -0
- package/package.json +32 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { WORKSPACE_TOPOLOGY } from "@yansirplus/core/runtime-protocol";
|
|
2
|
+
export type { WorkspaceTopologyKind } from "@yansirplus/core/runtime-protocol";
|
|
3
|
+
export { AUTHORING_DEFAULTS_VERSION } from "./agent-authoring/shared.js";
|
|
4
|
+
export type { AgentManifestFactKey, AgentManifestOrigin, AuthoredAgentJson, AuthoredAgentManifest, AuthoredAgentTree, AuthoredAgentTreeFile, AuthoredJsonFile, AuthoredMarkdownFile, AuthoredToolDeclaration, AuthoredToolEffect, AuthoredToolFile, AuthoredWorkspaceDefaultToolControl, AuthoredWorkspaceDefaultToolOverride, CompiledAgentManifest, CompileAgentTreeIssue, CompileAgentTreeResult, WorkspaceDefaultToolControl, } from "./agent-authoring/manifest-compiler.js";
|
|
5
|
+
export { compileAgentTree } from "./agent-authoring/manifest-compiler.js";
|
|
6
|
+
export { AGENTOS_CONFIG_CLIENT, AGENTOS_CONFIG_LLM_ROUTE, AGENTOS_CONFIG_PROFILE, AGENTOS_CONFIG_TARGET, decodeAgentOsConfig, llmMaterialEnvBindingsForRefs, llmMaterialEnvNameCollisionIssues, materialEnvNameForRef, normalizeAgentOsConfig, } from "./agent-authoring/config.js";
|
|
7
|
+
export type { AgentOsChatConfigV1, AgentOsConfigBase, AgentOsConfigClient, AgentOsConfigClientKind, AgentOsConfigCloudflareDoTarget, AgentOsConfigDeployment, AgentOsConfigFactKey, AgentOsConfigIssue, AgentOsConfigLlm, AgentOsConfigLlmRoute, AgentOsConfigOrigin, AgentOsConfigProfile, AgentOsConfigTarget, AgentOsConfigTargetKind, AgentOsConfigV1, AgentOsWorkspaceConfigV1, AgentOsConfigWorkspace, AgentOsConfigWorkspaceTopology, DecodeAgentOsConfigResult, LlmMaterialEnvBinding, LlmMaterialEnvKind, NormalizedAgentOsConfig, NormalizedAgentOsConfigBase, NormalizedChatAgentOsConfig, NormalizedWorkspaceAgentOsConfig, NormalizeAgentOsConfigResult, StaticTargetProvenance, } from "./agent-authoring/config.js";
|
|
8
|
+
export { linkWorkspaceStaticTarget } from "./agent-authoring/static-target.js";
|
|
9
|
+
export type { CanonicalDeploymentIR, MountIR, StaticTargetGeneratedFile, StaticTargetGeneratedFilePath, StaticTargetLink, StaticTargetLinkIssue, StaticTargetLinkOptions, StaticTargetLinkResult, StaticTargetModuleImport, StaticTargetModuleImportKind, } from "./agent-authoring/static-target.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { WORKSPACE_TOPOLOGY } from "@yansirplus/core/runtime-protocol";
|
|
2
|
+
export { AUTHORING_DEFAULTS_VERSION } from "./agent-authoring/shared.js";
|
|
3
|
+
export { compileAgentTree } from "./agent-authoring/manifest-compiler.js";
|
|
4
|
+
export { AGENTOS_CONFIG_CLIENT, AGENTOS_CONFIG_LLM_ROUTE, AGENTOS_CONFIG_PROFILE, AGENTOS_CONFIG_TARGET, decodeAgentOsConfig, llmMaterialEnvBindingsForRefs, llmMaterialEnvNameCollisionIssues, materialEnvNameForRef, normalizeAgentOsConfig, } from "./agent-authoring/config.js";
|
|
5
|
+
export { linkWorkspaceStaticTarget } from "./agent-authoring/static-target.js";
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { compileAgentTree, decodeAgentOsConfig, linkWorkspaceStaticTarget, normalizeAgentOsConfig, } from "./agent-authoring.js";
|
|
6
|
+
const parseBuildArgs = (rawArgs) => {
|
|
7
|
+
const args = {
|
|
8
|
+
cwd: process.cwd(),
|
|
9
|
+
config: "agentos.config.jsonc",
|
|
10
|
+
};
|
|
11
|
+
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
12
|
+
const arg = rawArgs[index];
|
|
13
|
+
switch (arg) {
|
|
14
|
+
case "--cwd":
|
|
15
|
+
if (rawArgs[index + 1] === undefined)
|
|
16
|
+
throw new Error("--cwd requires a value");
|
|
17
|
+
args.cwd = rawArgs[index + 1];
|
|
18
|
+
index += 1;
|
|
19
|
+
break;
|
|
20
|
+
case "--config":
|
|
21
|
+
if (rawArgs[index + 1] === undefined)
|
|
22
|
+
throw new Error("--config requires a value");
|
|
23
|
+
args.config = rawArgs[index + 1];
|
|
24
|
+
index += 1;
|
|
25
|
+
break;
|
|
26
|
+
case "--package-scope":
|
|
27
|
+
if (rawArgs[index + 1] === undefined)
|
|
28
|
+
throw new Error("--package-scope requires a value");
|
|
29
|
+
args.packageScope = rawArgs[index + 1];
|
|
30
|
+
index += 1;
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
throw new Error(`unexpected argument ${arg}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return args;
|
|
37
|
+
};
|
|
38
|
+
const parseArgs = (rawArgs) => {
|
|
39
|
+
const [command, ...rest] = rawArgs;
|
|
40
|
+
if (command === undefined || command === "--help" || command === "-h")
|
|
41
|
+
return { command: "help" };
|
|
42
|
+
if (command !== "build")
|
|
43
|
+
throw new Error("choose one of build");
|
|
44
|
+
if (rest.includes("--help") || rest.includes("-h"))
|
|
45
|
+
return { command: "help" };
|
|
46
|
+
return { command: "build", args: parseBuildArgs(rest) };
|
|
47
|
+
};
|
|
48
|
+
const help = `Usage:
|
|
49
|
+
agentos build [--cwd <path>] [--config <path>] [--package-scope <scope>]
|
|
50
|
+
|
|
51
|
+
Compiles agent/ + agentos.config.jsonc into .agentos/generated/.
|
|
52
|
+
`;
|
|
53
|
+
const stripJsonc = (text) => {
|
|
54
|
+
let output = "";
|
|
55
|
+
let index = 0;
|
|
56
|
+
let inString = false;
|
|
57
|
+
let quote = "";
|
|
58
|
+
let escaped = false;
|
|
59
|
+
while (index < text.length) {
|
|
60
|
+
const char = text[index];
|
|
61
|
+
const next = text[index + 1];
|
|
62
|
+
if (inString) {
|
|
63
|
+
output += char;
|
|
64
|
+
if (escaped) {
|
|
65
|
+
escaped = false;
|
|
66
|
+
}
|
|
67
|
+
else if (char === "\\") {
|
|
68
|
+
escaped = true;
|
|
69
|
+
}
|
|
70
|
+
else if (char === quote) {
|
|
71
|
+
inString = false;
|
|
72
|
+
quote = "";
|
|
73
|
+
}
|
|
74
|
+
index += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (char === '"' || char === "'") {
|
|
78
|
+
inString = true;
|
|
79
|
+
quote = char;
|
|
80
|
+
output += char;
|
|
81
|
+
index += 1;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (char === "/" && next === "/") {
|
|
85
|
+
while (index < text.length && text[index] !== "\n")
|
|
86
|
+
index += 1;
|
|
87
|
+
output += "\n";
|
|
88
|
+
if (text[index] === "\n")
|
|
89
|
+
index += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (char === "/" && next === "*") {
|
|
93
|
+
index += 2;
|
|
94
|
+
while (index < text.length && !(text[index] === "*" && text[index + 1] === "/")) {
|
|
95
|
+
output += text[index] === "\n" ? "\n" : " ";
|
|
96
|
+
index += 1;
|
|
97
|
+
}
|
|
98
|
+
index += 2;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
output += char;
|
|
102
|
+
index += 1;
|
|
103
|
+
}
|
|
104
|
+
return output;
|
|
105
|
+
};
|
|
106
|
+
const removeTrailingCommas = (text) => {
|
|
107
|
+
let output = "";
|
|
108
|
+
let index = 0;
|
|
109
|
+
let inString = false;
|
|
110
|
+
let escaped = false;
|
|
111
|
+
while (index < text.length) {
|
|
112
|
+
const char = text[index];
|
|
113
|
+
if (inString) {
|
|
114
|
+
output += char;
|
|
115
|
+
if (escaped) {
|
|
116
|
+
escaped = false;
|
|
117
|
+
}
|
|
118
|
+
else if (char === "\\") {
|
|
119
|
+
escaped = true;
|
|
120
|
+
}
|
|
121
|
+
else if (char === '"') {
|
|
122
|
+
inString = false;
|
|
123
|
+
}
|
|
124
|
+
index += 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (char === '"') {
|
|
128
|
+
inString = true;
|
|
129
|
+
output += char;
|
|
130
|
+
index += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (char === ",") {
|
|
134
|
+
let cursor = index + 1;
|
|
135
|
+
while (/\s/u.test(text[cursor] ?? ""))
|
|
136
|
+
cursor += 1;
|
|
137
|
+
if (text[cursor] === "}" || text[cursor] === "]") {
|
|
138
|
+
index += 1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
output += char;
|
|
143
|
+
index += 1;
|
|
144
|
+
}
|
|
145
|
+
return output;
|
|
146
|
+
};
|
|
147
|
+
const readJson = async (file) => JSON.parse(await readFile(file, "utf8"));
|
|
148
|
+
const readJsonc = async (file) => {
|
|
149
|
+
try {
|
|
150
|
+
return JSON.parse(removeTrailingCommas(stripJsonc(await readFile(file, "utf8"))));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
throw new Error(`${path.relative(process.cwd(), file)} is not valid JSONC: ${error instanceof Error ? error.message : String(error)}`);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const pathExists = async (file) => {
|
|
157
|
+
try {
|
|
158
|
+
await stat(file);
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (isRecord(error) && error.code === "ENOENT")
|
|
163
|
+
return false;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const toAuthoredPath = (cwd, file) => path.relative(cwd, file).split(path.sep).join("/");
|
|
168
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
169
|
+
const inferPackageScope = (config, explicitScope) => {
|
|
170
|
+
if (explicitScope !== undefined)
|
|
171
|
+
return explicitScope;
|
|
172
|
+
const schema = isRecord(config) && typeof config.$schema === "string" ? config.$schema : "";
|
|
173
|
+
const match = /(?:^|\/)node_modules\/(@[^/]+)\/config\/schema\.json$/u.exec(schema);
|
|
174
|
+
return match?.[1];
|
|
175
|
+
};
|
|
176
|
+
const loadToolDeclaration = async (file) => {
|
|
177
|
+
const mod = await import(`${pathToFileURL(file).href}?agentos-build=${Date.now()}`);
|
|
178
|
+
if (!Object.hasOwn(mod, "declaration")) {
|
|
179
|
+
throw new Error(`${file}: missing exported declaration`);
|
|
180
|
+
}
|
|
181
|
+
return mod.declaration;
|
|
182
|
+
};
|
|
183
|
+
const loadAuthoredTree = async (cwd, agentDir) => {
|
|
184
|
+
const files = [
|
|
185
|
+
{
|
|
186
|
+
path: toAuthoredPath(cwd, path.join(agentDir, "instructions.md")),
|
|
187
|
+
kind: "markdown",
|
|
188
|
+
text: await readFile(path.join(agentDir, "instructions.md"), "utf8"),
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
const agentJsonPath = path.join(agentDir, "agent.json");
|
|
192
|
+
if (await pathExists(agentJsonPath)) {
|
|
193
|
+
files.push({
|
|
194
|
+
path: toAuthoredPath(cwd, agentJsonPath),
|
|
195
|
+
kind: "json",
|
|
196
|
+
value: await readJson(agentJsonPath),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const toolsDir = path.join(agentDir, "tools");
|
|
200
|
+
if (await pathExists(toolsDir)) {
|
|
201
|
+
const toolFiles = (await readdir(toolsDir, { withFileTypes: true }))
|
|
202
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
|
203
|
+
.map((entry) => path.join(toolsDir, entry.name))
|
|
204
|
+
.sort((left, right) => left.localeCompare(right));
|
|
205
|
+
for (const file of toolFiles) {
|
|
206
|
+
files.push({
|
|
207
|
+
path: toAuthoredPath(cwd, file),
|
|
208
|
+
kind: "tool",
|
|
209
|
+
declaration: await loadToolDeclaration(file),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return { files };
|
|
214
|
+
};
|
|
215
|
+
const writeGeneratedFiles = async (cwd, files) => {
|
|
216
|
+
await rm(path.join(cwd, ".agentos", "generated"), { recursive: true, force: true });
|
|
217
|
+
for (const file of files) {
|
|
218
|
+
const output = path.join(cwd, file.path);
|
|
219
|
+
await mkdir(path.dirname(output), { recursive: true });
|
|
220
|
+
await writeFile(output, file.text);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const main = async () => {
|
|
224
|
+
const parsed = parseArgs(process.argv.slice(2));
|
|
225
|
+
if (parsed.command === "help") {
|
|
226
|
+
process.stdout.write(help);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const args = parsed.args;
|
|
230
|
+
if (process.versions.bun === undefined) {
|
|
231
|
+
throw new Error("agentos build must run under Bun because authored tools are TypeScript modules");
|
|
232
|
+
}
|
|
233
|
+
const cwd = path.resolve(args.cwd);
|
|
234
|
+
const configPath = path.resolve(cwd, args.config);
|
|
235
|
+
const configValue = await readJsonc(configPath);
|
|
236
|
+
const packageScope = inferPackageScope(configValue, args.packageScope);
|
|
237
|
+
const decodedConfig = decodeAgentOsConfig(configValue);
|
|
238
|
+
if (!decodedConfig.ok) {
|
|
239
|
+
throw new Error(`agentos.config.jsonc invalid: ${JSON.stringify(decodedConfig.issues, null, 2)}`);
|
|
240
|
+
}
|
|
241
|
+
const agentDir = path.resolve(cwd, decodedConfig.value.agent);
|
|
242
|
+
const tree = await loadAuthoredTree(cwd, agentDir);
|
|
243
|
+
const compiled = compileAgentTree(tree);
|
|
244
|
+
if (!compiled.ok) {
|
|
245
|
+
throw new Error(`agent tree invalid: ${JSON.stringify(compiled.issues, null, 2)}`);
|
|
246
|
+
}
|
|
247
|
+
const normalized = normalizeAgentOsConfig(decodedConfig.value, compiled.value);
|
|
248
|
+
if (!normalized.ok) {
|
|
249
|
+
throw new Error(`agentos config normalization failed: ${JSON.stringify(normalized.issues, null, 2)}`);
|
|
250
|
+
}
|
|
251
|
+
const linked = linkWorkspaceStaticTarget(normalized.value, packageScope === undefined ? {} : { packageScope });
|
|
252
|
+
if (!linked.ok) {
|
|
253
|
+
throw new Error(`static target link failed: ${JSON.stringify(linked.issues, null, 2)}`);
|
|
254
|
+
}
|
|
255
|
+
await writeGeneratedFiles(cwd, linked.value.files);
|
|
256
|
+
console.log(`generated ${linked.value.files.length} agentOS files`);
|
|
257
|
+
};
|
|
258
|
+
try {
|
|
259
|
+
await main();
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
process.stderr.write(`agentos build: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
263
|
+
process.exitCode = 1;
|
|
264
|
+
}
|