@aaac/runtime 0.1.25 → 0.1.27

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/index.js CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  pluginRegistry
10
10
  } from "./chunk-GZCEEIXQ.js";
11
11
  import {
12
+ OBSERVABILITY_ENV_VARS,
13
+ buildObservabilityEnv,
12
14
  buildSdkFunctionTools,
13
15
  createExecutionEnvelope,
14
16
  emitIterationClose,
@@ -24,7 +26,7 @@ import {
24
26
  emitToolExecOpen,
25
27
  emitToolchainClose,
26
28
  emitToolchainOpen
27
- } from "./chunk-3EWHYMKL.js";
29
+ } from "./chunk-HGI5VP4G.js";
28
30
  import {
29
31
  buildGuardrailContext,
30
32
  loadProjectConfig
@@ -576,6 +578,46 @@ function renderYamlObject(schema, indent, maxDepth) {
576
578
  }
577
579
  return lines.join("\n");
578
580
  }
581
+ function isNavigationIndex(value) {
582
+ if (typeof value !== "object" || value === null) return false;
583
+ const obj = value;
584
+ return typeof obj.system === "object" && obj.system !== null && typeof obj.artifacts === "object" && obj.artifacts !== null;
585
+ }
586
+ function renderNavigationIndexPrompt(navigationIndex) {
587
+ const system = navigationIndex.system;
588
+ const artifacts = navigationIndex.artifacts ?? {};
589
+ const ids = Object.keys(artifacts);
590
+ const sections = ["## Project Navigation Index"];
591
+ const systemLabel = system?.name ? `${system.name}${system.id ? ` (${system.id})` : ""}` : system?.id ?? "unknown";
592
+ sections.push(
593
+ `System: ${systemLabel}
594
+ Artifacts: ${ids.length}`
595
+ );
596
+ if (ids.length > 0) {
597
+ const lines = [];
598
+ for (const id of ids) {
599
+ const node = artifacts[id] ?? {};
600
+ const props = node.properties ?? {};
601
+ const tags = [props.type, props.authority].filter((v) => typeof v === "string" && v.length > 0).join(", ");
602
+ const editPolicy = typeof props.manual_edit === "string" ? `, edit:${props.manual_edit}` : "";
603
+ lines.push(`- ${id}${tags || editPolicy ? ` [${tags}${editPolicy}]` : ""}`);
604
+ const patterns = node.files?.path_patterns;
605
+ if (Array.isArray(patterns) && patterns.length > 0) {
606
+ lines.push(` files: ${patterns.join(", ")}`);
607
+ }
608
+ const derived = node.relations?.derived_artifacts;
609
+ if (Array.isArray(derived) && derived.length > 0) {
610
+ lines.push(` derived \u2192 ${derived.join(", ")}`);
611
+ }
612
+ const owners = node.agents?.owners;
613
+ if (Array.isArray(owners) && owners.length > 0) {
614
+ lines.push(` owners: ${owners.join(", ")}`);
615
+ }
616
+ }
617
+ sections.push(lines.join("\n"));
618
+ }
619
+ return sections.join("\n\n");
620
+ }
579
621
  function buildSplitTaskPrompt(agent, task, context, options) {
580
622
  const system = [];
581
623
  system.push(renderAgentSystemPrompt(agent));
@@ -667,8 +709,12 @@ ${context.acceptance_criteria.map((c) => `- ${c}`).join("\n")}`
667
709
  if (isContextPack(contextPack)) {
668
710
  userSections.push(renderContextPackPrompt(contextPack));
669
711
  }
712
+ const navigationIndex = context.variables.navigationIndex;
713
+ if (isNavigationIndex(navigationIndex)) {
714
+ userSections.push(renderNavigationIndexPrompt(navigationIndex));
715
+ }
670
716
  const otherVars = Object.entries(context.variables).filter(
671
- ([k]) => k !== "analyzerContextPack"
717
+ ([k]) => k !== "analyzerContextPack" && k !== "navigationIndex"
672
718
  );
673
719
  if (otherVars.length > 0) {
674
720
  const varLines = otherVars.map(([k, v]) => `- ${k}: ${typeof v === "string" ? v : JSON.stringify(v)}`).join("\n");
@@ -903,6 +949,7 @@ async function runTask(adapter, taskId, context, options) {
903
949
  taskId,
904
950
  agentContract.role_name
905
951
  );
952
+ const agentSessionId = options?.parentSpanId ?? taskEnvelope.parent_run_id ?? taskEnvelope.run_id;
906
953
  let closeStatus = "error";
907
954
  let closeCause;
908
955
  let spanClosed = false;
@@ -952,10 +999,10 @@ async function runTask(adapter, taskId, context, options) {
952
999
  memoryRef,
953
1000
  splitPrompt,
954
1001
  agents,
955
- options: { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId, maxFollowUps, attempt: 0 }
1002
+ options: { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId, sessionId: agentSessionId, maxFollowUps, attempt: 0 }
956
1003
  });
957
1004
  } else {
958
- fullOutput = await adapter.send(prompt, { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId });
1005
+ fullOutput = await adapter.send(prompt, { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId, sessionId: agentSessionId });
959
1006
  }
960
1007
  } catch (err) {
961
1008
  closeStatus = "error";
@@ -1080,11 +1127,13 @@ async function tryManifestFastPath(toolchainId, cwd) {
1080
1127
  return null;
1081
1128
  }
1082
1129
  }
1083
- async function executeCheck(command, cwd) {
1130
+ async function executeCheck(command, cwd, observabilityIds) {
1131
+ const env = observabilityIds ? buildObservabilityEnv(observabilityIds) : void 0;
1084
1132
  try {
1085
1133
  const { stdout, stderr } = await execFileAsync("sh", ["-c", command], {
1086
1134
  cwd,
1087
- timeout: SUBPROCESS_TIMEOUT_MS
1135
+ timeout: SUBPROCESS_TIMEOUT_MS,
1136
+ ...env ? { env } : {}
1088
1137
  });
1089
1138
  return { exitCode: 0, stdout, stderr };
1090
1139
  } catch (err) {
@@ -1110,7 +1159,8 @@ async function runToolchainChecks(options) {
1110
1159
  defaultAction,
1111
1160
  observer,
1112
1161
  parentSpanId,
1113
- componentId
1162
+ componentId,
1163
+ observabilityIds
1114
1164
  } = options;
1115
1165
  const cwd = workingDir ?? process.cwd();
1116
1166
  const contracts = await parseToolchainFile(toolchainsPath);
@@ -1137,7 +1187,7 @@ async function runToolchainChecks(options) {
1137
1187
  result = fastResult;
1138
1188
  } else {
1139
1189
  try {
1140
- const { exitCode, stderr } = await executeCheck(command, cwd);
1190
+ const { exitCode, stderr } = await executeCheck(command, cwd, observabilityIds);
1141
1191
  const durationMs = Math.round(performance.now() - start);
1142
1192
  result = {
1143
1193
  toolchainId,
@@ -1637,7 +1687,13 @@ ${JSON.stringify(data, null, 2)}`;
1637
1687
  await runToolchainChecks({
1638
1688
  ...options.toolchain,
1639
1689
  observer: options.observer,
1640
- parentSpanId: sessionSpanId
1690
+ parentSpanId: sessionSpanId,
1691
+ // Propagate session correlation to any git spawned by a check (#115):
1692
+ // the session id is the agent.session run_id (== sessionSpanId).
1693
+ observabilityIds: {
1694
+ sessionId: sessionSpanId ?? sessionEnvelope.run_id,
1695
+ runId: sessionEnvelope.run_id
1696
+ }
1641
1697
  });
1642
1698
  } catch {
1643
1699
  }
@@ -2856,6 +2912,59 @@ Install it with: npm install ${pkg2}`
2856
2912
 
2857
2913
  // src/lib/execute.ts
2858
2914
  import { resolve as resolve3 } from "path";
2915
+
2916
+ // src/lib/navigation-context.ts
2917
+ async function buildNavigationContext(options) {
2918
+ const diagnostics = [];
2919
+ let dsl;
2920
+ if (options.embeddedDsl != null) {
2921
+ if (options.projectDslPath) {
2922
+ const ctx = await loadDslContext({
2923
+ embeddedDsl: options.embeddedDsl,
2924
+ projectDslPath: options.projectDslPath
2925
+ });
2926
+ dsl = ctx.dsl;
2927
+ } else {
2928
+ dsl = options.embeddedDsl;
2929
+ }
2930
+ } else if (options.projectDslPath) {
2931
+ const { resolve: resolve5 } = await import("agent-contracts");
2932
+ const result = await resolve5(options.projectDslPath);
2933
+ dsl = result.data;
2934
+ } else {
2935
+ throw new Error("buildNavigationContext requires embeddedDsl or projectDslPath");
2936
+ }
2937
+ if (options.artifactBinding) {
2938
+ const { resolveBound } = await import("agent-contracts");
2939
+ const boundResult = await resolveBound(dsl, {
2940
+ artifactBinding: options.artifactBinding,
2941
+ paths: options.paths
2942
+ });
2943
+ dsl = boundResult.data;
2944
+ for (const d of boundResult.diagnostics) {
2945
+ diagnostics.push({
2946
+ path: d.rule,
2947
+ message: d.message,
2948
+ severity: d.severity
2949
+ });
2950
+ }
2951
+ }
2952
+ const { validateSchema, buildNavigationIndex } = await import("agent-contracts");
2953
+ const validation = validateSchema(dsl);
2954
+ for (const d of validation.diagnostics) {
2955
+ diagnostics.push({
2956
+ path: d.path,
2957
+ message: d.message,
2958
+ severity: d.severity ?? "error"
2959
+ });
2960
+ }
2961
+ const navigationIndex = buildNavigationIndex(
2962
+ validation.data ?? dsl
2963
+ );
2964
+ return { dsl, navigationIndex, diagnostics };
2965
+ }
2966
+
2967
+ // src/lib/execute.ts
2859
2968
  async function resolveExecutionContext(options, requiredEntities) {
2860
2969
  const useBoundResolver = options.resolvedComponent || options.bindingPaths && options.bindingPaths.length > 0 || options.artifactBinding;
2861
2970
  if (useBoundResolver) {
@@ -2913,11 +3022,35 @@ function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
2913
3022
  adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules);
2914
3023
  }
2915
3024
  }
2916
- function buildAnalyzerToolRegistry() {
2917
- const bridge = createAnalyzerBridge({ projectRoot: process.cwd() });
3025
+ function buildAnalyzerToolRegistry(options = {}) {
3026
+ const bridge = createAnalyzerBridge({
3027
+ projectRoot: options.projectRoot ?? process.cwd(),
3028
+ navigationIndex: options.navigationIndex,
3029
+ artifactPatterns: options.artifactPatterns
3030
+ });
2918
3031
  const tools = bridge.buildAnalyzerTools();
2919
3032
  return createRegistryFromSdkTools(tools);
2920
3033
  }
3034
+ function deriveArtifactPatterns(navigationIndex) {
3035
+ const patterns = /* @__PURE__ */ new Map();
3036
+ const artifacts = navigationIndex?.artifacts;
3037
+ if (!artifacts) return patterns;
3038
+ for (const [id, node] of Object.entries(artifacts)) {
3039
+ const pp = node?.files?.path_patterns;
3040
+ if (Array.isArray(pp) && pp.length > 0) {
3041
+ patterns.set(id, pp);
3042
+ }
3043
+ }
3044
+ return patterns;
3045
+ }
3046
+ async function buildNavigationContextSafely(execCtx) {
3047
+ if (!execCtx.dsl) return void 0;
3048
+ try {
3049
+ return await buildNavigationContext({ embeddedDsl: execCtx.dsl });
3050
+ } catch {
3051
+ return void 0;
3052
+ }
3053
+ }
2921
3054
  async function executeTask(taskId, options) {
2922
3055
  const execCtx = await resolveExecutionContext(options, { tasks: [taskId] });
2923
3056
  const targetAgentId = execCtx.registries.taskRegistry?.[taskId]?.target_agent;
@@ -2930,12 +3063,20 @@ async function executeTask(taskId, options) {
2930
3063
  const progressSink = createProgressSink(
2931
3064
  options.logFile ? { stderr: true, file: resolve3(options.logFile), naming: "single" } : { stderr: true }
2932
3065
  );
2933
- const analyzerTools = buildAnalyzerToolRegistry();
3066
+ const navContext = await buildNavigationContextSafely(execCtx);
3067
+ const analyzerTools = buildAnalyzerToolRegistry({
3068
+ navigationIndex: navContext?.navigationIndex,
3069
+ artifactPatterns: deriveArtifactPatterns(navContext?.navigationIndex)
3070
+ });
3071
+ const taskContext = { user_request: options.request };
3072
+ if (navContext?.navigationIndex) {
3073
+ taskContext.variables = { navigationIndex: navContext.navigationIndex };
3074
+ }
2934
3075
  try {
2935
3076
  if (options.hooks?.beforeTask) {
2936
3077
  await options.hooks.beforeTask({ adapter, registries: execCtx.registries, taskId });
2937
3078
  }
2938
- const result = await runTask(adapter, taskId, { user_request: options.request }, {
3079
+ const result = await runTask(adapter, taskId, taskContext, {
2939
3080
  maxFollowUps: options.maxFollowUps ?? 2,
2940
3081
  maxRetries: options.maxRetries ?? 0,
2941
3082
  progressOutput: progressSink,
@@ -2962,7 +3103,18 @@ async function executeWorkflow(workflowId, options) {
2962
3103
  const progressSink = createProgressSink(
2963
3104
  options.logFile ? { stderr: true, file: resolve3(options.logFile), naming: "single" } : { stderr: true }
2964
3105
  );
2965
- const analyzerTools = buildAnalyzerToolRegistry();
3106
+ const navContext = await buildNavigationContextSafely(execCtx);
3107
+ const analyzerTools = buildAnalyzerToolRegistry({
3108
+ navigationIndex: navContext?.navigationIndex,
3109
+ artifactPatterns: deriveArtifactPatterns(navContext?.navigationIndex)
3110
+ });
3111
+ const workflowContext = navContext?.navigationIndex ? {
3112
+ ...options.context,
3113
+ variables: {
3114
+ ...options.context?.variables,
3115
+ navigationIndex: navContext.navigationIndex
3116
+ }
3117
+ } : options.context;
2966
3118
  try {
2967
3119
  if (options.hooks?.beforeWorkflow) {
2968
3120
  await options.hooks.beforeWorkflow({ adapter, registries: execCtx.registries, workflowId });
@@ -2984,7 +3136,7 @@ async function executeWorkflow(workflowId, options) {
2984
3136
  onGate: options.hooks?.onGate ?? (options.autoApproveGates ? async () => true : void 0),
2985
3137
  onOptionalStep: options.hooks?.onOptionalStep
2986
3138
  },
2987
- context: options.context
3139
+ context: workflowContext
2988
3140
  };
2989
3141
  const result = await runWorkflow(adapter, invocation, execCtx.registries);
2990
3142
  if (options.hooks?.afterWorkflow) {
@@ -3329,57 +3481,6 @@ function createComponentScope(componentIR, binding, options) {
3329
3481
  };
3330
3482
  }
3331
3483
 
3332
- // src/lib/navigation-context.ts
3333
- async function buildNavigationContext(options) {
3334
- const diagnostics = [];
3335
- let dsl;
3336
- if (options.embeddedDsl != null) {
3337
- if (options.projectDslPath) {
3338
- const ctx = await loadDslContext({
3339
- embeddedDsl: options.embeddedDsl,
3340
- projectDslPath: options.projectDslPath
3341
- });
3342
- dsl = ctx.dsl;
3343
- } else {
3344
- dsl = options.embeddedDsl;
3345
- }
3346
- } else if (options.projectDslPath) {
3347
- const { resolve: resolve5 } = await import("agent-contracts");
3348
- const result = await resolve5(options.projectDslPath);
3349
- dsl = result.data;
3350
- } else {
3351
- throw new Error("buildNavigationContext requires embeddedDsl or projectDslPath");
3352
- }
3353
- if (options.artifactBinding) {
3354
- const { resolveBound } = await import("agent-contracts");
3355
- const boundResult = await resolveBound(dsl, {
3356
- artifactBinding: options.artifactBinding,
3357
- paths: options.paths
3358
- });
3359
- dsl = boundResult.data;
3360
- for (const d of boundResult.diagnostics) {
3361
- diagnostics.push({
3362
- path: d.rule,
3363
- message: d.message,
3364
- severity: d.severity
3365
- });
3366
- }
3367
- }
3368
- const { validateSchema, buildNavigationIndex } = await import("agent-contracts");
3369
- const validation = validateSchema(dsl);
3370
- for (const d of validation.diagnostics) {
3371
- diagnostics.push({
3372
- path: d.path,
3373
- message: d.message,
3374
- severity: d.severity ?? "error"
3375
- });
3376
- }
3377
- const navigationIndex = buildNavigationIndex(
3378
- validation.data ?? dsl
3379
- );
3380
- return { dsl, navigationIndex, diagnostics };
3381
- }
3382
-
3383
3484
  // src/lib/artifact-resolver.ts
3384
3485
  async function resolveArtifacts(options) {
3385
3486
  if (!options.artifactBinding) {
@@ -3675,6 +3776,7 @@ export {
3675
3776
  DslValidationError,
3676
3777
  FileMemoryStore,
3677
3778
  InMemoryStore,
3779
+ OBSERVABILITY_ENV_VARS,
3678
3780
  PROJECT_CONFIG_FILENAME,
3679
3781
  PluginRegistry,
3680
3782
  ToolchainManifestSchema,
@@ -3683,6 +3785,7 @@ export {
3683
3785
  buildGateEvaluationPrompt,
3684
3786
  buildGuardrailRulesFromDsl,
3685
3787
  buildNavigationContext,
3788
+ buildObservabilityEnv,
3686
3789
  buildPerAgentGuardrails,
3687
3790
  buildRegistriesFromDsl,
3688
3791
  buildRetryFollowUp,
@@ -3736,6 +3839,7 @@ export {
3736
3839
  guardrailContextToRuleData,
3737
3840
  hasBlockingViolation,
3738
3841
  isContextPack,
3842
+ isNavigationIndex,
3739
3843
  jsonSchemaToZod,
3740
3844
  listGuardrails,
3741
3845
  loadDslContext,
@@ -3748,6 +3852,7 @@ export {
3748
3852
  pluginRegistry,
3749
3853
  renderAgentSystemPrompt,
3750
3854
  renderContextPackPrompt,
3855
+ renderNavigationIndexPrompt,
3751
3856
  resolveArtifacts,
3752
3857
  runTask,
3753
3858
  runToolchainChecks,