@aaac/runtime 0.1.35 → 0.1.36

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.d.ts CHANGED
@@ -115,6 +115,12 @@ interface ProcessEditOptions {
115
115
  /** Optional observer — no-op when undefined. */
116
116
  observer?: ObserverEmitFn;
117
117
  }
118
+ /**
119
+ * True when a tool name denotes a file-mutating edit, so a process.edit event
120
+ * should be emitted for it. Used by the task runner to instrument the Process
121
+ * axis from live tool-use progress events (#167).
122
+ */
123
+ declare function isFileEditTool(toolName: string | undefined): boolean;
118
124
  /**
119
125
  * Emit process.workflow open span.
120
126
  */
@@ -873,4 +879,4 @@ declare function executePrompt(message: string, ir: ComponentIR, binding: Runtim
873
879
  /** Package version string. */
874
880
  declare const version: string;
875
881
 
876
- export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime, AgentContractLike, AgentLogWriter, type AgentLogWriterOptions, type AgentPlugin, type AnalyzeImpactInput, type AnalyzerBridge, type AnalyzerBridgeOptions, ArtifactBindingConfig, type ArtifactResolveOptions, type ArtifactResolveResult, type BuildCallGraphInput, type ComponentScope, type CreateAdapterOptions, type CreateComponentScopeOptions, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type EvaluateGuardrailOptions, type EvaluateGuardrailResult, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, type GenerateContextPackInput, type GuardStatusOptions, type GuardStatusResult, GuardrailCheckResult, GuardrailHooks, type GuardrailListEntry, type GuardrailResult, GuardrailRuleData, HandoffInput, HookResponse, LibraryToolDefinition, LibraryToolRegistry, type ListGuardrailsOptions, type ListGuardrailsResult, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, ModelMappingConfig, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, type OperationToolDef, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type PromptExecuteOptions, type PromptResult, type RequiredEntities, type ResolvedAdapterSelection, ResolvedComponent, ResolvedToolchain, type RunLogEvent, RunToolchainChecksOptions, type Runtime, type RuntimeBinding, type RuntimeConfig, SdkAdapter, SdkFunctionTool, StepCompleteEvent, StepResult, TaskContext, TaskContractLike, type TaskHookContext, TaskOutcome, TaskRunResult, WorkflowBuilder, type WorkflowHookContext, WorkflowRegistries, WorkflowResult, buildGuardrailRulesFromDsl, buildNavigationContext, buildRegistriesFromDsl, createAdapter, createAnalyzerBridge, createComponentScope, createProgressSink, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, evaluateGuardrail, executePrompt, executeTask, executeWorkflow, findProjectConfig, guardStatus, isContextPack, jsonSchemaToZod, listGuardrails, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, operationsToTools, parseRouterResponse, pluginRegistry, renderContextPackPrompt, resolveArtifacts, version };
882
+ export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime, AgentContractLike, AgentLogWriter, type AgentLogWriterOptions, type AgentPlugin, type AnalyzeImpactInput, type AnalyzerBridge, type AnalyzerBridgeOptions, ArtifactBindingConfig, type ArtifactResolveOptions, type ArtifactResolveResult, type BuildCallGraphInput, type ComponentScope, type CreateAdapterOptions, type CreateComponentScopeOptions, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type EvaluateGuardrailOptions, type EvaluateGuardrailResult, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, type GenerateContextPackInput, type GuardStatusOptions, type GuardStatusResult, GuardrailCheckResult, GuardrailHooks, type GuardrailListEntry, type GuardrailResult, GuardrailRuleData, HandoffInput, HookResponse, LibraryToolDefinition, LibraryToolRegistry, type ListGuardrailsOptions, type ListGuardrailsResult, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, ModelMappingConfig, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, type OperationToolDef, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type PromptExecuteOptions, type PromptResult, type RequiredEntities, type ResolvedAdapterSelection, ResolvedComponent, ResolvedToolchain, type RunLogEvent, RunToolchainChecksOptions, type Runtime, type RuntimeBinding, type RuntimeConfig, SdkAdapter, SdkFunctionTool, StepCompleteEvent, StepResult, TaskContext, TaskContractLike, type TaskHookContext, TaskOutcome, TaskRunResult, WorkflowBuilder, type WorkflowHookContext, WorkflowRegistries, WorkflowResult, buildGuardrailRulesFromDsl, buildNavigationContext, buildRegistriesFromDsl, createAdapter, createAnalyzerBridge, createComponentScope, createProgressSink, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, evaluateGuardrail, executePrompt, executeTask, executeWorkflow, findProjectConfig, guardStatus, isContextPack, isFileEditTool, jsonSchemaToZod, listGuardrails, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, operationsToTools, parseRouterResponse, pluginRegistry, renderContextPackPrompt, resolveArtifacts, version };
package/dist/index.js CHANGED
@@ -392,6 +392,110 @@ ${fileBlocks.join("\n\n")}`);
392
392
  return sections.join("\n\n");
393
393
  }
394
394
 
395
+ // src/lib/process-axis-bridge.ts
396
+ import { generateId } from "@aaac/observability";
397
+ function attrs(base) {
398
+ const out = {};
399
+ for (const [k, v] of Object.entries(base)) {
400
+ if (v !== void 0 && v !== "") out[k] = v;
401
+ }
402
+ return out;
403
+ }
404
+ var FILE_EDIT_TOOL_NAMES = /* @__PURE__ */ new Set([
405
+ "write",
406
+ "edit",
407
+ "multiedit",
408
+ "multi_edit",
409
+ "notebookedit",
410
+ "notebook_edit"
411
+ ]);
412
+ function isFileEditTool(toolName) {
413
+ if (!toolName) return false;
414
+ return FILE_EDIT_TOOL_NAMES.has(toolName.toLowerCase());
415
+ }
416
+ function emitProcessWorkflowOpen(options) {
417
+ if (!options.observer) return void 0;
418
+ const spanId = generateId();
419
+ options.observer({
420
+ source: "aaac-runtime",
421
+ eventType: "process.workflow",
422
+ lifecycle: "open",
423
+ spanId,
424
+ parentSpanId: options.parentSpanId,
425
+ attributes: attrs({
426
+ axis: "process",
427
+ "agent.session_id": options.sessionId,
428
+ "workflow.id": options.workflowId
429
+ })
430
+ });
431
+ return spanId;
432
+ }
433
+ function emitProcessWorkflowClose(spanId, options) {
434
+ if (!options.observer) return;
435
+ options.observer({
436
+ source: "aaac-runtime",
437
+ eventType: "process.workflow",
438
+ lifecycle: "close",
439
+ spanId,
440
+ attributes: attrs({
441
+ axis: "process",
442
+ "workflow.status": options.status,
443
+ ...options.durationMs !== void 0 ? { "workflow.duration_ms": options.durationMs } : {}
444
+ })
445
+ });
446
+ }
447
+ function emitProcessTaskOpen(options) {
448
+ if (!options.observer) return void 0;
449
+ const spanId = generateId();
450
+ options.observer({
451
+ source: "aaac-runtime",
452
+ eventType: "process.task",
453
+ lifecycle: "open",
454
+ spanId,
455
+ parentSpanId: options.parentSpanId,
456
+ attributes: attrs({
457
+ axis: "process",
458
+ "agent.session_id": options.sessionId,
459
+ "task.id": options.taskId,
460
+ "task.type": "implement",
461
+ "task.target_agent": options.targetAgent
462
+ })
463
+ });
464
+ return spanId;
465
+ }
466
+ function emitProcessTaskClose(spanId, options) {
467
+ if (!options.observer) return;
468
+ options.observer({
469
+ source: "aaac-runtime",
470
+ eventType: "process.task",
471
+ lifecycle: "close",
472
+ spanId,
473
+ attributes: attrs({
474
+ axis: "process",
475
+ "task.status": options.status,
476
+ ...options.durationMs !== void 0 ? { "task.duration_ms": options.durationMs } : {}
477
+ })
478
+ });
479
+ }
480
+ function emitProcessEdit(options) {
481
+ if (!options.observer) return void 0;
482
+ const spanId = generateId();
483
+ options.observer({
484
+ source: "aaac-runtime",
485
+ eventType: "process.edit",
486
+ lifecycle: "instant",
487
+ spanId,
488
+ parentSpanId: options.parentSpanId,
489
+ attributes: attrs({
490
+ axis: "process",
491
+ "agent.session_id": options.sessionId,
492
+ "edit.path": options.filePath,
493
+ "edit.artifact_id": options.artifactId
494
+ })
495
+ });
496
+ return spanId;
497
+ }
498
+
395
499
  // src/lib/task-runner.ts
396
500
  function getZodChecks(schema) {
397
501
  const def = schema._def;
@@ -966,9 +1070,27 @@ async function runTask(adapter, taskId, context, options) {
966
1070
  const maxFollowUps = options?.maxFollowUps ?? 2;
967
1071
  const maxRetries = options?.maxRetries ?? 0;
968
1072
  const decide = options?.decideRetryStrategy ?? defaultDecideRetryStrategy;
969
- const onProgress = options?.progressOutput ? (event) => {
970
- const line = formatProgressEvent(event, taskId, agentContract.id);
971
- if (line) options.progressOutput.write(line);
1073
+ const taskExecStart = Date.now();
1074
+ const effectiveSessionId = options?.sessionId ?? options?.parentSpanId ?? taskEnvelope.run_id;
1075
+ let processTaskSpanId;
1076
+ const emittedEditPaths = /* @__PURE__ */ new Set();
1077
+ const onProgress = options?.progressOutput || options?.observer ? (event) => {
1078
+ if (options?.progressOutput) {
1079
+ const line = formatProgressEvent(event, taskId, agentContract.id);
1080
+ if (line) options.progressOutput.write(line);
1081
+ }
1082
+ if (options?.observer && event.type === "tool_use" && isFileEditTool(event.tool_name)) {
1083
+ const input = event.input ?? {};
1084
+ const p = input.file_path ?? input.path ?? input.filename ?? input.file;
1085
+ if (typeof p === "string" && p.length > 0 && !emittedEditPaths.has(p)) {
1086
+ emittedEditPaths.add(p);
1087
+ emitProcessEdit({
1088
+ filePath: p,
1089
+ sessionId: effectiveSessionId,
1090
+ observer: options.observer
1091
+ });
1092
+ }
1093
+ }
972
1094
  } : void 0;
973
1095
  let followUpsUsed = 0;
974
1096
  let retriesUsed = 0;
@@ -979,8 +1101,6 @@ async function runTask(adapter, taskId, context, options) {
979
1101
  );
980
1102
  memoryRef = void 0;
981
1103
  }
982
- const taskExecStart = Date.now();
983
- const effectiveSessionId = options?.sessionId ?? options?.parentSpanId ?? taskEnvelope.run_id;
984
1104
  const subagentSpanId = emitSubagentOpen(
985
1105
  options?.observer,
986
1106
  taskEnvelope,
@@ -989,6 +1109,13 @@ async function runTask(adapter, taskId, context, options) {
989
1109
  agentContract.role_name,
990
1110
  effectiveSessionId
991
1111
  );
1112
+ processTaskSpanId = emitProcessTaskOpen({
1113
+ taskId,
1114
+ targetAgent: task.target_agent,
1115
+ sessionId: effectiveSessionId,
1116
+ parentSpanId: subagentSpanId ?? options?.parentSpanId,
1117
+ observer: options?.observer
1118
+ });
992
1119
  let closeStatus = "error";
993
1120
  let closeCause;
994
1121
  let spanClosed = false;
@@ -1020,6 +1147,13 @@ async function runTask(adapter, taskId, context, options) {
1020
1147
  closeCause,
1021
1148
  effectiveSessionId
1022
1149
  );
1150
+ if (processTaskSpanId) {
1151
+ emitProcessTaskClose(processTaskSpanId, {
1152
+ status: closeStatus,
1153
+ durationMs,
1154
+ observer: options?.observer
1155
+ });
1156
+ }
1023
1157
  };
1024
1158
  try {
1025
1159
  let fullOutput;
@@ -1353,7 +1487,7 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
1353
1487
  };
1354
1488
  }
1355
1489
  await pluginRegistry.runBeforeWorkflow(workflowId, options.user_request);
1356
- const sessionMeta = options.resolveModelMeta?.(void 0);
1490
+ const sessionMeta = options.resolveModelMeta?.("standard");
1357
1491
  const sessionEnvelope = createExecutionEnvelope({
1358
1492
  componentId: workflowId,
1359
1493
  adapter: sessionMeta?.adapter,
@@ -1884,98 +2018,6 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
1884
2018
  });
1885
2019
  }
1886
2020
 
1887
- // src/lib/process-axis-bridge.ts
1888
- import { generateId } from "@aaac/observability";
1889
- function attrs(base) {
1890
- const out = {};
1891
- for (const [k, v] of Object.entries(base)) {
1892
- if (v !== void 0 && v !== "") out[k] = v;
1893
- }
1894
- return out;
1895
- }
1896
- function emitProcessWorkflowOpen(options) {
1897
- if (!options.observer) return void 0;
1898
- const spanId = generateId();
1899
- options.observer({
1900
- source: "aaac-runtime",
1901
- eventType: "process.workflow",
1902
- lifecycle: "open",
1903
- spanId,
1904
- parentSpanId: options.parentSpanId,
1905
- attributes: attrs({
1906
- axis: "process",
1907
- "agent.session_id": options.sessionId,
1908
- "workflow.id": options.workflowId
1909
- })
1910
- });
1911
- return spanId;
1912
- }
1913
- function emitProcessWorkflowClose(spanId, options) {
1914
- if (!options.observer) return;
1915
- options.observer({
1916
- source: "aaac-runtime",
1917
- eventType: "process.workflow",
1918
- lifecycle: "close",
1919
- spanId,
1920
- attributes: attrs({
1921
- axis: "process",
1922
- "workflow.status": options.status,
1923
- ...options.durationMs !== void 0 ? { "workflow.duration_ms": options.durationMs } : {}
1924
- })
1925
- });
1926
- }
1927
- function emitProcessTaskOpen(options) {
1928
- if (!options.observer) return void 0;
1929
- const spanId = generateId();
1930
- options.observer({
1931
- source: "aaac-runtime",
1932
- eventType: "process.task",
1933
- lifecycle: "open",
1934
- spanId,
1935
- parentSpanId: options.parentSpanId,
1936
- attributes: attrs({
1937
- axis: "process",
1938
- "agent.session_id": options.sessionId,
1939
- "task.id": options.taskId,
1940
- "task.type": "implement",
1941
- "task.target_agent": options.targetAgent
1942
- })
1943
- });
1944
- return spanId;
1945
- }
1946
- function emitProcessTaskClose(spanId, options) {
1947
- if (!options.observer) return;
1948
- options.observer({
1949
- source: "aaac-runtime",
1950
- eventType: "process.task",
1951
- lifecycle: "close",
1952
- spanId,
1953
- attributes: attrs({
1954
- axis: "process",
1955
- "task.status": options.status,
1956
- ...options.durationMs !== void 0 ? { "task.duration_ms": options.durationMs } : {}
1957
- })
1958
- });
1959
- }
1960
- function emitProcessEdit(options) {
1961
- if (!options.observer) return void 0;
1962
- const spanId = generateId();
1963
- options.observer({
1964
- source: "aaac-runtime",
1965
- eventType: "process.edit",
1966
- lifecycle: "instant",
1967
- spanId,
1968
- parentSpanId: options.parentSpanId,
1969
- attributes: attrs({
1970
- axis: "process",
1971
- "agent.session_id": options.sessionId,
1972
- "edit.path": options.filePath,
1973
- "edit.artifact_id": options.artifactId
1974
- })
1975
- });
1976
- return spanId;
1977
- }
1978
-
1979
2021
  // src/lib/bound-resolver.ts
1980
2022
  import { readFile as readFile3 } from "fs/promises";
1981
2023
  import YAML2 from "yaml";
@@ -3911,6 +3953,7 @@ export {
3911
3953
  guardrailContextToRuleData,
3912
3954
  hasBlockingViolation,
3913
3955
  isContextPack,
3956
+ isFileEditTool,
3914
3957
  isNavigationIndex,
3915
3958
  jsonSchemaToZod,
3916
3959
  listGuardrails,