@liy/agent-runner 0.3.2 → 0.3.3

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.
@@ -14011,40 +14011,7 @@ var visualComposerInputSchema = external_exports.object({
14011
14011
  assetGraph: assetGraphSchema.optional()
14012
14012
  }).strict();
14013
14013
 
14014
- // ../mote-core/dist/debug/log-event.js
14015
- var defaultMoteLogRedactPaths = [
14016
- "attributes.auth.token",
14017
- "attributes.http.request.header.authorization",
14018
- "attributes.http.request.header.cookie",
14019
- "body.headers.authorization",
14020
- "body.headers.cookie",
14021
- "body.apiKey",
14022
- "body.context",
14023
- "body.password",
14024
- "body.token",
14025
- "body.error.stack"
14026
- ];
14027
- var moteLogPolicyPresets = {
14028
- localDebug: {
14029
- bodyMode: "full",
14030
- redactionMode: "censor",
14031
- maxBodyBytes: 256 * 1024,
14032
- redactPaths: defaultMoteLogRedactPaths
14033
- },
14034
- production: {
14035
- bodyMode: "summary",
14036
- redactionMode: "remove",
14037
- maxBodyBytes: 4 * 1024,
14038
- redactPaths: defaultMoteLogRedactPaths
14039
- },
14040
- thirdParty: {
14041
- bodyMode: "drop",
14042
- redactionMode: "remove",
14043
- redactPaths: defaultMoteLogRedactPaths
14044
- }
14045
- };
14046
-
14047
- // ../mote-core/dist/debug/planner-artifact-pool-snapshot.js
14014
+ // ../mote-core/dist/planner-artifact-pool-observability.js
14048
14015
  var DEFAULT_PLANNER_ARTIFACT_POOL_SNAPSHOT_MAX_BYTES = 64 * 1024;
14049
14016
 
14050
14017
  // ../mote-core/dist/contracts/data-result.js
@@ -14964,7 +14931,7 @@ var QuerySchema = external_exports.object({
14964
14931
  limit: external_exports.number().int().positive().max(1e4).default(1e3),
14965
14932
  accessLevel: AccessLevelSchema.default("serving")
14966
14933
  }).superRefine((query, ctx) => {
14967
- const surfaces = [query.from.surface, ...query.joins.map((join3) => join3.surface)];
14934
+ const surfaces = [query.from.surface, ...query.joins.map((join2) => join2.surface)];
14968
14935
  const knownSurfaces = /* @__PURE__ */ new Set();
14969
14936
  for (const [index, surface] of surfaces.entries()) {
14970
14937
  if (knownSurfaces.has(surface)) {
@@ -14999,8 +14966,8 @@ var QuerySchema = external_exports.object({
14999
14966
  path: ["time", "bucket", "fn"]
15000
14967
  });
15001
14968
  }
15002
- for (const [index, join3] of query.joins.entries()) {
15003
- visitConditionFields(join3.on, (field) => {
14969
+ for (const [index, join2] of query.joins.entries()) {
14970
+ visitConditionFields(join2.on, (field) => {
15004
14971
  validateFieldRef(field, ["joins", index, "on"]);
15005
14972
  });
15006
14973
  }
@@ -15456,92 +15423,6 @@ async function forwardHarnessLines(stream, handler) {
15456
15423
 
15457
15424
  // src/harness-drivers/pi-rpc.ts
15458
15425
  import { spawn as nodeSpawn2 } from "node:child_process";
15459
-
15460
- // src/debug/pi-rpc-trace.ts
15461
- import { once } from "node:events";
15462
- import { createWriteStream, mkdirSync } from "node:fs";
15463
- import { dirname, join } from "node:path";
15464
- var MAX_TRACE_LINE_BYTES = 16384;
15465
- var MAX_TRACE_PREVIEW_CHARS = 8e3;
15466
- function createPiRpcTrace(input) {
15467
- const filePath = join(input.workspaceDir, "debug", "pi-rpc.jsonl");
15468
- try {
15469
- mkdirSync(dirname(filePath), { recursive: true });
15470
- const stream = createWriteStream(filePath, {
15471
- flags: "a",
15472
- mode: 384
15473
- });
15474
- return createStreamTrace({
15475
- filePath,
15476
- stream,
15477
- taskId: input.taskId,
15478
- now: input.now ?? (() => /* @__PURE__ */ new Date())
15479
- });
15480
- } catch {
15481
- return createNoopTrace();
15482
- }
15483
- }
15484
- function createStreamTrace(input) {
15485
- let closed = false;
15486
- let failed = false;
15487
- input.stream.on("error", () => {
15488
- failed = true;
15489
- });
15490
- return {
15491
- filePath: input.filePath,
15492
- write(event) {
15493
- if (closed || failed) {
15494
- return;
15495
- }
15496
- input.stream.write(serializeTraceRecord({
15497
- ts: input.now().toISOString(),
15498
- taskId: input.taskId,
15499
- ...event
15500
- }));
15501
- },
15502
- async close() {
15503
- if (closed) {
15504
- return;
15505
- }
15506
- closed = true;
15507
- if (failed) {
15508
- return;
15509
- }
15510
- input.stream.end();
15511
- await once(input.stream, "finish").then(() => void 0, () => void 0);
15512
- }
15513
- };
15514
- }
15515
- function createNoopTrace() {
15516
- return {
15517
- write() {
15518
- },
15519
- async close() {
15520
- }
15521
- };
15522
- }
15523
- function serializeTraceRecord(record2) {
15524
- const line = `${JSON.stringify(record2)}
15525
- `;
15526
- if (Buffer.byteLength(line, "utf8") <= MAX_TRACE_LINE_BYTES) {
15527
- return line;
15528
- }
15529
- return `${JSON.stringify({
15530
- ...record2,
15531
- truncated: true,
15532
- payload: previewPayload(record2.payload)
15533
- })}
15534
- `;
15535
- }
15536
- function previewPayload(payload) {
15537
- const text = typeof payload === "string" ? payload : JSON.stringify(payload) ?? "undefined";
15538
- if (text.length <= MAX_TRACE_PREVIEW_CHARS) {
15539
- return text;
15540
- }
15541
- return `${text.slice(0, MAX_TRACE_PREVIEW_CHARS)}...[truncated]`;
15542
- }
15543
-
15544
- // src/harness-drivers/pi-rpc.ts
15545
15426
  var driverOwnedPiFlags = /* @__PURE__ */ new Set([
15546
15427
  "--mode",
15547
15428
  "--provider",
@@ -15599,8 +15480,7 @@ function buildPiRpcArgs(harness) {
15599
15480
  }
15600
15481
  function startPiRpcHarness(input, spawnProcess) {
15601
15482
  const harness = input.harness;
15602
- const args = buildPiRpcArgs(harness);
15603
- const child = spawnProcess(harness.command, args, {
15483
+ const child = spawnProcess(harness.command, buildPiRpcArgs(harness), {
15604
15484
  cwd: input.spec.workspaceDir,
15605
15485
  env: input.env,
15606
15486
  stdio: ["pipe", "pipe", "pipe"]
@@ -15608,19 +15488,6 @@ function startPiRpcHarness(input, spawnProcess) {
15608
15488
  const sanitizer = createHarnessOutputSanitizer(input.env, [
15609
15489
  ...input.harness.secretEnv ?? []
15610
15490
  ]);
15611
- const trace = createPiRpcTrace({
15612
- taskId: input.spec.taskId,
15613
- workspaceDir: input.spec.workspaceDir
15614
- });
15615
- trace.write({
15616
- kind: "process.started",
15617
- stream: "process",
15618
- payload: {
15619
- command: harness.command,
15620
- args,
15621
- cwd: input.spec.workspaceDir
15622
- }
15623
- });
15624
15491
  let cleanupTermination = () => void 0;
15625
15492
  let agentEndReached = false;
15626
15493
  let resolveAgentEnd = () => void 0;
@@ -15637,7 +15504,6 @@ function startPiRpcHarness(input, spawnProcess) {
15637
15504
  input,
15638
15505
  line,
15639
15506
  sanitizer,
15640
- trace,
15641
15507
  onAgentEnd() {
15642
15508
  agentEndReached = true;
15643
15509
  resolveAgentEnd("agent-end");
@@ -15648,36 +15514,20 @@ function startPiRpcHarness(input, spawnProcess) {
15648
15514
  });
15649
15515
  });
15650
15516
  const stderrDone = forwardJsonlByteStream(child.stderr, (line) => {
15651
- forwardPiStderrLine(input, line, sanitizer, trace);
15517
+ forwardPiStderrLine(input, line, sanitizer);
15652
15518
  });
15653
- const promptCommand = {
15519
+ writePiRpcCommand(child, {
15654
15520
  id: `mote-${input.spec.taskId}`,
15655
15521
  type: "prompt",
15656
15522
  message: input.prompt
15657
- };
15658
- writePiRpcCommand(child, promptCommand);
15659
- trace.write({
15660
- kind: "prompt.sent",
15661
- stream: "stdin",
15662
- payload: {
15663
- id: promptCommand.id,
15664
- type: promptCommand.type,
15665
- messageLength: input.prompt.length
15666
- }
15667
15523
  });
15668
15524
  const result = (async () => {
15669
15525
  let terminal;
15670
15526
  try {
15671
15527
  terminal = await Promise.race([closePromise, agentEndPromise]);
15672
15528
  } catch (error48) {
15673
- trace.write({
15674
- kind: "process.error",
15675
- stream: "process",
15676
- payload: formatTraceError(error48)
15677
- });
15678
15529
  cleanupTermination();
15679
15530
  cleanupTermination = terminateChildProcess(child);
15680
- await trace.close();
15681
15531
  throw error48;
15682
15532
  }
15683
15533
  if (terminal === "agent-end") {
@@ -15686,12 +15536,6 @@ function startPiRpcHarness(input, spawnProcess) {
15686
15536
  const closeResult = await closePromise;
15687
15537
  cleanupTermination();
15688
15538
  await Promise.all([stdoutDone, stderrDone]);
15689
- trace.write({
15690
- kind: "process.closed",
15691
- stream: "process",
15692
- payload: closeResult
15693
- });
15694
- await trace.close();
15695
15539
  return {
15696
15540
  exitCode: closeResult.exitCode,
15697
15541
  signal: closeResult.signal,
@@ -15700,12 +15544,6 @@ function startPiRpcHarness(input, spawnProcess) {
15700
15544
  }
15701
15545
  cleanupTermination();
15702
15546
  await Promise.all([stdoutDone, stderrDone]);
15703
- trace.write({
15704
- kind: "process.closed",
15705
- stream: "process",
15706
- payload: terminal
15707
- });
15708
- await trace.close();
15709
15547
  if (!agentEndReached && terminal.exitCode !== 0) {
15710
15548
  forwardPiHarnessStreamLine(
15711
15549
  input,
@@ -15733,44 +15571,20 @@ function handlePiRpcStdoutLine(input) {
15733
15571
  try {
15734
15572
  parsed = JSON.parse(trimmed);
15735
15573
  } catch {
15736
- const message = input.sanitizer.redactText(trimmed);
15737
- input.trace.write({
15738
- kind: "stdout.text",
15739
- stream: "stdout",
15740
- payload: {
15741
- message
15742
- }
15743
- });
15744
- forwardPiHarnessStreamLine(input.input, "stdout", message);
15574
+ forwardPiHarnessStreamLine(input.input, "stdout", input.sanitizer.redactText(trimmed));
15745
15575
  return;
15746
15576
  }
15747
- const redacted = input.sanitizer.redactJson(parsed);
15748
15577
  if (isPiRpcResponse(parsed)) {
15749
- input.trace.write({
15750
- kind: "stdout.response",
15751
- stream: "stdout",
15752
- payload: redacted
15753
- });
15754
15578
  if (parsed.command === "prompt" && parsed.success === false) {
15755
15579
  input.onPromptRejected(new Error(`Pi RPC prompt was rejected: ${formatPiRpcError(parsed, input.sanitizer.redactText)}`));
15756
15580
  }
15757
15581
  return;
15758
15582
  }
15759
15583
  if (isPiExtensionUiRequest(parsed)) {
15760
- input.trace.write({
15761
- kind: "stdout.extension_ui_request",
15762
- stream: "stdout",
15763
- payload: redacted
15764
- });
15765
- forwardPiExtensionUiRequest(input.input, redacted);
15584
+ forwardPiExtensionUiRequest(input.input, input.sanitizer.redactJson(parsed));
15766
15585
  return;
15767
15586
  }
15768
- input.trace.write({
15769
- kind: "stdout.event",
15770
- stream: "stdout",
15771
- payload: redacted
15772
- });
15773
- forwardPiEvent(input.input, redacted);
15587
+ forwardPiEvent(input.input, input.sanitizer.redactJson(parsed));
15774
15588
  if (parsed.type === "agent_end") {
15775
15589
  input.onAgentEnd();
15776
15590
  }
@@ -15805,16 +15619,8 @@ function forwardPiHarnessStreamLine(input, stream, message) {
15805
15619
  message: trimmed
15806
15620
  }));
15807
15621
  }
15808
- function forwardPiStderrLine(input, line, sanitizer, trace) {
15809
- const message = sanitizer.redactText(line);
15810
- trace.write({
15811
- kind: "stderr.line",
15812
- stream: "stderr",
15813
- payload: {
15814
- message
15815
- }
15816
- });
15817
- forwardPiHarnessStreamLine(input, "stderr", message);
15622
+ function forwardPiStderrLine(input, line, sanitizer) {
15623
+ forwardPiHarnessStreamLine(input, "stderr", sanitizer.redactText(line));
15818
15624
  }
15819
15625
  function writePiRpcCommand(child, command) {
15820
15626
  child.stdin.write(`${JSON.stringify(command)}
@@ -15853,17 +15659,6 @@ function formatPiRpcError(parsed, redactText) {
15853
15659
  }
15854
15660
  return "unknown error";
15855
15661
  }
15856
- function formatTraceError(error48) {
15857
- if (error48 instanceof Error) {
15858
- return {
15859
- name: error48.name,
15860
- message: error48.message
15861
- };
15862
- }
15863
- return {
15864
- message: String(error48)
15865
- };
15866
- }
15867
15662
 
15868
15663
  // src/prompt.ts
15869
15664
  import { existsSync, readFileSync } from "node:fs";
@@ -15913,14 +15708,14 @@ function renderHarnessPromptTemplate(input) {
15913
15708
 
15914
15709
  // src/runtime.ts
15915
15710
  import { mkdir, readFile as readFile2, stat, writeFile } from "node:fs/promises";
15916
- import { dirname as dirname2, join as join2 } from "node:path";
15711
+ import { dirname, join } from "node:path";
15917
15712
  var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
15918
15713
  function createTaskAgentWorkspacePaths(workspaceDir) {
15919
15714
  const normalized = workspaceDir.replace(/\/+$/g, "");
15920
15715
  return {
15921
15716
  workspaceDir: normalized,
15922
- stateDir: join2(normalized, "state"),
15923
- artifactsDir: join2(normalized, "artifacts")
15717
+ stateDir: join(normalized, "state"),
15718
+ artifactsDir: join(normalized, "artifacts")
15924
15719
  };
15925
15720
  }
15926
15721
  async function ensureTaskAgentWorkspace(paths) {
@@ -15930,10 +15725,10 @@ async function ensureTaskAgentWorkspace(paths) {
15930
15725
  ]);
15931
15726
  }
15932
15727
  async function writeTaskCompletion(input) {
15933
- await writeJsonFile(join2(input.paths.stateDir, "completion.json"), input.completion);
15728
+ await writeJsonFile(join(input.paths.stateDir, "completion.json"), input.completion);
15934
15729
  }
15935
15730
  async function readTaskCompletion(paths) {
15936
- const raw = await readFile2(join2(paths.stateDir, "completion.json"), "utf8");
15731
+ const raw = await readFile2(join(paths.stateDir, "completion.json"), "utf8");
15937
15732
  const parsed = JSON.parse(raw);
15938
15733
  if (parsed.status !== "completed" && parsed.status !== "partial" && parsed.status !== "failed" && parsed.status !== "cancelled") {
15939
15734
  throw new Error("completion status must be completed, partial, failed, or cancelled");
@@ -15951,13 +15746,13 @@ async function readTaskCompletion(paths) {
15951
15746
  }
15952
15747
  async function validateTaskArtifactFiles(input) {
15953
15748
  for (const artifactId of input.completion.artifactIds) {
15954
- const artifactPath = join2(createArtifactDir(input.paths, artifactId), "artifact.json");
15749
+ const artifactPath = join(createArtifactDir(input.paths, artifactId), "artifact.json");
15955
15750
  const artifact = taskArtifactDraftSchema.parse(JSON.parse(await readFile2(artifactPath, "utf8")));
15956
15751
  if (artifact.artifactId !== artifactId) {
15957
15752
  throw new Error(`artifact id mismatch for ${artifactId}`);
15958
15753
  }
15959
15754
  if ("dataset" in artifact) {
15960
- const dataPath = join2(createArtifactDir(input.paths, artifactId), "data.csv");
15755
+ const dataPath = join(createArtifactDir(input.paths, artifactId), "data.csv");
15961
15756
  const dataStat = await stat(dataPath);
15962
15757
  if (dataStat.size <= 0) {
15963
15758
  throw new Error(`dataset artifact ${artifactId} data.csv must be non-empty`);
@@ -15972,10 +15767,10 @@ function assertTaskArtifactId(artifactId) {
15972
15767
  }
15973
15768
  function createArtifactDir(paths, artifactId) {
15974
15769
  assertTaskArtifactId(artifactId);
15975
- return join2(paths.artifactsDir, artifactId);
15770
+ return join(paths.artifactsDir, artifactId);
15976
15771
  }
15977
15772
  async function writeJsonFile(path, value) {
15978
- await mkdir(dirname2(path), { recursive: true });
15773
+ await mkdir(dirname(path), { recursive: true });
15979
15774
  await writeFile(path, `${JSON.stringify(value, null, 2)}
15980
15775
  `);
15981
15776
  }