agent-valley 2.0.0 → 2.2.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.
@@ -6618,8 +6618,90 @@ var init_capture_schema = __esm(() => {
6618
6618
  });
6619
6619
  });
6620
6620
 
6621
+ // ../../packages/core/src/chief/container-observation-policy.ts
6622
+ function containerTargetHealthy(result) {
6623
+ return result.status === "collected" && result.state === "running" && result.ready === true && result.logsAvailable !== false && result.statsAvailable !== false && result.issues.length === 0;
6624
+ }
6625
+ var targetName, contextName, dnsName, timestamp, digest, containerObservationTargetSchema, containerObservationPolicySchema, containerObservationResultSchema, containerObservationSnapshotSchema;
6626
+ var init_container_observation_policy = __esm(() => {
6627
+ init_zod();
6628
+ targetName = string2().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/, "Use a container name or ID, without CLI flags.");
6629
+ contextName = string2().regex(/^[A-Za-z0-9][A-Za-z0-9_.:@/-]{0,199}$/, "Use an existing CLI context name.").refine((value) => !value.includes("://"), "Use a context name, not a URL or credentials.");
6630
+ dnsName = string2().regex(/^[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?$/, "Use an explicit Kubernetes name.");
6631
+ timestamp = string2().datetime({ offset: true });
6632
+ digest = string2().regex(/^[a-f0-9]{64}$/);
6633
+ containerObservationTargetSchema = discriminatedUnion("kind", [
6634
+ strictObject({ id: targetName, kind: literal("docker"), container: targetName, context: contextName.optional() }),
6635
+ strictObject({
6636
+ id: targetName,
6637
+ kind: literal("kubernetes"),
6638
+ namespace: dnsName,
6639
+ pod: dnsName,
6640
+ container: targetName,
6641
+ context: contextName.optional()
6642
+ })
6643
+ ]);
6644
+ containerObservationPolicySchema = strictObject({
6645
+ enabled: boolean2().default(true),
6646
+ targets: array(containerObservationTargetSchema).min(1).max(20),
6647
+ poll_interval_sec: number2().int().min(1).max(3600).default(30),
6648
+ timeout_ms: number2().int().min(100).max(60000).default(1e4),
6649
+ max_output_bytes: number2().int().min(1024).max(1048576).default(65536),
6650
+ log_tail: number2().int().min(1).max(200).default(50),
6651
+ log_since_sec: number2().int().min(1).max(86400).default(300),
6652
+ cpu_percent_threshold: number2().finite().positive().max(1e4).optional(),
6653
+ memory_percent_threshold: number2().finite().positive().max(100).optional()
6654
+ }).superRefine((policy, ctx) => {
6655
+ if (new Set(policy.targets.map((target) => target.id)).size !== policy.targets.length)
6656
+ ctx.addIssue({ code: "custom", path: ["targets"], message: "Container observation target IDs must be unique." });
6657
+ });
6658
+ containerObservationResultSchema = strictObject({
6659
+ targetId: targetName,
6660
+ kind: _enum(["docker", "kubernetes"]),
6661
+ status: _enum(["collected", "unavailable"]),
6662
+ identity: string2().min(1).max(500).optional(),
6663
+ state: _enum(["running", "waiting", "terminated", "unknown"]).optional(),
6664
+ ready: boolean2().optional(),
6665
+ health: string2().max(100).optional(),
6666
+ exitCode: number2().int().optional(),
6667
+ restartCount: number2().int().nonnegative().optional(),
6668
+ oomKilled: boolean2().optional(),
6669
+ cpuPercent: number2().finite().nonnegative().optional(),
6670
+ memoryPercent: number2().finite().nonnegative().optional(),
6671
+ logExcerpt: string2().max(8192).optional(),
6672
+ logsAvailable: boolean2().optional(),
6673
+ statsAvailable: boolean2().optional(),
6674
+ reason: string2().max(1000).optional(),
6675
+ issues: array(_enum([
6676
+ "not-running",
6677
+ "unhealthy",
6678
+ "oom-killed",
6679
+ "restarting",
6680
+ "restart-increase",
6681
+ "log-error",
6682
+ "cpu-high",
6683
+ "memory-high"
6684
+ ])).max(8),
6685
+ fingerprint: digest
6686
+ });
6687
+ containerObservationSnapshotSchema = strictObject({
6688
+ collectedAt: timestamp,
6689
+ nextPollAt: timestamp,
6690
+ fingerprint: digest,
6691
+ results: array(containerObservationResultSchema).max(20)
6692
+ });
6693
+ });
6694
+
6621
6695
  // ../../packages/core/src/chief/execution.ts
6622
6696
  import { createHash } from "node:crypto";
6697
+ function chiefRecoveryStopped(mission) {
6698
+ const decision = mission.supervision?.decisions.at(-1);
6699
+ if (decision?.action !== "stop")
6700
+ return false;
6701
+ const stoppedAt = Date.parse(decision.at);
6702
+ const intervenedAt = Date.parse(mission.execution?.interventionAt ?? "");
6703
+ return !Number.isFinite(stoppedAt) || !Number.isFinite(intervenedAt) || intervenedAt <= stoppedAt;
6704
+ }
6623
6705
  function classifyFailure(reason) {
6624
6706
  if (/unauthori[sz]ed|authentication|login required|log in|expired token|invalid.*(?:token|api.key)|\b401\b|\b403\b/i.test(reason))
6625
6707
  return "authentication";
@@ -6654,21 +6736,21 @@ function assertExecutionBudget(mission, now = Date.now()) {
6654
6736
  return;
6655
6737
  const state = executionState(mission);
6656
6738
  if (now - Date.parse(state.startedAt) >= policy.maxDurationSec * 1000)
6657
- throw new MissionPause("Mission time limit reached. Increase --duration on resume to continue the original goal.", "budget");
6739
+ throw new MissionPause("Mission time limit reached. The original goal remains unresolved within its saved duration.", "budget");
6658
6740
  if (state.runsStarted >= policy.maxRuns)
6659
- throw new MissionPause("Mission Actor call limit reached. Increase --runs on resume to continue.", "budget");
6741
+ throw new MissionPause("Mission Actor call limit reached. The original goal remains unresolved within its saved call budget.", "budget");
6660
6742
  if (policy.maxEstimatedCostUsd !== undefined) {
6661
6743
  const finished = mission.operations?.runs.filter((run) => run.finishedAt) ?? [];
6662
6744
  const reconciled = new Map(state.costReconciliations?.map((entry) => [entry.runId, entry.costUsd]));
6663
6745
  if (finished.some((run) => run.costUsd === null && !reconciled.has(run.runId)))
6664
- throw new MissionPause("Cost headroom is unknown. Inspect billing, then reconcile each unresolved run using --account-run <id> --account-cost <usd> on resume; no zero-cost assumption was made.", "budget");
6746
+ throw new MissionPause("Cost headroom is unknown. Unresolved billing evidence prevents further calls; no zero-cost assumption was made.", "budget");
6665
6747
  if (finished.reduce((sum, run) => sum + (run.costUsd ?? reconciled.get(run.runId) ?? 0), 0) >= policy.maxEstimatedCostUsd)
6666
- throw new MissionPause("Configured-price estimated cost limit reached. Increase --cost on resume to continue.", "budget");
6748
+ throw new MissionPause("Configured-price estimated cost limit reached. The goal remains unresolved within its saved cost budget.", "budget");
6667
6749
  }
6668
6750
  }
6669
6751
  function assertExecutionDeadline(mission, now = Date.now()) {
6670
6752
  if (mission.executionPolicy && now - Date.parse(executionState(mission).startedAt) >= mission.executionPolicy.maxDurationSec * 1000)
6671
- throw new MissionPause("Mission time limit reached. Increase --duration on resume to continue the original goal.", "budget");
6753
+ throw new MissionPause("Mission time limit reached. The original goal remains unresolved within its saved duration.", "budget");
6672
6754
  }
6673
6755
  function reconcileRunCost(mission, runId, costUsd) {
6674
6756
  const run = mission.operations?.runs.find((entry) => entry.runId === runId);
@@ -6693,7 +6775,8 @@ function progressKey(mission, fingerprint) {
6693
6775
  value: metric.value,
6694
6776
  timestamp: metric.timestamp
6695
6777
  })),
6696
- effects: mission.tasks.map((task) => ({ id: task.id, effectState: task.effectState }))
6778
+ effects: mission.tasks.map((task) => ({ id: task.id, effectState: task.effectState })),
6779
+ containers: mission.containerObservation?.fingerprint
6697
6780
  })).digest("hex");
6698
6781
  }
6699
6782
  function pauseForFailure(mission, reason, taskId) {
@@ -6703,16 +6786,22 @@ function pauseForFailure(mission, reason, taskId) {
6703
6786
  const state = mission.tasks.find((entry) => entry.id === taskId);
6704
6787
  if (task?.effectScope === "external" && state?.effectState === "running") {
6705
6788
  state.effectState = "unknown";
6706
- throw new MissionPause(`External effect for ${taskId} is uncertain. Inspect the destination, then resume with --resolve-effect ${taskId} --effect-result completed|not-applied.`, "unknown-effect");
6789
+ throw new MissionPause(`External effect for ${taskId} is uncertain. Its destination outcome has not been established; it will not be repeated.`, "unknown-effect");
6707
6790
  }
6708
6791
  const kind = classifyFailure(reason);
6709
- if (kind === "authentication" || kind === "environment")
6710
- throw new MissionPause(`${reason} Restore the required service or CLI, then use --resume with --retry.`, kind);
6792
+ if (kind === "authentication" || kind === "environment") {
6793
+ if (mission.supervision)
6794
+ return;
6795
+ throw new MissionPause(`${reason} Required source access is unavailable; the goal remains unresolved.`, kind);
6796
+ }
6711
6797
  if (kind !== "rate-limit" && kind !== "provider")
6712
6798
  return;
6713
6799
  const execution = executionState(mission);
6714
- if (execution.retries >= mission.executionPolicy.maxRetries)
6715
- throw new MissionPause(`${reason} Automatic retries exhausted. Repair the provider and resume with --retry.`, kind);
6800
+ if (execution.retries >= mission.executionPolicy.maxRetries) {
6801
+ if (mission.supervision)
6802
+ return;
6803
+ throw new MissionPause(`${reason} Automatic retries exhausted; the goal remains unresolved.`, kind);
6804
+ }
6716
6805
  execution.retries += 1;
6717
6806
  const delay = Math.min(300000, mission.executionPolicy.retryDelayMs * 2 ** (execution.retries - 1));
6718
6807
  throw new MissionPause(reason, kind, new Date(Date.now() + delay).toISOString());
@@ -6770,7 +6859,10 @@ var init_execution = __esm(() => {
6770
6859
  "implementation",
6771
6860
  "unknown-effect",
6772
6861
  "budget",
6773
- "interrupted"
6862
+ "interrupted",
6863
+ "chief-wait",
6864
+ "chief-unavailable",
6865
+ "integrity"
6774
6866
  ]).optional(),
6775
6867
  progressKey: string2().optional(),
6776
6868
  interventionAt: exports_iso.datetime().optional(),
@@ -7168,6 +7260,7 @@ var price, chiefConfigSchema;
7168
7260
  var init_chief_schema = __esm(() => {
7169
7261
  init_zod();
7170
7262
  init_capture_schema();
7263
+ init_container_observation_policy();
7171
7264
  init_execution();
7172
7265
  init_metric_source_policy();
7173
7266
  init_operations();
@@ -7176,6 +7269,7 @@ var init_chief_schema = __esm(() => {
7176
7269
  init_tool_environment();
7177
7270
  price = number2().finite().nonnegative().optional();
7178
7271
  chiefConfigSchema = strictObject({
7272
+ container_observation: containerObservationPolicySchema.optional(),
7179
7273
  tool_env_keys: toolEnvKeysSchema.optional(),
7180
7274
  execution: strictObject({
7181
7275
  max_parallel: number2().int().min(1).max(8).default(3),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-valley",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=26.10.0",