agent-contracts 0.22.5 → 0.22.7
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/cli-contract.yaml +1 -1
- package/dist/cli.js +215 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -12
- package/dist/index.js.map +1 -1
- package/docs/cli-reference.md +438 -3
- package/package.json +3 -3
package/cli-contract.yaml
CHANGED
package/dist/cli.js
CHANGED
|
@@ -48896,8 +48896,195 @@ import { resolve as resolve8, dirname as dirname8 } from "path";
|
|
|
48896
48896
|
// src/generated/cli-contract/program.ts
|
|
48897
48897
|
import { Command } from "commander";
|
|
48898
48898
|
|
|
48899
|
+
// src/generated/cli-contract/policy-runtime.ts
|
|
48900
|
+
var RISK_ORDER = {
|
|
48901
|
+
low: 0,
|
|
48902
|
+
medium: 1,
|
|
48903
|
+
high: 2,
|
|
48904
|
+
critical: 3
|
|
48905
|
+
};
|
|
48906
|
+
function maxRiskLevel(...levels) {
|
|
48907
|
+
let max = "low";
|
|
48908
|
+
for (const level of levels) {
|
|
48909
|
+
if (RISK_ORDER[level] > RISK_ORDER[max]) {
|
|
48910
|
+
max = level;
|
|
48911
|
+
}
|
|
48912
|
+
}
|
|
48913
|
+
return max;
|
|
48914
|
+
}
|
|
48915
|
+
function isOptionActive(definition, value, specified) {
|
|
48916
|
+
const schemaType = definition.schema?.type;
|
|
48917
|
+
if (schemaType === "boolean") {
|
|
48918
|
+
return value === true;
|
|
48919
|
+
}
|
|
48920
|
+
if (definition.repeatable) {
|
|
48921
|
+
return specified && Array.isArray(value) && value.length > 0;
|
|
48922
|
+
}
|
|
48923
|
+
return specified && value != null;
|
|
48924
|
+
}
|
|
48925
|
+
function derivePolicy(input) {
|
|
48926
|
+
const sideEffects = /* @__PURE__ */ new Set();
|
|
48927
|
+
const reads = [];
|
|
48928
|
+
const writes = [];
|
|
48929
|
+
const networkEffects = [];
|
|
48930
|
+
const riskLevels = [];
|
|
48931
|
+
let executionMode;
|
|
48932
|
+
let explicitConfirmation;
|
|
48933
|
+
if (input.commandEffects) {
|
|
48934
|
+
const ce2 = input.commandEffects;
|
|
48935
|
+
riskLevels.push(ce2.riskLevel ?? "low");
|
|
48936
|
+
if (ce2.writes) {
|
|
48937
|
+
sideEffects.add("file_write");
|
|
48938
|
+
for (const w2 of ce2.writes) {
|
|
48939
|
+
writes.push({
|
|
48940
|
+
kind: "semantic",
|
|
48941
|
+
target: w2.target,
|
|
48942
|
+
description: w2.description,
|
|
48943
|
+
overwrite: w2.overwrite,
|
|
48944
|
+
destructive: w2.destructive,
|
|
48945
|
+
...w2.idempotent !== void 0 ? { idempotent: w2.idempotent } : {},
|
|
48946
|
+
...w2.idempotencyKey ? { idempotencyKey: w2.idempotencyKey } : {},
|
|
48947
|
+
...w2.idempotentNote ? { idempotentNote: w2.idempotentNote } : {},
|
|
48948
|
+
source: `command:${input.commandId}`
|
|
48949
|
+
});
|
|
48950
|
+
}
|
|
48951
|
+
}
|
|
48952
|
+
if (ce2.reads) {
|
|
48953
|
+
for (const r3 of ce2.reads) {
|
|
48954
|
+
reads.push({
|
|
48955
|
+
kind: "semantic",
|
|
48956
|
+
target: r3.target,
|
|
48957
|
+
description: r3.description,
|
|
48958
|
+
source: `command:${input.commandId}`
|
|
48959
|
+
});
|
|
48960
|
+
}
|
|
48961
|
+
}
|
|
48962
|
+
if (ce2.network) {
|
|
48963
|
+
sideEffects.add("network");
|
|
48964
|
+
if (typeof ce2.network === "object") {
|
|
48965
|
+
networkEffects.push({
|
|
48966
|
+
...ce2.network.description ? { description: ce2.network.description } : {},
|
|
48967
|
+
...ce2.network.domains ? { domains: ce2.network.domains } : {},
|
|
48968
|
+
...ce2.network.idempotent !== void 0 ? { idempotent: ce2.network.idempotent } : {},
|
|
48969
|
+
...ce2.network.idempotencyKey ? { idempotencyKey: ce2.network.idempotencyKey } : {},
|
|
48970
|
+
...ce2.network.idempotentNote ? { idempotentNote: ce2.network.idempotentNote } : {},
|
|
48971
|
+
source: `command:${input.commandId}`
|
|
48972
|
+
});
|
|
48973
|
+
}
|
|
48974
|
+
}
|
|
48975
|
+
if (ce2.executionMode) {
|
|
48976
|
+
executionMode = ce2.executionMode;
|
|
48977
|
+
}
|
|
48978
|
+
if (ce2.requiresConfirmation !== void 0) {
|
|
48979
|
+
explicitConfirmation = ce2.requiresConfirmation;
|
|
48980
|
+
}
|
|
48981
|
+
}
|
|
48982
|
+
for (const [optName, optInput] of Object.entries(input.options)) {
|
|
48983
|
+
const { definition, value, specified } = optInput;
|
|
48984
|
+
const active = isOptionActive(definition, value, specified);
|
|
48985
|
+
if (!active) continue;
|
|
48986
|
+
if (definition.file) {
|
|
48987
|
+
const filePath = typeof value === "string" ? value : void 0;
|
|
48988
|
+
const mode = definition.file.mode;
|
|
48989
|
+
if (mode === "read" || mode === "readWrite") {
|
|
48990
|
+
reads.push({
|
|
48991
|
+
kind: "option-file",
|
|
48992
|
+
option: optName,
|
|
48993
|
+
path: filePath,
|
|
48994
|
+
source: `option:${optName}`
|
|
48995
|
+
});
|
|
48996
|
+
}
|
|
48997
|
+
if (mode === "write" || mode === "append" || mode === "readWrite") {
|
|
48998
|
+
sideEffects.add("file_write");
|
|
48999
|
+
writes.push({
|
|
49000
|
+
kind: "option-file",
|
|
49001
|
+
option: optName,
|
|
49002
|
+
path: filePath,
|
|
49003
|
+
mode,
|
|
49004
|
+
source: `option:${optName}`
|
|
49005
|
+
});
|
|
49006
|
+
}
|
|
49007
|
+
}
|
|
49008
|
+
if (definition.effects) {
|
|
49009
|
+
const eff = definition.effects;
|
|
49010
|
+
riskLevels.push(eff.riskLevel ?? "low");
|
|
49011
|
+
if (eff.writes) {
|
|
49012
|
+
sideEffects.add("file_write");
|
|
49013
|
+
for (const w2 of eff.writes) {
|
|
49014
|
+
writes.push({
|
|
49015
|
+
kind: "semantic",
|
|
49016
|
+
target: w2.target,
|
|
49017
|
+
description: w2.description,
|
|
49018
|
+
overwrite: w2.overwrite,
|
|
49019
|
+
destructive: w2.destructive,
|
|
49020
|
+
...w2.idempotent !== void 0 ? { idempotent: w2.idempotent } : {},
|
|
49021
|
+
...w2.idempotencyKey ? { idempotencyKey: w2.idempotencyKey } : {},
|
|
49022
|
+
...w2.idempotentNote ? { idempotentNote: w2.idempotentNote } : {},
|
|
49023
|
+
source: `option:${optName}`
|
|
49024
|
+
});
|
|
49025
|
+
}
|
|
49026
|
+
}
|
|
49027
|
+
if (eff.reads) {
|
|
49028
|
+
for (const r3 of eff.reads) {
|
|
49029
|
+
reads.push({
|
|
49030
|
+
kind: "semantic",
|
|
49031
|
+
target: r3.target,
|
|
49032
|
+
description: r3.description,
|
|
49033
|
+
source: `option:${optName}`
|
|
49034
|
+
});
|
|
49035
|
+
}
|
|
49036
|
+
}
|
|
49037
|
+
if (eff.network) {
|
|
49038
|
+
sideEffects.add("network");
|
|
49039
|
+
if (typeof eff.network === "object") {
|
|
49040
|
+
networkEffects.push({
|
|
49041
|
+
...eff.network.description ? { description: eff.network.description } : {},
|
|
49042
|
+
...eff.network.domains ? { domains: eff.network.domains } : {},
|
|
49043
|
+
...eff.network.idempotent !== void 0 ? { idempotent: eff.network.idempotent } : {},
|
|
49044
|
+
...eff.network.idempotencyKey ? { idempotencyKey: eff.network.idempotencyKey } : {},
|
|
49045
|
+
...eff.network.idempotentNote ? { idempotentNote: eff.network.idempotentNote } : {},
|
|
49046
|
+
source: `option:${optName}`
|
|
49047
|
+
});
|
|
49048
|
+
}
|
|
49049
|
+
}
|
|
49050
|
+
if (eff.executionMode && !executionMode) {
|
|
49051
|
+
executionMode = eff.executionMode;
|
|
49052
|
+
}
|
|
49053
|
+
if (eff.requiresConfirmation !== void 0 && explicitConfirmation === void 0) {
|
|
49054
|
+
explicitConfirmation = eff.requiresConfirmation;
|
|
49055
|
+
}
|
|
49056
|
+
}
|
|
49057
|
+
}
|
|
49058
|
+
const finalRiskLevel = riskLevels.length > 0 ? maxRiskLevel(...riskLevels) : "low";
|
|
49059
|
+
const requiresConfirmation = explicitConfirmation ?? (finalRiskLevel === "high" || finalRiskLevel === "critical");
|
|
49060
|
+
let requiresSecrets;
|
|
49061
|
+
if (input.env) {
|
|
49062
|
+
const secrets = [];
|
|
49063
|
+
for (const [envName, envVar] of Object.entries(input.env)) {
|
|
49064
|
+
if (envVar.sensitive) {
|
|
49065
|
+
secrets.push(envName);
|
|
49066
|
+
}
|
|
49067
|
+
}
|
|
49068
|
+
if (secrets.length > 0) {
|
|
49069
|
+
requiresSecrets = secrets;
|
|
49070
|
+
}
|
|
49071
|
+
}
|
|
49072
|
+
const semanticWrites = writes.filter((w2) => w2.kind === "semantic");
|
|
49073
|
+
const idempotent = semanticWrites.every((w2) => w2.idempotent === true) && networkEffects.every((n3) => n3.idempotent === true);
|
|
49074
|
+
return {
|
|
49075
|
+
riskLevel: finalRiskLevel,
|
|
49076
|
+
requiresConfirmation,
|
|
49077
|
+
idempotent,
|
|
49078
|
+
sideEffects: [...sideEffects],
|
|
49079
|
+
reads,
|
|
49080
|
+
writes,
|
|
49081
|
+
...networkEffects.length > 0 ? { network: networkEffects } : {},
|
|
49082
|
+
...executionMode ? { executionMode } : {},
|
|
49083
|
+
...requiresSecrets ? { requiresSecrets } : {}
|
|
49084
|
+
};
|
|
49085
|
+
}
|
|
49086
|
+
|
|
48899
49087
|
// src/generated/cli-contract/policy.ts
|
|
48900
|
-
import { derivePolicy, isOptionActive } from "cli-contracts/policy";
|
|
48901
49088
|
var commandDefinitions = {
|
|
48902
49089
|
"resolve": {
|
|
48903
49090
|
"options": [
|
|
@@ -50876,24 +51063,39 @@ function mergeDsl(base, project) {
|
|
|
50876
51063
|
|
|
50877
51064
|
// src/resolver/resolve.ts
|
|
50878
51065
|
import { dirname as dirname3, resolve as resolvePath } from "path";
|
|
50879
|
-
async function
|
|
50880
|
-
const
|
|
50881
|
-
const projectResult = await loadDsl(absPath);
|
|
50882
|
-
const projectData = projectResult.data;
|
|
50883
|
-
const extendsValue = projectData["extends"];
|
|
51066
|
+
async function resolveExtendsChain(data, filePath, seen) {
|
|
51067
|
+
const extendsValue = data["extends"];
|
|
50884
51068
|
if (typeof extendsValue !== "string") {
|
|
50885
|
-
return {
|
|
50886
|
-
data: projectData,
|
|
50887
|
-
projectPath: projectResult.filePath
|
|
50888
|
-
};
|
|
51069
|
+
return { data, basePaths: [] };
|
|
50889
51070
|
}
|
|
50890
|
-
const projectDir = dirname3(
|
|
51071
|
+
const projectDir = dirname3(filePath);
|
|
50891
51072
|
const baseResult = await resolveBase(extendsValue, projectDir);
|
|
50892
|
-
const
|
|
51073
|
+
const basePath = baseResult.filePath;
|
|
51074
|
+
if (seen.has(basePath)) {
|
|
51075
|
+
throw new BaseResolveError(
|
|
51076
|
+
`Circular extends detected: ${basePath}`
|
|
51077
|
+
);
|
|
51078
|
+
}
|
|
51079
|
+
seen.add(basePath);
|
|
51080
|
+
const { data: resolvedBase, basePaths: ancestorPaths } = await resolveExtendsChain(baseResult.data, basePath, seen);
|
|
51081
|
+
const merged = mergeDsl(resolvedBase, data);
|
|
50893
51082
|
return {
|
|
50894
51083
|
data: merged,
|
|
51084
|
+
basePaths: [...ancestorPaths, basePath]
|
|
51085
|
+
};
|
|
51086
|
+
}
|
|
51087
|
+
async function resolve4(projectDirOrFile) {
|
|
51088
|
+
const absPath = resolvePath(projectDirOrFile);
|
|
51089
|
+
const projectResult = await loadDsl(absPath);
|
|
51090
|
+
const { data, basePaths } = await resolveExtendsChain(
|
|
51091
|
+
projectResult.data,
|
|
51092
|
+
projectResult.filePath,
|
|
51093
|
+
/* @__PURE__ */ new Set()
|
|
51094
|
+
);
|
|
51095
|
+
return {
|
|
51096
|
+
data,
|
|
50895
51097
|
projectPath: projectResult.filePath,
|
|
50896
|
-
|
|
51098
|
+
basePaths
|
|
50897
51099
|
};
|
|
50898
51100
|
}
|
|
50899
51101
|
|