@rowan-agent/agent 0.27.0 → 0.29.0

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +1613 -1625
  2. package/dist/index.js +60 -32
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2235,6 +2235,19 @@ async function loadSkills(targetPath) {
2235
2235
  var PHASE_MARKER = "PHASE.md";
2236
2236
  var SKILL_MARKER2 = "SKILL.md";
2237
2237
  var RESOURCE_MARKERS = /* @__PURE__ */ new Set([PHASE_MARKER, SKILL_MARKER2]);
2238
+ var KNOWN_PHASE_KEYS = /* @__PURE__ */ new Set([
2239
+ "name",
2240
+ "description",
2241
+ "target",
2242
+ "input",
2243
+ "prompt-guidelines",
2244
+ "tools",
2245
+ "model",
2246
+ "isolated",
2247
+ "disable-auto-invocation",
2248
+ "disable-implicit-invocation",
2249
+ "skills"
2250
+ ]);
2238
2251
  function resolvePhasePath(input) {
2239
2252
  const resolved = resolve4(input);
2240
2253
  return existsSync2(resolved) && statSync2(resolved).isDirectory() ? join2(resolved, PHASE_MARKER) : resolved;
@@ -2274,6 +2287,15 @@ async function loadPhase(targetPath) {
2274
2287
  }
2275
2288
  diagnostics.push(...description.warnings);
2276
2289
  diagnostics.push(...validatePhaseTarget(metadata.target));
2290
+ const extraMetadata = {};
2291
+ for (const [key, value] of Object.entries(metadata)) {
2292
+ if (KNOWN_PHASE_KEYS.has(key)) continue;
2293
+ if (isJsonValue(value)) {
2294
+ extraMetadata[key] = value;
2295
+ } else {
2296
+ diagnostics.push(`metadata key "${key}" must be a JSON-safe value`);
2297
+ }
2298
+ }
2277
2299
  warnResourceDiagnostics("phase", resolved, diagnostics);
2278
2300
  const baseDir = dirname4(resolved);
2279
2301
  const skills = await loadPhaseSkills(baseDir);
@@ -2299,7 +2321,8 @@ async function loadPhase(targetPath) {
2299
2321
  content: definition.prompt,
2300
2322
  model: definition.model,
2301
2323
  disableAutoInvocation: metadata["disable-auto-invocation"] === true,
2302
- disableImplicitInvocation: metadata["disable-implicit-invocation"] === true
2324
+ disableImplicitInvocation: metadata["disable-implicit-invocation"] === true,
2325
+ ...Object.keys(extraMetadata).length > 0 ? { metadata: Object.freeze(extraMetadata) } : {}
2303
2326
  };
2304
2327
  const codePath = await discoverPhaseCode(baseDir);
2305
2328
  if (codePath) {
@@ -3706,7 +3729,8 @@ async function executeToolCall(input) {
3706
3729
  contentBlocks: input.contentBlocks,
3707
3730
  driver: input.driver,
3708
3731
  options: input.options,
3709
- ...input.providerInitiated ? { providerInitiated: true } : {}
3732
+ ...input.providerInitiated ? { providerInitiated: true } : {},
3733
+ ...input.phase !== void 0 ? { phase: input.phase } : {}
3710
3734
  });
3711
3735
  } else {
3712
3736
  const toolContext = {
@@ -3736,7 +3760,8 @@ async function executeToolCalls(input) {
3736
3760
  contentBlocks: input.contentBlocks,
3737
3761
  driver: input.driver,
3738
3762
  model: input.model,
3739
- usage: input.usage
3763
+ usage: input.usage,
3764
+ ...input.phase !== void 0 ? { phase: input.phase } : {}
3740
3765
  });
3741
3766
  if (results2.length !== input.toolCalls.length) throw new Error("Runtime returned an invalid Tool batch result");
3742
3767
  return results2.map((result, index) => ({
@@ -3752,6 +3777,10 @@ async function executeToolCalls(input) {
3752
3777
  return results;
3753
3778
  }
3754
3779
  function createPhaseExecution(config, state, phase, messageManager, toolExecutionManager, registry) {
3780
+ const phaseInfo = Object.freeze({
3781
+ name: phase.name,
3782
+ ...phase.metadata !== void 0 ? { metadata: phase.metadata } : {}
3783
+ });
3755
3784
  const interaction = createRunInteractionDriver(state, phase.name, config.signal);
3756
3785
  const executePhaseTool = async (phaseContext, toolCall, options, providerInitiated = false) => {
3757
3786
  return runTurn(async () => {
@@ -3770,7 +3799,8 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
3770
3799
  toolCall,
3771
3800
  driver: interaction,
3772
3801
  options,
3773
- providerInitiated
3802
+ providerInitiated,
3803
+ phase: phaseInfo
3774
3804
  });
3775
3805
  await toolExecutionManager.end(result.toolCallId, result.toolName, result, !result.ok);
3776
3806
  return result;
@@ -3779,22 +3809,6 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
3779
3809
  const execution = {
3780
3810
  interaction,
3781
3811
  messages: messageManager,
3782
- snapshot() {
3783
- return {
3784
- systemPrompt: config.context.systemPrompt,
3785
- messages: [...config.context.messages],
3786
- currentPhase: state.currentPhase ?? "",
3787
- availablePhases: Array.from(registry.phases.keys()),
3788
- turnNumber: state.metrics.iterations
3789
- };
3790
- },
3791
- restore(snapshot) {
3792
- config.context.systemPrompt = snapshot.systemPrompt;
3793
- config.context.messages.length = 0;
3794
- config.context.messages.push(...snapshot.messages);
3795
- state.currentPhase = snapshot.currentPhase;
3796
- state.metrics.iterations = snapshot.turnNumber;
3797
- },
3798
3812
  async invokeModel(phaseContext, options = {}) {
3799
3813
  if (config.beforePrompt) {
3800
3814
  phaseContext = await config.beforePrompt(phase.name, phaseContext);
@@ -3896,7 +3910,6 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
3896
3910
  async reportStatus(status) {
3897
3911
  await config.onPhaseStatus?.(phase.name, status);
3898
3912
  },
3899
- executeTool: executePhaseTool,
3900
3913
  async executeTools(phaseContext, toolCalls, contentBlocks, meta) {
3901
3914
  return runTurn(async () => {
3902
3915
  const tools = phaseContext.tools.filter((tool) => tool.name !== PhaseRouteTool);
@@ -3917,7 +3930,8 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
3917
3930
  contentBlocks,
3918
3931
  driver: interaction,
3919
3932
  model: meta?.model,
3920
- usage: meta?.usage
3933
+ usage: meta?.usage,
3934
+ phase: phaseInfo
3921
3935
  });
3922
3936
  for (const result of results) {
3923
3937
  await toolExecutionManager.end(result.toolCallId, result.toolName, result, !result.ok);
@@ -4701,7 +4715,8 @@ function snapshotPhase(phase) {
4701
4715
  ...phase.promptGuidelines ? { promptGuidelines: Object.freeze([...phase.promptGuidelines]) } : {},
4702
4716
  skills: Object.freeze((phase.skills ?? []).map((skill) => Object.freeze({ ...skill }))),
4703
4717
  ...phase.input ? { input: Object.freeze({ ...phase.input }) } : {},
4704
- ...phase.model ? { model: Object.freeze({ ...phase.model }) } : {}
4718
+ ...phase.model ? { model: Object.freeze({ ...phase.model }) } : {},
4719
+ ...phase.metadata ? { metadata: Object.freeze({ ...phase.metadata }) } : {}
4705
4720
  });
4706
4721
  }
4707
4722
  function snapshotConfiguration(config) {
@@ -5267,7 +5282,8 @@ function assembleRegisteredExtensions(snapshot, runner, options = {}) {
5267
5282
  ...input.context.agentMetadata === void 0 ? {} : { agentMetadata: input.context.agentMetadata },
5268
5283
  answer: input.answer,
5269
5284
  scope: input.context.scope,
5270
- turn: input.context.turn
5285
+ turn: input.context.turn,
5286
+ ...input.context.phase === void 0 ? {} : { phase: input.context.phase }
5271
5287
  });
5272
5288
  if (decision.interaction !== void 0) {
5273
5289
  return { interaction: decision.interaction };
@@ -5285,7 +5301,8 @@ function assembleRegisteredExtensions(snapshot, runner, options = {}) {
5285
5301
  toolCallId: input.context.toolCallId,
5286
5302
  metadata: input.context.runMetadata,
5287
5303
  scope: input.context.scope,
5288
- turn: input.context.turn
5304
+ turn: input.context.turn,
5305
+ ...input.context.phase === void 0 ? {} : { phase: input.context.phase }
5289
5306
  }
5290
5307
  );
5291
5308
  return fromLoopResult(result);
@@ -8612,7 +8629,8 @@ var ExtensionRunner = class {
8612
8629
  ...context?.agentMetadata !== void 0 ? { agentMetadata: context.agentMetadata } : {},
8613
8630
  ...context?.answer !== void 0 ? { answer: context.answer } : {},
8614
8631
  scope,
8615
- turn
8632
+ turn,
8633
+ ...context?.phase !== void 0 ? { phase: context.phase } : {}
8616
8634
  });
8617
8635
  return result ?? { allow: true };
8618
8636
  }
@@ -8628,7 +8646,8 @@ var ExtensionRunner = class {
8628
8646
  ...context?.toolCallId !== void 0 ? { toolCallId: context.toolCallId } : {},
8629
8647
  ...context?.metadata !== void 0 ? { metadata: context.metadata } : {},
8630
8648
  scope,
8631
- turn
8649
+ turn,
8650
+ ...context?.phase !== void 0 ? { phase: context.phase } : {}
8632
8651
  });
8633
8652
  return hookResult?.result ?? result;
8634
8653
  }
@@ -9398,7 +9417,8 @@ function snapshotResourceValue(kind, value) {
9398
9417
  ...phase.promptGuidelines ? { promptGuidelines: Object.freeze([...phase.promptGuidelines]) } : {},
9399
9418
  skills: Object.freeze((phase.skills ?? []).map((skill) => Object.freeze({ ...skill }))),
9400
9419
  ...phase.input ? { input: Object.freeze({ ...phase.input }) } : {},
9401
- ...phase.model ? { model: Object.freeze({ ...phase.model }) } : {}
9420
+ ...phase.model ? { model: Object.freeze({ ...phase.model }) } : {},
9421
+ ...phase.metadata ? { metadata: Object.freeze({ ...phase.metadata }) } : {}
9402
9422
  };
9403
9423
  return Object.freeze(snapshot);
9404
9424
  }
@@ -10643,7 +10663,7 @@ var AgentRuntime = class _AgentRuntime {
10643
10663
  onContext: assembly.setContext,
10644
10664
  runtime: {
10645
10665
  interact: (request) => this.liveInteract(run.id, request, controller.signal),
10646
- tools: ({ toolCall, contentBlocks, driver, options, providerInitiated, model: callModel, usage: callUsage }) => {
10666
+ tools: ({ toolCall, contentBlocks, driver, options, providerInitiated, model: callModel, usage: callUsage, phase: callPhase }) => {
10647
10667
  const task = toolQueue.then(async () => {
10648
10668
  if (!providerInitiated) {
10649
10669
  const execution = await this.executeToolBatch({
@@ -10659,6 +10679,7 @@ var AgentRuntime = class _AgentRuntime {
10659
10679
  options,
10660
10680
  model: callModel ?? model,
10661
10681
  usage: callUsage,
10682
+ phase: callPhase,
10662
10683
  onRevision: (rev) => {
10663
10684
  executionRevision = rev;
10664
10685
  }
@@ -10685,6 +10706,7 @@ var AgentRuntime = class _AgentRuntime {
10685
10706
  interactionIds,
10686
10707
  model: callModel ?? model,
10687
10708
  usage: callUsage,
10709
+ phase: callPhase,
10688
10710
  onRevision: (rev) => {
10689
10711
  executionRevision = rev;
10690
10712
  }
@@ -10775,7 +10797,7 @@ var AgentRuntime = class _AgentRuntime {
10775
10797
  toolQueue = task.then(() => void 0, () => void 0);
10776
10798
  return task;
10777
10799
  },
10778
- toolsBatch: ({ toolCalls, contentBlocks, driver, options, model: batchModel, usage: batchUsage }) => {
10800
+ toolsBatch: ({ toolCalls, contentBlocks, driver, options, model: batchModel, usage: batchUsage, phase: batchPhase }) => {
10779
10801
  const task = toolQueue.then(async () => {
10780
10802
  const execution = await this.executeToolBatch({
10781
10803
  run,
@@ -10790,6 +10812,7 @@ var AgentRuntime = class _AgentRuntime {
10790
10812
  options,
10791
10813
  model: batchModel ?? model,
10792
10814
  usage: batchUsage,
10815
+ phase: batchPhase,
10793
10816
  onRevision: (rev) => {
10794
10817
  executionRevision = rev;
10795
10818
  }
@@ -10979,6 +11002,7 @@ var AgentRuntime = class _AgentRuntime {
10979
11002
  scope,
10980
11003
  ...cwd ? { cwd } : {},
10981
11004
  turn,
11005
+ ...input.phase === void 0 ? {} : { phase: input.phase },
10982
11006
  interaction: createRunInteractionDriver({
10983
11007
  currentPhase: "default",
10984
11008
  attempt: 0,
@@ -11119,7 +11143,8 @@ var AgentRuntime = class _AgentRuntime {
11119
11143
  signal: input.signal,
11120
11144
  afterToolCall: input.toolConfig.afterToolCall,
11121
11145
  currentToolState,
11122
- options: input.options
11146
+ options: input.options,
11147
+ ...input.phase === void 0 ? {} : { phase: input.phase }
11123
11148
  });
11124
11149
  results2.push(toolResult2);
11125
11150
  }
@@ -11227,6 +11252,7 @@ var AgentRuntime = class _AgentRuntime {
11227
11252
  scope,
11228
11253
  ...cwd ? { cwd } : {},
11229
11254
  turn,
11255
+ ...input.phase === void 0 ? {} : { phase: input.phase },
11230
11256
  interaction: interactionDriver,
11231
11257
  reportProgress: () => {
11232
11258
  }
@@ -11439,7 +11465,8 @@ var AgentRuntime = class _AgentRuntime {
11439
11465
  afterToolCall: input.toolConfig.afterToolCall,
11440
11466
  currentToolState,
11441
11467
  options: input.options,
11442
- providerInitiated: input.providerInitiated
11468
+ providerInitiated: input.providerInitiated,
11469
+ ...input.phase === void 0 ? {} : { phase: input.phase }
11443
11470
  });
11444
11471
  results.push(toolResult2);
11445
11472
  }
@@ -11490,6 +11517,7 @@ var AgentRuntime = class _AgentRuntime {
11490
11517
  scope: input.scope,
11491
11518
  ...input.cwd ? { cwd: input.cwd } : {},
11492
11519
  turn: input.turn,
11520
+ ...input.phase === void 0 ? {} : { phase: input.phase },
11493
11521
  interaction: interactionDriver,
11494
11522
  reportProgress: (progress) => {
11495
11523
  const active = this.executions.get(input.runId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowan-agent/agent",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",