@aaac/runtime 0.1.53 → 0.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/adk-sdk.d.ts +1 -1
- package/dist/adapters/adk-sdk.js +1 -1
- package/dist/adapters/claude-agent-sdk.d.ts +1 -1
- package/dist/adapters/mock.d.ts +1 -1
- package/dist/adapters/openai-agents-sdk.d.ts +1 -1
- package/dist/{chunk-YZQRSVDZ.js → chunk-3H3PVPPF.js} +198 -4
- package/dist/chunk-3H3PVPPF.js.map +1 -0
- package/dist/chunk-LDCQZPDG.js +11 -0
- package/dist/chunk-LDCQZPDG.js.map +1 -0
- package/dist/{chunk-M3GJAHLX.js → chunk-N4KNGDYY.js} +343 -28
- package/dist/chunk-N4KNGDYY.js.map +1 -0
- package/dist/{chunk-EH5VFZYJ.js → chunk-NMX4C6LC.js} +6 -2
- package/dist/chunk-NMX4C6LC.js.map +1 -0
- package/dist/{chunk-KNYJV2Q6.js → chunk-QVH5KKBR.js} +5 -9
- package/dist/chunk-QVH5KKBR.js.map +1 -0
- package/dist/claude-bundles/full.js +223 -217
- package/dist/claude-bundles/lean.js +5 -5
- package/dist/generator/index.d.ts +2 -286
- package/dist/generator/index.js +1 -1
- package/dist/index-LqEvaRk-.d.ts +299 -0
- package/dist/index.d.ts +29 -17
- package/dist/index.js +75 -414
- package/dist/index.js.map +1 -1
- package/dist/lib/claude-native/hooks-lite.d.ts +18 -325
- package/dist/lib/claude-native/hooks-lite.js +8 -2
- package/dist/lib/claude-native/index.d.ts +153 -20
- package/dist/lib/claude-native/index.js +162 -37
- package/dist/lib/claude-native/index.js.map +1 -1
- package/dist/{navigation-context-xrReMkTn.d.ts → navigation-context-D_E1NIUf.d.ts} +11 -3
- package/dist/{task-runner-Sez_CXcD.d.ts → task-runner-CLc8iTzy.d.ts} +5 -8
- package/dist/workspace-pre-tool-use-C6nidc0q.d.ts +333 -0
- package/package.json +1 -1
- package/dist/chunk-EH5VFZYJ.js.map +0 -1
- package/dist/chunk-KNYJV2Q6.js.map +0 -1
- package/dist/chunk-M3GJAHLX.js.map +0 -1
- package/dist/chunk-YZQRSVDZ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,14 +2,11 @@ import {
|
|
|
2
2
|
buildSdkFunctionTools
|
|
3
3
|
} from "./chunk-DBM5XN67.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
loadProjectConfig
|
|
7
|
-
} from "./chunk-YZQRSVDZ.js";
|
|
8
|
-
import {
|
|
5
|
+
BoundResolver,
|
|
9
6
|
DslValidationError,
|
|
10
7
|
buildCandidateAgents,
|
|
11
|
-
buildGuardrailRulesFromDsl,
|
|
12
8
|
buildNavigationContext,
|
|
9
|
+
buildPerAgentGuardrails,
|
|
13
10
|
buildRegistriesFromDsl,
|
|
14
11
|
buildRetryFollowUp,
|
|
15
12
|
buildSplitTaskPrompt,
|
|
@@ -17,12 +14,16 @@ import {
|
|
|
17
14
|
collectAnalyzerToolIds,
|
|
18
15
|
computeCostUsd,
|
|
19
16
|
createAnalyzerBridge,
|
|
17
|
+
deriveToolchainsForAgents,
|
|
20
18
|
emitProcessEdit,
|
|
21
19
|
emitProcessTaskClose,
|
|
22
20
|
emitProcessTaskOpen,
|
|
23
21
|
emitProcessWorkflowClose,
|
|
24
22
|
emitProcessWorkflowOpen,
|
|
25
23
|
extractStructuredResult,
|
|
24
|
+
getEffectiveGuardrailIds,
|
|
25
|
+
getGuardrailRulesForAgent,
|
|
26
|
+
guardrailContextToRuleData,
|
|
26
27
|
isContextPack,
|
|
27
28
|
isFileEditTool,
|
|
28
29
|
isNavigationIndex,
|
|
@@ -31,11 +32,13 @@ import {
|
|
|
31
32
|
renderAnalyzerExplorationMandatePrompt,
|
|
32
33
|
renderContextPackPrompt,
|
|
33
34
|
renderNavigationIndexPrompt,
|
|
35
|
+
resolveArtifacts,
|
|
36
|
+
resolveGuardrailContext,
|
|
34
37
|
runTask,
|
|
35
38
|
shouldInjectAnalyzerExplorationMandate,
|
|
36
39
|
zodSchemaToPromptDescription,
|
|
37
40
|
zodSchemaToYamlExample
|
|
38
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-N4KNGDYY.js";
|
|
39
42
|
import {
|
|
40
43
|
jsonSchemaToZod
|
|
41
44
|
} from "./chunk-ET6TGQRT.js";
|
|
@@ -58,6 +61,14 @@ import {
|
|
|
58
61
|
emitToolchainOpen,
|
|
59
62
|
serializeObserverEmit
|
|
60
63
|
} from "./chunk-KXGUWBGK.js";
|
|
64
|
+
import {
|
|
65
|
+
PROJECT_CONFIG_FILENAME,
|
|
66
|
+
loadProjectConfig,
|
|
67
|
+
loadWorkspaceMembers
|
|
68
|
+
} from "./chunk-3H3PVPPF.js";
|
|
69
|
+
import {
|
|
70
|
+
guardrailCacheKey
|
|
71
|
+
} from "./chunk-LDCQZPDG.js";
|
|
61
72
|
import {
|
|
62
73
|
PluginRegistry,
|
|
63
74
|
createGuardrailHooks,
|
|
@@ -67,7 +78,7 @@ import {
|
|
|
67
78
|
getWarnings,
|
|
68
79
|
hasBlockingViolation,
|
|
69
80
|
pluginRegistry
|
|
70
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-NMX4C6LC.js";
|
|
71
82
|
import {
|
|
72
83
|
__commonJS,
|
|
73
84
|
__require,
|
|
@@ -6803,258 +6814,6 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
|
|
|
6803
6814
|
});
|
|
6804
6815
|
}
|
|
6805
6816
|
|
|
6806
|
-
// src/lib/bound-resolver.ts
|
|
6807
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
6808
|
-
import YAML from "yaml";
|
|
6809
|
-
function getEffectiveGuardrailIds(dsl, agentId) {
|
|
6810
|
-
const ids = /* @__PURE__ */ new Set();
|
|
6811
|
-
const agents = dsl.agents ?? {};
|
|
6812
|
-
const agent = agents[agentId];
|
|
6813
|
-
if (agent) {
|
|
6814
|
-
for (const ref of agent.guardrails ?? []) {
|
|
6815
|
-
ids.add(ref);
|
|
6816
|
-
}
|
|
6817
|
-
}
|
|
6818
|
-
const guardrails = dsl.guardrails ?? {};
|
|
6819
|
-
for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
|
|
6820
|
-
if (guardrail.scope?.agents?.includes(agentId)) {
|
|
6821
|
-
ids.add(guardrailId);
|
|
6822
|
-
}
|
|
6823
|
-
}
|
|
6824
|
-
return ids;
|
|
6825
|
-
}
|
|
6826
|
-
function guardrailCheckToCommandRule(c) {
|
|
6827
|
-
return {
|
|
6828
|
-
guardrail_id: c.guardrail_id,
|
|
6829
|
-
pattern: c.pattern,
|
|
6830
|
-
action: c.action,
|
|
6831
|
-
message: c.message
|
|
6832
|
-
};
|
|
6833
|
-
}
|
|
6834
|
-
function guardrailCheckToFileRule(c) {
|
|
6835
|
-
return {
|
|
6836
|
-
guardrail_id: c.guardrail_id,
|
|
6837
|
-
pattern: c.pattern,
|
|
6838
|
-
action: c.action,
|
|
6839
|
-
message: c.message,
|
|
6840
|
-
...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
|
|
6841
|
-
};
|
|
6842
|
-
}
|
|
6843
|
-
function guardrailCheckToContentRule(c) {
|
|
6844
|
-
return {
|
|
6845
|
-
guardrail_id: c.guardrail_id,
|
|
6846
|
-
pattern: c.pattern,
|
|
6847
|
-
action: c.action,
|
|
6848
|
-
message: c.message,
|
|
6849
|
-
...c.file_glob ? { file_glob: c.file_glob } : {},
|
|
6850
|
-
...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
|
|
6851
|
-
};
|
|
6852
|
-
}
|
|
6853
|
-
function guardrailContextToRuleData(ctx, effectiveIds) {
|
|
6854
|
-
const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
|
|
6855
|
-
return {
|
|
6856
|
-
commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
|
|
6857
|
-
fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
|
|
6858
|
-
contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
|
|
6859
|
-
};
|
|
6860
|
-
}
|
|
6861
|
-
function buildPerAgentGuardrails(dsl, guardrailCtx) {
|
|
6862
|
-
const perAgent = /* @__PURE__ */ new Map();
|
|
6863
|
-
const agents = dsl.agents ?? {};
|
|
6864
|
-
for (const agentId of Object.keys(agents)) {
|
|
6865
|
-
const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
|
|
6866
|
-
const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
|
|
6867
|
-
if (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) {
|
|
6868
|
-
perAgent.set(agentId, rules);
|
|
6869
|
-
}
|
|
6870
|
-
}
|
|
6871
|
-
return perAgent;
|
|
6872
|
-
}
|
|
6873
|
-
function hasGuardrailRules(rules) {
|
|
6874
|
-
return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
|
|
6875
|
-
}
|
|
6876
|
-
function mergeDerivedWithAgentTools(derivedTools, agentToolIds, allToolchains) {
|
|
6877
|
-
const merged = /* @__PURE__ */ new Map();
|
|
6878
|
-
for (const tc of derivedTools) {
|
|
6879
|
-
merged.set(tc.id, tc);
|
|
6880
|
-
}
|
|
6881
|
-
for (const toolId of agentToolIds) {
|
|
6882
|
-
if (!merged.has(toolId)) {
|
|
6883
|
-
if (allToolchains[toolId]) {
|
|
6884
|
-
merged.set(toolId, { ...allToolchains[toolId], source: "merged" });
|
|
6885
|
-
}
|
|
6886
|
-
} else {
|
|
6887
|
-
const existing = merged.get(toolId);
|
|
6888
|
-
merged.set(toolId, { ...existing, source: "merged" });
|
|
6889
|
-
}
|
|
6890
|
-
}
|
|
6891
|
-
return Array.from(merged.values());
|
|
6892
|
-
}
|
|
6893
|
-
function deriveToolchainsForAgents(dsl, toolchains) {
|
|
6894
|
-
const result = /* @__PURE__ */ new Map();
|
|
6895
|
-
const agents = dsl.agents ?? {};
|
|
6896
|
-
for (const [agentId, agent] of Object.entries(agents)) {
|
|
6897
|
-
const derivedTools = [];
|
|
6898
|
-
const canReadArtifacts = agent.can_read_artifacts ?? [];
|
|
6899
|
-
const canWriteArtifacts = agent.can_write_artifacts ?? [];
|
|
6900
|
-
const agentArtifacts = agent.artifacts;
|
|
6901
|
-
const readArtifacts = /* @__PURE__ */ new Set([
|
|
6902
|
-
...canReadArtifacts,
|
|
6903
|
-
...agentArtifacts?.consumes ?? []
|
|
6904
|
-
]);
|
|
6905
|
-
const writeArtifacts = /* @__PURE__ */ new Set([
|
|
6906
|
-
...canWriteArtifacts,
|
|
6907
|
-
...agentArtifacts?.produces ?? []
|
|
6908
|
-
]);
|
|
6909
|
-
for (const tc of Object.values(toolchains)) {
|
|
6910
|
-
let matched = false;
|
|
6911
|
-
for (const artifactId of tc.artifacts.consumes) {
|
|
6912
|
-
if (readArtifacts.has(artifactId) || writeArtifacts.has(artifactId)) {
|
|
6913
|
-
matched = true;
|
|
6914
|
-
break;
|
|
6915
|
-
}
|
|
6916
|
-
}
|
|
6917
|
-
if (!matched) {
|
|
6918
|
-
for (const artifactId of tc.artifacts.produces) {
|
|
6919
|
-
if (writeArtifacts.has(artifactId)) {
|
|
6920
|
-
matched = true;
|
|
6921
|
-
break;
|
|
6922
|
-
}
|
|
6923
|
-
}
|
|
6924
|
-
}
|
|
6925
|
-
if (matched) {
|
|
6926
|
-
derivedTools.push(tc);
|
|
6927
|
-
}
|
|
6928
|
-
}
|
|
6929
|
-
if (derivedTools.length > 0) {
|
|
6930
|
-
const agentTools = agent.can_execute_tools ?? [];
|
|
6931
|
-
const mergedTools = mergeDerivedWithAgentTools(
|
|
6932
|
-
derivedTools,
|
|
6933
|
-
agentTools,
|
|
6934
|
-
toolchains
|
|
6935
|
-
);
|
|
6936
|
-
result.set(agentId, mergedTools);
|
|
6937
|
-
}
|
|
6938
|
-
}
|
|
6939
|
-
return result;
|
|
6940
|
-
}
|
|
6941
|
-
var BoundResolver = class {
|
|
6942
|
-
cache = /* @__PURE__ */ new Map();
|
|
6943
|
-
/**
|
|
6944
|
-
* Resolve binding + policy in one pass. Results are cached by component id.
|
|
6945
|
-
*/
|
|
6946
|
-
async resolve(opts) {
|
|
6947
|
-
const cached = this.cache.get(opts.id);
|
|
6948
|
-
if (cached) return cached;
|
|
6949
|
-
const diagnostics = [];
|
|
6950
|
-
let dsl;
|
|
6951
|
-
if (opts.embeddedDsl) {
|
|
6952
|
-
dsl = opts.embeddedDsl;
|
|
6953
|
-
} else if (opts.dslPath) {
|
|
6954
|
-
const { resolve: resolveDsl } = await import("agent-contracts");
|
|
6955
|
-
const result = await resolveDsl(opts.dslPath);
|
|
6956
|
-
dsl = result.data;
|
|
6957
|
-
} else {
|
|
6958
|
-
throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
|
|
6959
|
-
}
|
|
6960
|
-
if (opts.artifactBinding) {
|
|
6961
|
-
const { resolveBound } = await import("agent-contracts");
|
|
6962
|
-
const boundResult = await resolveBound(dsl, {
|
|
6963
|
-
artifactBinding: opts.artifactBinding,
|
|
6964
|
-
paths: opts.paths
|
|
6965
|
-
});
|
|
6966
|
-
dsl = boundResult.data;
|
|
6967
|
-
for (const d of boundResult.diagnostics) {
|
|
6968
|
-
diagnostics.push({
|
|
6969
|
-
path: d.rule,
|
|
6970
|
-
message: d.message,
|
|
6971
|
-
severity: d.severity
|
|
6972
|
-
});
|
|
6973
|
-
}
|
|
6974
|
-
}
|
|
6975
|
-
let guardrailCtx = {
|
|
6976
|
-
commandChecks: [],
|
|
6977
|
-
fileChecks: [],
|
|
6978
|
-
contentChecks: [],
|
|
6979
|
-
allChecks: [],
|
|
6980
|
-
hasGuardrails: false
|
|
6981
|
-
};
|
|
6982
|
-
if (opts.bindingPaths && opts.bindingPaths.length > 0) {
|
|
6983
|
-
for (const bindingPath of opts.bindingPaths) {
|
|
6984
|
-
const raw = await readFile2(bindingPath, "utf8");
|
|
6985
|
-
const binding = YAML.parse(raw);
|
|
6986
|
-
guardrailCtx = buildGuardrailContext(
|
|
6987
|
-
dsl,
|
|
6988
|
-
binding,
|
|
6989
|
-
opts.activeGuardrailPolicy
|
|
6990
|
-
);
|
|
6991
|
-
}
|
|
6992
|
-
}
|
|
6993
|
-
const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
|
|
6994
|
-
let toolchains;
|
|
6995
|
-
let toolchainsByAgent;
|
|
6996
|
-
if (opts.toolchainContractsPath) {
|
|
6997
|
-
const toolchainPkg = "@aaac/toolchain";
|
|
6998
|
-
const mod = await import(
|
|
6999
|
-
/* webpackIgnore: true */
|
|
7000
|
-
toolchainPkg
|
|
7001
|
-
);
|
|
7002
|
-
const tcDoc = await mod.loadToolchainContracts(opts.toolchainContractsPath);
|
|
7003
|
-
toolchains = {};
|
|
7004
|
-
for (const [id, tc] of Object.entries(tcDoc.toolchains)) {
|
|
7005
|
-
toolchains[id] = {
|
|
7006
|
-
id,
|
|
7007
|
-
kind: tc.kind,
|
|
7008
|
-
description: tc.description,
|
|
7009
|
-
module: tc.module,
|
|
7010
|
-
command: tc.command,
|
|
7011
|
-
cli_contract: tc.cli_contract,
|
|
7012
|
-
component_contract: tc.component_contract,
|
|
7013
|
-
artifacts: {
|
|
7014
|
-
consumes: [...tc.artifacts.consumes],
|
|
7015
|
-
produces: [...tc.artifacts.produces]
|
|
7016
|
-
},
|
|
7017
|
-
operations: tc.operations ? [...tc.operations] : void 0,
|
|
7018
|
-
source: "toolchain-contracts"
|
|
7019
|
-
};
|
|
7020
|
-
}
|
|
7021
|
-
toolchainsByAgent = deriveToolchainsForAgents(dsl, toolchains);
|
|
7022
|
-
}
|
|
7023
|
-
const component = {
|
|
7024
|
-
id: opts.id,
|
|
7025
|
-
dsl,
|
|
7026
|
-
registries: buildRegistriesFromDsl(dsl),
|
|
7027
|
-
guardrails: { perAgent },
|
|
7028
|
-
diagnostics,
|
|
7029
|
-
...toolchains ? { toolchains } : {},
|
|
7030
|
-
...toolchainsByAgent ? { toolchainsByAgent } : {}
|
|
7031
|
-
};
|
|
7032
|
-
this.cache.set(opts.id, component);
|
|
7033
|
-
return component;
|
|
7034
|
-
}
|
|
7035
|
-
/** Clear cached components (e.g. for testing). */
|
|
7036
|
-
clearCache() {
|
|
7037
|
-
this.cache.clear();
|
|
7038
|
-
}
|
|
7039
|
-
};
|
|
7040
|
-
function getGuardrailRulesForAgent(component, agentId, fallbackDsl) {
|
|
7041
|
-
const perAgent = component.guardrails.perAgent.get(agentId);
|
|
7042
|
-
if (perAgent && hasGuardrailRules(perAgent)) {
|
|
7043
|
-
return perAgent;
|
|
7044
|
-
}
|
|
7045
|
-
if (fallbackDsl) {
|
|
7046
|
-
const raw = fallbackDsl._guardrailRules;
|
|
7047
|
-
if (raw) {
|
|
7048
|
-
return {
|
|
7049
|
-
commandRules: raw.commandRules ?? [],
|
|
7050
|
-
fileRules: raw.fileRules ?? [],
|
|
7051
|
-
contentRules: raw.contentRules ?? []
|
|
7052
|
-
};
|
|
7053
|
-
}
|
|
7054
|
-
}
|
|
7055
|
-
return void 0;
|
|
7056
|
-
}
|
|
7057
|
-
|
|
7058
6817
|
// src/lib/builder.ts
|
|
7059
6818
|
function createRuntime(config) {
|
|
7060
6819
|
return {
|
|
@@ -7314,7 +7073,7 @@ var InMemoryStore = class {
|
|
|
7314
7073
|
};
|
|
7315
7074
|
|
|
7316
7075
|
// src/lib/file-memory-store.ts
|
|
7317
|
-
import { mkdir, readFile as
|
|
7076
|
+
import { mkdir, readFile as readFile2, unlink, writeFile } from "fs/promises";
|
|
7318
7077
|
import { join as join3 } from "path";
|
|
7319
7078
|
function resolveFilePath2(baseDir, ref) {
|
|
7320
7079
|
const runId = ref.parent_run_id ?? "unknown";
|
|
@@ -7333,7 +7092,7 @@ var FileMemoryStore = class {
|
|
|
7333
7092
|
async load(ref) {
|
|
7334
7093
|
const filePath = resolveFilePath2(this.baseDir, ref);
|
|
7335
7094
|
try {
|
|
7336
|
-
const raw = await
|
|
7095
|
+
const raw = await readFile2(filePath, "utf-8");
|
|
7337
7096
|
return JSON.parse(raw);
|
|
7338
7097
|
} catch (error) {
|
|
7339
7098
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -7356,7 +7115,7 @@ var FileMemoryStore = class {
|
|
|
7356
7115
|
};
|
|
7357
7116
|
|
|
7358
7117
|
// src/lib/agent-log-writer.ts
|
|
7359
|
-
import { mkdir as mkdir2, readFile as
|
|
7118
|
+
import { mkdir as mkdir2, readFile as readFile3, readdir as readdir2, stat, unlink as unlink2, writeFile as writeFile2, appendFile } from "fs/promises";
|
|
7360
7119
|
import { join as join4 } from "path";
|
|
7361
7120
|
var AgentLogWriter = class {
|
|
7362
7121
|
baseDir;
|
|
@@ -7380,7 +7139,7 @@ var AgentLogWriter = class {
|
|
|
7380
7139
|
async readRunLog(runId) {
|
|
7381
7140
|
const filePath = join4(this.baseDir, "runs", `${runId}.jsonl`);
|
|
7382
7141
|
try {
|
|
7383
|
-
const raw = await
|
|
7142
|
+
const raw = await readFile3(filePath, "utf-8");
|
|
7384
7143
|
return raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
7385
7144
|
} catch (error) {
|
|
7386
7145
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -7398,7 +7157,7 @@ var AgentLogWriter = class {
|
|
|
7398
7157
|
async readHandoff(runId, step) {
|
|
7399
7158
|
const filePath = join4(this.baseDir, "handoffs", `${runId}_${step}.json`);
|
|
7400
7159
|
try {
|
|
7401
|
-
const raw = await
|
|
7160
|
+
const raw = await readFile3(filePath, "utf-8");
|
|
7402
7161
|
return JSON.parse(raw);
|
|
7403
7162
|
} catch (error) {
|
|
7404
7163
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -7695,18 +7454,8 @@ async function resolveExecutionContext(options, requiredEntities) {
|
|
|
7695
7454
|
}
|
|
7696
7455
|
function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
|
|
7697
7456
|
if (adapterOptions.guardrailHooks) return;
|
|
7698
|
-
if (execCtx.resolvedComponent
|
|
7699
|
-
|
|
7700
|
-
execCtx.resolvedComponent,
|
|
7701
|
-
targetAgentId,
|
|
7702
|
-
execCtx.dsl
|
|
7703
|
-
);
|
|
7704
|
-
if (rules2 && (rules2.commandRules.length > 0 || rules2.fileRules.length > 0 || rules2.contentRules.length > 0)) {
|
|
7705
|
-
adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules2);
|
|
7706
|
-
}
|
|
7707
|
-
return;
|
|
7708
|
-
}
|
|
7709
|
-
const rules = buildGuardrailRulesFromDsl(execCtx.dsl);
|
|
7457
|
+
if (!execCtx.resolvedComponent || !targetAgentId) return;
|
|
7458
|
+
const rules = getGuardrailRulesForAgent(execCtx.resolvedComponent, targetAgentId);
|
|
7710
7459
|
if (rules && (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0)) {
|
|
7711
7460
|
adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules);
|
|
7712
7461
|
}
|
|
@@ -7976,11 +7725,8 @@ async function dispatchOperation(operationName, op, options, input, ctx, handler
|
|
|
7976
7725
|
|
|
7977
7726
|
// src/lib/project-runtime.ts
|
|
7978
7727
|
import { existsSync as existsSync3 } from "fs";
|
|
7979
|
-
import { readFile as readFile5 } from "fs/promises";
|
|
7980
7728
|
import { resolve as resolve4, dirname as dirname2 } from "path";
|
|
7981
|
-
import YAML2 from "yaml";
|
|
7982
7729
|
import { createPipeline } from "@aaac/observability";
|
|
7983
|
-
var PROJECT_CONFIG_FILENAME = "project.yaml";
|
|
7984
7730
|
var DEFAULT_ADAPTER = "claude";
|
|
7985
7731
|
function findProjectConfig(startDir, filename = PROJECT_CONFIG_FILENAME) {
|
|
7986
7732
|
let dir = resolve4(startDir);
|
|
@@ -8007,14 +7753,12 @@ async function createProjectRuntime(options) {
|
|
|
8007
7753
|
}
|
|
8008
7754
|
const config = await loadProjectConfig(configPath);
|
|
8009
7755
|
const env = options.env ?? process.env;
|
|
8010
|
-
|
|
8011
|
-
const overlayExplicit = typeof rawManifest?.agents === "string" || typeof rawManifest?.dsl === "string";
|
|
8012
|
-
if (overlayExplicit && !existsSync3(config.dslPath)) {
|
|
7756
|
+
if (config.dslDeclared && !existsSync3(config.dslPath)) {
|
|
8013
7757
|
throw new Error(
|
|
8014
7758
|
`Project agents DSL not found: ${config.dslPath} (referenced by ${configPath}).`
|
|
8015
7759
|
);
|
|
8016
7760
|
}
|
|
8017
|
-
const projectDslPath =
|
|
7761
|
+
const projectDslPath = config.dslDeclared ? config.dslPath : void 0;
|
|
8018
7762
|
let observer;
|
|
8019
7763
|
let observerSink;
|
|
8020
7764
|
let observerClosed = false;
|
|
@@ -8193,29 +7937,9 @@ function createComponentScope(componentIR, binding, options) {
|
|
|
8193
7937
|
};
|
|
8194
7938
|
}
|
|
8195
7939
|
|
|
8196
|
-
// src/lib/artifact-resolver.ts
|
|
8197
|
-
async function resolveArtifacts(options) {
|
|
8198
|
-
if (!options.artifactBinding) {
|
|
8199
|
-
return { dsl: options.dsl, diagnostics: [] };
|
|
8200
|
-
}
|
|
8201
|
-
const { resolveBound } = await import("agent-contracts");
|
|
8202
|
-
const result = await resolveBound(options.dsl, {
|
|
8203
|
-
artifactBinding: options.artifactBinding,
|
|
8204
|
-
paths: options.paths
|
|
8205
|
-
});
|
|
8206
|
-
return {
|
|
8207
|
-
dsl: result.data,
|
|
8208
|
-
diagnostics: result.diagnostics.map((d) => ({
|
|
8209
|
-
path: d.rule,
|
|
8210
|
-
message: d.message,
|
|
8211
|
-
severity: d.severity
|
|
8212
|
-
}))
|
|
8213
|
-
};
|
|
8214
|
-
}
|
|
8215
|
-
|
|
8216
7940
|
// src/lib/guard-commands.ts
|
|
8217
|
-
import { readFile as
|
|
8218
|
-
import
|
|
7941
|
+
import { readFile as readFile4, readdir as readdir3 } from "fs/promises";
|
|
7942
|
+
import "yaml";
|
|
8219
7943
|
async function evaluateGuardrail(opts) {
|
|
8220
7944
|
let hookInput;
|
|
8221
7945
|
try {
|
|
@@ -8225,29 +7949,12 @@ async function evaluateGuardrail(opts) {
|
|
|
8225
7949
|
`Invalid hook JSON: input must be valid JSON. ${cause.message}`
|
|
8226
7950
|
);
|
|
8227
7951
|
}
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
};
|
|
8235
|
-
for (const bindingPath of opts.bindingPaths) {
|
|
8236
|
-
let raw;
|
|
8237
|
-
try {
|
|
8238
|
-
raw = await readFile6(bindingPath, "utf8");
|
|
8239
|
-
} catch (err) {
|
|
8240
|
-
const code = err.code;
|
|
8241
|
-
if (code === "ENOENT") continue;
|
|
8242
|
-
throw err;
|
|
8243
|
-
}
|
|
8244
|
-
const binding = YAML3.parse(raw);
|
|
8245
|
-
guardrailCtx = buildGuardrailContext(
|
|
8246
|
-
opts.dsl,
|
|
8247
|
-
binding,
|
|
8248
|
-
opts.activeGuardrailPolicy
|
|
8249
|
-
);
|
|
8250
|
-
}
|
|
7952
|
+
const guardrailCtx = await resolveGuardrailContext(
|
|
7953
|
+
opts.dsl,
|
|
7954
|
+
opts.bindingPaths,
|
|
7955
|
+
opts.activeGuardrailPolicy,
|
|
7956
|
+
{ skipMissing: true }
|
|
7957
|
+
);
|
|
8251
7958
|
const ruleData = guardrailContextToRuleData(guardrailCtx);
|
|
8252
7959
|
const hooks = createGuardrailHooksFromRules(ruleData);
|
|
8253
7960
|
const command = hookInput.command;
|
|
@@ -8257,9 +7964,10 @@ async function evaluateGuardrail(opts) {
|
|
|
8257
7964
|
const content = hookInput.content;
|
|
8258
7965
|
let response = {};
|
|
8259
7966
|
let checks = [];
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
7967
|
+
const shellCommand = command ?? toolInput?.command;
|
|
7968
|
+
if (shellCommand !== void 0) {
|
|
7969
|
+
response = hooks.beforeShellExecution({ command: shellCommand });
|
|
7970
|
+
checks = hooks.runChecks({ command: shellCommand });
|
|
8263
7971
|
} else if (toolName !== void 0 || toolInput !== void 0) {
|
|
8264
7972
|
response = hooks.preToolUse({ tool_name: toolName, tool_input: toolInput });
|
|
8265
7973
|
const checkFilePath = toolInput?.file_path ?? toolInput?.path ?? "";
|
|
@@ -8274,29 +7982,12 @@ async function evaluateGuardrail(opts) {
|
|
|
8274
7982
|
return { response, exitCode, checks };
|
|
8275
7983
|
}
|
|
8276
7984
|
async function listGuardrails(opts) {
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
};
|
|
8284
|
-
for (const bindingPath of opts.bindingPaths) {
|
|
8285
|
-
let raw;
|
|
8286
|
-
try {
|
|
8287
|
-
raw = await readFile6(bindingPath, "utf8");
|
|
8288
|
-
} catch (err) {
|
|
8289
|
-
const code = err.code;
|
|
8290
|
-
if (code === "ENOENT") continue;
|
|
8291
|
-
throw err;
|
|
8292
|
-
}
|
|
8293
|
-
const binding = YAML3.parse(raw);
|
|
8294
|
-
guardrailCtx = buildGuardrailContext(
|
|
8295
|
-
opts.dsl,
|
|
8296
|
-
binding,
|
|
8297
|
-
opts.activeGuardrailPolicy
|
|
8298
|
-
);
|
|
8299
|
-
}
|
|
7985
|
+
const guardrailCtx = await resolveGuardrailContext(
|
|
7986
|
+
opts.dsl,
|
|
7987
|
+
opts.bindingPaths,
|
|
7988
|
+
opts.activeGuardrailPolicy,
|
|
7989
|
+
{ skipMissing: true }
|
|
7990
|
+
);
|
|
8300
7991
|
const entries = guardrailCtx.allChecks.map(
|
|
8301
7992
|
(c) => ({
|
|
8302
7993
|
guardrail_id: c.guardrail_id,
|
|
@@ -8343,7 +8034,7 @@ async function guardStatus(opts = {}) {
|
|
|
8343
8034
|
const filePath = `${runsDir}/${file}`;
|
|
8344
8035
|
let raw;
|
|
8345
8036
|
try {
|
|
8346
|
-
raw = await
|
|
8037
|
+
raw = await readFile4(filePath, "utf8");
|
|
8347
8038
|
} catch {
|
|
8348
8039
|
continue;
|
|
8349
8040
|
}
|
|
@@ -8366,32 +8057,7 @@ async function guardStatus(opts = {}) {
|
|
|
8366
8057
|
}
|
|
8367
8058
|
|
|
8368
8059
|
// src/lib/claude-materialize/config.ts
|
|
8369
|
-
import { basename as basename2 } from "path";
|
|
8370
8060
|
import { z as z2 } from "zod";
|
|
8371
|
-
var WorkspaceMemberBindingSchema = z2.object({
|
|
8372
|
-
/**
|
|
8373
|
-
* Workspace-relative path to the member directory
|
|
8374
|
-
* (e.g. `"./aaac"`). The member's agent-contracts.yaml is resolved
|
|
8375
|
-
* relative to this directory using `config_path`.
|
|
8376
|
-
*/
|
|
8377
|
-
path: z2.string(),
|
|
8378
|
-
/**
|
|
8379
|
-
* Path to the member's agent-contracts DSL, relative to the member
|
|
8380
|
-
* root. Defaults to `"./agent-contracts.yaml"`.
|
|
8381
|
-
*/
|
|
8382
|
-
config_path: z2.string().optional()
|
|
8383
|
-
});
|
|
8384
|
-
var WorkspaceBindingConfigSchema = z2.object({
|
|
8385
|
-
members: z2.array(WorkspaceMemberBindingSchema),
|
|
8386
|
-
/**
|
|
8387
|
-
* @deprecated Since #241 the generated hook bins are bundled into
|
|
8388
|
-
* self-contained ESM (`@aaac/runtime` inlined) at `claude sync` time, so no
|
|
8389
|
-
* `node_modules` resolution — and thus no `NODE_PATH` export — is needed at
|
|
8390
|
-
* runtime. This field is still accepted for config backward-compatibility but
|
|
8391
|
-
* is ignored (no-op). Remove it from your binding config at your convenience.
|
|
8392
|
-
*/
|
|
8393
|
-
resolve_from: z2.string().optional()
|
|
8394
|
-
});
|
|
8395
8061
|
var ClaudeCommandsEmitSchema = z2.object({
|
|
8396
8062
|
/**
|
|
8397
8063
|
* Project-root-relative output path with a required `{name}` placeholder.
|
|
@@ -8419,7 +8085,13 @@ var ClaudeEmitSchema = z2.object({
|
|
|
8419
8085
|
var ClaudeConfigSchema = z2.object({
|
|
8420
8086
|
/** Root directory for Claude artifacts (relative to the project root). */
|
|
8421
8087
|
output_dir: z2.string().default(".claude"),
|
|
8422
|
-
/**
|
|
8088
|
+
/**
|
|
8089
|
+
* Agents DSL path (relative to the project root) baked into the generated
|
|
8090
|
+
* nav hook bins as the FALLBACK for a project root with no `project.yaml`
|
|
8091
|
+
* (a bare component checkout). When a manifest exists it is authoritative:
|
|
8092
|
+
* the hooks resolve `agents:` and `artifacts:` from it at hook runtime
|
|
8093
|
+
* (#260), so this value is not consulted.
|
|
8094
|
+
*/
|
|
8423
8095
|
config_path: z2.string().default("./agent-contracts.yaml"),
|
|
8424
8096
|
/**
|
|
8425
8097
|
* Additive-artifact emission toggles. Defaults keep the historical
|
|
@@ -8432,27 +8104,8 @@ var ClaudeConfigSchema = z2.object({
|
|
|
8432
8104
|
*/
|
|
8433
8105
|
guard_command: z2.string().optional(),
|
|
8434
8106
|
/** Override component id; defaults to `dsl.system.id`. */
|
|
8435
|
-
component_id: z2.string().optional()
|
|
8436
|
-
/**
|
|
8437
|
-
* Workspace binding configuration. When present the generator emits
|
|
8438
|
-
* workspace-router bins instead of single-component bins (AC3).
|
|
8439
|
-
*/
|
|
8440
|
-
workspace: WorkspaceBindingConfigSchema.optional()
|
|
8107
|
+
component_id: z2.string().optional()
|
|
8441
8108
|
}).strip();
|
|
8442
|
-
function resolveWorkspaceMembers(ws) {
|
|
8443
|
-
return ws.members.map((m) => {
|
|
8444
|
-
const name = basename2(m.path.replace(/\/+$/, "")) || m.path;
|
|
8445
|
-
const configPath = m.config_path ?? "./agent-contracts.yaml";
|
|
8446
|
-
const cacheKey2 = `navigation-index.${name}`;
|
|
8447
|
-
return {
|
|
8448
|
-
name,
|
|
8449
|
-
path: m.path,
|
|
8450
|
-
configPath,
|
|
8451
|
-
cacheKey: cacheKey2,
|
|
8452
|
-
guardrailCacheKey: `${cacheKey2}.guardrails`
|
|
8453
|
-
};
|
|
8454
|
-
});
|
|
8455
|
-
}
|
|
8456
8109
|
function parseClaudeConfig(raw) {
|
|
8457
8110
|
return ClaudeConfigSchema.parse(raw ?? {});
|
|
8458
8111
|
}
|
|
@@ -8995,7 +8648,7 @@ function renderCommandFiles(dsl, outputTemplate, templateSource) {
|
|
|
8995
8648
|
|
|
8996
8649
|
// src/lib/claude-materialize/materialize.ts
|
|
8997
8650
|
import { existsSync as existsSync4 } from "fs";
|
|
8998
|
-
import { mkdir as mkdir3, readFile as
|
|
8651
|
+
import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
8999
8652
|
import { dirname as dirname5, join as join7, resolve as resolve5 } from "path";
|
|
9000
8653
|
import {
|
|
9001
8654
|
claudeGenerator
|
|
@@ -9253,14 +8906,23 @@ function absPath(root, file) {
|
|
|
9253
8906
|
}
|
|
9254
8907
|
async function readIfExists(path) {
|
|
9255
8908
|
if (!existsSync4(path)) return void 0;
|
|
9256
|
-
return
|
|
8909
|
+
return readFile5(path, "utf8");
|
|
8910
|
+
}
|
|
8911
|
+
async function workspaceMembersForProject(root) {
|
|
8912
|
+
const manifestPath = join7(root, PROJECT_CONFIG_FILENAME);
|
|
8913
|
+
if (!existsSync4(manifestPath)) return [];
|
|
8914
|
+
const members = await loadWorkspaceMembers(manifestPath);
|
|
8915
|
+
return members.map((m) => ({
|
|
8916
|
+
name: m.name,
|
|
8917
|
+
path: m.path,
|
|
8918
|
+
cacheKey: m.cacheKey,
|
|
8919
|
+
guardrailCacheKey: guardrailCacheKey(m.cacheKey)
|
|
8920
|
+
}));
|
|
9257
8921
|
}
|
|
9258
|
-
function renderFiles(dsl, config) {
|
|
8922
|
+
async function renderFiles(root, dsl, config) {
|
|
9259
8923
|
const ir = buildComponentIR(dsl, config);
|
|
9260
|
-
const
|
|
9261
|
-
|
|
9262
|
-
resolve_from: config.workspace.resolve_from
|
|
9263
|
-
} : void 0;
|
|
8924
|
+
const members = await workspaceMembersForProject(root);
|
|
8925
|
+
const workspaceOptions = members.length > 0 ? { members } : void 0;
|
|
9264
8926
|
return claudeGenerator.generate(ir, {
|
|
9265
8927
|
outputDir: "",
|
|
9266
8928
|
componentPath: "",
|
|
@@ -9353,7 +9015,7 @@ async function commandFiles(dsl, config, root) {
|
|
|
9353
9015
|
let templateSource = DEFAULT_COMMAND_TEMPLATE;
|
|
9354
9016
|
if (commands.template) {
|
|
9355
9017
|
const templatePath = resolve5(root, commands.template);
|
|
9356
|
-
templateSource = await
|
|
9018
|
+
templateSource = await readFile5(templatePath, "utf8");
|
|
9357
9019
|
}
|
|
9358
9020
|
return renderCommandFiles(dsl, outputTemplate, templateSource);
|
|
9359
9021
|
}
|
|
@@ -9365,7 +9027,7 @@ async function syncClaude(opts) {
|
|
|
9365
9027
|
const config = parseClaudeConfig(opts.config);
|
|
9366
9028
|
const root = resolve5(opts.projectRoot);
|
|
9367
9029
|
const result = { files: [] };
|
|
9368
|
-
for (const file of renderFiles(opts.dsl, config)) {
|
|
9030
|
+
for (const file of await renderFiles(root, opts.dsl, config)) {
|
|
9369
9031
|
const rel = relPath(file);
|
|
9370
9032
|
const abs = absPath(root, file);
|
|
9371
9033
|
const existing = await readIfExists(abs);
|
|
@@ -9407,7 +9069,7 @@ async function checkClaude(opts) {
|
|
|
9407
9069
|
const config = parseClaudeConfig(opts.config);
|
|
9408
9070
|
const root = resolve5(opts.projectRoot);
|
|
9409
9071
|
const drift = [];
|
|
9410
|
-
for (const file of renderFiles(opts.dsl, config)) {
|
|
9072
|
+
for (const file of await renderFiles(root, opts.dsl, config)) {
|
|
9411
9073
|
const rel = relPath(file);
|
|
9412
9074
|
const existing = await readIfExists(absPath(root, file));
|
|
9413
9075
|
if (isHookBin(file.targetDir, file.path)) {
|
|
@@ -9441,7 +9103,7 @@ async function checkClaude(opts) {
|
|
|
9441
9103
|
}
|
|
9442
9104
|
|
|
9443
9105
|
// src/lib/prompt-executor.ts
|
|
9444
|
-
import * as
|
|
9106
|
+
import * as YAML2 from "yaml";
|
|
9445
9107
|
function unwrapInputSchema(input) {
|
|
9446
9108
|
if (!input) {
|
|
9447
9109
|
return { type: "object", properties: {} };
|
|
@@ -9500,7 +9162,7 @@ function parseRouterResponse(response, validNames) {
|
|
|
9500
9162
|
const content = yamlMatch ? yamlMatch[1].trim() : response.trim();
|
|
9501
9163
|
let parsed;
|
|
9502
9164
|
try {
|
|
9503
|
-
parsed =
|
|
9165
|
+
parsed = YAML2.parse(content);
|
|
9504
9166
|
} catch {
|
|
9505
9167
|
const jsonMatch = response.match(/\{[\s\S]*"operation"[\s\S]*\}/);
|
|
9506
9168
|
if (jsonMatch) {
|
|
@@ -9571,7 +9233,6 @@ export {
|
|
|
9571
9233
|
WorkflowBuilder,
|
|
9572
9234
|
buildCandidateAgents,
|
|
9573
9235
|
buildGateEvaluationPrompt,
|
|
9574
|
-
buildGuardrailRulesFromDsl,
|
|
9575
9236
|
buildNavigationContext,
|
|
9576
9237
|
buildObservabilityEnv,
|
|
9577
9238
|
buildPerAgentGuardrails,
|