@cortexkit/pi-magic-context 0.31.4 → 0.31.5
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 +74 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -157588,18 +157588,48 @@ function inferAccountingSubagent(agent) {
|
|
|
157588
157588
|
return "recomp";
|
|
157589
157589
|
return "historian";
|
|
157590
157590
|
}
|
|
157591
|
+
var ALREADY_PROCESSING_PREFIX = "Agent is already processing";
|
|
157592
|
+
var ISOLATED_RETRY_MODEL_UNAVAILABLE_MESSAGE = "model unavailable in isolated retry: it is provided by a disabled extension; configure it through models.json or add a built-in/provider-configured fallback";
|
|
157593
|
+
var MODEL_RESOLUTION_ERROR_PATTERNS = [
|
|
157594
|
+
/unknown model/i,
|
|
157595
|
+
/unknown provider/i,
|
|
157596
|
+
/model.+not found/i,
|
|
157597
|
+
/provider.+not found/i,
|
|
157598
|
+
/could not resolve model/i,
|
|
157599
|
+
/no models? (matched|available|configured)/i,
|
|
157600
|
+
/model.+not configured/i
|
|
157601
|
+
];
|
|
157591
157602
|
|
|
157592
157603
|
class PiSubagentRunner {
|
|
157593
157604
|
harness = "pi";
|
|
157594
157605
|
invocation;
|
|
157595
157606
|
spawnImpl;
|
|
157596
157607
|
platform;
|
|
157608
|
+
extraArgs;
|
|
157597
157609
|
constructor(options = {}) {
|
|
157598
157610
|
this.invocation = options.piBinary ? { command: options.piBinary, prefixArgs: [] } : resolvePiInvocation();
|
|
157599
157611
|
this.spawnImpl = options.spawnImpl ?? childProcess.spawn;
|
|
157600
157612
|
this.platform = options.platform ?? process.platform;
|
|
157613
|
+
this.extraArgs = options.extraArgs ?? [];
|
|
157601
157614
|
}
|
|
157602
157615
|
async run(options) {
|
|
157616
|
+
const primaryRunMode = { disableDiscoveredExtensions: false };
|
|
157617
|
+
const primaryResult = await this.runModelChain(options, primaryRunMode);
|
|
157618
|
+
if (this.spawnUsesNoExtensions(primaryRunMode) || !isPiExtensionCollisionFailure(primaryResult)) {
|
|
157619
|
+
return primaryResult;
|
|
157620
|
+
}
|
|
157621
|
+
const sessionId = options.accountingSessionId ?? "pi-subagent";
|
|
157622
|
+
sessionLog(sessionId, "pi subagent: a loaded Pi extension started an agent turn before the child's prompt could run; retrying with an isolated extension set (user extensions disabled for this run)");
|
|
157623
|
+
const isolatedResult = await this.runModelChain(options, {
|
|
157624
|
+
disableDiscoveredExtensions: true
|
|
157625
|
+
});
|
|
157626
|
+
if (!isolatedResult.ok && isIsolatedRetryModelUnavailable(isolatedResult)) {
|
|
157627
|
+
sessionLog(sessionId, ISOLATED_RETRY_MODEL_UNAVAILABLE_MESSAGE);
|
|
157628
|
+
return annotateIsolatedRetryModelUnavailable(isolatedResult);
|
|
157629
|
+
}
|
|
157630
|
+
return isolatedResult;
|
|
157631
|
+
}
|
|
157632
|
+
async runModelChain(options, runMode) {
|
|
157603
157633
|
const models = [options.model, ...options.fallbackModels ?? []].filter((model) => typeof model === "string" && model.length > 0);
|
|
157604
157634
|
const attempts = models.length > 0 ? models : [undefined];
|
|
157605
157635
|
let lastResult = null;
|
|
@@ -157610,17 +157640,23 @@ class PiSubagentRunner {
|
|
|
157610
157640
|
model,
|
|
157611
157641
|
fallbackModels: undefined
|
|
157612
157642
|
};
|
|
157613
|
-
const result = await this.runOnce(attemptOptions);
|
|
157643
|
+
const result = await this.runOnce(attemptOptions, runMode);
|
|
157614
157644
|
if (result.ok)
|
|
157615
157645
|
return result;
|
|
157616
157646
|
lastResult = result;
|
|
157647
|
+
if (!this.spawnUsesNoExtensions(runMode) && isPiExtensionCollisionFailure(result)) {
|
|
157648
|
+
return result;
|
|
157649
|
+
}
|
|
157617
157650
|
if (index >= attempts.length - 1 || !isFallbackEligible(result.reason)) {
|
|
157618
157651
|
return result;
|
|
157619
157652
|
}
|
|
157620
157653
|
}
|
|
157621
|
-
return lastResult ?? this.runOnce({ ...options, fallbackModels: undefined });
|
|
157654
|
+
return lastResult ?? this.runOnce({ ...options, fallbackModels: undefined }, runMode);
|
|
157655
|
+
}
|
|
157656
|
+
spawnUsesNoExtensions(runMode) {
|
|
157657
|
+
return runMode.disableDiscoveredExtensions || hasNoExtensionsArg([...this.invocation.prefixArgs, ...this.extraArgs]);
|
|
157622
157658
|
}
|
|
157623
|
-
async runOnce(options) {
|
|
157659
|
+
async runOnce(options, runMode) {
|
|
157624
157660
|
const startTime = Date.now();
|
|
157625
157661
|
let recordedAccounting = false;
|
|
157626
157662
|
const recordAccounting = (result, messages = []) => {
|
|
@@ -157695,6 +157731,7 @@ class PiSubagentRunner {
|
|
|
157695
157731
|
}
|
|
157696
157732
|
}
|
|
157697
157733
|
const args = buildArgs(options, {
|
|
157734
|
+
disableDiscoveredExtensions: runMode.disableDiscoveredExtensions,
|
|
157698
157735
|
omitPositionalMessage: deliverViaStdin,
|
|
157699
157736
|
systemPromptPath
|
|
157700
157737
|
});
|
|
@@ -157722,7 +157759,7 @@ class PiSubagentRunner {
|
|
|
157722
157759
|
};
|
|
157723
157760
|
let child;
|
|
157724
157761
|
try {
|
|
157725
|
-
child = this.spawnImpl(this.invocation.command, [...this.invocation.prefixArgs, ...args], {
|
|
157762
|
+
child = this.spawnImpl(this.invocation.command, [...this.invocation.prefixArgs, ...this.extraArgs, ...args], {
|
|
157726
157763
|
cwd: options.cwd,
|
|
157727
157764
|
env: {
|
|
157728
157765
|
...process.env,
|
|
@@ -158016,6 +158053,32 @@ class PiSubagentRunner {
|
|
|
158016
158053
|
});
|
|
158017
158054
|
}
|
|
158018
158055
|
}
|
|
158056
|
+
function getResultStderr(result) {
|
|
158057
|
+
const stderr = result.meta?.stderr;
|
|
158058
|
+
return typeof stderr === "string" ? stderr : "";
|
|
158059
|
+
}
|
|
158060
|
+
function hasNoExtensionsArg(args) {
|
|
158061
|
+
return args.includes("--no-extensions");
|
|
158062
|
+
}
|
|
158063
|
+
function isPiExtensionCollisionFailure(result) {
|
|
158064
|
+
return !result.ok && result.reason === "non_zero_exit" && getResultStderr(result).includes(ALREADY_PROCESSING_PREFIX);
|
|
158065
|
+
}
|
|
158066
|
+
function isIsolatedRetryModelUnavailable(result) {
|
|
158067
|
+
if (result.ok)
|
|
158068
|
+
return false;
|
|
158069
|
+
const diagnosticText = `${result.error}
|
|
158070
|
+
${getResultStderr(result)}`;
|
|
158071
|
+
return MODEL_RESOLUTION_ERROR_PATTERNS.some((pattern) => pattern.test(diagnosticText));
|
|
158072
|
+
}
|
|
158073
|
+
function annotateIsolatedRetryModelUnavailable(result) {
|
|
158074
|
+
if (result.error.startsWith(ISOLATED_RETRY_MODEL_UNAVAILABLE_MESSAGE)) {
|
|
158075
|
+
return result;
|
|
158076
|
+
}
|
|
158077
|
+
return {
|
|
158078
|
+
...result,
|
|
158079
|
+
error: `${ISOLATED_RETRY_MODEL_UNAVAILABLE_MESSAGE}. Original failure: ${result.error}`
|
|
158080
|
+
};
|
|
158081
|
+
}
|
|
158019
158082
|
function isFallbackEligible(reason) {
|
|
158020
158083
|
return reason === "model_failed" || reason === "truncated" || reason === "non_zero_exit" || reason === "no_assistant";
|
|
158021
158084
|
}
|
|
@@ -158030,9 +158093,13 @@ function buildArgs(options, opts) {
|
|
|
158030
158093
|
"--no-prompt-templates",
|
|
158031
158094
|
"--no-context-files"
|
|
158032
158095
|
];
|
|
158033
|
-
|
|
158096
|
+
if (opts?.disableDiscoveredExtensions) {
|
|
158097
|
+
args.push("--no-extensions");
|
|
158098
|
+
}
|
|
158099
|
+
const subagentEntryPath = opts?.subagentEntryPath ?? SUBAGENT_ENTRY_PATH;
|
|
158100
|
+
const shouldLoadSubagentExtension = subagentEntryPath && (SEARCH_ONLY_SUBAGENT_TOOL_AGENTS.has(options.agent) || DREAMER_ACTION_AGENTS.has(options.agent));
|
|
158034
158101
|
if (shouldLoadSubagentExtension) {
|
|
158035
|
-
args.push("--extension",
|
|
158102
|
+
args.push("--extension", subagentEntryPath);
|
|
158036
158103
|
if (DREAMER_ACTION_AGENTS.has(options.agent)) {
|
|
158037
158104
|
args.push("--magic-context-dreamer-actions");
|
|
158038
158105
|
}
|
|
@@ -201923,7 +201990,7 @@ function formatThresholdPercent(value) {
|
|
|
201923
201990
|
// package.json
|
|
201924
201991
|
var package_default = {
|
|
201925
201992
|
name: "@cortexkit/pi-magic-context",
|
|
201926
|
-
version: "0.31.
|
|
201993
|
+
version: "0.31.5",
|
|
201927
201994
|
type: "module",
|
|
201928
201995
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
201929
201996
|
main: "dist/index.js",
|
package/package.json
CHANGED