@amaster.ai/employee-runtime-connector 0.1.0-beta.52 → 0.1.0-beta.53
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.
|
@@ -2162,6 +2162,12 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2162
2162
|
if (typeof sourceConfig.channel === "string" && ["stable", "beta", "dev", "canary"].includes(sourceConfig.channel)) {
|
|
2163
2163
|
config.channel = sourceConfig.channel;
|
|
2164
2164
|
}
|
|
2165
|
+
if (typeof sourceConfig.sessionMode === "string" && ["persistent", "isolated", "existing"].includes(sourceConfig.sessionMode)) {
|
|
2166
|
+
config.sessionMode = sourceConfig.sessionMode;
|
|
2167
|
+
}
|
|
2168
|
+
if (typeof sourceConfig.userDataDir === "string" && sourceConfig.userDataDir.trim().length > 0) {
|
|
2169
|
+
config.userDataDir = sourceConfig.userDataDir.trim();
|
|
2170
|
+
}
|
|
2165
2171
|
return {
|
|
2166
2172
|
packageSpec,
|
|
2167
2173
|
plugin: {
|
|
@@ -2904,10 +2910,8 @@ function removeRunCompletionState(directory, commandId) {
|
|
|
2904
2910
|
}
|
|
2905
2911
|
|
|
2906
2912
|
// src/amaster-runtime-daemon/prompt-compiler.mjs
|
|
2907
|
-
var DEFAULT_PROMPT_BUDGET_CHARS = 2e5;
|
|
2908
2913
|
var DEADLINE_POSTURE_GUARD = "Named-window:skip_this_window_and_continue; no lower-quality/approval-bypass/fabrication/whole-task-stop; deadline_posture_receipt=targetMilestoneRef,posture,onMiss,taskContinuation,next owner/action; not Server proof";
|
|
2909
2914
|
var MIN_PROMPT_BUDGET_CHARS = 8192;
|
|
2910
|
-
var MAX_PROMPT_SECTION_JSON_CHARS = 1e5;
|
|
2911
2915
|
var CONTINUATION_WAKE_PATTERN = /(continuation|continued|retry|approved|liveness|resume|max_turn)/i;
|
|
2912
2916
|
var RECOVERY_WAKE_REASONS = /* @__PURE__ */ new Set([
|
|
2913
2917
|
"finish_successful_run_handoff",
|
|
@@ -2916,15 +2920,6 @@ var RECOVERY_WAKE_REASONS = /* @__PURE__ */ new Set([
|
|
|
2916
2920
|
function isRecoveryWakeReason(wakeReason) {
|
|
2917
2921
|
return RECOVERY_WAKE_REASONS.has(wakeReason);
|
|
2918
2922
|
}
|
|
2919
|
-
function stringifyBoundedJson(value, maxChars = 24e3) {
|
|
2920
|
-
let text = "";
|
|
2921
|
-
try {
|
|
2922
|
-
text = JSON.stringify(value, null, 2);
|
|
2923
|
-
} catch {
|
|
2924
|
-
text = String(value);
|
|
2925
|
-
}
|
|
2926
|
-
return truncateText(text, maxChars);
|
|
2927
|
-
}
|
|
2928
2923
|
function jsonText(value) {
|
|
2929
2924
|
return JSON.stringify(value, null, 2);
|
|
2930
2925
|
}
|
|
@@ -3173,7 +3168,7 @@ function verifiedCompanyContextSection(context) {
|
|
|
3173
3168
|
content: [
|
|
3174
3169
|
"Use these server-snapshotted current Company facts as authoritative context for this run.",
|
|
3175
3170
|
"The current verification contract does not supply shareholder structure or a financial baseline; treat them as unknown unless separate evidence is present, and do not describe the verified registration facts below as missing.",
|
|
3176
|
-
|
|
3171
|
+
jsonText(companyContext)
|
|
3177
3172
|
].join("\n"),
|
|
3178
3173
|
sourceRef: [
|
|
3179
3174
|
`company:${companyId}`,
|
|
@@ -3230,7 +3225,7 @@ function interactionResolutionText(context) {
|
|
|
3230
3225
|
"Treat this resolved interaction as the authoritative delta for this run.",
|
|
3231
3226
|
readString(resolution.status) === "changes_requested" ? "Apply every requested change before creating a replacement review." : "",
|
|
3232
3227
|
exactDocumentRevisionDirective,
|
|
3233
|
-
|
|
3228
|
+
jsonText(resolution)
|
|
3234
3229
|
].filter(Boolean).join("\n");
|
|
3235
3230
|
}
|
|
3236
3231
|
function recoveryInstructionText(input) {
|
|
@@ -3437,15 +3432,15 @@ function buildManifest(mode, maxChars, sections, governedReadProvenance, usedCha
|
|
|
3437
3432
|
budget: {
|
|
3438
3433
|
totalChars: maxChars,
|
|
3439
3434
|
usedChars,
|
|
3440
|
-
utilization: (usedChars / maxChars).toFixed(4)
|
|
3435
|
+
utilization: maxChars === null ? null : (usedChars / maxChars).toFixed(4)
|
|
3441
3436
|
},
|
|
3442
3437
|
sections: sections.map(manifestEntry),
|
|
3443
3438
|
governedReadProvenance
|
|
3444
3439
|
};
|
|
3445
3440
|
}
|
|
3446
3441
|
function compileCommandPromptWithManifest(input, options = {}) {
|
|
3447
|
-
const maxChars = Number(options.maxChars
|
|
3448
|
-
if (!Number.isInteger(maxChars) || maxChars < MIN_PROMPT_BUDGET_CHARS) {
|
|
3442
|
+
const maxChars = options.maxChars == null ? null : Number(options.maxChars);
|
|
3443
|
+
if (maxChars !== null && (!Number.isInteger(maxChars) || maxChars < MIN_PROMPT_BUDGET_CHARS)) {
|
|
3449
3444
|
throw new RangeError(`Prompt budget must be an integer of at least ${MIN_PROMPT_BUDGET_CHARS} characters`);
|
|
3450
3445
|
}
|
|
3451
3446
|
const context = asRecord(input.context);
|
|
@@ -3535,6 +3530,14 @@ ${resolvedDependencies.details.content}` : ""
|
|
|
3535
3530
|
let prompt = "";
|
|
3536
3531
|
let compactManifest = false;
|
|
3537
3532
|
let manifest = buildManifest(mode, maxChars, sections, governedReads.provenance, 0);
|
|
3533
|
+
if (maxChars === null) {
|
|
3534
|
+
for (let telemetryPass = 0; telemetryPass < 20; telemetryPass += 1) {
|
|
3535
|
+
prompt = renderPrompt(sections, manifest);
|
|
3536
|
+
if (manifest.budget.usedChars === prompt.length) return { prompt, manifest };
|
|
3537
|
+
manifest = buildManifest(mode, null, sections, governedReads.provenance, prompt.length);
|
|
3538
|
+
}
|
|
3539
|
+
throw new Error("Prompt compiler could not stabilize the unbounded Context Manifest");
|
|
3540
|
+
}
|
|
3538
3541
|
for (let pass = 0; pass < 20; pass += 1) {
|
|
3539
3542
|
let usedChars = 0;
|
|
3540
3543
|
for (let telemetryPass = 0; telemetryPass < 3; telemetryPass += 1) {
|
|
@@ -4370,6 +4373,7 @@ var CODEX_USAGE_LIMIT_RE = /you(?:'|’)ve hit your usage limit for .+\.\s+switc
|
|
|
4370
4373
|
var PI_PROVIDER_AUTH_RE = /(?:(?:\b401\b|\b403\b)[^\n]*(?:unauthorized|forbidden|auth(?:entication|orization)?|api[_\s-]?key)|(?:invalid|missing|expired|revoked)\s+(?:provider\s+)?api[_\s-]?key|provider\s+authentication\s+required)/i;
|
|
4371
4374
|
var PI_PROVIDER_QUOTA_EXHAUSTED_RE = /(?:\binsufficient[_\s-]?user[_\s-]?quota\b|河狸币余额不足|\b402\b[^\n]*(?:余额不足|payment\s+required))/i;
|
|
4372
4375
|
var PI_PROVIDER_TRANSIENT_RE = /(?:\b(?:429|5\d{2})\b|rate[-\s]?limit(?:ed)?|too\s+many\s+requests|billing\s+admission\s+failed|service\s+unavailable|upstream[^\n]*(?:unavailable|failed|timeout)|connect(?:ion)?[^\n]*refused|temporar(?:y|ily)[^\n]*(?:unavailable|failed)|try\s+again\s+later)/i;
|
|
4376
|
+
var PI_PROVIDER_PROTOCOL_RE = /provider[^\n]*finish_reason[^\n]*unexpected_state/i;
|
|
4373
4377
|
var PI_PROVIDER_RETRY_AFTER_SECONDS_RE = /retry[-\s]?after\s*[:=]?\s*(\d{1,6})\s*(?:seconds?|secs?|s)\b/i;
|
|
4374
4378
|
var PI_TERMINAL_CLEANUP_PERMISSION_RE = /(?:\bkill\b[^\n]*\bEPERM\b|\bEPERM\b[^\n]*\bkill\b)/i;
|
|
4375
4379
|
var MAX_PI_PROVIDER_RETRY_AFTER_SECONDS = 7 * 24 * 60 * 60;
|
|
@@ -4712,6 +4716,12 @@ function extractPiProviderRetryNotBefore(errorMessage, now) {
|
|
|
4712
4716
|
function classifyPiProviderError(input, now = /* @__PURE__ */ new Date()) {
|
|
4713
4717
|
const errorMessage = readString(asRecord(input).errorMessage);
|
|
4714
4718
|
if (!errorMessage) return null;
|
|
4719
|
+
if (PI_PROVIDER_PROTOCOL_RE.test(errorMessage)) {
|
|
4720
|
+
return {
|
|
4721
|
+
errorCode: "pi_provider_protocol_failure",
|
|
4722
|
+
errorFamily: "provider_protocol"
|
|
4723
|
+
};
|
|
4724
|
+
}
|
|
4715
4725
|
if (PI_PROVIDER_QUOTA_EXHAUSTED_RE.test(errorMessage)) {
|
|
4716
4726
|
return {
|
|
4717
4727
|
errorCode: "pi_provider_quota_exhausted",
|
|
@@ -4956,13 +4966,17 @@ function parsePiJsonl(stdout) {
|
|
|
4956
4966
|
let hasAssistantOutput = false;
|
|
4957
4967
|
let nonCleanupErrorCount = 0;
|
|
4958
4968
|
let nonCleanupErrorMessage = null;
|
|
4969
|
+
let terminalEventIndex = null;
|
|
4970
|
+
let eventIndex = -1;
|
|
4959
4971
|
const messages = [];
|
|
4960
4972
|
const mcpToolResults = [];
|
|
4961
4973
|
const cleanupDiagnostics = [];
|
|
4974
|
+
const diagnostics = [];
|
|
4962
4975
|
const usage = { inputTokens: 0, cachedInputTokens: 0, outputTokens: 0 };
|
|
4963
4976
|
for (const rawLine of String(stdout ?? "").split(/\r?\n/)) {
|
|
4964
4977
|
const event = parseJsonLine(rawLine.trim());
|
|
4965
4978
|
if (!event) continue;
|
|
4979
|
+
eventIndex += 1;
|
|
4966
4980
|
mcpToolResults.push(...piMcpToolResults(event));
|
|
4967
4981
|
if (event.type === "session") {
|
|
4968
4982
|
sessionId = readString(event.sessionId) ?? readString(event.id) ?? sessionId;
|
|
@@ -4987,13 +5001,26 @@ function parsePiJsonl(stdout) {
|
|
|
4987
5001
|
}
|
|
4988
5002
|
if (["message", "message_update", "message_end", "turn_end", "agent_end"].includes(event.type)) {
|
|
4989
5003
|
if (event.type === "turn_end") sawTurnEnd = true;
|
|
4990
|
-
if (event.type === "turn_end" || event.type === "agent_end")
|
|
5004
|
+
if (event.type === "turn_end" || event.type === "agent_end") {
|
|
5005
|
+
terminalEventType = event.type;
|
|
5006
|
+
terminalEventIndex = eventIndex;
|
|
5007
|
+
}
|
|
4991
5008
|
stopReason = readString(event.stopReason ?? event.stop_reason) ?? piNestedMessageStopReason(event) ?? stopReason;
|
|
4992
5009
|
const terminalError = piStopReasonErrorText(event) ?? piNestedMessageErrorText(event);
|
|
4993
5010
|
if (terminalError) {
|
|
4994
5011
|
nonCleanupErrorCount += 1;
|
|
4995
5012
|
nonCleanupErrorMessage = terminalError;
|
|
4996
5013
|
errorMessage = terminalError;
|
|
5014
|
+
if (PI_PROVIDER_PROTOCOL_RE.test(terminalError)) {
|
|
5015
|
+
diagnostics.push({
|
|
5016
|
+
source: "provider",
|
|
5017
|
+
phase: "terminal",
|
|
5018
|
+
severity: "error",
|
|
5019
|
+
code: "pi_provider_protocol_failure",
|
|
5020
|
+
message: terminalError,
|
|
5021
|
+
eventIndex
|
|
5022
|
+
});
|
|
5023
|
+
}
|
|
4997
5024
|
}
|
|
4998
5025
|
hasAssistantOutput = maybeCapturePiMessage(event, messages, usage) || hasAssistantOutput;
|
|
4999
5026
|
continue;
|
|
@@ -5002,16 +5029,33 @@ function parsePiJsonl(stdout) {
|
|
|
5002
5029
|
const eventError = readString(event.message);
|
|
5003
5030
|
if (!eventError) continue;
|
|
5004
5031
|
if (PI_TERMINAL_CLEANUP_PERMISSION_RE.test(eventError)) {
|
|
5005
|
-
|
|
5032
|
+
const diagnostic = {
|
|
5006
5033
|
code: "pi_terminal_cleanup_permission_denied",
|
|
5007
5034
|
message: eventError,
|
|
5008
5035
|
phase: terminalEventType === "agent_end" ? "post_terminal" : "pre_terminal"
|
|
5036
|
+
};
|
|
5037
|
+
cleanupDiagnostics.push(diagnostic);
|
|
5038
|
+
diagnostics.push({
|
|
5039
|
+
source: "executor",
|
|
5040
|
+
severity: "warning",
|
|
5041
|
+
...diagnostic,
|
|
5042
|
+
eventIndex
|
|
5009
5043
|
});
|
|
5010
5044
|
errorMessage = nonCleanupErrorMessage ?? eventError;
|
|
5011
5045
|
} else {
|
|
5012
5046
|
nonCleanupErrorCount += 1;
|
|
5013
5047
|
nonCleanupErrorMessage = eventError;
|
|
5014
5048
|
errorMessage = eventError;
|
|
5049
|
+
if (PI_PROVIDER_PROTOCOL_RE.test(eventError)) {
|
|
5050
|
+
diagnostics.push({
|
|
5051
|
+
source: "provider",
|
|
5052
|
+
phase: terminalEventType === "agent_end" ? "post_terminal" : "pre_terminal",
|
|
5053
|
+
severity: "error",
|
|
5054
|
+
code: "pi_provider_protocol_failure",
|
|
5055
|
+
message: eventError,
|
|
5056
|
+
eventIndex
|
|
5057
|
+
});
|
|
5058
|
+
}
|
|
5015
5059
|
}
|
|
5016
5060
|
}
|
|
5017
5061
|
}
|
|
@@ -5022,11 +5066,13 @@ function parsePiJsonl(stdout) {
|
|
|
5022
5066
|
usage,
|
|
5023
5067
|
sawTurnEnd,
|
|
5024
5068
|
terminalEventType,
|
|
5069
|
+
terminalEventIndex,
|
|
5025
5070
|
stopReason,
|
|
5026
5071
|
hasAssistantOutput,
|
|
5027
5072
|
errorMessage,
|
|
5028
5073
|
...nonCleanupErrorCount > 0 ? { nonCleanupErrorCount } : {},
|
|
5029
5074
|
...cleanupDiagnostics.length > 0 ? { cleanupDiagnostics } : {},
|
|
5075
|
+
...diagnostics.length > 0 ? { diagnostics } : {},
|
|
5030
5076
|
...uniqueMcpToolResults.length > 0 ? { mcpToolResults: uniqueMcpToolResults } : {}
|
|
5031
5077
|
};
|
|
5032
5078
|
}
|
|
@@ -8698,7 +8744,7 @@ function createPublicNetworkScope(options = {}) {
|
|
|
8698
8744
|
}
|
|
8699
8745
|
|
|
8700
8746
|
// src/amaster-runtime-daemon.mjs
|
|
8701
|
-
var CONNECTOR_VERSION = "0.1.0-beta.
|
|
8747
|
+
var CONNECTOR_VERSION = "0.1.0-beta.53";
|
|
8702
8748
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
8703
8749
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
8704
8750
|
var CHECKPOINT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -13030,7 +13076,8 @@ async function executeRunCommand(config, command) {
|
|
|
13030
13076
|
...piCompanyMemory ? { companyMemory: piCompanyMemory.attestation } : {}
|
|
13031
13077
|
});
|
|
13032
13078
|
}
|
|
13033
|
-
|
|
13079
|
+
const promptBudgetSummary = contextManifest.budget.totalChars === null ? `${contextManifest.budget.usedChars} characters (unbounded)` : `${contextManifest.budget.usedChars}/${contextManifest.budget.totalChars} characters`;
|
|
13080
|
+
await ingestLog(config, command, "system", "info", `Compiled ${contextManifest.mode} prompt using ${promptBudgetSummary}`, {
|
|
13034
13081
|
presentationKind: "context_manifest",
|
|
13035
13082
|
contextManifest
|
|
13036
13083
|
});
|
|
@@ -13253,17 +13300,17 @@ async function executeRunCommand(config, command) {
|
|
|
13253
13300
|
command,
|
|
13254
13301
|
"system",
|
|
13255
13302
|
"warn",
|
|
13256
|
-
"Pi
|
|
13303
|
+
"Pi reported a post-terminal cleanup permission failure; server disposition evaluation remains authoritative",
|
|
13257
13304
|
{
|
|
13258
13305
|
presentationKind: "pi_terminal_cleanup",
|
|
13259
13306
|
cleanupDisposition
|
|
13260
13307
|
}
|
|
13261
13308
|
);
|
|
13262
13309
|
}
|
|
13263
|
-
const parsedForValidation =
|
|
13310
|
+
const parsedForValidation = parsed;
|
|
13264
13311
|
const piTurnLimitFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiTurnLimitResult(parsedForValidation) : null;
|
|
13265
13312
|
const piInvalidOutputError = executor.kind === "pi" ? piOutputValidationError(parsedForValidation, {
|
|
13266
|
-
allowMissingTurnEnd: completionOutputStopped
|
|
13313
|
+
allowMissingTurnEnd: completionOutputStopped,
|
|
13267
13314
|
allowMissingAssistantOutput: execution.completionOutputType === "approval_required"
|
|
13268
13315
|
}) : null;
|
|
13269
13316
|
const piProviderFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiProviderError(parsedForValidation) : null;
|
|
@@ -13273,13 +13320,22 @@ async function executeRunCommand(config, command) {
|
|
|
13273
13320
|
stderr: execution.stderr,
|
|
13274
13321
|
errorMessage: parsedErrorMessage
|
|
13275
13322
|
}) : null;
|
|
13276
|
-
const succeeded = !cancelled && !hasOutputFlood && !hasMemoryLimit && (execution.exitCode === 0 || completionOutputStopped
|
|
13323
|
+
const succeeded = !cancelled && !hasOutputFlood && !hasMemoryLimit && (execution.exitCode === 0 || completionOutputStopped) && !execution.timedOut && !execution.spawnError && !parsedErrorMessage;
|
|
13277
13324
|
const resultStderr = filterExecutionStderrForResult(executor.kind, execution.stderr);
|
|
13278
13325
|
const error = execution.timedOut ? `Executor timed out after ${config.executorTimeoutSeconds}s` : cancelled ? "Executor cancelled by AMaster control plane" : execution.spawnError ?? parsedErrorMessage ?? (succeeded ? null : `Executor exited with code ${execution.exitCode ?? "unknown"}`);
|
|
13279
13326
|
const costUsage = parsedCostUsage(parsed.usage);
|
|
13327
|
+
const executorOutcome = {
|
|
13328
|
+
status: cancelled ? "cancelled" : execution.timedOut ? "timed_out" : execution.exitCode === 0 && execution.signal === null ? "completed" : "failed",
|
|
13329
|
+
exitCode: execution.exitCode,
|
|
13330
|
+
signal: execution.signal,
|
|
13331
|
+
terminalEvent: ["agent_end", "turn_end"].includes(readString(parsed.terminalEventType) ?? "") ? readString(parsed.terminalEventType) : null,
|
|
13332
|
+
terminalEventIndex: Number.isInteger(parsed.terminalEventIndex) ? parsed.terminalEventIndex : null
|
|
13333
|
+
};
|
|
13280
13334
|
let result3 = {
|
|
13281
13335
|
evidenceContract: { version: 1 },
|
|
13282
13336
|
executorKind: executor.kind,
|
|
13337
|
+
executorOutcome,
|
|
13338
|
+
...Array.isArray(parsed.diagnostics) && parsed.diagnostics.length > 0 ? { diagnostics: parsed.diagnostics } : {},
|
|
13283
13339
|
command: invocation.command,
|
|
13284
13340
|
args: invocation.args,
|
|
13285
13341
|
cwd,
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
5
5
|
import { homedir, hostname } from "node:os";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
|
-
const CONNECTOR_VERSION = "0.1.0-beta.
|
|
8
|
+
const CONNECTOR_VERSION = "0.1.0-beta.53";
|
|
9
9
|
|
|
10
10
|
const CAPABILITIES = [
|
|
11
11
|
"remote_registration",
|