agent-contracts 0.22.4 → 0.22.6
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 +208 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +20 -3
- 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": [
|
|
@@ -49957,13 +50144,13 @@ var DslSchema = z15.object({
|
|
|
49957
50144
|
// src/schema/json-schema-utils.ts
|
|
49958
50145
|
function resolveAllOf(schema) {
|
|
49959
50146
|
const allOf = schema["allOf"];
|
|
49960
|
-
if (!Array.isArray(allOf)) return schema;
|
|
50147
|
+
if (!Array.isArray(allOf)) return resolveNestedProperties(schema);
|
|
49961
50148
|
let mergedProperties = {};
|
|
49962
50149
|
let mergedRequired = [];
|
|
49963
50150
|
const mergedTop = {};
|
|
49964
50151
|
for (const sub of allOf) {
|
|
49965
50152
|
if (typeof sub !== "object" || sub === null || Array.isArray(sub)) continue;
|
|
49966
|
-
const subSchema = sub;
|
|
50153
|
+
const subSchema = resolveAllOf(sub);
|
|
49967
50154
|
if (subSchema["properties"] && typeof subSchema["properties"] === "object") {
|
|
49968
50155
|
mergedProperties = {
|
|
49969
50156
|
...mergedProperties,
|
|
@@ -49994,13 +50181,30 @@ function resolveAllOf(schema) {
|
|
|
49994
50181
|
}
|
|
49995
50182
|
const result = { ...mergedTop };
|
|
49996
50183
|
if (Object.keys(mergedProperties).length > 0) {
|
|
49997
|
-
result["properties"] = mergedProperties;
|
|
50184
|
+
result["properties"] = resolvePropertySchemas(mergedProperties);
|
|
49998
50185
|
}
|
|
49999
50186
|
if (mergedRequired.length > 0) {
|
|
50000
50187
|
result["required"] = [...new Set(mergedRequired)];
|
|
50001
50188
|
}
|
|
50002
50189
|
return result;
|
|
50003
50190
|
}
|
|
50191
|
+
function resolveNestedProperties(schema) {
|
|
50192
|
+
const props = schema["properties"];
|
|
50193
|
+
if (!props || typeof props !== "object") return schema;
|
|
50194
|
+
return { ...schema, properties: resolvePropertySchemas(props) };
|
|
50195
|
+
}
|
|
50196
|
+
function resolvePropertySchemas(properties) {
|
|
50197
|
+
const result = {};
|
|
50198
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
50199
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
50200
|
+
const propSchema = value;
|
|
50201
|
+
result[key] = propSchema["allOf"] ? resolveAllOf(propSchema) : propSchema;
|
|
50202
|
+
} else {
|
|
50203
|
+
result[key] = value;
|
|
50204
|
+
}
|
|
50205
|
+
}
|
|
50206
|
+
return result;
|
|
50207
|
+
}
|
|
50004
50208
|
|
|
50005
50209
|
// src/schema/merge-operators.ts
|
|
50006
50210
|
import { z as z16 } from "zod";
|