opencrowd 0.5.4 → 0.6.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.
- package/bundle/opencrowd.js +452 -180
- package/package.json +1 -1
package/bundle/opencrowd.js
CHANGED
|
@@ -15548,7 +15548,7 @@ var init_commands = __esm({
|
|
|
15548
15548
|
});
|
|
15549
15549
|
|
|
15550
15550
|
// ../../packages/protocol/dist/events.js
|
|
15551
|
-
var eventBase, runScoped, turnField, WorkerReadyEventSchema, CommandAcceptedEventSchema, CommandRejectionReasonSchema, CommandRejectedEventSchema, RunStateEventSchema, AssistantDeltaEventSchema, AssistantMessageEventSchema, ToolStartedEventSchema, ToolStatusSchema, ToolFinishedEventSchema, ArtifactCreatedEventSchema, UsageUpdatedEventSchema, ApprovalRequestSchema, ApprovalRequiredEventSchema, FundingRequiredEventSchema, DelegationProblemSchema, DelegationRequiredEventSchema, PaymentUnknownEventSchema, CheckpointReasonSchema, CheckpointCompletedEventSchema, RunFinishedEventSchema, RuntimeErrorEventSchema, UserMessageEventSchema, EVENT_TYPES, EventTypeSchema, EventSchema;
|
|
15551
|
+
var eventBase, runScoped, turnField, WorkerReadyEventSchema, CommandAcceptedEventSchema, CommandRejectionReasonSchema, CommandRejectedEventSchema, RunStateEventSchema, AssistantDeltaEventSchema, AssistantMessageEventSchema, ToolStartedEventSchema, ToolStatusSchema, ToolFinishedEventSchema, ModelStartedEventSchema, ModelFinishedEventSchema, ArtifactCreatedEventSchema, UsageUpdatedEventSchema, ApprovalRequestSchema, ApprovalRequiredEventSchema, FundingRequiredEventSchema, DelegationProblemSchema, DelegationRequiredEventSchema, PaymentUnknownEventSchema, CheckpointReasonSchema, CheckpointCompletedEventSchema, RunFinishedEventSchema, RuntimeErrorEventSchema, UserMessageEventSchema, EVENT_TYPES, EventTypeSchema, EventSchema;
|
|
15552
15552
|
var init_events = __esm({
|
|
15553
15553
|
"../../packages/protocol/dist/events.js"() {
|
|
15554
15554
|
"use strict";
|
|
@@ -15667,6 +15667,22 @@ var init_events = __esm({
|
|
|
15667
15667
|
...turnField
|
|
15668
15668
|
})
|
|
15669
15669
|
});
|
|
15670
|
+
ModelStartedEventSchema = external_exports.looseObject({
|
|
15671
|
+
...runScoped,
|
|
15672
|
+
type: external_exports.literal("model.started"),
|
|
15673
|
+
payload: external_exports.looseObject({ callId: IdSchema, model: external_exports.string(), ...turnField })
|
|
15674
|
+
});
|
|
15675
|
+
ModelFinishedEventSchema = external_exports.looseObject({
|
|
15676
|
+
...runScoped,
|
|
15677
|
+
type: external_exports.literal("model.finished"),
|
|
15678
|
+
payload: external_exports.looseObject({
|
|
15679
|
+
callId: IdSchema,
|
|
15680
|
+
model: external_exports.string(),
|
|
15681
|
+
status: ToolStatusSchema,
|
|
15682
|
+
durationMs: external_exports.number().nonnegative(),
|
|
15683
|
+
...turnField
|
|
15684
|
+
})
|
|
15685
|
+
});
|
|
15670
15686
|
ArtifactCreatedEventSchema = external_exports.looseObject({
|
|
15671
15687
|
...runScoped,
|
|
15672
15688
|
type: external_exports.literal("artifact.created"),
|
|
@@ -15805,6 +15821,8 @@ var init_events = __esm({
|
|
|
15805
15821
|
"assistant.delta",
|
|
15806
15822
|
"assistant.message",
|
|
15807
15823
|
"user.message",
|
|
15824
|
+
"model.started",
|
|
15825
|
+
"model.finished",
|
|
15808
15826
|
"tool.started",
|
|
15809
15827
|
"tool.finished",
|
|
15810
15828
|
"artifact.created",
|
|
@@ -15826,6 +15844,8 @@ var init_events = __esm({
|
|
|
15826
15844
|
RunStateEventSchema,
|
|
15827
15845
|
AssistantDeltaEventSchema,
|
|
15828
15846
|
AssistantMessageEventSchema,
|
|
15847
|
+
ModelStartedEventSchema,
|
|
15848
|
+
ModelFinishedEventSchema,
|
|
15829
15849
|
ToolStartedEventSchema,
|
|
15830
15850
|
ToolFinishedEventSchema,
|
|
15831
15851
|
ArtifactCreatedEventSchema,
|
|
@@ -15875,6 +15895,48 @@ var init_redact = __esm({
|
|
|
15875
15895
|
}
|
|
15876
15896
|
});
|
|
15877
15897
|
|
|
15898
|
+
// ../../packages/protocol/dist/telemetry.js
|
|
15899
|
+
function scrubText(text) {
|
|
15900
|
+
return text.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/g, "[REDACTED]").replace(/\bBearer\s+[A-Za-z0-9._~+\/-]+=*/gi, "Bearer [REDACTED]").replace(/\b(?:sk-[A-Za-z0-9_-]{16,}|ph[csx]_[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)\b/g, "[REDACTED]").replace(/\b((?:[A-Z_]*(?:SECRET|PASSWORD|API_KEY|PRIVATE_KEY|ACCESS_TOKEN)[A-Z_]*|authorization|cookie|signature|x-amz-signature)\s*[=:]\s*)[^\s&,;]+/gi, "$1[REDACTED]").replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/g, "$1[REDACTED]@");
|
|
15901
|
+
}
|
|
15902
|
+
function captureDetail(input2, maxBytes = 96 * 1024) {
|
|
15903
|
+
let redacted = false;
|
|
15904
|
+
const clean3 = (value2, depth = 0) => {
|
|
15905
|
+
if (depth > 30)
|
|
15906
|
+
return "[depth limit]";
|
|
15907
|
+
if (typeof value2 === "string") {
|
|
15908
|
+
const s3 = scrubText(value2);
|
|
15909
|
+
redacted ||= s3 !== value2;
|
|
15910
|
+
return s3;
|
|
15911
|
+
}
|
|
15912
|
+
if (Array.isArray(value2))
|
|
15913
|
+
return value2.map((v) => clean3(v, depth + 1));
|
|
15914
|
+
if (value2 && typeof value2 === "object") {
|
|
15915
|
+
return Object.fromEntries(Object.entries(value2).map(([key, v]) => {
|
|
15916
|
+
if (isSensitiveKey(key) || /^(signature|privatekey|seedphrase|mnemonic)$/i.test(key)) {
|
|
15917
|
+
redacted = true;
|
|
15918
|
+
return [key, "[REDACTED]"];
|
|
15919
|
+
}
|
|
15920
|
+
return [key, clean3(v, depth + 1)];
|
|
15921
|
+
}));
|
|
15922
|
+
}
|
|
15923
|
+
return typeof value2 === "bigint" ? value2.toString() : value2 ?? null;
|
|
15924
|
+
};
|
|
15925
|
+
const value = clean3(input2), json3 = JSON.stringify(value), bytes = new TextEncoder().encode(json3).length;
|
|
15926
|
+
return {
|
|
15927
|
+
value: bytes > maxBytes ? { preview: json3.slice(0, Math.floor(maxBytes / 6)) } : value,
|
|
15928
|
+
redacted,
|
|
15929
|
+
truncated: bytes > maxBytes,
|
|
15930
|
+
bytes
|
|
15931
|
+
};
|
|
15932
|
+
}
|
|
15933
|
+
var init_telemetry = __esm({
|
|
15934
|
+
"../../packages/protocol/dist/telemetry.js"() {
|
|
15935
|
+
"use strict";
|
|
15936
|
+
init_redact();
|
|
15937
|
+
}
|
|
15938
|
+
});
|
|
15939
|
+
|
|
15878
15940
|
// ../../packages/protocol/dist/seq.js
|
|
15879
15941
|
var init_seq = __esm({
|
|
15880
15942
|
"../../packages/protocol/dist/seq.js"() {
|
|
@@ -16062,6 +16124,7 @@ var init_dist = __esm({
|
|
|
16062
16124
|
init_commands();
|
|
16063
16125
|
init_events();
|
|
16064
16126
|
init_redact();
|
|
16127
|
+
init_telemetry();
|
|
16065
16128
|
init_seq();
|
|
16066
16129
|
init_codec();
|
|
16067
16130
|
init_context();
|
|
@@ -16348,7 +16411,7 @@ function normalizeConfig(value) {
|
|
|
16348
16411
|
const proxyDefaults = providerDefaults(raw["openrouter-x402-proxy"] ?? raw.x402, DEFAULT_CONFIG["openrouter-x402-proxy"]);
|
|
16349
16412
|
const mcpServers = recordValue(raw.mcpServers);
|
|
16350
16413
|
const servers = { ...DEFAULT_CONFIG.mcpServers, ...mcpServers };
|
|
16351
|
-
if (servers.crowdcode?.command === "npx" && ["0.5", "0.5.2"].some((version6) => JSON.stringify(servers.crowdcode.args) === JSON.stringify(["--yes", `crowdcode-mcp@${version6}`]))) {
|
|
16414
|
+
if (servers.crowdcode?.command === "npx" && ["0.5", "0.5.2", "0.5.3"].some((version6) => JSON.stringify(servers.crowdcode.args) === JSON.stringify(["--yes", `crowdcode-mcp@${version6}`]))) {
|
|
16352
16415
|
servers.crowdcode = { ...servers.crowdcode, args: [...DEFAULT_CONFIG.mcpServers.crowdcode.args] };
|
|
16353
16416
|
}
|
|
16354
16417
|
return {
|
|
@@ -16398,7 +16461,7 @@ var init_config = __esm({
|
|
|
16398
16461
|
configVersion: 3,
|
|
16399
16462
|
mcpServers: {
|
|
16400
16463
|
agentcash: { command: "npx", args: ["--yes", "agentcash@0.17"] },
|
|
16401
|
-
crowdcode: { command: "npx", args: ["--yes", "crowdcode-mcp@0.
|
|
16464
|
+
crowdcode: { command: "npx", args: ["--yes", "crowdcode-mcp@0.6.0"] }
|
|
16402
16465
|
},
|
|
16403
16466
|
// GAIA provider benchmark (2026-08-25): same-model BlockRun matched the
|
|
16404
16467
|
// current route's accuracy and completed the sample 6.7x faster. The
|
|
@@ -33523,6 +33586,9 @@ var init_crowdcode = __esm({
|
|
|
33523
33586
|
constructor(connection) {
|
|
33524
33587
|
this.connection = connection;
|
|
33525
33588
|
}
|
|
33589
|
+
async manage(name, args) {
|
|
33590
|
+
return this.connection.call(name, args);
|
|
33591
|
+
}
|
|
33526
33592
|
async getServiceScore(query) {
|
|
33527
33593
|
const result = await this.connection.call("get_service_score", {
|
|
33528
33594
|
...query.apiEndpoint ? { api_endpoint: query.apiEndpoint } : {},
|
|
@@ -33555,6 +33621,53 @@ var init_crowdcode = __esm({
|
|
|
33555
33621
|
}
|
|
33556
33622
|
});
|
|
33557
33623
|
|
|
33624
|
+
// ../../packages/economy/dist/crowdcode-preferences.js
|
|
33625
|
+
import { mkdir as mkdir8, readFile as readFile8, rename as rename2, writeFile as writeFile4 } from "node:fs/promises";
|
|
33626
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
33627
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
33628
|
+
var CrowdCodePreferences;
|
|
33629
|
+
var init_crowdcode_preferences = __esm({
|
|
33630
|
+
"../../packages/economy/dist/crowdcode-preferences.js"() {
|
|
33631
|
+
"use strict";
|
|
33632
|
+
CrowdCodePreferences = class {
|
|
33633
|
+
session;
|
|
33634
|
+
constructor(session) {
|
|
33635
|
+
this.session = session;
|
|
33636
|
+
}
|
|
33637
|
+
path(scope) {
|
|
33638
|
+
return join9(scope === "session" ? this.session.sessionDir : this.session.workspaceRoot, "crowdcode-preferences.json");
|
|
33639
|
+
}
|
|
33640
|
+
async read(scope) {
|
|
33641
|
+
try {
|
|
33642
|
+
const value = JSON.parse(await readFile8(this.path(scope), "utf8"));
|
|
33643
|
+
return typeof value.enabled === "boolean" ? value.enabled : void 0;
|
|
33644
|
+
} catch (error53) {
|
|
33645
|
+
if (error53.code === "ENOENT")
|
|
33646
|
+
return void 0;
|
|
33647
|
+
throw error53;
|
|
33648
|
+
}
|
|
33649
|
+
}
|
|
33650
|
+
async status() {
|
|
33651
|
+
const default_enabled = await this.read("default") ?? true;
|
|
33652
|
+
const session_enabled = await this.read("session");
|
|
33653
|
+
return { enabled: session_enabled ?? default_enabled, default_enabled, scope: session_enabled === void 0 ? "default" : "session" };
|
|
33654
|
+
}
|
|
33655
|
+
async write(scope, enabled) {
|
|
33656
|
+
const path3 = this.path(scope), temporary = `${path3}.${randomUUID4()}.tmp`;
|
|
33657
|
+
await mkdir8(dirname7(path3), { recursive: true });
|
|
33658
|
+
await writeFile4(temporary, JSON.stringify({ enabled }) + "\n", { mode: 384 });
|
|
33659
|
+
await rename2(temporary, path3);
|
|
33660
|
+
}
|
|
33661
|
+
async set(enabled, scope) {
|
|
33662
|
+
await this.write(scope, enabled);
|
|
33663
|
+
if (scope === "default")
|
|
33664
|
+
await this.write("session");
|
|
33665
|
+
return this.status();
|
|
33666
|
+
}
|
|
33667
|
+
};
|
|
33668
|
+
}
|
|
33669
|
+
});
|
|
33670
|
+
|
|
33558
33671
|
// ../../packages/economy/dist/media.js
|
|
33559
33672
|
import { createHash as createHash2 } from "node:crypto";
|
|
33560
33673
|
async function extractMedia(session, value, depth = 0) {
|
|
@@ -33586,14 +33699,14 @@ var init_media = __esm({
|
|
|
33586
33699
|
});
|
|
33587
33700
|
|
|
33588
33701
|
// ../../packages/economy/dist/purchases.js
|
|
33589
|
-
import { appendFile as appendFile3, mkdir as
|
|
33590
|
-
import { dirname as
|
|
33591
|
-
import { randomUUID as
|
|
33702
|
+
import { appendFile as appendFile3, mkdir as mkdir9, readFile as readFile9 } from "node:fs/promises";
|
|
33703
|
+
import { dirname as dirname8, join as join10 } from "node:path";
|
|
33704
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
33592
33705
|
function purchasesPath(session) {
|
|
33593
|
-
return
|
|
33706
|
+
return join10(session.sessionDir, "purchases.jsonl");
|
|
33594
33707
|
}
|
|
33595
33708
|
function newPurchaseId() {
|
|
33596
|
-
return `pur_${
|
|
33709
|
+
return `pur_${randomUUID5().slice(0, 12)}`;
|
|
33597
33710
|
}
|
|
33598
33711
|
async function appendPurchase(session, record3) {
|
|
33599
33712
|
await appendPurchaseEvent(session, { type: "purchase", record: record3 });
|
|
@@ -33609,16 +33722,20 @@ async function recordReviewSubmitted(session, purchaseId, rating) {
|
|
|
33609
33722
|
async function recordReviewFailed(session, purchaseId) {
|
|
33610
33723
|
await appendPurchaseEvent(session, { type: "review_failed", purchase_id: purchaseId, attempted_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
33611
33724
|
}
|
|
33725
|
+
async function skipPendingReviews(session) {
|
|
33726
|
+
for (const state of await pendingRequiredReviews(session))
|
|
33727
|
+
await appendPurchaseEvent(session, { type: "review_skipped", purchase_id: state.record.purchase_id });
|
|
33728
|
+
}
|
|
33612
33729
|
async function appendPurchaseEvent(session, event) {
|
|
33613
33730
|
const path3 = purchasesPath(session);
|
|
33614
|
-
await
|
|
33731
|
+
await mkdir9(dirname8(path3), { recursive: true });
|
|
33615
33732
|
await appendFile3(path3, `${JSON.stringify(event)}
|
|
33616
33733
|
`, "utf8");
|
|
33617
33734
|
}
|
|
33618
33735
|
async function listPurchases(session) {
|
|
33619
33736
|
let text;
|
|
33620
33737
|
try {
|
|
33621
|
-
text = await
|
|
33738
|
+
text = await readFile9(purchasesPath(session), "utf8");
|
|
33622
33739
|
} catch (error53) {
|
|
33623
33740
|
if (error53.code === "ENOENT") {
|
|
33624
33741
|
return [];
|
|
@@ -33641,6 +33758,10 @@ async function listPurchases(session) {
|
|
|
33641
33758
|
record: event.record,
|
|
33642
33759
|
reviewStatus: event.record.review_required ? "pending" : "not_required"
|
|
33643
33760
|
});
|
|
33761
|
+
} else if (event.type === "review_skipped") {
|
|
33762
|
+
const state = states.get(event.purchase_id);
|
|
33763
|
+
if (state)
|
|
33764
|
+
state.reviewStatus = "not_required";
|
|
33644
33765
|
} else if (event.type === "review_failed") {
|
|
33645
33766
|
const state = states.get(event.purchase_id);
|
|
33646
33767
|
if (state)
|
|
@@ -33683,6 +33804,8 @@ var init_purchases = __esm({
|
|
|
33683
33804
|
});
|
|
33684
33805
|
|
|
33685
33806
|
// ../../packages/economy/dist/gateway.js
|
|
33807
|
+
import { readFile as readFile10, writeFile as writeFile5 } from "node:fs/promises";
|
|
33808
|
+
import { join as join11 } from "node:path";
|
|
33686
33809
|
function inspectionKey(endpoint, method) {
|
|
33687
33810
|
return `${method} ${endpoint}`;
|
|
33688
33811
|
}
|
|
@@ -33743,11 +33866,17 @@ var GATEWAY_TOOL_NAMES, EconomyGateway, GATEWAY_TOOL_DEFINITIONS;
|
|
|
33743
33866
|
var init_gateway = __esm({
|
|
33744
33867
|
"../../packages/economy/dist/gateway.js"() {
|
|
33745
33868
|
"use strict";
|
|
33869
|
+
init_crowdcode_preferences();
|
|
33746
33870
|
init_media();
|
|
33747
33871
|
init_dist2();
|
|
33748
33872
|
init_approvals();
|
|
33749
33873
|
init_purchases();
|
|
33750
33874
|
GATEWAY_TOOL_NAMES = [
|
|
33875
|
+
"crowdcode_status",
|
|
33876
|
+
"set_crowdcode_enabled",
|
|
33877
|
+
"request_service",
|
|
33878
|
+
"list_my_reviews",
|
|
33879
|
+
"delete_my_review",
|
|
33751
33880
|
"read_service",
|
|
33752
33881
|
"get_wallet_status",
|
|
33753
33882
|
"find_paid_service",
|
|
@@ -33758,10 +33887,36 @@ var init_gateway = __esm({
|
|
|
33758
33887
|
];
|
|
33759
33888
|
EconomyGateway = class {
|
|
33760
33889
|
options;
|
|
33761
|
-
|
|
33890
|
+
/**
|
|
33891
|
+
* Inspections are keyed by endpoint+method and persisted under the session so
|
|
33892
|
+
* a run resumed on a fresh gateway instance (funds pause, worker restart) still
|
|
33893
|
+
* honours the inspect-before-call rule instead of failing its first call.
|
|
33894
|
+
*/
|
|
33895
|
+
inspections;
|
|
33762
33896
|
constructor(options) {
|
|
33763
33897
|
this.options = options;
|
|
33764
33898
|
}
|
|
33899
|
+
get inspectionsPath() {
|
|
33900
|
+
return join11(this.options.session.sessionDir, "inspections.json");
|
|
33901
|
+
}
|
|
33902
|
+
async loadInspections() {
|
|
33903
|
+
if (this.inspections)
|
|
33904
|
+
return this.inspections;
|
|
33905
|
+
const map3 = /* @__PURE__ */ new Map();
|
|
33906
|
+
try {
|
|
33907
|
+
const stored = JSON.parse(await readFile10(this.inspectionsPath, "utf8"));
|
|
33908
|
+
for (const [key, value] of Object.entries(stored))
|
|
33909
|
+
map3.set(key, value);
|
|
33910
|
+
} catch {
|
|
33911
|
+
}
|
|
33912
|
+
this.inspections = map3;
|
|
33913
|
+
return map3;
|
|
33914
|
+
}
|
|
33915
|
+
async rememberInspection(key, inspection) {
|
|
33916
|
+
const map3 = await this.loadInspections();
|
|
33917
|
+
map3.set(key, inspection);
|
|
33918
|
+
await writeFile5(this.inspectionsPath, JSON.stringify(Object.fromEntries(map3)), "utf8");
|
|
33919
|
+
}
|
|
33765
33920
|
definitions() {
|
|
33766
33921
|
return GATEWAY_TOOL_DEFINITIONS;
|
|
33767
33922
|
}
|
|
@@ -33770,11 +33925,17 @@ var init_gateway = __esm({
|
|
|
33770
33925
|
}
|
|
33771
33926
|
/** True while a confirmed paid purchase still needs its required review. */
|
|
33772
33927
|
async hasPendingRequiredReviews() {
|
|
33773
|
-
return (await pendingRequiredReviews(this.options.session)).length > 0;
|
|
33928
|
+
return await this.crowdcodeEnabled() && (await pendingRequiredReviews(this.options.session)).length > 0;
|
|
33774
33929
|
}
|
|
33775
33930
|
async execute(name, args, operationId) {
|
|
33776
33931
|
try {
|
|
33777
33932
|
switch (name) {
|
|
33933
|
+
case "crowdcode_status":
|
|
33934
|
+
case "set_crowdcode_enabled":
|
|
33935
|
+
case "request_service":
|
|
33936
|
+
case "list_my_reviews":
|
|
33937
|
+
case "delete_my_review":
|
|
33938
|
+
return await this.manageCrowdCode(name, args);
|
|
33778
33939
|
case "get_wallet_status":
|
|
33779
33940
|
return await this.getWalletStatus();
|
|
33780
33941
|
case "find_paid_service":
|
|
@@ -33798,6 +33959,38 @@ var init_gateway = __esm({
|
|
|
33798
33959
|
return { ok: false, error: error53.message };
|
|
33799
33960
|
}
|
|
33800
33961
|
}
|
|
33962
|
+
async crowdcodeEnabled() {
|
|
33963
|
+
if (!this.options.hostedSpending && !this.options.crowdcode.manage)
|
|
33964
|
+
return true;
|
|
33965
|
+
const status = await this.manageCrowdCode("crowdcode_status", {});
|
|
33966
|
+
if (!status.ok)
|
|
33967
|
+
throw new Error(status.error ?? "CrowdCode preferences unavailable");
|
|
33968
|
+
return status.data?.enabled === true;
|
|
33969
|
+
}
|
|
33970
|
+
async manageCrowdCode(name, args) {
|
|
33971
|
+
if (name === "set_crowdcode_enabled") {
|
|
33972
|
+
if (typeof args.enabled !== "boolean" || args.scope !== void 0 && args.scope !== "session" && args.scope !== "default")
|
|
33973
|
+
return { ok: false, error: "Provide enabled (boolean) and scope (session or default)" };
|
|
33974
|
+
}
|
|
33975
|
+
if (this.options.hostedSpending && (name === "crowdcode_status" || name === "set_crowdcode_enabled")) {
|
|
33976
|
+
const preferences = new CrowdCodePreferences(this.options.session);
|
|
33977
|
+
const data = name === "crowdcode_status" ? await preferences.status() : await preferences.set(args.enabled, args.scope ?? "session");
|
|
33978
|
+
if (name === "set_crowdcode_enabled" && args.enabled === false)
|
|
33979
|
+
await skipPendingReviews(this.options.session);
|
|
33980
|
+
return { ok: true, data };
|
|
33981
|
+
}
|
|
33982
|
+
if (name === "request_service" && !await this.crowdcodeEnabled())
|
|
33983
|
+
return { ok: false, error: "CrowdCode is off. Turn it on to submit service requests." };
|
|
33984
|
+
if (!this.options.crowdcode.manage)
|
|
33985
|
+
return { ok: false, error: "CrowdCode management is unavailable" };
|
|
33986
|
+
const result = await this.options.crowdcode.manage(name, args);
|
|
33987
|
+
if (result.ok && name === "set_crowdcode_enabled" && args.enabled === false)
|
|
33988
|
+
await skipPendingReviews(this.options.session);
|
|
33989
|
+
return result;
|
|
33990
|
+
}
|
|
33991
|
+
async serviceEvidence(endpoint) {
|
|
33992
|
+
return await this.crowdcodeEnabled() ? this.options.crowdcode.getServiceScore({ apiEndpoint: endpoint }) : { ok: true, unproven: true, summary: "CrowdCode is off; reputation checks and submissions are disabled." };
|
|
33993
|
+
}
|
|
33801
33994
|
async getWalletStatus() {
|
|
33802
33995
|
const result = await this.options.agentcash.getBalance();
|
|
33803
33996
|
if (!result.ok) {
|
|
@@ -33832,10 +34025,10 @@ var init_gateway = __esm({
|
|
|
33832
34025
|
if (!schema.ok) {
|
|
33833
34026
|
return { ok: false, error: schema.error };
|
|
33834
34027
|
}
|
|
33835
|
-
const evidence = await this.
|
|
34028
|
+
const evidence = await this.serviceEvidence(endpoint);
|
|
33836
34029
|
const rail = railFromSchema(schema.data);
|
|
33837
34030
|
const priceCeilingCents = priceCeilingFromSchema(schema.data);
|
|
33838
|
-
this.
|
|
34031
|
+
await this.rememberInspection(inspectionKey(endpoint, method), {
|
|
33839
34032
|
endpoint,
|
|
33840
34033
|
method,
|
|
33841
34034
|
rail,
|
|
@@ -33869,7 +34062,7 @@ var init_gateway = __esm({
|
|
|
33869
34062
|
error: "external-service purchases are disabled (approval mode `off`). Local tools and LLM inference remain available; switch with /approval ask|auto."
|
|
33870
34063
|
};
|
|
33871
34064
|
}
|
|
33872
|
-
const pending = await pendingRequiredReviews(session);
|
|
34065
|
+
const pending = await this.crowdcodeEnabled() ? await pendingRequiredReviews(session) : [];
|
|
33873
34066
|
if (pending.length > 0) {
|
|
33874
34067
|
return {
|
|
33875
34068
|
ok: false,
|
|
@@ -33881,7 +34074,7 @@ var init_gateway = __esm({
|
|
|
33881
34074
|
return { ok: false, error: "call_paid_service requires `url`" };
|
|
33882
34075
|
}
|
|
33883
34076
|
const method = (stringArg(args.method) ?? "POST").toUpperCase();
|
|
33884
|
-
const inspection = this.
|
|
34077
|
+
const inspection = (await this.loadInspections()).get(inspectionKey(endpoint, method));
|
|
33885
34078
|
if (!inspection) {
|
|
33886
34079
|
return { ok: false, error: `inspect_paid_service must run for ${method} ${endpoint} before call_paid_service` };
|
|
33887
34080
|
}
|
|
@@ -33908,7 +34101,7 @@ var init_gateway = __esm({
|
|
|
33908
34101
|
if (quotedCostCents === void 0) {
|
|
33909
34102
|
return { ok: false, error: "no price ceiling: pass `max_cost_cents` (the inspection did not report a price)" };
|
|
33910
34103
|
}
|
|
33911
|
-
const evidence = await this.
|
|
34104
|
+
const evidence = await this.serviceEvidence(endpoint);
|
|
33912
34105
|
if (!evidence.ok) {
|
|
33913
34106
|
return {
|
|
33914
34107
|
ok: false,
|
|
@@ -33967,7 +34160,7 @@ var init_gateway = __esm({
|
|
|
33967
34160
|
artifact_path: artifact?.path,
|
|
33968
34161
|
// Confirmed paid successes AND paid failures require reviews; free,
|
|
33969
34162
|
// SIWX, and unknown outcomes create no paid receipt to review.
|
|
33970
|
-
review_required: paid && supportedRail,
|
|
34163
|
+
review_required: paid && supportedRail && await this.crowdcodeEnabled(),
|
|
33971
34164
|
evidence: result.payment,
|
|
33972
34165
|
notes: result.ambiguous ? `${result.ambiguityReason ?? "ambiguous"}: payment state unknown; never auto-retried` : result.error
|
|
33973
34166
|
};
|
|
@@ -34083,6 +34276,8 @@ var init_gateway = __esm({
|
|
|
34083
34276
|
return void 0;
|
|
34084
34277
|
}
|
|
34085
34278
|
async reviewPaidService(args) {
|
|
34279
|
+
if (!await this.crowdcodeEnabled())
|
|
34280
|
+
return { ok: false, error: "CrowdCode is off; review submission is disabled." };
|
|
34086
34281
|
const purchaseId = stringArg(args.purchase_id);
|
|
34087
34282
|
const rating = intArg(args.rating);
|
|
34088
34283
|
const reason = stringArg(args.reason);
|
|
@@ -34164,6 +34359,11 @@ var init_gateway = __esm({
|
|
|
34164
34359
|
}
|
|
34165
34360
|
};
|
|
34166
34361
|
GATEWAY_TOOL_DEFINITIONS = [
|
|
34362
|
+
{ name: "crowdcode_status", description: "Check whether CrowdCode is enabled for this session and by default.", parameters: { type: "object", properties: {}, additionalProperties: false } },
|
|
34363
|
+
{ name: "set_crowdcode_enabled", description: "Handle 'CrowdCode on/off'. Disable reputation checks, automatic reviews and requests. Default scope is this session; scope default also sets the agent default for future sessions. Listing and deleting your reviews remain available while off. Does not change spending permissions.", parameters: { type: "object", properties: { enabled: { type: "boolean" }, scope: { type: "string", enum: ["session", "default"] } }, required: ["enabled"], additionalProperties: false } },
|
|
34364
|
+
{ name: "request_service", description: "Before finishing a real task, record a concrete service worth paying for that would fix an observed failure, poor result, excessive cost or detour. State exact input, paid deliverable, acceptance criteria, actual obstacle and why paying is worthwhile. No purchase or spending authority is required. Skip generic Python/runtime wishes, web search that worked well, and gaps without a sellable remedy. Submit distinct gaps once; submit nothing if everything worked well and cheaply. Exclude private data and secrets.", parameters: { type: "object", properties: { service_description: { type: "string", maxLength: 8e3 }, task_context: { type: "string", maxLength: 4e3 } }, required: ["service_description"], additionalProperties: false } },
|
|
34365
|
+
{ name: "list_my_reviews", description: "List this agent's own submitted reviews with IDs for selective deletion; works while CrowdCode is off. Paginate with next_before_id.", parameters: { type: "object", properties: { before_id: { type: "integer", minimum: 0 }, limit: { type: "integer", minimum: 1, maximum: 100 } }, additionalProperties: false } },
|
|
34366
|
+
{ name: "delete_my_review", description: "Delete one of this agent's reviews when the user asks, using its ID from list_my_reviews. Works while CrowdCode is off. Never delete unrelated reviews.", parameters: { type: "object", properties: { review_id: { type: "integer", minimum: 1 } }, required: ["review_id"], additionalProperties: false } },
|
|
34167
34367
|
{
|
|
34168
34368
|
name: "read_service",
|
|
34169
34369
|
description: "Read a service URL without payment, authenticating with the wallet when required (SIWX). Use this to poll a paid generation job until complete; never resubmit a pending job. Download returned media URLs with run_shell.",
|
|
@@ -34452,7 +34652,7 @@ async function sharedEconomyRuntime(log) {
|
|
|
34452
34652
|
agentcash: new McpAgentCashAdapter(agentcashConnection),
|
|
34453
34653
|
crowdcode: new McpCrowdCodeAdapter(crowdcodeConnection),
|
|
34454
34654
|
instructions: () => [agentcashConnection, crowdcodeConnection].map((connection) => connection.instructions()).filter((text) => Boolean(text)).map((text, index2) => `Instructions from the ${index2 === 0 ? "agentcash" : "crowdcode"} vendor:
|
|
34455
|
-
${text.slice(0,
|
|
34655
|
+
${text.slice(0, 16e3)}`),
|
|
34456
34656
|
close: async () => {
|
|
34457
34657
|
await Promise.all([agentcashConnection.close(), crowdcodeConnection.close()]);
|
|
34458
34658
|
shared = void 0;
|
|
@@ -34518,7 +34718,7 @@ var init_dist4 = __esm({
|
|
|
34518
34718
|
|
|
34519
34719
|
// ../../packages/agent-runtime/dist/context.js
|
|
34520
34720
|
import { createHash as createHash3 } from "node:crypto";
|
|
34521
|
-
import { relative as relative3, join as
|
|
34721
|
+
import { relative as relative3, join as join12 } from "node:path";
|
|
34522
34722
|
async function completeWithContext(session, messages, options) {
|
|
34523
34723
|
for (; ; ) {
|
|
34524
34724
|
options.signal?.throwIfAborted();
|
|
@@ -34576,13 +34776,13 @@ async function compactContext(session, messages, options) {
|
|
|
34576
34776
|
return { tokensBefore, tokensAfter: tokensBefore };
|
|
34577
34777
|
const raw = messages.map((message) => JSON.stringify(message)).join("\n") + "\n";
|
|
34578
34778
|
const digest = createHash3("sha256").update(raw).digest("hex");
|
|
34579
|
-
const dir = await containedPath(session.sessionDir,
|
|
34580
|
-
const path3 =
|
|
34779
|
+
const dir = await containedPath(session.sessionDir, join12("context", digest));
|
|
34780
|
+
const path3 = join12(dir, "transcript.jsonl");
|
|
34581
34781
|
await atomicWrite(path3, raw);
|
|
34582
34782
|
const archivePath = relative3(session.workspaceRoot, path3).split("\\").join("/");
|
|
34583
34783
|
const ref = (index2) => `${relative3(session.workspaceRoot, dir).split("\\").join("/")}/message-${index2 + 1}.txt`;
|
|
34584
34784
|
const externalize = async (message, index2) => {
|
|
34585
|
-
await atomicWrite(
|
|
34785
|
+
await atomicWrite(join12(dir, `message-${index2 + 1}.txt`), messages[index2].content);
|
|
34586
34786
|
return `[Full ${message.role} message saved verbatim to ${ref(index2)}. Use rg/grep and sed/head/tail to read relevant portions before proceeding; do not load the entire file.]`;
|
|
34587
34787
|
};
|
|
34588
34788
|
const list = messages.map((m, index2) => ({ message: structuredClone(m), index: index2 })).filter(({ message }) => !message.contextArchive);
|
|
@@ -34644,11 +34844,11 @@ var init_context2 = __esm({
|
|
|
34644
34844
|
});
|
|
34645
34845
|
|
|
34646
34846
|
// ../../packages/agent-runtime/dist/knowledge.js
|
|
34647
|
-
import { access, cp, mkdir as
|
|
34648
|
-
import { dirname as
|
|
34847
|
+
import { access, cp, mkdir as mkdir10, readFile as readFile11, writeFile as writeFile6 } from "node:fs/promises";
|
|
34848
|
+
import { dirname as dirname9, join as join13, resolve as resolve4 } from "node:path";
|
|
34649
34849
|
import { fileURLToPath } from "node:url";
|
|
34650
34850
|
function bundledKnowledgeDir() {
|
|
34651
|
-
return resolve4(
|
|
34851
|
+
return resolve4(dirname9(fileURLToPath(import.meta.url)), "..", "knowledge");
|
|
34652
34852
|
}
|
|
34653
34853
|
function knowledgeDisabledByEnv() {
|
|
34654
34854
|
const value = process.env.OPENCROWD_KNOWLEDGE_DIR?.trim().toLowerCase();
|
|
@@ -34664,7 +34864,7 @@ async function resolveKnowledgeDir(options = {}) {
|
|
|
34664
34864
|
}
|
|
34665
34865
|
const bundled = bundledKnowledgeDir();
|
|
34666
34866
|
try {
|
|
34667
|
-
await access(
|
|
34867
|
+
await access(join13(bundled, "L0.md"));
|
|
34668
34868
|
return bundled;
|
|
34669
34869
|
} catch {
|
|
34670
34870
|
return void 0;
|
|
@@ -34677,20 +34877,20 @@ async function loadKnowledgeTree(session, options = {}) {
|
|
|
34677
34877
|
}
|
|
34678
34878
|
let l0;
|
|
34679
34879
|
try {
|
|
34680
|
-
l0 = (await
|
|
34880
|
+
l0 = (await readFile11(join13(dir, "L0.md"), "utf8")).trim();
|
|
34681
34881
|
} catch {
|
|
34682
34882
|
return void 0;
|
|
34683
34883
|
}
|
|
34684
34884
|
const version6 = await readVersion(dir, l0);
|
|
34685
|
-
const target =
|
|
34885
|
+
const target = join13(session.artifactsDir, "knowledge");
|
|
34686
34886
|
if (await currentVersion(target) !== version6) {
|
|
34687
|
-
await
|
|
34887
|
+
await mkdir10(session.artifactsDir, { recursive: true });
|
|
34688
34888
|
await cp(dir, target, {
|
|
34689
34889
|
recursive: true,
|
|
34690
34890
|
force: true,
|
|
34691
34891
|
filter: (source) => !source.endsWith("proposal.raw.txt")
|
|
34692
34892
|
});
|
|
34693
|
-
await
|
|
34893
|
+
await writeFile6(join13(target, VERSION_FILE), `${version6}
|
|
34694
34894
|
`, "utf8");
|
|
34695
34895
|
}
|
|
34696
34896
|
if (session.knowledge?.version !== version6 || session.knowledge?.source !== dir) {
|
|
@@ -34708,7 +34908,7 @@ function renderCapabilityIndex(l0) {
|
|
|
34708
34908
|
}
|
|
34709
34909
|
async function readVersion(dir, l0) {
|
|
34710
34910
|
try {
|
|
34711
|
-
const meta4 = JSON.parse(await
|
|
34911
|
+
const meta4 = JSON.parse(await readFile11(join13(dir, "meta.json"), "utf8"));
|
|
34712
34912
|
if (typeof meta4.content_hash === "string" && meta4.content_hash) {
|
|
34713
34913
|
return meta4.id ? `${meta4.id}@${meta4.content_hash}` : meta4.content_hash;
|
|
34714
34914
|
}
|
|
@@ -34719,7 +34919,7 @@ async function readVersion(dir, l0) {
|
|
|
34719
34919
|
}
|
|
34720
34920
|
async function currentVersion(target) {
|
|
34721
34921
|
try {
|
|
34722
|
-
return (await
|
|
34922
|
+
return (await readFile11(join13(target, VERSION_FILE), "utf8")).trim();
|
|
34723
34923
|
} catch {
|
|
34724
34924
|
return void 0;
|
|
34725
34925
|
}
|
|
@@ -35345,7 +35545,7 @@ function alphabet(letters) {
|
|
|
35345
35545
|
};
|
|
35346
35546
|
}
|
|
35347
35547
|
// @__NO_SIDE_EFFECTS__
|
|
35348
|
-
function
|
|
35548
|
+
function join14(separator = "") {
|
|
35349
35549
|
astr("join", separator);
|
|
35350
35550
|
return {
|
|
35351
35551
|
encode: (from16) => {
|
|
@@ -35425,7 +35625,7 @@ function radix(num2) {
|
|
|
35425
35625
|
var genBase58, base58;
|
|
35426
35626
|
var init_esm = __esm({
|
|
35427
35627
|
"../../node_modules/@scure/base/lib/esm/index.js"() {
|
|
35428
|
-
genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */
|
|
35628
|
+
genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join14(""));
|
|
35429
35629
|
base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
35430
35630
|
}
|
|
35431
35631
|
});
|
|
@@ -79842,6 +80042,8 @@ var init_llm_runtime = __esm({
|
|
|
79842
80042
|
|
|
79843
80043
|
// ../../packages/agent-runtime/dist/economy-tools.js
|
|
79844
80044
|
function economyTools(economy, options = {}) {
|
|
80045
|
+
let reflected = false;
|
|
80046
|
+
const supportsReflection = economy.definitions().some((tool) => tool.name === "request_service");
|
|
79845
80047
|
return {
|
|
79846
80048
|
definitions: economy.definitions().filter((tool) => !options.hidden?.has(tool.name)),
|
|
79847
80049
|
execute: async (name, args, operationId) => {
|
|
@@ -79849,7 +80051,17 @@ function economyTools(economy, options = {}) {
|
|
|
79849
80051
|
await economy.execute("inspect_paid_service", { url: args.url, method: args.method, sample_body: args.body });
|
|
79850
80052
|
return economy.execute(name, args, operationId);
|
|
79851
80053
|
},
|
|
79852
|
-
completionGate: async () =>
|
|
80054
|
+
completionGate: async () => {
|
|
80055
|
+
const pending = await economy.hasPendingRequiredReviews();
|
|
80056
|
+
const review = pending ? "A paid purchase still needs its required review; submit it with review_paid_service." : "";
|
|
80057
|
+
if (reflected || !supportsReflection)
|
|
80058
|
+
return review || void 0;
|
|
80059
|
+
reflected = true;
|
|
80060
|
+
const status = await economy.execute("crowdcode_status", {});
|
|
80061
|
+
if (!status.ok || !status.data?.enabled)
|
|
80062
|
+
return review || void 0;
|
|
80063
|
+
return [review, "Before your final answer, reflect once: What concrete services would have been worth paying for to solve this task? For each observed failure, poor result, excessive cost or avoidable detour with a reusable paid remedy, call request_service. Specify exact inputs, the paid deliverable, acceptance criteria, the actual use case and why paying would help. A prior purchase or spending permission is not required. Do not invent budgets. Skip generic local computation, ordinary agent mistakes without a sellable remedy, and services such as web search that already worked well. If everything worked well and cheaply, submit nothing. Then finish the user's task."].filter(Boolean).join(" ");
|
|
80064
|
+
}
|
|
79853
80065
|
};
|
|
79854
80066
|
}
|
|
79855
80067
|
var init_economy_tools = __esm({
|
|
@@ -79860,9 +80072,9 @@ var init_economy_tools = __esm({
|
|
|
79860
80072
|
});
|
|
79861
80073
|
|
|
79862
80074
|
// ../../packages/agent-runtime/dist/runtime.js
|
|
79863
|
-
import { readFile as
|
|
79864
|
-
import { join as
|
|
79865
|
-
import { randomUUID as
|
|
80075
|
+
import { readFile as readFile12, rm as rm2 } from "node:fs/promises";
|
|
80076
|
+
import { join as join19 } from "node:path";
|
|
80077
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
79866
80078
|
function createOpenCrowdRuntime(options) {
|
|
79867
80079
|
const storage = options.storage ?? localRuntimeStorage;
|
|
79868
80080
|
async function prepare(session, runOptions) {
|
|
@@ -79889,10 +80101,10 @@ function createOpenCrowdRuntime(options) {
|
|
|
79889
80101
|
};
|
|
79890
80102
|
}
|
|
79891
80103
|
async function execute2(session, task, runOptions = {}) {
|
|
79892
|
-
const path3 =
|
|
80104
|
+
const path3 = join19(session.sessionDir, "query-checkpoint.json");
|
|
79893
80105
|
let persisted;
|
|
79894
80106
|
try {
|
|
79895
|
-
persisted = JSON.parse(await
|
|
80107
|
+
persisted = JSON.parse(await readFile12(path3, "utf8"));
|
|
79896
80108
|
} catch (error53) {
|
|
79897
80109
|
if (error53.code !== "ENOENT")
|
|
79898
80110
|
throw error53;
|
|
@@ -79900,7 +80112,7 @@ function createOpenCrowdRuntime(options) {
|
|
|
79900
80112
|
const resuming = task === "" && !!persisted;
|
|
79901
80113
|
if (persisted && !resuming)
|
|
79902
80114
|
throw new Error("A query is unfinished. Resume it or decline its pending approval before starting another query.");
|
|
79903
|
-
const saved = resuming ? persisted : { id: runOptions.runId ??
|
|
80115
|
+
const saved = resuming ? persisted : { id: runOptions.runId ?? randomUUID6(), task };
|
|
79904
80116
|
await beginQuery(session, saved.id);
|
|
79905
80117
|
const checkpoint = async (value) => {
|
|
79906
80118
|
saved.checkpoint = value;
|
|
@@ -80132,8 +80344,8 @@ var init_hosted_provider = __esm({
|
|
|
80132
80344
|
});
|
|
80133
80345
|
|
|
80134
80346
|
// ../../packages/agent-runtime/dist/hosted-economy.js
|
|
80135
|
-
import { randomUUID as
|
|
80136
|
-
import { join as
|
|
80347
|
+
import { randomUUID as randomUUID7, createHash as createHash4 } from "node:crypto";
|
|
80348
|
+
import { join as join20 } from "node:path";
|
|
80137
80349
|
function createHostedEconomy(options) {
|
|
80138
80350
|
const fetcher = options.fetcher ?? fetch;
|
|
80139
80351
|
const socket = { socketPath: options.socketPath, runId: options.runId, sessionId: options.sessionId };
|
|
@@ -80146,7 +80358,7 @@ function createHostedEconomy(options) {
|
|
|
80146
80358
|
hostedSpending: true,
|
|
80147
80359
|
minServiceScore: 2,
|
|
80148
80360
|
// Hosted rules live with the agent's session, never in a user config dir.
|
|
80149
|
-
approvalRulesPath:
|
|
80361
|
+
approvalRulesPath: join20(options.session.sessionDir, "approval-rules.json")
|
|
80150
80362
|
});
|
|
80151
80363
|
}
|
|
80152
80364
|
function hostedDynamicTools(economy) {
|
|
@@ -80336,7 +80548,7 @@ var init_hosted_economy = __esm({
|
|
|
80336
80548
|
const method = request2.method.toUpperCase();
|
|
80337
80549
|
const body = request2.body === void 0 ? void 0 : typeof request2.body === "string" ? request2.body : JSON.stringify(request2.body);
|
|
80338
80550
|
const hash5 = request2.operationId ? createHash4("sha256").update(`${this.socket.runId}:${request2.operationId}`).digest("hex") : void 0;
|
|
80339
|
-
const purchaseId = hash5 ? `${hash5.slice(0, 8)}-${hash5.slice(8, 12)}-4${hash5.slice(13, 16)}-8${hash5.slice(17, 20)}-${hash5.slice(20, 32)}` :
|
|
80551
|
+
const purchaseId = hash5 ? `${hash5.slice(0, 8)}-${hash5.slice(8, 12)}-4${hash5.slice(13, 16)}-8${hash5.slice(17, 20)}-${hash5.slice(20, 32)}` : randomUUID7();
|
|
80340
80552
|
let reply;
|
|
80341
80553
|
try {
|
|
80342
80554
|
reply = await postHostedTool(this.socket, "economy.pay", {
|
|
@@ -80423,6 +80635,9 @@ var init_hosted_economy = __esm({
|
|
|
80423
80635
|
HostedCrowdCodeAdapter = class {
|
|
80424
80636
|
directory;
|
|
80425
80637
|
socket;
|
|
80638
|
+
async manage(name, args) {
|
|
80639
|
+
return postHostedTool(this.socket, "economy.crowdcode", { name, ...args });
|
|
80640
|
+
}
|
|
80426
80641
|
constructor(directory, socket) {
|
|
80427
80642
|
this.directory = directory;
|
|
80428
80643
|
this.socket = socket;
|
|
@@ -80484,9 +80699,9 @@ var init_hosted_economy = __esm({
|
|
|
80484
80699
|
});
|
|
80485
80700
|
|
|
80486
80701
|
// ../../packages/agent-runtime/dist/worker.js
|
|
80487
|
-
import { readFile as
|
|
80488
|
-
import { join as
|
|
80489
|
-
import { createHash as createHash5, randomUUID as
|
|
80702
|
+
import { readFile as readFile13, mkdir as mkdir11 } from "node:fs/promises";
|
|
80703
|
+
import { join as join21 } from "node:path";
|
|
80704
|
+
import { createHash as createHash5, randomUUID as randomUUID8 } from "node:crypto";
|
|
80490
80705
|
function isWaiting(outcome) {
|
|
80491
80706
|
return ["waiting_for_approval", "waiting_for_funds", "waiting_for_delegation", "payment_unknown"].includes(outcome);
|
|
80492
80707
|
}
|
|
@@ -80513,6 +80728,7 @@ var RuntimePause, MachineWorker;
|
|
|
80513
80728
|
var init_worker = __esm({
|
|
80514
80729
|
"../../packages/agent-runtime/dist/worker.js"() {
|
|
80515
80730
|
"use strict";
|
|
80731
|
+
init_dist();
|
|
80516
80732
|
init_dist2();
|
|
80517
80733
|
init_dist2();
|
|
80518
80734
|
init_dist();
|
|
@@ -80541,13 +80757,13 @@ var init_worker = __esm({
|
|
|
80541
80757
|
constructor(options) {
|
|
80542
80758
|
this.options = options;
|
|
80543
80759
|
this.paths = resolveAgentPaths({ agentHome: options.agentHome });
|
|
80544
|
-
this.statePath =
|
|
80760
|
+
this.statePath = join21(this.paths.metadata, "worker.json");
|
|
80545
80761
|
}
|
|
80546
80762
|
async initialize() {
|
|
80547
80763
|
await containedPath(this.paths.home, "metadata/worker.json");
|
|
80548
|
-
await
|
|
80764
|
+
await mkdir11(this.paths.metadata, { recursive: true });
|
|
80549
80765
|
try {
|
|
80550
|
-
this.state = JSON.parse(await
|
|
80766
|
+
this.state = JSON.parse(await readFile13(this.statePath, "utf8"));
|
|
80551
80767
|
if (this.state.version !== 1 || !Number.isSafeInteger(this.state.seq) || !this.state.commands || !this.state.runs) {
|
|
80552
80768
|
throw new Error("worker checkpoint version or shape is invalid");
|
|
80553
80769
|
}
|
|
@@ -80574,7 +80790,7 @@ var init_worker = __esm({
|
|
|
80574
80790
|
await this.mutate(() => {
|
|
80575
80791
|
line = encodeEvent({
|
|
80576
80792
|
protocolVersion: 1,
|
|
80577
|
-
id: this.options.id?.() ??
|
|
80793
|
+
id: this.options.id?.() ?? randomUUID8(),
|
|
80578
80794
|
seq: ++this.state.seq,
|
|
80579
80795
|
emittedAt: (this.options.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
80580
80796
|
type,
|
|
@@ -80683,9 +80899,9 @@ var init_worker = __esm({
|
|
|
80683
80899
|
} else if (!run) {
|
|
80684
80900
|
run = {
|
|
80685
80901
|
start: command,
|
|
80686
|
-
sessionId: command.payload.session.sessionId ??
|
|
80902
|
+
sessionId: command.payload.session.sessionId ?? randomUUID8(),
|
|
80687
80903
|
commandId: command.id,
|
|
80688
|
-
checkpointId:
|
|
80904
|
+
checkpointId: randomUUID8(),
|
|
80689
80905
|
tools: /* @__PURE__ */ Object.create(null)
|
|
80690
80906
|
};
|
|
80691
80907
|
}
|
|
@@ -80734,7 +80950,7 @@ var init_worker = __esm({
|
|
|
80734
80950
|
const dynamicTools = economy ? hostedDynamicTools(economy) : void 0;
|
|
80735
80951
|
const record3 = async (name, args, invoke) => {
|
|
80736
80952
|
const call2 = run.checkpoint?.response?.toolCalls.find((c) => c.name === name && !run.checkpoint?.completedTools[c.id]);
|
|
80737
|
-
const id = `${run.checkpoint?.turn ?? 0}:${call2?.id ??
|
|
80953
|
+
const id = `${run.checkpoint?.turn ?? 0}:${call2?.id ?? randomUUID8()}`;
|
|
80738
80954
|
const digest = createHash5("sha256").update(JSON.stringify({ name, args })).digest("hex");
|
|
80739
80955
|
const saved = run.tools[id];
|
|
80740
80956
|
if (saved && saved.digest !== digest)
|
|
@@ -80748,7 +80964,8 @@ var init_worker = __esm({
|
|
|
80748
80964
|
await this.mutate(() => {
|
|
80749
80965
|
run.tools[id] = { digest };
|
|
80750
80966
|
});
|
|
80751
|
-
await this.emit("tool.started", { toolCallId: id, toolName: name, input: summarizeToolInput(name, args) }, runId, run.commandId);
|
|
80967
|
+
await this.emit("tool.started", { toolCallId: id, toolName: name, input: summarizeToolInput(name, args), details: captureDetail({ input: args }), turn: run.checkpoint?.turn ?? 0 }, runId, run.commandId);
|
|
80968
|
+
const started = Date.now();
|
|
80752
80969
|
let output3;
|
|
80753
80970
|
try {
|
|
80754
80971
|
if (saved?.approvalPending && name === "call_paid_service" && economy)
|
|
@@ -80759,6 +80976,15 @@ var init_worker = __esm({
|
|
|
80759
80976
|
await this.mutate(() => {
|
|
80760
80977
|
run.tools[id].approvalPending = true;
|
|
80761
80978
|
});
|
|
80979
|
+
await this.emit("tool.finished", {
|
|
80980
|
+
toolCallId: id,
|
|
80981
|
+
toolName: name,
|
|
80982
|
+
status: error53 instanceof RuntimePause ? "blocked" : signal.aborted ? "cancelled" : "error",
|
|
80983
|
+
durationMs: Date.now() - started,
|
|
80984
|
+
turn: run.checkpoint?.turn ?? 0,
|
|
80985
|
+
error: scrubText(error53 instanceof Error ? error53.message : String(error53)),
|
|
80986
|
+
details: captureDetail({ error: error53 instanceof Error ? { name: error53.name, message: error53.message, stack: error53.stack } : String(error53) })
|
|
80987
|
+
}, runId, run.commandId);
|
|
80762
80988
|
throw error53;
|
|
80763
80989
|
}
|
|
80764
80990
|
await this.mutate(() => {
|
|
@@ -80768,7 +80994,10 @@ var init_worker = __esm({
|
|
|
80768
80994
|
toolCallId: id,
|
|
80769
80995
|
toolName: name,
|
|
80770
80996
|
status: output3.ok ? "ok" : "error",
|
|
80771
|
-
error: output3.error
|
|
80997
|
+
error: output3.error ? scrubText(output3.error) : void 0,
|
|
80998
|
+
durationMs: Date.now() - started,
|
|
80999
|
+
turn: run.checkpoint?.turn ?? 0,
|
|
81000
|
+
details: captureDetail({ output: output3 })
|
|
80772
81001
|
}, runId, run.commandId);
|
|
80773
81002
|
if (name === "save_file" && output3.ok)
|
|
80774
81003
|
await this.emit("artifact.created", {
|
|
@@ -80778,6 +81007,42 @@ var init_worker = __esm({
|
|
|
80778
81007
|
}, runId, run.commandId);
|
|
80779
81008
|
return output3;
|
|
80780
81009
|
};
|
|
81010
|
+
const baseProvider = this.options.provider(run.start, session, dynamicTools?.definitions ?? []);
|
|
81011
|
+
const provider = {
|
|
81012
|
+
complete: async (messages, context) => {
|
|
81013
|
+
const callId = randomUUID8(), started = Date.now(), turn = run.checkpoint?.turn ?? 0;
|
|
81014
|
+
await this.emit("model.started", {
|
|
81015
|
+
callId,
|
|
81016
|
+
model: run.start.payload.modelPolicy.model ?? "demo",
|
|
81017
|
+
turn,
|
|
81018
|
+
details: captureDetail({ input: messages })
|
|
81019
|
+
}, runId, run.commandId);
|
|
81020
|
+
try {
|
|
81021
|
+
const result2 = await baseProvider.complete(messages, context);
|
|
81022
|
+
await this.emit("model.finished", {
|
|
81023
|
+
callId,
|
|
81024
|
+
model: run.start.payload.modelPolicy.model ?? "demo",
|
|
81025
|
+
turn,
|
|
81026
|
+
status: "ok",
|
|
81027
|
+
durationMs: Date.now() - started,
|
|
81028
|
+
usage: result2.usage,
|
|
81029
|
+
details: captureDetail({ output: result2 })
|
|
81030
|
+
}, runId, run.commandId);
|
|
81031
|
+
return result2;
|
|
81032
|
+
} catch (error53) {
|
|
81033
|
+
await this.emit("model.finished", {
|
|
81034
|
+
callId,
|
|
81035
|
+
model: run.start.payload.modelPolicy.model ?? "demo",
|
|
81036
|
+
turn,
|
|
81037
|
+
status: error53 instanceof RuntimePause ? "blocked" : signal.aborted ? "cancelled" : "error",
|
|
81038
|
+
durationMs: Date.now() - started,
|
|
81039
|
+
error: scrubText(error53 instanceof Error ? error53.message : String(error53)),
|
|
81040
|
+
details: captureDetail({ error: error53 instanceof Error ? { name: error53.name, message: error53.message, stack: error53.stack } : String(error53) })
|
|
81041
|
+
}, runId, run.commandId);
|
|
81042
|
+
throw error53;
|
|
81043
|
+
}
|
|
81044
|
+
}
|
|
81045
|
+
};
|
|
80781
81046
|
const acknowledgedMessages = /* @__PURE__ */ new Set();
|
|
80782
81047
|
const result = await runAgentTaskDetailed(session, run.start.payload.prompt, {
|
|
80783
81048
|
inbox: {
|
|
@@ -80800,7 +81065,7 @@ var init_worker = __esm({
|
|
|
80800
81065
|
maxTurns: run.start.payload.maxTurns,
|
|
80801
81066
|
contextWindowTokens: run.start.payload.modelPolicy.contextWindowTokens,
|
|
80802
81067
|
maxOutputTokens: run.start.payload.modelPolicy.maxOutputTokens,
|
|
80803
|
-
provider
|
|
81068
|
+
provider,
|
|
80804
81069
|
history: run.checkpoint ? void 0 : await this.history(session),
|
|
80805
81070
|
...dynamicTools ? {
|
|
80806
81071
|
dynamicTools: { definitions: dynamicTools.definitions, execute: (name, args) => record3(name, args, () => dynamicTools.execute(name, args, `${run.checkpoint?.turn ?? 0}:${run.checkpoint?.response?.toolCalls.find((c) => c.name === name && !run.checkpoint?.completedTools[c.id])?.id}`)) },
|
|
@@ -80810,14 +81075,14 @@ var init_worker = __esm({
|
|
|
80810
81075
|
onCheckpoint: async (checkpoint) => {
|
|
80811
81076
|
await this.mutate(() => {
|
|
80812
81077
|
run.checkpoint = checkpoint;
|
|
80813
|
-
run.checkpointId =
|
|
81078
|
+
run.checkpointId = randomUUID8();
|
|
80814
81079
|
});
|
|
80815
|
-
await atomicWrite(
|
|
81080
|
+
await atomicWrite(join21(session.sessionDir, "messages.jsonl"), checkpoint.messages.filter((m) => m.role !== "system").map((message) => JSON.stringify({ type: "message", timestamp: (/* @__PURE__ */ new Date()).toISOString(), message }) + "\n").join(""));
|
|
80816
81081
|
},
|
|
80817
81082
|
onMessage: async (message) => {
|
|
80818
81083
|
if (message.role === "assistant" && message.content)
|
|
80819
81084
|
await this.emit("assistant.message", {
|
|
80820
|
-
messageId:
|
|
81085
|
+
messageId: randomUUID8(),
|
|
80821
81086
|
content: message.content
|
|
80822
81087
|
}, runId, run.commandId);
|
|
80823
81088
|
},
|
|
@@ -80825,6 +81090,13 @@ var init_worker = __esm({
|
|
|
80825
81090
|
});
|
|
80826
81091
|
await this.finish(runId, run, result.outcome === "stopped" ? "user_stopped" : result.outcome, String(result.summary.final_message ?? ""));
|
|
80827
81092
|
} catch (error53) {
|
|
81093
|
+
if (!(error53 instanceof RuntimePause) && !signal.aborted)
|
|
81094
|
+
await this.emit("runtime.error", {
|
|
81095
|
+
code: "run_exception",
|
|
81096
|
+
message: scrubText(error53 instanceof Error ? error53.message : String(error53)),
|
|
81097
|
+
fatal: false,
|
|
81098
|
+
details: captureDetail({ error: error53 instanceof Error ? { name: error53.name, message: error53.message, stack: error53.stack } : String(error53) })
|
|
81099
|
+
}, runId, run.commandId);
|
|
80828
81100
|
if (signal.aborted)
|
|
80829
81101
|
await this.finish(runId, run, "cancelled", "Run cancelled");
|
|
80830
81102
|
else if (error53 instanceof RuntimePause) {
|
|
@@ -80849,7 +81121,7 @@ var init_worker = __esm({
|
|
|
80849
81121
|
}
|
|
80850
81122
|
async history(session) {
|
|
80851
81123
|
try {
|
|
80852
|
-
return (await
|
|
81124
|
+
return (await readFile13(join21(session.sessionDir, "messages.jsonl"), "utf8")).split("\n").filter(Boolean).map((line) => JSON.parse(line).message).filter(Boolean);
|
|
80853
81125
|
} catch (error53) {
|
|
80854
81126
|
if (error53.code === "ENOENT")
|
|
80855
81127
|
return [];
|
|
@@ -80860,7 +81132,7 @@ var init_worker = __esm({
|
|
|
80860
81132
|
await this.mutate(() => {
|
|
80861
81133
|
run.outcome = outcome;
|
|
80862
81134
|
run.summary = summary;
|
|
80863
|
-
run.checkpointId =
|
|
81135
|
+
run.checkpointId = randomUUID8();
|
|
80864
81136
|
if (!isWaiting(outcome) && this.state.activeRunId === runId)
|
|
80865
81137
|
this.state.activeRunId = void 0;
|
|
80866
81138
|
});
|
|
@@ -80887,7 +81159,7 @@ var init_worker = __esm({
|
|
|
80887
81159
|
});
|
|
80888
81160
|
|
|
80889
81161
|
// ../../packages/agent-runtime/dist/inbox.js
|
|
80890
|
-
import { readFile as
|
|
81162
|
+
import { readFile as readFile14 } from "node:fs/promises";
|
|
80891
81163
|
var FileSteeringInbox;
|
|
80892
81164
|
var init_inbox = __esm({
|
|
80893
81165
|
"../../packages/agent-runtime/dist/inbox.js"() {
|
|
@@ -80901,7 +81173,7 @@ var init_inbox = __esm({
|
|
|
80901
81173
|
}
|
|
80902
81174
|
async read() {
|
|
80903
81175
|
try {
|
|
80904
|
-
return JSON.parse(await
|
|
81176
|
+
return JSON.parse(await readFile14(this.path, "utf8"));
|
|
80905
81177
|
} catch (e6) {
|
|
80906
81178
|
if (e6.code === "ENOENT")
|
|
80907
81179
|
return [];
|
|
@@ -80929,8 +81201,8 @@ var init_inbox = __esm({
|
|
|
80929
81201
|
|
|
80930
81202
|
// ../../packages/agent-runtime/dist/index.js
|
|
80931
81203
|
import { createHash as createHash6 } from "node:crypto";
|
|
80932
|
-
import { appendFile as appendFile4, mkdir as
|
|
80933
|
-
import { join as
|
|
81204
|
+
import { appendFile as appendFile4, mkdir as mkdir12, readFile as readFile15 } from "node:fs/promises";
|
|
81205
|
+
import { join as join22 } from "node:path";
|
|
80934
81206
|
function lastUserMessageIndex(messages) {
|
|
80935
81207
|
for (let index2 = messages.length - 1; index2 >= 0; index2 -= 1) {
|
|
80936
81208
|
if (messages[index2].role === "user") {
|
|
@@ -81121,7 +81393,7 @@ async function runAgentTaskDetailed(session, task, options = {}) {
|
|
|
81121
81393
|
"Before repeatedly fighting the local environment, decide whether the task needs external capability such as hosting, persistent infrastructure, remote compute, specialized APIs, live data, or access the user's device does not have."
|
|
81122
81394
|
];
|
|
81123
81395
|
if (options.dynamicTools) {
|
|
81124
|
-
systemPromptParts.push("When the local computer is not the right environment, or after one clear local capability failure, buy external capability: find_paid_service to discover, inspect_paid_service to see the exact schema/price/reputation, call_paid_service to execute through the enforced purchase lifecycle, and review_paid_service for the required review after every confirmed paid call (success or failure). The same review tool accepts unpaid experiences; review relevant free results or failed attempts without inventing payment evidence. Distinguish provider faults from local errors and uncertain failures.", ...options.hosted ? ["Discover services through AgentCash search and provider catalogs. You can use new services without prior CrowdCode reviews. Only x402 USDC on Base is payable, within the user's configured limits; over-limit quotes request approval. Use read_service for authenticated job polling and never resubmit a pending generation job."] : [], capabilityIndex ?? DEFAULT_CAPABILITY_INDEX, "When a task needs current web facts, search results, or unfamiliar page content, make one paid web search your FIRST move \u2014 do not serially guess URLs with curl; one paid search replaces minutes of blind fetching and costs less than the LLM turns it saves.", "Approval, budget, reputation, and payment rails are enforced in code \u2014 you cannot bypass them, so state costs plainly and never invent payment details.", "Each tool result includes the budget before and after that tool call. Never ask for wallet private keys or secrets.", ...options.promptSections ?? []);
|
|
81396
|
+
systemPromptParts.push("When the local computer is not the right environment, or after one clear local capability failure, buy external capability: find_paid_service to discover, inspect_paid_service to see the exact schema/price/reputation, call_paid_service to execute through the enforced purchase lifecycle, and review_paid_service for the required review after every confirmed paid call (success or failure). The same review tool accepts unpaid experiences; review relevant free results or failed attempts without inventing payment evidence. Distinguish provider faults from local errors and uncertain failures.", ...options.hosted ? ["Discover services through AgentCash search and provider catalogs. You can use new services without prior CrowdCode reviews. Only x402 USDC on Base is payable, within the user's configured limits; over-limit quotes request approval. Use read_service for authenticated job polling and never resubmit a pending generation job."] : [], capabilityIndex ?? DEFAULT_CAPABILITY_INDEX, "When a task needs current web facts, search results, or unfamiliar page content, make one paid web search your FIRST move \u2014 do not serially guess URLs with curl; one paid search replaces minutes of blind fetching and costs less than the LLM turns it saves.", "Approval, budget, reputation, and payment rails are enforced in code \u2014 you cannot bypass them, so state costs plainly and never invent payment details.", "When the user says CrowdCode on/off, call set_crowdcode_enabled; default to session scope unless they ask for a persistent default. Use list_my_reviews and delete_my_review for user-directed review management, including while off. Before finishing a substantive task, consider concrete paid services that would fix real shortcomings and submit qualifying demand with request_service, unless CrowdCode is off. Never invent a purchase or demand.", "Each tool result includes the budget before and after that tool call. Never ask for wallet private keys or secrets.", ...options.promptSections ?? []);
|
|
81125
81397
|
} else {
|
|
81126
81398
|
systemPromptParts.push("Paid external services are unavailable in this run; work with local tools only and say so if the task truly requires external capability.");
|
|
81127
81399
|
}
|
|
@@ -81449,9 +81721,9 @@ async function runSubagentTask(session, args, subagent, index2, parentOptions, o
|
|
|
81449
81721
|
return { ok: false, error: "spawn_subagent requires a task" };
|
|
81450
81722
|
}
|
|
81451
81723
|
const subagentId = `${session.sessionId}#sub${index2}`;
|
|
81452
|
-
const trajectoryDir =
|
|
81453
|
-
const trajectoryPath =
|
|
81454
|
-
await
|
|
81724
|
+
const trajectoryDir = join22(session.sessionDir, "subagents", operationKey ?? String(index2));
|
|
81725
|
+
const trajectoryPath = join22(trajectoryDir, "messages.jsonl");
|
|
81726
|
+
await mkdir12(trajectoryDir, { recursive: true });
|
|
81455
81727
|
const record3 = async (message) => {
|
|
81456
81728
|
await appendFile4(trajectoryPath, `${JSON.stringify({ type: "message", timestamp: (/* @__PURE__ */ new Date()).toISOString(), message })}
|
|
81457
81729
|
`, "utf8");
|
|
@@ -81481,11 +81753,11 @@ async function runSubagentTask(session, args, subagent, index2, parentOptions, o
|
|
|
81481
81753
|
].filter(Boolean).join("\n\n")
|
|
81482
81754
|
}
|
|
81483
81755
|
];
|
|
81484
|
-
const statePath =
|
|
81756
|
+
const statePath = join22(trajectoryDir, "checkpoint.json");
|
|
81485
81757
|
let saved;
|
|
81486
81758
|
if (operationKey)
|
|
81487
81759
|
try {
|
|
81488
|
-
saved = JSON.parse(await
|
|
81760
|
+
saved = JSON.parse(await readFile15(statePath, "utf8"));
|
|
81489
81761
|
} catch (e6) {
|
|
81490
81762
|
if (e6.code !== "ENOENT")
|
|
81491
81763
|
throw e6;
|
|
@@ -82202,7 +82474,7 @@ var init_dist6 = __esm({
|
|
|
82202
82474
|
|
|
82203
82475
|
// src/shared.ts
|
|
82204
82476
|
import { readdir } from "node:fs/promises";
|
|
82205
|
-
import { join as
|
|
82477
|
+
import { join as join23, resolve as resolve5 } from "node:path";
|
|
82206
82478
|
import { stdout as output } from "node:process";
|
|
82207
82479
|
function renderKeyValues(value) {
|
|
82208
82480
|
return Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => ` ${style(key, "muted").padEnd(24)} ${formatCell(item, 80, key)}`).join("\n");
|
|
@@ -82324,7 +82596,7 @@ function isConsumedOption(args, index2, options) {
|
|
|
82324
82596
|
return options.includes(args[index2]) || index2 > 0 && options.includes(args[index2 - 1]);
|
|
82325
82597
|
}
|
|
82326
82598
|
async function latestSessionId(workspaceRoot) {
|
|
82327
|
-
const sessionsDir =
|
|
82599
|
+
const sessionsDir = join23(resolve5(workspaceRoot), "sessions");
|
|
82328
82600
|
try {
|
|
82329
82601
|
const entries = await readdir(sessionsDir, { withFileTypes: true });
|
|
82330
82602
|
return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort().at(-1);
|
|
@@ -82471,8 +82743,8 @@ var init_doctor = __esm({
|
|
|
82471
82743
|
});
|
|
82472
82744
|
|
|
82473
82745
|
// ../../packages/evals/dist/gaia.js
|
|
82474
|
-
import { mkdir as
|
|
82475
|
-
import { dirname as
|
|
82746
|
+
import { mkdir as mkdir13, readFile as readFile16, writeFile as writeFile7, access as access2 } from "node:fs/promises";
|
|
82747
|
+
import { dirname as dirname11, join as join25 } from "node:path";
|
|
82476
82748
|
import { homedir as homedir7 } from "node:os";
|
|
82477
82749
|
function isUnsupportedModality(fileName) {
|
|
82478
82750
|
if (!fileName) {
|
|
@@ -82482,18 +82754,18 @@ function isUnsupportedModality(fileName) {
|
|
|
82482
82754
|
return UNSUPPORTED_EXTENSIONS.some((extension2) => lower.endsWith(extension2));
|
|
82483
82755
|
}
|
|
82484
82756
|
function defaultGaiaCacheDir() {
|
|
82485
|
-
return process.env.OPENCROWD_GAIA_CACHE_DIR ??
|
|
82757
|
+
return process.env.OPENCROWD_GAIA_CACHE_DIR ?? join25(homedir7(), ".cache", "opencrowd", "gaia", "2023", "validation");
|
|
82486
82758
|
}
|
|
82487
82759
|
async function fetchGaiaValidation(options = {}) {
|
|
82488
82760
|
const cacheDir = options.cacheDir ?? defaultGaiaCacheDir();
|
|
82489
|
-
await
|
|
82490
|
-
const metadataPath =
|
|
82761
|
+
await mkdir13(cacheDir, { recursive: true });
|
|
82762
|
+
const metadataPath = join25(cacheDir, "metadata.jsonl");
|
|
82491
82763
|
let metadataText;
|
|
82492
82764
|
try {
|
|
82493
|
-
metadataText = await
|
|
82765
|
+
metadataText = await readFile16(metadataPath, "utf8");
|
|
82494
82766
|
} catch {
|
|
82495
82767
|
metadataText = await fetchValidationRows(options);
|
|
82496
|
-
await
|
|
82768
|
+
await writeFile7(metadataPath, metadataText, "utf8");
|
|
82497
82769
|
}
|
|
82498
82770
|
return metadataText.split(/\r?\n/).filter(Boolean).map((line) => parseGaiaRecord(JSON.parse(line)));
|
|
82499
82771
|
}
|
|
@@ -82542,7 +82814,7 @@ async function ensureGaiaAttachments(questions, options = {}) {
|
|
|
82542
82814
|
const cacheDir = options.cacheDir ?? defaultGaiaCacheDir();
|
|
82543
82815
|
for (const question of questions) {
|
|
82544
82816
|
if (question.file_name && !isUnsupportedModality(question.file_name)) {
|
|
82545
|
-
const filePath =
|
|
82817
|
+
const filePath = join25(cacheDir, question.file_name);
|
|
82546
82818
|
await cachedDownload(filePath, `${GAIA_BASE_URL}/${encodeURIComponent(question.file_name)}`, options, true);
|
|
82547
82819
|
question.file_path = filePath;
|
|
82548
82820
|
}
|
|
@@ -82572,7 +82844,7 @@ function parseGaiaRecord(record3) {
|
|
|
82572
82844
|
async function cachedDownload(path3, url3, options, binary = false) {
|
|
82573
82845
|
try {
|
|
82574
82846
|
await access2(path3);
|
|
82575
|
-
return binary ? "" : await
|
|
82847
|
+
return binary ? "" : await readFile16(path3, "utf8");
|
|
82576
82848
|
} catch {
|
|
82577
82849
|
}
|
|
82578
82850
|
options.log?.(`fetching ${url3}`);
|
|
@@ -82591,14 +82863,14 @@ async function cachedDownload(path3, url3, options, binary = false) {
|
|
|
82591
82863
|
if (!response.ok) {
|
|
82592
82864
|
throw new Error(`GAIA download failed: ${response.status} ${response.statusText} for ${url3}`);
|
|
82593
82865
|
}
|
|
82594
|
-
await
|
|
82866
|
+
await mkdir13(dirname11(path3), { recursive: true });
|
|
82595
82867
|
if (binary) {
|
|
82596
82868
|
const buffer2 = Buffer.from(await response.arrayBuffer());
|
|
82597
|
-
await
|
|
82869
|
+
await writeFile7(path3, buffer2);
|
|
82598
82870
|
return "";
|
|
82599
82871
|
}
|
|
82600
82872
|
const text = await response.text();
|
|
82601
|
-
await
|
|
82873
|
+
await writeFile7(path3, text, "utf8");
|
|
82602
82874
|
return text;
|
|
82603
82875
|
}
|
|
82604
82876
|
var GAIA_BASE_URL, GAIA_ROWS_URL, GAIA_TIERS, UNSUPPORTED_EXTENSIONS;
|
|
@@ -82632,9 +82904,9 @@ var init_gaia = __esm({
|
|
|
82632
82904
|
});
|
|
82633
82905
|
|
|
82634
82906
|
// ../../packages/evals/dist/grader.js
|
|
82635
|
-
import { readFile as
|
|
82907
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
82636
82908
|
async function gradeTrajectoryFile(path3) {
|
|
82637
|
-
const text = await
|
|
82909
|
+
const text = await readFile17(path3, "utf8");
|
|
82638
82910
|
const entries = text.split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));
|
|
82639
82911
|
return gradeTrajectory(entries);
|
|
82640
82912
|
}
|
|
@@ -82767,8 +83039,8 @@ var init_grader = __esm({
|
|
|
82767
83039
|
// ../../packages/evals/dist/harnesses.js
|
|
82768
83040
|
import { execFile } from "node:child_process";
|
|
82769
83041
|
import { promisify } from "node:util";
|
|
82770
|
-
import { copyFile, mkdir as
|
|
82771
|
-
import { basename, join as
|
|
83042
|
+
import { copyFile, mkdir as mkdir14, readFile as readFile18 } from "node:fs/promises";
|
|
83043
|
+
import { basename, join as join26 } from "node:path";
|
|
82772
83044
|
function resolveHarness(name) {
|
|
82773
83045
|
switch (name) {
|
|
82774
83046
|
case "opencrowd":
|
|
@@ -82797,7 +83069,7 @@ function gaiaPrompt(question, attachmentNote) {
|
|
|
82797
83069
|
}
|
|
82798
83070
|
async function countPaidPurchases(path3) {
|
|
82799
83071
|
try {
|
|
82800
|
-
const text = await
|
|
83072
|
+
const text = await readFile18(path3, "utf8");
|
|
82801
83073
|
return text.split(/\r?\n/).filter(Boolean).filter((line) => {
|
|
82802
83074
|
const entry = asRecord3(parseJson3(line));
|
|
82803
83075
|
const outcome = asRecord3(entry.record).outcome ?? entry.outcome;
|
|
@@ -82812,7 +83084,7 @@ async function comparatorPrompt(context) {
|
|
|
82812
83084
|
return context.prompt;
|
|
82813
83085
|
}
|
|
82814
83086
|
const name = basename(context.attachmentPath);
|
|
82815
|
-
await copyFile(context.attachmentPath,
|
|
83087
|
+
await copyFile(context.attachmentPath, join26(context.runDir, name));
|
|
82816
83088
|
return `${context.prompt}
|
|
82817
83089
|
|
|
82818
83090
|
An input file is available in the working directory at ./${name}`;
|
|
@@ -82906,11 +83178,11 @@ var init_harnesses = __esm({
|
|
|
82906
83178
|
let prompt = context.prompt;
|
|
82907
83179
|
if (context.attachmentPath) {
|
|
82908
83180
|
const name = basename(context.attachmentPath);
|
|
82909
|
-
await
|
|
82910
|
-
await copyFile(context.attachmentPath,
|
|
83181
|
+
await mkdir14(session.artifactsDir, { recursive: true });
|
|
83182
|
+
await copyFile(context.attachmentPath, join26(session.artifactsDir, name));
|
|
82911
83183
|
prompt = `${prompt}
|
|
82912
83184
|
|
|
82913
|
-
An input file is available at the session artifact path \`${name}\` (use read_file, or run_shell against ${
|
|
83185
|
+
An input file is available at the session artifact path \`${name}\` (use read_file, or run_shell against ${join26(session.artifactsDir, name)}).`;
|
|
82914
83186
|
}
|
|
82915
83187
|
const llm = context.testMode ? void 0 : await resolveLlmRuntime(session, {
|
|
82916
83188
|
model: context.model,
|
|
@@ -82941,7 +83213,7 @@ An input file is available at the session artifact path \`${name}\` (use read_fi
|
|
|
82941
83213
|
onMessage: (message) => appendConversationMessage(session, message)
|
|
82942
83214
|
});
|
|
82943
83215
|
const budget = asRecord3(result.summary.budget);
|
|
82944
|
-
const trajectoryPath =
|
|
83216
|
+
const trajectoryPath = join26(session.sessionDir, "messages.jsonl");
|
|
82945
83217
|
return {
|
|
82946
83218
|
final_message: String(result.summary.final_message ?? ""),
|
|
82947
83219
|
turns: result.turns,
|
|
@@ -82952,7 +83224,7 @@ An input file is available at the session artifact path \`${name}\` (use read_fi
|
|
|
82952
83224
|
knowledge_version: session.knowledge?.version,
|
|
82953
83225
|
session_dir: session.sessionDir,
|
|
82954
83226
|
artifacts_dir: session.artifactsDir,
|
|
82955
|
-
paid_calls: await countPaidPurchases(
|
|
83227
|
+
paid_calls: await countPaidPurchases(join26(session.sessionDir, "purchases.jsonl")),
|
|
82956
83228
|
model_policy: llm?.models,
|
|
82957
83229
|
compliance: await gradeTrajectoryFile(trajectoryPath).catch(() => void 0)
|
|
82958
83230
|
};
|
|
@@ -83155,8 +83427,8 @@ var init_scorer = __esm({
|
|
|
83155
83427
|
});
|
|
83156
83428
|
|
|
83157
83429
|
// ../../packages/evals/dist/runner.js
|
|
83158
|
-
import { appendFile as appendFile5, mkdir as
|
|
83159
|
-
import { join as
|
|
83430
|
+
import { appendFile as appendFile5, mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
83431
|
+
import { join as join27, resolve as resolve6 } from "node:path";
|
|
83160
83432
|
async function runGaiaBenchmark(options) {
|
|
83161
83433
|
const log = options.log ?? (() => void 0);
|
|
83162
83434
|
const harnesses = options.harnesses.map(resolveHarness);
|
|
@@ -83182,8 +83454,8 @@ async function runGaiaBenchmark(options) {
|
|
|
83182
83454
|
}
|
|
83183
83455
|
const runId = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
83184
83456
|
const resultsDir = resolve6(options.workspaceRoot, "evals", "gaia", runId);
|
|
83185
|
-
await
|
|
83186
|
-
const resultsPath =
|
|
83457
|
+
await mkdir15(resultsDir, { recursive: true });
|
|
83458
|
+
const resultsPath = join27(resultsDir, "results.jsonl");
|
|
83187
83459
|
log(`GAIA ${options.tier}: ${runnable.length} questions, ${skipped.length} skipped (unsupported modality), results in ${resultsDir}`);
|
|
83188
83460
|
const parallel = Math.max(1, options.parallel ?? 4);
|
|
83189
83461
|
const rows = [];
|
|
@@ -83209,13 +83481,13 @@ async function runGaiaBenchmark(options) {
|
|
|
83209
83481
|
harnesses: harnesses.map((harness) => summarizeHarness(harness, rows.filter((row) => row.harness === harness.name))),
|
|
83210
83482
|
rows
|
|
83211
83483
|
};
|
|
83212
|
-
await
|
|
83484
|
+
await writeFile8(join27(resultsDir, "report.json"), `${JSON.stringify(report, null, 2)}
|
|
83213
83485
|
`, "utf8");
|
|
83214
83486
|
return report;
|
|
83215
83487
|
}
|
|
83216
83488
|
async function runOneQuestion(harness, question, resultsDir, options) {
|
|
83217
|
-
const runDir =
|
|
83218
|
-
await
|
|
83489
|
+
const runDir = join27(resultsDir, harness.name, question.task_id);
|
|
83490
|
+
await mkdir15(runDir, { recursive: true });
|
|
83219
83491
|
const prompt = gaiaPrompt(question);
|
|
83220
83492
|
const started = Date.now();
|
|
83221
83493
|
let run;
|
|
@@ -83346,9 +83618,9 @@ var init_runner = __esm({
|
|
|
83346
83618
|
});
|
|
83347
83619
|
|
|
83348
83620
|
// ../../packages/evals/dist/tasks.js
|
|
83349
|
-
import { readFile as
|
|
83621
|
+
import { readFile as readFile19 } from "node:fs/promises";
|
|
83350
83622
|
import { createHash as createHash7 } from "node:crypto";
|
|
83351
|
-
import { dirname as
|
|
83623
|
+
import { dirname as dirname12, join as join28 } from "node:path";
|
|
83352
83624
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
83353
83625
|
import { homedir as homedir8 } from "node:os";
|
|
83354
83626
|
async function loadTaskSet(name, options = {}) {
|
|
@@ -83370,10 +83642,10 @@ async function loadTaskSet(name, options = {}) {
|
|
|
83370
83642
|
}
|
|
83371
83643
|
}
|
|
83372
83644
|
function tasksDir() {
|
|
83373
|
-
return
|
|
83645
|
+
return join28(dirname12(fileURLToPath2(import.meta.url)), "..", "tasks");
|
|
83374
83646
|
}
|
|
83375
83647
|
async function loadUsageTasks() {
|
|
83376
|
-
const raw = JSON.parse(await
|
|
83648
|
+
const raw = JSON.parse(await readFile19(join28(tasksDir(), "usage.json"), "utf8"));
|
|
83377
83649
|
return raw.tasks.map((task) => ({
|
|
83378
83650
|
task_id: String(task.id),
|
|
83379
83651
|
suite: "usage",
|
|
@@ -83385,7 +83657,7 @@ async function loadUsageTasks() {
|
|
|
83385
83657
|
capability: typeof task.capability === "string" ? task.capability : void 0,
|
|
83386
83658
|
expect_paid: task.expect_paid,
|
|
83387
83659
|
file_name: typeof task.attachment === "string" ? task.attachment : void 0,
|
|
83388
|
-
file_path: typeof task.attachment === "string" ?
|
|
83660
|
+
file_path: typeof task.attachment === "string" ? join28(tasksDir(), "attachments", task.attachment) : void 0
|
|
83389
83661
|
}));
|
|
83390
83662
|
}
|
|
83391
83663
|
async function loadGaiaHard(options = {}) {
|
|
@@ -83411,13 +83683,13 @@ function gaiaToTask(question) {
|
|
|
83411
83683
|
};
|
|
83412
83684
|
}
|
|
83413
83685
|
function defaultAssistantBenchCachePath() {
|
|
83414
|
-
return process.env.OPENCROWD_ASSISTANTBENCH_CACHE ??
|
|
83686
|
+
return process.env.OPENCROWD_ASSISTANTBENCH_CACHE ?? join28(homedir8(), ".cache", "opencrowd", "assistantbench", "validation.jsonl");
|
|
83415
83687
|
}
|
|
83416
83688
|
async function loadAssistantBench(options = {}) {
|
|
83417
83689
|
const cachePath = defaultAssistantBenchCachePath();
|
|
83418
83690
|
let text;
|
|
83419
83691
|
try {
|
|
83420
|
-
text = await
|
|
83692
|
+
text = await readFile19(cachePath, "utf8");
|
|
83421
83693
|
} catch {
|
|
83422
83694
|
options.log?.(`fetching ${ASSISTANTBENCH_ROWS_URL}`);
|
|
83423
83695
|
const headers = options.hfToken ? { authorization: `Bearer ${options.hfToken}` } : {};
|
|
@@ -83428,9 +83700,9 @@ async function loadAssistantBench(options = {}) {
|
|
|
83428
83700
|
const body = await response.json();
|
|
83429
83701
|
text = `${(body.rows ?? []).map((item) => JSON.stringify(item.row)).join("\n")}
|
|
83430
83702
|
`;
|
|
83431
|
-
const { mkdir:
|
|
83432
|
-
await
|
|
83433
|
-
await
|
|
83703
|
+
const { mkdir: mkdir21, writeFile: writeFile13 } = await import("node:fs/promises");
|
|
83704
|
+
await mkdir21(dirname12(cachePath), { recursive: true });
|
|
83705
|
+
await writeFile13(cachePath, text, "utf8");
|
|
83434
83706
|
}
|
|
83435
83707
|
const rows = text.split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));
|
|
83436
83708
|
const selected = seededSample(rows, ASSISTANTBENCH_COUNT, `${options.seed ?? DEFAULT_SEED}:assistantbench`, (row) => String(row.id));
|
|
@@ -83486,9 +83758,9 @@ var init_tasks = __esm({
|
|
|
83486
83758
|
});
|
|
83487
83759
|
|
|
83488
83760
|
// ../../packages/evals/dist/scoring.js
|
|
83489
|
-
import { readFile as
|
|
83761
|
+
import { readFile as readFile20, stat } from "node:fs/promises";
|
|
83490
83762
|
import { resolve as resolveDns } from "node:dns/promises";
|
|
83491
|
-
import { join as
|
|
83763
|
+
import { join as join29 } from "node:path";
|
|
83492
83764
|
async function scoreTask(task, finalMessage, context = {}) {
|
|
83493
83765
|
const answer = extractAnswerText(finalMessage);
|
|
83494
83766
|
const spec = task.scorer;
|
|
@@ -83533,7 +83805,7 @@ async function scoreTask(task, finalMessage, context = {}) {
|
|
|
83533
83805
|
return { score: 0, correct: false, detail: "no artifacts dir" };
|
|
83534
83806
|
}
|
|
83535
83807
|
for (const name of spec.names) {
|
|
83536
|
-
const path3 =
|
|
83808
|
+
const path3 = join29(context.artifactsDir, name);
|
|
83537
83809
|
let size5;
|
|
83538
83810
|
try {
|
|
83539
83811
|
size5 = (await stat(path3)).size;
|
|
@@ -83543,7 +83815,7 @@ async function scoreTask(task, finalMessage, context = {}) {
|
|
|
83543
83815
|
if (spec.min_bytes !== void 0 && size5 < spec.min_bytes) {
|
|
83544
83816
|
return { score: 0, correct: false, detail: `${name} too small (${size5} bytes)` };
|
|
83545
83817
|
}
|
|
83546
|
-
const buffer2 = await
|
|
83818
|
+
const buffer2 = await readFile20(path3);
|
|
83547
83819
|
if (spec.image && !looksLikeImage(buffer2)) {
|
|
83548
83820
|
return { score: 0, correct: false, detail: `${name} is not a PNG/JPEG/WebP` };
|
|
83549
83821
|
}
|
|
@@ -83730,8 +84002,8 @@ var init_scoring = __esm({
|
|
|
83730
84002
|
});
|
|
83731
84003
|
|
|
83732
84004
|
// ../../packages/evals/dist/suite.js
|
|
83733
|
-
import { appendFile as appendFile6, mkdir as
|
|
83734
|
-
import { join as
|
|
84005
|
+
import { appendFile as appendFile6, mkdir as mkdir16, writeFile as writeFile9 } from "node:fs/promises";
|
|
84006
|
+
import { join as join30, resolve as resolve7 } from "node:path";
|
|
83735
84007
|
async function runSuite(options) {
|
|
83736
84008
|
const log = options.log ?? (() => void 0);
|
|
83737
84009
|
const harness = resolveHarness(options.harness ?? "opencrowd");
|
|
@@ -83745,8 +84017,8 @@ async function runSuite(options) {
|
|
|
83745
84017
|
}
|
|
83746
84018
|
const runId = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}${options.tag ? `-${slug(options.tag)}` : ""}`;
|
|
83747
84019
|
const resultsDir = resolve7(options.resultsRoot, runId);
|
|
83748
|
-
await
|
|
83749
|
-
const resultsPath =
|
|
84020
|
+
await mkdir16(resultsDir, { recursive: true });
|
|
84021
|
+
const resultsPath = join30(resultsDir, "results.jsonl");
|
|
83750
84022
|
log(`suite ${options.set}${options.tag ? ` [${options.tag}]` : ""}: ${tasks.length} tasks, knowledge=${options.knowledgeDir ?? "none"}, results in ${resultsDir}`);
|
|
83751
84023
|
const limit = createLimiter3(Math.max(1, options.parallel ?? 3));
|
|
83752
84024
|
const rows = await Promise.all(tasks.map((task, index2) => limit(async () => {
|
|
@@ -83770,15 +84042,15 @@ async function runSuite(options) {
|
|
|
83770
84042
|
summary: summarize(rows),
|
|
83771
84043
|
rows
|
|
83772
84044
|
};
|
|
83773
|
-
await
|
|
84045
|
+
await writeFile9(join30(resultsDir, "report.json"), `${JSON.stringify(report, null, 2)}
|
|
83774
84046
|
`, "utf8");
|
|
83775
|
-
await
|
|
84047
|
+
await writeFile9(join30(resultsDir, "report.md"), `${renderSuiteReport(report)}
|
|
83776
84048
|
`, "utf8");
|
|
83777
84049
|
return report;
|
|
83778
84050
|
}
|
|
83779
84051
|
async function runOneTask(harnessName, harness, task, resultsDir, runId, options) {
|
|
83780
|
-
const runDir =
|
|
83781
|
-
await
|
|
84052
|
+
const runDir = join30(resultsDir, harnessName, task.task_id);
|
|
84053
|
+
await mkdir16(runDir, { recursive: true });
|
|
83782
84054
|
const started = Date.now();
|
|
83783
84055
|
let run;
|
|
83784
84056
|
try {
|
|
@@ -83937,13 +84209,13 @@ var init_suite = __esm({
|
|
|
83937
84209
|
});
|
|
83938
84210
|
|
|
83939
84211
|
// ../../packages/evals/dist/evidence.js
|
|
83940
|
-
import { mkdir as
|
|
83941
|
-
import { dirname as
|
|
84212
|
+
import { mkdir as mkdir17, readFile as readFile21, writeFile as writeFile10 } from "node:fs/promises";
|
|
84213
|
+
import { dirname as dirname13 } from "node:path";
|
|
83942
84214
|
async function fetchCrowdCodeEvidence(options = {}) {
|
|
83943
84215
|
const cachePath = options.cachePath;
|
|
83944
84216
|
if (cachePath && options.useCache !== false) {
|
|
83945
84217
|
try {
|
|
83946
|
-
return JSON.parse(await
|
|
84218
|
+
return JSON.parse(await readFile21(cachePath, "utf8"));
|
|
83947
84219
|
} catch {
|
|
83948
84220
|
}
|
|
83949
84221
|
}
|
|
@@ -83955,8 +84227,8 @@ async function fetchCrowdCodeEvidence(options = {}) {
|
|
|
83955
84227
|
const exported = await fetchGatedExport(fetchImpl, baseUrl, exportToken, log);
|
|
83956
84228
|
if (exported) {
|
|
83957
84229
|
if (cachePath) {
|
|
83958
|
-
await
|
|
83959
|
-
await
|
|
84230
|
+
await mkdir17(dirname13(cachePath), { recursive: true });
|
|
84231
|
+
await writeFile10(cachePath, `${JSON.stringify(exported, null, 1)}
|
|
83960
84232
|
`, "utf8");
|
|
83961
84233
|
}
|
|
83962
84234
|
return exported;
|
|
@@ -83986,8 +84258,8 @@ async function fetchCrowdCodeEvidence(options = {}) {
|
|
|
83986
84258
|
}
|
|
83987
84259
|
};
|
|
83988
84260
|
if (cachePath) {
|
|
83989
|
-
await
|
|
83990
|
-
await
|
|
84261
|
+
await mkdir17(dirname13(cachePath), { recursive: true });
|
|
84262
|
+
await writeFile10(cachePath, `${JSON.stringify(bundle, null, 1)}
|
|
83991
84263
|
`, "utf8");
|
|
83992
84264
|
}
|
|
83993
84265
|
return bundle;
|
|
@@ -84155,8 +84427,8 @@ var init_evidence = __esm({
|
|
|
84155
84427
|
|
|
84156
84428
|
// ../../packages/evals/dist/knowledge.js
|
|
84157
84429
|
import { createHash as createHash8 } from "node:crypto";
|
|
84158
|
-
import { mkdir as
|
|
84159
|
-
import { dirname as
|
|
84430
|
+
import { mkdir as mkdir18, readdir as readdir2, readFile as readFile22, writeFile as writeFile11 } from "node:fs/promises";
|
|
84431
|
+
import { dirname as dirname14, join as join31, relative as relative4 } from "node:path";
|
|
84160
84432
|
function approxTokens(text) {
|
|
84161
84433
|
return Math.ceil(text.length / 4);
|
|
84162
84434
|
}
|
|
@@ -84245,32 +84517,32 @@ function validateTree(tree, evidence) {
|
|
|
84245
84517
|
};
|
|
84246
84518
|
}
|
|
84247
84519
|
async function writeTree(dir, tree, meta4) {
|
|
84248
|
-
await
|
|
84520
|
+
await mkdir18(dir, { recursive: true });
|
|
84249
84521
|
for (const [name, content] of Object.entries(tree)) {
|
|
84250
|
-
const path3 =
|
|
84251
|
-
await
|
|
84252
|
-
await
|
|
84522
|
+
const path3 = join31(dir, name);
|
|
84523
|
+
await mkdir18(dirname14(path3), { recursive: true });
|
|
84524
|
+
await writeFile11(path3, content.endsWith("\n") ? content : `${content}
|
|
84253
84525
|
`, "utf8");
|
|
84254
84526
|
}
|
|
84255
|
-
await
|
|
84527
|
+
await writeFile11(join31(dir, "meta.json"), `${JSON.stringify(meta4, null, 2)}
|
|
84256
84528
|
`, "utf8");
|
|
84257
84529
|
}
|
|
84258
84530
|
async function readTree(dir) {
|
|
84259
84531
|
const tree = {};
|
|
84260
84532
|
const walk3 = async (current) => {
|
|
84261
84533
|
for (const entry of await readdir2(current, { withFileTypes: true })) {
|
|
84262
|
-
const path3 =
|
|
84534
|
+
const path3 = join31(current, entry.name);
|
|
84263
84535
|
if (entry.isDirectory()) {
|
|
84264
84536
|
await walk3(path3);
|
|
84265
84537
|
} else if (entry.name.endsWith(".md")) {
|
|
84266
|
-
tree[relative4(dir, path3)] = await
|
|
84538
|
+
tree[relative4(dir, path3)] = await readFile22(path3, "utf8");
|
|
84267
84539
|
}
|
|
84268
84540
|
}
|
|
84269
84541
|
};
|
|
84270
84542
|
await walk3(dir);
|
|
84271
84543
|
let meta4;
|
|
84272
84544
|
try {
|
|
84273
|
-
meta4 = JSON.parse(await
|
|
84545
|
+
meta4 = JSON.parse(await readFile22(join31(dir, "meta.json"), "utf8"));
|
|
84274
84546
|
} catch {
|
|
84275
84547
|
meta4 = void 0;
|
|
84276
84548
|
}
|
|
@@ -84278,7 +84550,7 @@ async function readTree(dir) {
|
|
|
84278
84550
|
}
|
|
84279
84551
|
async function updateTreeMeta(dir, patch) {
|
|
84280
84552
|
const { meta: meta4 } = await readTree(dir);
|
|
84281
|
-
await
|
|
84553
|
+
await writeFile11(join31(dir, "meta.json"), `${JSON.stringify({ ...meta4 ?? {}, ...patch }, null, 2)}
|
|
84282
84554
|
`, "utf8");
|
|
84283
84555
|
}
|
|
84284
84556
|
async function proposeTree(options) {
|
|
@@ -84394,23 +84666,23 @@ var init_knowledge2 = __esm({
|
|
|
84394
84666
|
});
|
|
84395
84667
|
|
|
84396
84668
|
// ../../packages/evals/dist/evolve.js
|
|
84397
|
-
import { mkdir as
|
|
84398
|
-
import { join as
|
|
84669
|
+
import { mkdir as mkdir19, readFile as readFile23, writeFile as writeFile12 } from "node:fs/promises";
|
|
84670
|
+
import { join as join32, resolve as resolve8 } from "node:path";
|
|
84399
84671
|
async function runEvolution(options) {
|
|
84400
84672
|
const log = options.log ?? (() => void 0);
|
|
84401
84673
|
const root = resolve8(options.resultsRoot);
|
|
84402
|
-
const treesDir =
|
|
84403
|
-
const runsDir =
|
|
84404
|
-
await
|
|
84405
|
-
await
|
|
84406
|
-
const evidencePath = options.evidencePath ??
|
|
84674
|
+
const treesDir = join32(root, "trees");
|
|
84675
|
+
const runsDir = join32(root, "runs");
|
|
84676
|
+
await mkdir19(treesDir, { recursive: true });
|
|
84677
|
+
await mkdir19(runsDir, { recursive: true });
|
|
84678
|
+
const evidencePath = options.evidencePath ?? join32(root, "evidence", "crowdcode-evidence.json");
|
|
84407
84679
|
const evidence = await fetchCrowdCodeEvidence({ cachePath: evidencePath, useCache: !options.refreshEvidence, log });
|
|
84408
84680
|
const digest = renderEvidenceDigest(evidence, { detailTop: 90, maxReviewsPerService: 4 });
|
|
84409
84681
|
const evidenceHash = hashContent(digest);
|
|
84410
84682
|
log(`evidence: ${evidence.stats.services} services, ${evidence.stats.reviews} reviews, digest ~${Math.round(digest.length / 4)} tokens`);
|
|
84411
84683
|
const heldin = await loadTaskSet("heldin", { hfToken: options.hfToken, log });
|
|
84412
84684
|
const proposer = await buildProposerProviders(root, options.proposerModels);
|
|
84413
|
-
const archivePath =
|
|
84685
|
+
const archivePath = join32(root, "archive.json");
|
|
84414
84686
|
const archive = await readArchive(archivePath) ?? {
|
|
84415
84687
|
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
84416
84688
|
agent_model: options.agentModel,
|
|
@@ -84418,9 +84690,9 @@ async function runEvolution(options) {
|
|
|
84418
84690
|
entries: []
|
|
84419
84691
|
};
|
|
84420
84692
|
const save = async () => {
|
|
84421
|
-
await
|
|
84693
|
+
await writeFile12(archivePath, `${JSON.stringify(archive, null, 2)}
|
|
84422
84694
|
`, "utf8");
|
|
84423
|
-
await
|
|
84695
|
+
await writeFile12(join32(root, "frontier.md"), `${renderArchive(archive)}
|
|
84424
84696
|
`, "utf8");
|
|
84425
84697
|
};
|
|
84426
84698
|
const evaluate = async (entry, knowledgeDir) => {
|
|
@@ -84447,7 +84719,7 @@ async function runEvolution(options) {
|
|
|
84447
84719
|
if (!archive.entries.some((entry) => entry.id === "baseline")) {
|
|
84448
84720
|
const baseline = { id: "baseline", generation: 0, children: 0, status: "evaluated" };
|
|
84449
84721
|
if (options.baselineReport) {
|
|
84450
|
-
const report = JSON.parse(await
|
|
84722
|
+
const report = JSON.parse(await readFile23(options.baselineReport, "utf8"));
|
|
84451
84723
|
const rows = report.rows.filter((row) => row.suite === "usage");
|
|
84452
84724
|
baseline.report_dir = report.results_dir;
|
|
84453
84725
|
baseline.metrics = metricsOfRows(rows);
|
|
@@ -84528,7 +84800,7 @@ async function runEvolution(options) {
|
|
|
84528
84800
|
}
|
|
84529
84801
|
const best = bestEntry(archive);
|
|
84530
84802
|
if (best?.dir) {
|
|
84531
|
-
await
|
|
84803
|
+
await writeFile12(join32(root, "BEST"), `${best.dir}
|
|
84532
84804
|
`, "utf8");
|
|
84533
84805
|
}
|
|
84534
84806
|
await save();
|
|
@@ -84561,9 +84833,9 @@ async function proposeCandidate(input2) {
|
|
|
84561
84833
|
log: input2.log
|
|
84562
84834
|
});
|
|
84563
84835
|
const validation = validateTree(proposal.tree, input2.evidence);
|
|
84564
|
-
const dir =
|
|
84565
|
-
await
|
|
84566
|
-
await
|
|
84836
|
+
const dir = join32(input2.treesDir, id);
|
|
84837
|
+
await mkdir19(dir, { recursive: true });
|
|
84838
|
+
await writeFile12(join32(dir, "proposal.raw.txt"), proposal.rawResponse, "utf8");
|
|
84567
84839
|
if (!validation.ok) {
|
|
84568
84840
|
errors = validation.errors;
|
|
84569
84841
|
input2.log(`${id}: invalid (${validation.errors.join("; ")})`);
|
|
@@ -84650,7 +84922,7 @@ function metricsOfRows(rows) {
|
|
|
84650
84922
|
};
|
|
84651
84923
|
}
|
|
84652
84924
|
async function casesFromReport(reportDir) {
|
|
84653
|
-
const report = JSON.parse(await
|
|
84925
|
+
const report = JSON.parse(await readFile23(join32(reportDir, "report.json"), "utf8"));
|
|
84654
84926
|
const cases = [];
|
|
84655
84927
|
for (const row of report.rows) {
|
|
84656
84928
|
cases.push({
|
|
@@ -84671,7 +84943,7 @@ async function casesFromReport(reportDir) {
|
|
|
84671
84943
|
async function summarizeTrajectory(path3) {
|
|
84672
84944
|
let text;
|
|
84673
84945
|
try {
|
|
84674
|
-
text = await
|
|
84946
|
+
text = await readFile23(path3, "utf8");
|
|
84675
84947
|
} catch {
|
|
84676
84948
|
return void 0;
|
|
84677
84949
|
}
|
|
@@ -84703,7 +84975,7 @@ async function summarizeTrajectory(path3) {
|
|
|
84703
84975
|
return steps.length > 0 ? steps.join(" -> ") : void 0;
|
|
84704
84976
|
}
|
|
84705
84977
|
async function buildProposerProviders(root, models) {
|
|
84706
|
-
const session = await createOpenCrowdSession({ workspaceRoot:
|
|
84978
|
+
const session = await createOpenCrowdSession({ workspaceRoot: join32(root, "proposer"), approvalMode: "auto", shellEnabled: false });
|
|
84707
84979
|
const providers = /* @__PURE__ */ new Map();
|
|
84708
84980
|
for (const model of new Set(models)) {
|
|
84709
84981
|
const llm = await resolveLlmRuntime(session, { model, subagentModel: "off", nonInteractive: true });
|
|
@@ -84720,7 +84992,7 @@ async function buildProposerProviders(root, models) {
|
|
|
84720
84992
|
}
|
|
84721
84993
|
async function readArchive(path3) {
|
|
84722
84994
|
try {
|
|
84723
|
-
return JSON.parse(await
|
|
84995
|
+
return JSON.parse(await readFile23(path3, "utf8"));
|
|
84724
84996
|
} catch {
|
|
84725
84997
|
return void 0;
|
|
84726
84998
|
}
|
|
@@ -84865,8 +85137,8 @@ init_dist2();
|
|
|
84865
85137
|
init_dist4();
|
|
84866
85138
|
init_dist6();
|
|
84867
85139
|
init_shared();
|
|
84868
|
-
import { copyFile as copyFile2, mkdir as
|
|
84869
|
-
import { basename as basename2, join as
|
|
85140
|
+
import { copyFile as copyFile2, mkdir as mkdir20, readFile as readFile24, rm as rm3 } from "node:fs/promises";
|
|
85141
|
+
import { basename as basename2, join as join33 } from "node:path";
|
|
84870
85142
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
84871
85143
|
import { stdin as input, stdout as output2 } from "node:process";
|
|
84872
85144
|
|
|
@@ -85597,8 +85869,8 @@ function indent(text) {
|
|
|
85597
85869
|
|
|
85598
85870
|
// src/tui/app.tsx
|
|
85599
85871
|
init_dist2();
|
|
85600
|
-
import { join as
|
|
85601
|
-
import { randomUUID as
|
|
85872
|
+
import { join as join24 } from "node:path";
|
|
85873
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
85602
85874
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
85603
85875
|
import { Box, render, Static, Text, useApp, useInput, usePaste, useStdout } from "ink";
|
|
85604
85876
|
init_dist6();
|
|
@@ -85637,7 +85909,7 @@ function App({ session: initialSession, initialTestMode, initialTestSeed, defaul
|
|
|
85637
85909
|
const runningRef = useRef(false);
|
|
85638
85910
|
const inboxPausedRef = useRef(false);
|
|
85639
85911
|
const [inboxRevision, setInboxRevision] = useState(0);
|
|
85640
|
-
const inbox = useMemo(() => new FileSteeringInbox(
|
|
85912
|
+
const inbox = useMemo(() => new FileSteeringInbox(join24(session.sessionDir, "inbox.json")), [session.sessionDir]);
|
|
85641
85913
|
const [activity, setActivity] = useState("");
|
|
85642
85914
|
const [spinnerFrame, setSpinnerFrame] = useState(0);
|
|
85643
85915
|
const [modal, setModal] = useState(null);
|
|
@@ -86071,7 +86343,7 @@ function App({ session: initialSession, initialTestMode, initialTestSeed, defaul
|
|
|
86071
86343
|
if (text) {
|
|
86072
86344
|
setInput("");
|
|
86073
86345
|
setCursor(0);
|
|
86074
|
-
void inbox.push({ id:
|
|
86346
|
+
void inbox.push({ id: randomUUID9(), prompt: text }).then(() => {
|
|
86075
86347
|
push({ kind: "user", text: `${text} (queued)` });
|
|
86076
86348
|
setInboxRevision((n) => n + 1);
|
|
86077
86349
|
}).catch((e6) => push({ kind: "error", text: e6.message }));
|
|
@@ -86490,7 +86762,7 @@ async function main(argv) {
|
|
|
86490
86762
|
case "--version":
|
|
86491
86763
|
case "-v":
|
|
86492
86764
|
case "version": {
|
|
86493
|
-
const pkg2 = JSON.parse(await
|
|
86765
|
+
const pkg2 = JSON.parse(await readFile24(new URL("../package.json", import.meta.url), "utf8"));
|
|
86494
86766
|
console.log(pkg2.version);
|
|
86495
86767
|
return;
|
|
86496
86768
|
}
|
|
@@ -86595,11 +86867,11 @@ async function headlessRunCommand(args) {
|
|
|
86595
86867
|
let task = prompt;
|
|
86596
86868
|
if (attach) {
|
|
86597
86869
|
const attachmentName = basename2(attach);
|
|
86598
|
-
await
|
|
86599
|
-
await copyFile2(attach,
|
|
86870
|
+
await mkdir20(session.artifactsDir, { recursive: true });
|
|
86871
|
+
await copyFile2(attach, join33(session.artifactsDir, attachmentName));
|
|
86600
86872
|
task = `${prompt}
|
|
86601
86873
|
|
|
86602
|
-
An input file is available at the session artifact path \`${attachmentName}\` (use read_file, or run_shell against ${
|
|
86874
|
+
An input file is available at the session artifact path \`${attachmentName}\` (use read_file, or run_shell against ${join33(session.artifactsDir, attachmentName)}).`;
|
|
86603
86875
|
}
|
|
86604
86876
|
const result = await runPersistentAgentTaskDetailed(session, task, {
|
|
86605
86877
|
model: readOption(args, "--model"),
|
|
@@ -86623,7 +86895,7 @@ An input file is available at the session artifact path \`${attachmentName}\` (u
|
|
|
86623
86895
|
final_message: result.summary.final_message ?? null,
|
|
86624
86896
|
session_id: session.sessionId,
|
|
86625
86897
|
session_dir: session.sessionDir,
|
|
86626
|
-
trajectory_path:
|
|
86898
|
+
trajectory_path: join33(session.sessionDir, "messages.jsonl"),
|
|
86627
86899
|
turns: result.turns,
|
|
86628
86900
|
model_policy: session.models ?? null,
|
|
86629
86901
|
usdc_spent_cents: {
|
|
@@ -86706,7 +86978,7 @@ async function ledgerCommand(args) {
|
|
|
86706
86978
|
if (!sessionId) {
|
|
86707
86979
|
throw new Error("no local sessions found");
|
|
86708
86980
|
}
|
|
86709
|
-
const rows = await readLedger(
|
|
86981
|
+
const rows = await readLedger(join33(process.cwd(), "sessions", sessionId, "ledger.csv"));
|
|
86710
86982
|
printValue("Ledger", rows, {
|
|
86711
86983
|
json: json3,
|
|
86712
86984
|
pretty: renderTable(rows.map(asRecord), [
|
|
@@ -86743,7 +87015,7 @@ async function resumeCommand(args) {
|
|
|
86743
87015
|
} catch (e6) {
|
|
86744
87016
|
if (!(e6 instanceof SpendingDeclined)) throw e6;
|
|
86745
87017
|
}
|
|
86746
|
-
await rm3(
|
|
87018
|
+
await rm3(join33(session.sessionDir, "query-checkpoint.json"), { force: true });
|
|
86747
87019
|
console.log("Query declined. Nothing was paid for the pending call.");
|
|
86748
87020
|
return;
|
|
86749
87021
|
}
|
|
@@ -86882,7 +87154,7 @@ async function evalsSuiteCommand(rest) {
|
|
|
86882
87154
|
const report = await runSuite2({
|
|
86883
87155
|
set: set3,
|
|
86884
87156
|
harness: readOption(rest, "--harness") ?? "opencrowd",
|
|
86885
|
-
resultsRoot: readOption(rest, "--out") ??
|
|
87157
|
+
resultsRoot: readOption(rest, "--out") ?? join33(process.cwd(), "evals", "suite"),
|
|
86886
87158
|
tag: readOption(rest, "--tag"),
|
|
86887
87159
|
knowledgeDir: readOption(rest, "--knowledge"),
|
|
86888
87160
|
hfToken: readOption(rest, "--hf-token") ?? process.env.HF_TOKEN,
|
|
@@ -86901,7 +87173,7 @@ async function evalsSuiteCommand(rest) {
|
|
|
86901
87173
|
async function evalsEvolveCommand(rest) {
|
|
86902
87174
|
const { runEvolution: runEvolution2, renderArchive: renderArchive2 } = await Promise.resolve().then(() => (init_dist7(), dist_exports));
|
|
86903
87175
|
const { archive, best } = await runEvolution2({
|
|
86904
|
-
resultsRoot: readOption(rest, "--out") ??
|
|
87176
|
+
resultsRoot: readOption(rest, "--out") ?? join33(process.cwd(), "evals", "evolve"),
|
|
86905
87177
|
evidencePath: readOption(rest, "--evidence"),
|
|
86906
87178
|
refreshEvidence: rest.includes("--refresh-evidence"),
|
|
86907
87179
|
generations: Number(readOption(rest, "--generations") ?? 2),
|