@brainervirus/workit-pi 8.30.0 → 8.31.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/dist/workit.js +71 -5
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -24752,6 +24752,28 @@ var PI_DESCRIPTOR = {
|
|
|
24752
24752
|
}
|
|
24753
24753
|
]
|
|
24754
24754
|
};
|
|
24755
|
+
// packages/workit-core/src/hooks/model-switch.ts
|
|
24756
|
+
var MAX_SESSIONS = 256;
|
|
24757
|
+
var modelSwitched = (models, sessionId, model) => {
|
|
24758
|
+
if (!model)
|
|
24759
|
+
return false;
|
|
24760
|
+
const previous = models.get(sessionId);
|
|
24761
|
+
models.delete(sessionId);
|
|
24762
|
+
models.set(sessionId, model);
|
|
24763
|
+
if (models.size > MAX_SESSIONS)
|
|
24764
|
+
models.delete(models.keys().next().value);
|
|
24765
|
+
return previous !== undefined && previous !== model;
|
|
24766
|
+
};
|
|
24767
|
+
var modelKey = (model) => {
|
|
24768
|
+
if (model === null || typeof model !== "object")
|
|
24769
|
+
return null;
|
|
24770
|
+
const { id, providerID, provider } = model;
|
|
24771
|
+
if (typeof id !== "string" || !id)
|
|
24772
|
+
return null;
|
|
24773
|
+
const source = typeof providerID === "string" ? providerID : provider;
|
|
24774
|
+
return typeof source === "string" && source ? `${source}/${id}` : id;
|
|
24775
|
+
};
|
|
24776
|
+
|
|
24755
24777
|
// packages/workit-pi/src/context.ts
|
|
24756
24778
|
var piCapabilities = (ctx) => capabilitiesFor(PI_DESCRIPTOR, { ui: ctx?.hasUI === true });
|
|
24757
24779
|
var piContext = (ctx) => ({
|
|
@@ -24767,7 +24789,7 @@ var piContext = (ctx) => ({
|
|
|
24767
24789
|
constraints: [],
|
|
24768
24790
|
now: () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
24769
24791
|
});
|
|
24770
|
-
var
|
|
24792
|
+
var taskTurnContext = (ctx) => {
|
|
24771
24793
|
if (!ctx.isProjectTrusted())
|
|
24772
24794
|
return null;
|
|
24773
24795
|
try {
|
|
@@ -24777,6 +24799,13 @@ var turnContext = (ctx) => {
|
|
|
24777
24799
|
return null;
|
|
24778
24800
|
}
|
|
24779
24801
|
};
|
|
24802
|
+
var sessionModels = new Map;
|
|
24803
|
+
var turnContext = (ctx) => {
|
|
24804
|
+
const task = taskTurnContext(ctx);
|
|
24805
|
+
const switched = modelSwitched(sessionModels, ctx.sessionManager.getSessionId(), modelKey(ctx.model));
|
|
24806
|
+
return switched && ctx.isProjectTrusted() ? `${invariantBootstrap()}${task ? `
|
|
24807
|
+
${task}` : ""}` : task;
|
|
24808
|
+
};
|
|
24780
24809
|
var turnInput = (ctx) => ({
|
|
24781
24810
|
host: "pi",
|
|
24782
24811
|
cwd: ctx.cwd,
|
|
@@ -24797,7 +24826,7 @@ var standingNotice = (ctx) => {
|
|
|
24797
24826
|
const input = turnInput(ctx);
|
|
24798
24827
|
return standingDelta(worker ? { ...input, session: { ...input.session, id: worker } } : input);
|
|
24799
24828
|
};
|
|
24800
|
-
var workitContext = (ctx, taskContext =
|
|
24829
|
+
var workitContext = (ctx, taskContext = taskTurnContext(ctx)) => {
|
|
24801
24830
|
const session = ctx.sessionManager.getSessionId();
|
|
24802
24831
|
if (!ctx.isProjectTrusted())
|
|
24803
24832
|
return `${invariantBootstrap()}
|
|
@@ -24820,6 +24849,38 @@ var unfinishedTaskOffer2 = (ctx) => {
|
|
|
24820
24849
|
}
|
|
24821
24850
|
};
|
|
24822
24851
|
|
|
24852
|
+
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
24853
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
24854
|
+
var SAME_CALL_FAILED = "Same call failed twice:";
|
|
24855
|
+
var MAX_SESSIONS2 = 256;
|
|
24856
|
+
var stable = (value) => JSON.stringify(value, (_key, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([a], [b]) => a.localeCompare(b))) : entry) ?? "null";
|
|
24857
|
+
var hashOf = (call) => createHash18("sha256").update(call).digest("hex").slice(0, 32);
|
|
24858
|
+
var record2 = (memo, sessionId, call, failed, next) => {
|
|
24859
|
+
const previous = memo.get(sessionId);
|
|
24860
|
+
memo.delete(sessionId);
|
|
24861
|
+
if (!failed)
|
|
24862
|
+
return null;
|
|
24863
|
+
const hash = hashOf(call);
|
|
24864
|
+
memo.set(sessionId, hash);
|
|
24865
|
+
if (memo.size > MAX_SESSIONS2)
|
|
24866
|
+
memo.delete(memo.keys().next().value);
|
|
24867
|
+
return previous === hash && next ? `${SAME_CALL_FAILED} ${next}` : null;
|
|
24868
|
+
};
|
|
24869
|
+
var isFailure = (result) => result !== null && typeof result === "object" && result.ok === false && typeof result.error === "string";
|
|
24870
|
+
var correctedPayload = (tool, result) => {
|
|
24871
|
+
const example = /Example: (\{.*\})\s*$/.exec(result.error)?.[1];
|
|
24872
|
+
if (example)
|
|
24873
|
+
return `${tool} ${example}`;
|
|
24874
|
+
const guidance = result.details?.guidance;
|
|
24875
|
+
return typeof guidance === "string" && guidance ? guidance : null;
|
|
24876
|
+
};
|
|
24877
|
+
var escalateToolFailure = (memo, sessionId, tool, input, result) => {
|
|
24878
|
+
const failed = isFailure(result);
|
|
24879
|
+
const line = record2(memo, sessionId, `tool\x00${tool}\x00${stable(input)}`, failed, failed ? correctedPayload(tool, result) : null);
|
|
24880
|
+
return line && failed ? { ...result, error: `${result.error}
|
|
24881
|
+
${line}` } : result;
|
|
24882
|
+
};
|
|
24883
|
+
|
|
24823
24884
|
// packages/workit-pi/src/tools.ts
|
|
24824
24885
|
var readOnlyActions = new Set(["list", "inspect", "preview", "explain", "export"]);
|
|
24825
24886
|
var output = (result) => ({
|
|
@@ -24847,18 +24908,23 @@ var trustedForMutation = (ctx, action) => {
|
|
|
24847
24908
|
return success(null, null, null);
|
|
24848
24909
|
return failure2("permission_denied", "Pi project is not trusted for Workit mutations");
|
|
24849
24910
|
};
|
|
24911
|
+
var failures = new Map;
|
|
24850
24912
|
var executeFamily = async (family, input, ctx) => {
|
|
24913
|
+
const result = runFamily(family, input, ctx);
|
|
24914
|
+
return output(escalateToolFailure(failures, piContext(ctx).caller.actor, `workit_${family}`, input, result));
|
|
24915
|
+
};
|
|
24916
|
+
var runFamily = (family, input, ctx) => {
|
|
24851
24917
|
const parsed = parseAdvertisedOperation(family, input, "pi");
|
|
24852
24918
|
if (!parsed.ok)
|
|
24853
|
-
return
|
|
24919
|
+
return parsed;
|
|
24854
24920
|
const trust = trustedForMutation(ctx, parsed.data.action);
|
|
24855
24921
|
if (!trust.ok)
|
|
24856
|
-
return
|
|
24922
|
+
return trust;
|
|
24857
24923
|
const context = piContext(ctx);
|
|
24858
24924
|
const core = new WorkitCore(new TaskStore(ctx.cwd), context);
|
|
24859
24925
|
const run = core[family];
|
|
24860
24926
|
const result = run.call(core, parsed.data);
|
|
24861
|
-
return
|
|
24927
|
+
return family === "task" && (context.workerId ?? null) !== null ? briefInspectResult(parsed.data, result) : result;
|
|
24862
24928
|
};
|
|
24863
24929
|
var registerWorkitTools = (pi, options = {}) => {
|
|
24864
24930
|
for (const family of OPERATION_FAMILIES)
|