@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.
- package/dist/bin/agent-runner.js +21 -226
- package/dist/bin/agent-runner.js.map +4 -4
- package/dist/index.js +12 -217
- package/dist/index.js.map +4 -4
- package/package.json +13 -13
- package/dist/debug/pi-rpc-trace.d.ts +0 -54
package/dist/index.js
CHANGED
|
@@ -14126,40 +14126,7 @@ var visualComposerInputSchema = external_exports.object({
|
|
|
14126
14126
|
assetGraph: assetGraphSchema.optional()
|
|
14127
14127
|
}).strict();
|
|
14128
14128
|
|
|
14129
|
-
// ../mote-core/dist/
|
|
14130
|
-
var defaultMoteLogRedactPaths = [
|
|
14131
|
-
"attributes.auth.token",
|
|
14132
|
-
"attributes.http.request.header.authorization",
|
|
14133
|
-
"attributes.http.request.header.cookie",
|
|
14134
|
-
"body.headers.authorization",
|
|
14135
|
-
"body.headers.cookie",
|
|
14136
|
-
"body.apiKey",
|
|
14137
|
-
"body.context",
|
|
14138
|
-
"body.password",
|
|
14139
|
-
"body.token",
|
|
14140
|
-
"body.error.stack"
|
|
14141
|
-
];
|
|
14142
|
-
var moteLogPolicyPresets = {
|
|
14143
|
-
localDebug: {
|
|
14144
|
-
bodyMode: "full",
|
|
14145
|
-
redactionMode: "censor",
|
|
14146
|
-
maxBodyBytes: 256 * 1024,
|
|
14147
|
-
redactPaths: defaultMoteLogRedactPaths
|
|
14148
|
-
},
|
|
14149
|
-
production: {
|
|
14150
|
-
bodyMode: "summary",
|
|
14151
|
-
redactionMode: "remove",
|
|
14152
|
-
maxBodyBytes: 4 * 1024,
|
|
14153
|
-
redactPaths: defaultMoteLogRedactPaths
|
|
14154
|
-
},
|
|
14155
|
-
thirdParty: {
|
|
14156
|
-
bodyMode: "drop",
|
|
14157
|
-
redactionMode: "remove",
|
|
14158
|
-
redactPaths: defaultMoteLogRedactPaths
|
|
14159
|
-
}
|
|
14160
|
-
};
|
|
14161
|
-
|
|
14162
|
-
// ../mote-core/dist/debug/planner-artifact-pool-snapshot.js
|
|
14129
|
+
// ../mote-core/dist/planner-artifact-pool-observability.js
|
|
14163
14130
|
var DEFAULT_PLANNER_ARTIFACT_POOL_SNAPSHOT_MAX_BYTES = 64 * 1024;
|
|
14164
14131
|
|
|
14165
14132
|
// ../mote-core/dist/contracts/data-result.js
|
|
@@ -15079,7 +15046,7 @@ var QuerySchema = external_exports.object({
|
|
|
15079
15046
|
limit: external_exports.number().int().positive().max(1e4).default(1e3),
|
|
15080
15047
|
accessLevel: AccessLevelSchema.default("serving")
|
|
15081
15048
|
}).superRefine((query, ctx) => {
|
|
15082
|
-
const surfaces = [query.from.surface, ...query.joins.map((
|
|
15049
|
+
const surfaces = [query.from.surface, ...query.joins.map((join2) => join2.surface)];
|
|
15083
15050
|
const knownSurfaces = /* @__PURE__ */ new Set();
|
|
15084
15051
|
for (const [index, surface] of surfaces.entries()) {
|
|
15085
15052
|
if (knownSurfaces.has(surface)) {
|
|
@@ -15114,8 +15081,8 @@ var QuerySchema = external_exports.object({
|
|
|
15114
15081
|
path: ["time", "bucket", "fn"]
|
|
15115
15082
|
});
|
|
15116
15083
|
}
|
|
15117
|
-
for (const [index,
|
|
15118
|
-
visitConditionFields(
|
|
15084
|
+
for (const [index, join2] of query.joins.entries()) {
|
|
15085
|
+
visitConditionFields(join2.on, (field) => {
|
|
15119
15086
|
validateFieldRef(field, ["joins", index, "on"]);
|
|
15120
15087
|
});
|
|
15121
15088
|
}
|
|
@@ -15632,92 +15599,6 @@ async function forwardHarnessLines(stream, handler) {
|
|
|
15632
15599
|
|
|
15633
15600
|
// src/harness-drivers/pi-rpc.ts
|
|
15634
15601
|
import { spawn as nodeSpawn2 } from "node:child_process";
|
|
15635
|
-
|
|
15636
|
-
// src/debug/pi-rpc-trace.ts
|
|
15637
|
-
import { once } from "node:events";
|
|
15638
|
-
import { createWriteStream, mkdirSync } from "node:fs";
|
|
15639
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
15640
|
-
var MAX_TRACE_LINE_BYTES = 16384;
|
|
15641
|
-
var MAX_TRACE_PREVIEW_CHARS = 8e3;
|
|
15642
|
-
function createPiRpcTrace(input) {
|
|
15643
|
-
const filePath = join2(input.workspaceDir, "debug", "pi-rpc.jsonl");
|
|
15644
|
-
try {
|
|
15645
|
-
mkdirSync(dirname2(filePath), { recursive: true });
|
|
15646
|
-
const stream = createWriteStream(filePath, {
|
|
15647
|
-
flags: "a",
|
|
15648
|
-
mode: 384
|
|
15649
|
-
});
|
|
15650
|
-
return createStreamTrace({
|
|
15651
|
-
filePath,
|
|
15652
|
-
stream,
|
|
15653
|
-
taskId: input.taskId,
|
|
15654
|
-
now: input.now ?? (() => /* @__PURE__ */ new Date())
|
|
15655
|
-
});
|
|
15656
|
-
} catch {
|
|
15657
|
-
return createNoopTrace();
|
|
15658
|
-
}
|
|
15659
|
-
}
|
|
15660
|
-
function createStreamTrace(input) {
|
|
15661
|
-
let closed = false;
|
|
15662
|
-
let failed = false;
|
|
15663
|
-
input.stream.on("error", () => {
|
|
15664
|
-
failed = true;
|
|
15665
|
-
});
|
|
15666
|
-
return {
|
|
15667
|
-
filePath: input.filePath,
|
|
15668
|
-
write(event) {
|
|
15669
|
-
if (closed || failed) {
|
|
15670
|
-
return;
|
|
15671
|
-
}
|
|
15672
|
-
input.stream.write(serializeTraceRecord({
|
|
15673
|
-
ts: input.now().toISOString(),
|
|
15674
|
-
taskId: input.taskId,
|
|
15675
|
-
...event
|
|
15676
|
-
}));
|
|
15677
|
-
},
|
|
15678
|
-
async close() {
|
|
15679
|
-
if (closed) {
|
|
15680
|
-
return;
|
|
15681
|
-
}
|
|
15682
|
-
closed = true;
|
|
15683
|
-
if (failed) {
|
|
15684
|
-
return;
|
|
15685
|
-
}
|
|
15686
|
-
input.stream.end();
|
|
15687
|
-
await once(input.stream, "finish").then(() => void 0, () => void 0);
|
|
15688
|
-
}
|
|
15689
|
-
};
|
|
15690
|
-
}
|
|
15691
|
-
function createNoopTrace() {
|
|
15692
|
-
return {
|
|
15693
|
-
write() {
|
|
15694
|
-
},
|
|
15695
|
-
async close() {
|
|
15696
|
-
}
|
|
15697
|
-
};
|
|
15698
|
-
}
|
|
15699
|
-
function serializeTraceRecord(record2) {
|
|
15700
|
-
const line = `${JSON.stringify(record2)}
|
|
15701
|
-
`;
|
|
15702
|
-
if (Buffer.byteLength(line, "utf8") <= MAX_TRACE_LINE_BYTES) {
|
|
15703
|
-
return line;
|
|
15704
|
-
}
|
|
15705
|
-
return `${JSON.stringify({
|
|
15706
|
-
...record2,
|
|
15707
|
-
truncated: true,
|
|
15708
|
-
payload: previewPayload(record2.payload)
|
|
15709
|
-
})}
|
|
15710
|
-
`;
|
|
15711
|
-
}
|
|
15712
|
-
function previewPayload(payload) {
|
|
15713
|
-
const text = typeof payload === "string" ? payload : JSON.stringify(payload) ?? "undefined";
|
|
15714
|
-
if (text.length <= MAX_TRACE_PREVIEW_CHARS) {
|
|
15715
|
-
return text;
|
|
15716
|
-
}
|
|
15717
|
-
return `${text.slice(0, MAX_TRACE_PREVIEW_CHARS)}...[truncated]`;
|
|
15718
|
-
}
|
|
15719
|
-
|
|
15720
|
-
// src/harness-drivers/pi-rpc.ts
|
|
15721
15602
|
var driverOwnedPiFlags = /* @__PURE__ */ new Set([
|
|
15722
15603
|
"--mode",
|
|
15723
15604
|
"--provider",
|
|
@@ -15775,8 +15656,7 @@ function buildPiRpcArgs(harness) {
|
|
|
15775
15656
|
}
|
|
15776
15657
|
function startPiRpcHarness(input, spawnProcess) {
|
|
15777
15658
|
const harness = input.harness;
|
|
15778
|
-
const
|
|
15779
|
-
const child = spawnProcess(harness.command, args, {
|
|
15659
|
+
const child = spawnProcess(harness.command, buildPiRpcArgs(harness), {
|
|
15780
15660
|
cwd: input.spec.workspaceDir,
|
|
15781
15661
|
env: input.env,
|
|
15782
15662
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -15784,19 +15664,6 @@ function startPiRpcHarness(input, spawnProcess) {
|
|
|
15784
15664
|
const sanitizer = createHarnessOutputSanitizer(input.env, [
|
|
15785
15665
|
...input.harness.secretEnv ?? []
|
|
15786
15666
|
]);
|
|
15787
|
-
const trace = createPiRpcTrace({
|
|
15788
|
-
taskId: input.spec.taskId,
|
|
15789
|
-
workspaceDir: input.spec.workspaceDir
|
|
15790
|
-
});
|
|
15791
|
-
trace.write({
|
|
15792
|
-
kind: "process.started",
|
|
15793
|
-
stream: "process",
|
|
15794
|
-
payload: {
|
|
15795
|
-
command: harness.command,
|
|
15796
|
-
args,
|
|
15797
|
-
cwd: input.spec.workspaceDir
|
|
15798
|
-
}
|
|
15799
|
-
});
|
|
15800
15667
|
let cleanupTermination = () => void 0;
|
|
15801
15668
|
let agentEndReached = false;
|
|
15802
15669
|
let resolveAgentEnd = () => void 0;
|
|
@@ -15813,7 +15680,6 @@ function startPiRpcHarness(input, spawnProcess) {
|
|
|
15813
15680
|
input,
|
|
15814
15681
|
line,
|
|
15815
15682
|
sanitizer,
|
|
15816
|
-
trace,
|
|
15817
15683
|
onAgentEnd() {
|
|
15818
15684
|
agentEndReached = true;
|
|
15819
15685
|
resolveAgentEnd("agent-end");
|
|
@@ -15824,36 +15690,20 @@ function startPiRpcHarness(input, spawnProcess) {
|
|
|
15824
15690
|
});
|
|
15825
15691
|
});
|
|
15826
15692
|
const stderrDone = forwardJsonlByteStream(child.stderr, (line) => {
|
|
15827
|
-
forwardPiStderrLine(input, line, sanitizer
|
|
15693
|
+
forwardPiStderrLine(input, line, sanitizer);
|
|
15828
15694
|
});
|
|
15829
|
-
|
|
15695
|
+
writePiRpcCommand(child, {
|
|
15830
15696
|
id: `mote-${input.spec.taskId}`,
|
|
15831
15697
|
type: "prompt",
|
|
15832
15698
|
message: input.prompt
|
|
15833
|
-
};
|
|
15834
|
-
writePiRpcCommand(child, promptCommand);
|
|
15835
|
-
trace.write({
|
|
15836
|
-
kind: "prompt.sent",
|
|
15837
|
-
stream: "stdin",
|
|
15838
|
-
payload: {
|
|
15839
|
-
id: promptCommand.id,
|
|
15840
|
-
type: promptCommand.type,
|
|
15841
|
-
messageLength: input.prompt.length
|
|
15842
|
-
}
|
|
15843
15699
|
});
|
|
15844
15700
|
const result = (async () => {
|
|
15845
15701
|
let terminal;
|
|
15846
15702
|
try {
|
|
15847
15703
|
terminal = await Promise.race([closePromise, agentEndPromise]);
|
|
15848
15704
|
} catch (error48) {
|
|
15849
|
-
trace.write({
|
|
15850
|
-
kind: "process.error",
|
|
15851
|
-
stream: "process",
|
|
15852
|
-
payload: formatTraceError(error48)
|
|
15853
|
-
});
|
|
15854
15705
|
cleanupTermination();
|
|
15855
15706
|
cleanupTermination = terminateChildProcess(child);
|
|
15856
|
-
await trace.close();
|
|
15857
15707
|
throw error48;
|
|
15858
15708
|
}
|
|
15859
15709
|
if (terminal === "agent-end") {
|
|
@@ -15862,12 +15712,6 @@ function startPiRpcHarness(input, spawnProcess) {
|
|
|
15862
15712
|
const closeResult = await closePromise;
|
|
15863
15713
|
cleanupTermination();
|
|
15864
15714
|
await Promise.all([stdoutDone, stderrDone]);
|
|
15865
|
-
trace.write({
|
|
15866
|
-
kind: "process.closed",
|
|
15867
|
-
stream: "process",
|
|
15868
|
-
payload: closeResult
|
|
15869
|
-
});
|
|
15870
|
-
await trace.close();
|
|
15871
15715
|
return {
|
|
15872
15716
|
exitCode: closeResult.exitCode,
|
|
15873
15717
|
signal: closeResult.signal,
|
|
@@ -15876,12 +15720,6 @@ function startPiRpcHarness(input, spawnProcess) {
|
|
|
15876
15720
|
}
|
|
15877
15721
|
cleanupTermination();
|
|
15878
15722
|
await Promise.all([stdoutDone, stderrDone]);
|
|
15879
|
-
trace.write({
|
|
15880
|
-
kind: "process.closed",
|
|
15881
|
-
stream: "process",
|
|
15882
|
-
payload: terminal
|
|
15883
|
-
});
|
|
15884
|
-
await trace.close();
|
|
15885
15723
|
if (!agentEndReached && terminal.exitCode !== 0) {
|
|
15886
15724
|
forwardPiHarnessStreamLine(
|
|
15887
15725
|
input,
|
|
@@ -15909,44 +15747,20 @@ function handlePiRpcStdoutLine(input) {
|
|
|
15909
15747
|
try {
|
|
15910
15748
|
parsed = JSON.parse(trimmed);
|
|
15911
15749
|
} catch {
|
|
15912
|
-
|
|
15913
|
-
input.trace.write({
|
|
15914
|
-
kind: "stdout.text",
|
|
15915
|
-
stream: "stdout",
|
|
15916
|
-
payload: {
|
|
15917
|
-
message
|
|
15918
|
-
}
|
|
15919
|
-
});
|
|
15920
|
-
forwardPiHarnessStreamLine(input.input, "stdout", message);
|
|
15750
|
+
forwardPiHarnessStreamLine(input.input, "stdout", input.sanitizer.redactText(trimmed));
|
|
15921
15751
|
return;
|
|
15922
15752
|
}
|
|
15923
|
-
const redacted = input.sanitizer.redactJson(parsed);
|
|
15924
15753
|
if (isPiRpcResponse(parsed)) {
|
|
15925
|
-
input.trace.write({
|
|
15926
|
-
kind: "stdout.response",
|
|
15927
|
-
stream: "stdout",
|
|
15928
|
-
payload: redacted
|
|
15929
|
-
});
|
|
15930
15754
|
if (parsed.command === "prompt" && parsed.success === false) {
|
|
15931
15755
|
input.onPromptRejected(new Error(`Pi RPC prompt was rejected: ${formatPiRpcError(parsed, input.sanitizer.redactText)}`));
|
|
15932
15756
|
}
|
|
15933
15757
|
return;
|
|
15934
15758
|
}
|
|
15935
15759
|
if (isPiExtensionUiRequest(parsed)) {
|
|
15936
|
-
input.
|
|
15937
|
-
kind: "stdout.extension_ui_request",
|
|
15938
|
-
stream: "stdout",
|
|
15939
|
-
payload: redacted
|
|
15940
|
-
});
|
|
15941
|
-
forwardPiExtensionUiRequest(input.input, redacted);
|
|
15760
|
+
forwardPiExtensionUiRequest(input.input, input.sanitizer.redactJson(parsed));
|
|
15942
15761
|
return;
|
|
15943
15762
|
}
|
|
15944
|
-
input.
|
|
15945
|
-
kind: "stdout.event",
|
|
15946
|
-
stream: "stdout",
|
|
15947
|
-
payload: redacted
|
|
15948
|
-
});
|
|
15949
|
-
forwardPiEvent(input.input, redacted);
|
|
15763
|
+
forwardPiEvent(input.input, input.sanitizer.redactJson(parsed));
|
|
15950
15764
|
if (parsed.type === "agent_end") {
|
|
15951
15765
|
input.onAgentEnd();
|
|
15952
15766
|
}
|
|
@@ -15981,16 +15795,8 @@ function forwardPiHarnessStreamLine(input, stream, message) {
|
|
|
15981
15795
|
message: trimmed
|
|
15982
15796
|
}));
|
|
15983
15797
|
}
|
|
15984
|
-
function forwardPiStderrLine(input, line, sanitizer
|
|
15985
|
-
|
|
15986
|
-
trace.write({
|
|
15987
|
-
kind: "stderr.line",
|
|
15988
|
-
stream: "stderr",
|
|
15989
|
-
payload: {
|
|
15990
|
-
message
|
|
15991
|
-
}
|
|
15992
|
-
});
|
|
15993
|
-
forwardPiHarnessStreamLine(input, "stderr", message);
|
|
15798
|
+
function forwardPiStderrLine(input, line, sanitizer) {
|
|
15799
|
+
forwardPiHarnessStreamLine(input, "stderr", sanitizer.redactText(line));
|
|
15994
15800
|
}
|
|
15995
15801
|
function writePiRpcCommand(child, command) {
|
|
15996
15802
|
child.stdin.write(`${JSON.stringify(command)}
|
|
@@ -16029,17 +15835,6 @@ function formatPiRpcError(parsed, redactText) {
|
|
|
16029
15835
|
}
|
|
16030
15836
|
return "unknown error";
|
|
16031
15837
|
}
|
|
16032
|
-
function formatTraceError(error48) {
|
|
16033
|
-
if (error48 instanceof Error) {
|
|
16034
|
-
return {
|
|
16035
|
-
name: error48.name,
|
|
16036
|
-
message: error48.message
|
|
16037
|
-
};
|
|
16038
|
-
}
|
|
16039
|
-
return {
|
|
16040
|
-
message: String(error48)
|
|
16041
|
-
};
|
|
16042
|
-
}
|
|
16043
15838
|
|
|
16044
15839
|
// src/prompt.ts
|
|
16045
15840
|
import { existsSync, readFileSync } from "node:fs";
|