@cortexkit/pi-magic-context 0.32.3 → 0.32.4
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/index.js +43 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -158851,6 +158851,7 @@ var STRICT_TOOL_ALLOWLIST_ENTRIES = [
|
|
|
158851
158851
|
["magic-context-dreamer", ["ctx_memory"]]
|
|
158852
158852
|
];
|
|
158853
158853
|
var STRICT_TOOL_ALLOWLIST = new Map(STRICT_TOOL_ALLOWLIST_ENTRIES);
|
|
158854
|
+
var ZERO_TOOL_PROMPT_REQUIRED_AGENTS = new Set(STRICT_TOOL_ALLOWLIST_ENTRIES.filter(([, tools]) => tools.length === 0).map(([agent]) => agent));
|
|
158854
158855
|
function inferAccountingSubagent(agent) {
|
|
158855
158856
|
if (agent.includes("sidekick"))
|
|
158856
158857
|
return "sidekick";
|
|
@@ -158968,12 +158969,13 @@ class PiSubagentRunner {
|
|
|
158968
158969
|
}
|
|
158969
158970
|
return result;
|
|
158970
158971
|
}
|
|
158971
|
-
const failBeforeSpawn = (reason, error) => {
|
|
158972
|
+
const failBeforeSpawn = (reason, error, transient = false) => {
|
|
158972
158973
|
const result = {
|
|
158973
158974
|
ok: false,
|
|
158974
158975
|
reason,
|
|
158975
158976
|
error,
|
|
158976
|
-
durationMs: Date.now() - startTime
|
|
158977
|
+
durationMs: Date.now() - startTime,
|
|
158978
|
+
...transient ? { transient: true } : {}
|
|
158977
158979
|
};
|
|
158978
158980
|
try {
|
|
158979
158981
|
recordAccounting(result);
|
|
@@ -158982,6 +158984,9 @@ class PiSubagentRunner {
|
|
|
158982
158984
|
}
|
|
158983
158985
|
return result;
|
|
158984
158986
|
};
|
|
158987
|
+
if (ZERO_TOOL_PROMPT_REQUIRED_AGENTS.has(options.agent) && options.systemPrompt.trim().length === 0) {
|
|
158988
|
+
return failBeforeSpawn("invalid_prompt", `zero-tool Pi subagent "${options.agent}" requires a non-empty system prompt`, true);
|
|
158989
|
+
}
|
|
158985
158990
|
const promptBytes = Buffer.byteLength(options.userMessage, "utf8");
|
|
158986
158991
|
const deliverViaStdin = promptBytes > PROMPT_ARGV_MAX_BYTES || this.platform === "win32";
|
|
158987
158992
|
let systemPromptTempDir;
|
|
@@ -159836,6 +159841,9 @@ init_logger();
|
|
|
159836
159841
|
// ../plugin/src/shared/model-suggestion-retry.ts
|
|
159837
159842
|
init_logger();
|
|
159838
159843
|
var ABORT_CALL_TIMEOUT_MS = 3000;
|
|
159844
|
+
function copyPromptArgs(args, body) {
|
|
159845
|
+
return { ...args, body: { ...body } };
|
|
159846
|
+
}
|
|
159839
159847
|
function extractMessage(error) {
|
|
159840
159848
|
if (typeof error === "string")
|
|
159841
159849
|
return error;
|
|
@@ -159949,40 +159957,41 @@ function shortErr(error) {
|
|
|
159949
159957
|
return extractMessage(error);
|
|
159950
159958
|
}
|
|
159951
159959
|
async function attemptOnce(client, args, timeoutMs, signal, callContext, label) {
|
|
159960
|
+
const originalBody = { ...args.body };
|
|
159961
|
+
const attemptArgs = copyPromptArgs(args, originalBody);
|
|
159952
159962
|
try {
|
|
159953
|
-
await promptWithTimeout(client,
|
|
159963
|
+
await promptWithTimeout(client, attemptArgs, timeoutMs, signal);
|
|
159954
159964
|
return;
|
|
159955
159965
|
} catch (error) {
|
|
159956
159966
|
if (isNonRetryable(error, signal))
|
|
159957
159967
|
throw error;
|
|
159958
159968
|
const suggestion = parseModelSuggestion(error);
|
|
159959
|
-
if (!suggestion || !
|
|
159969
|
+
if (!suggestion || !originalBody.model) {
|
|
159960
159970
|
throw error;
|
|
159961
159971
|
}
|
|
159962
159972
|
log(`[${callContext}] ${label}: model not found, retrying with suggestion`, {
|
|
159963
159973
|
original: `${suggestion.providerID}/${suggestion.modelID}`,
|
|
159964
159974
|
suggested: suggestion.suggestion
|
|
159965
159975
|
});
|
|
159966
|
-
await promptWithTimeout(client, {
|
|
159967
|
-
...
|
|
159968
|
-
|
|
159969
|
-
|
|
159970
|
-
|
|
159971
|
-
providerID: suggestion.providerID,
|
|
159972
|
-
modelID: suggestion.suggestion
|
|
159973
|
-
}
|
|
159976
|
+
await promptWithTimeout(client, copyPromptArgs(args, {
|
|
159977
|
+
...originalBody,
|
|
159978
|
+
model: {
|
|
159979
|
+
providerID: suggestion.providerID,
|
|
159980
|
+
modelID: suggestion.suggestion
|
|
159974
159981
|
}
|
|
159975
|
-
}, timeoutMs, signal);
|
|
159982
|
+
}), timeoutMs, signal);
|
|
159976
159983
|
}
|
|
159977
159984
|
}
|
|
159978
159985
|
async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
159979
159986
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
159980
159987
|
const callContext = options.callContext ?? "subagent";
|
|
159981
159988
|
const fallbacks = options.fallbackModels ?? [];
|
|
159982
|
-
const
|
|
159989
|
+
const baseBody = { ...args.body };
|
|
159990
|
+
const baseArgs = copyPromptArgs(args, baseBody);
|
|
159991
|
+
const explicitPrimaryLabel = baseBody.model?.providerID && baseBody.model.modelID ? `${baseBody.model.providerID}/${baseBody.model.modelID}` : "primary";
|
|
159983
159992
|
let lastError = null;
|
|
159984
159993
|
try {
|
|
159985
|
-
await attemptOnce(client,
|
|
159994
|
+
await attemptOnce(client, baseArgs, timeoutMs, options.signal, callContext, explicitPrimaryLabel);
|
|
159986
159995
|
return;
|
|
159987
159996
|
} catch (error) {
|
|
159988
159997
|
lastError = error;
|
|
@@ -160000,10 +160009,10 @@ async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
|
160000
160009
|
continue;
|
|
160001
160010
|
}
|
|
160002
160011
|
const label = `${parsed.providerID}/${parsed.modelID}`;
|
|
160003
|
-
const attemptArgs = {
|
|
160004
|
-
...
|
|
160005
|
-
|
|
160006
|
-
};
|
|
160012
|
+
const attemptArgs = copyPromptArgs(baseArgs, {
|
|
160013
|
+
...baseBody,
|
|
160014
|
+
model: parsed
|
|
160015
|
+
});
|
|
160007
160016
|
try {
|
|
160008
160017
|
await attemptOnce(client, attemptArgs, timeoutMs, options.signal, callContext, label);
|
|
160009
160018
|
log(`[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`);
|
|
@@ -160031,17 +160040,19 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
160031
160040
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
160032
160041
|
const callContext = options.callContext ?? "subagent";
|
|
160033
160042
|
const fallbacks = options.fallbackModels ?? [];
|
|
160034
|
-
const
|
|
160043
|
+
const baseBody = { ...args.body };
|
|
160044
|
+
const baseArgs = copyPromptArgs(args, baseBody);
|
|
160045
|
+
const explicitPrimaryLabel = baseBody.model?.providerID && baseBody.model.modelID ? `${baseBody.model.providerID}/${baseBody.model.modelID}` : "primary";
|
|
160035
160046
|
const totalAttempts = fallbacks.length + 1;
|
|
160036
160047
|
let firstError = null;
|
|
160037
160048
|
let lastError = null;
|
|
160038
160049
|
try {
|
|
160039
|
-
return await attemptAndValidate(client,
|
|
160050
|
+
return await attemptAndValidate(client, baseArgs, timeoutMs, options.signal, callContext, {
|
|
160040
160051
|
label: explicitPrimaryLabel,
|
|
160041
160052
|
attemptIndex: 0,
|
|
160042
160053
|
isFallback: false,
|
|
160043
160054
|
totalAttempts,
|
|
160044
|
-
model:
|
|
160055
|
+
model: baseBody.model
|
|
160045
160056
|
}, options);
|
|
160046
160057
|
} catch (error) {
|
|
160047
160058
|
firstError = error;
|
|
@@ -160060,10 +160071,10 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
160060
160071
|
continue;
|
|
160061
160072
|
}
|
|
160062
160073
|
const label = `${parsed.providerID}/${parsed.modelID}`;
|
|
160063
|
-
const attemptArgs = {
|
|
160064
|
-
...
|
|
160065
|
-
|
|
160066
|
-
};
|
|
160074
|
+
const attemptArgs = copyPromptArgs(baseArgs, {
|
|
160075
|
+
...baseBody,
|
|
160076
|
+
model: parsed
|
|
160077
|
+
});
|
|
160067
160078
|
const attempt = {
|
|
160068
160079
|
label,
|
|
160069
160080
|
attemptIndex: i + 1,
|
|
@@ -189660,7 +189671,11 @@ function createPiDreamerClient(opts) {
|
|
|
189660
189671
|
try {
|
|
189661
189672
|
const result = await runPromise;
|
|
189662
189673
|
if (!result.ok) {
|
|
189663
|
-
|
|
189674
|
+
const error51 = new Error(`Pi dreamer subagent failed (${result.reason}): ${result.error}`);
|
|
189675
|
+
if (result.transient) {
|
|
189676
|
+
error51.transient = true;
|
|
189677
|
+
}
|
|
189678
|
+
throw error51;
|
|
189664
189679
|
}
|
|
189665
189680
|
dreamSession.messages = [
|
|
189666
189681
|
makeMessage("user", [{ type: "text", text: userMessage }]),
|
|
@@ -207600,7 +207615,7 @@ function formatThresholdPercent(value) {
|
|
|
207600
207615
|
// package.json
|
|
207601
207616
|
var package_default = {
|
|
207602
207617
|
name: "@cortexkit/pi-magic-context",
|
|
207603
|
-
version: "0.32.
|
|
207618
|
+
version: "0.32.4",
|
|
207604
207619
|
type: "module",
|
|
207605
207620
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
207606
207621
|
main: "dist/index.js",
|
package/package.json
CHANGED