@amaster.ai/employee-runtime-connector 0.1.1-beta.220 → 0.1.1-beta.222
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/amaster-runtime-daemon.mjs +257 -17
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -12261,6 +12261,12 @@ var externalObjectSummarySchema = external_exports.object({
|
|
|
12261
12261
|
var agentAdapterTypeSchema = external_exports.string().trim().min(1).default("process").describe(`Known built-in adapters: ${AGENT_ADAPTER_TYPES.join(", ")}. External adapters may register additional non-empty string types at runtime.`);
|
|
12262
12262
|
var optionalAgentAdapterTypeSchema = external_exports.string().trim().min(1).optional();
|
|
12263
12263
|
|
|
12264
|
+
// ../shared/src/agent-eligibility.ts
|
|
12265
|
+
var NON_ASSIGNABLE_AGENT_STATUSES = ["pending_approval", "terminated"];
|
|
12266
|
+
var ASSIGNABLE_AGENT_STATUSES = ["active", "paused", "idle", "running", "error"];
|
|
12267
|
+
var NON_ASSIGNABLE_AGENT_STATUS_SET = new Set(NON_ASSIGNABLE_AGENT_STATUSES);
|
|
12268
|
+
var ASSIGNABLE_AGENT_STATUS_SET = new Set(ASSIGNABLE_AGENT_STATUSES);
|
|
12269
|
+
|
|
12264
12270
|
// ../shared/src/trust-policy.ts
|
|
12265
12271
|
var TRUST_PRESETS = ["standard", "low_trust_review"];
|
|
12266
12272
|
var LOW_TRUST_REVIEW_PRESET = "low_trust_review";
|
|
@@ -19999,6 +20005,81 @@ function inspectDesktopPiFinalContextReadiness(input = {}) {
|
|
|
19999
20005
|
|
|
20000
20006
|
// src/amaster-runtime-daemon/pi-managed-mcp-profile.mjs
|
|
20001
20007
|
var MANAGED_PI_DIRECT_TYPED_MCP_TOOL_MODE = "direct_typed";
|
|
20008
|
+
var MANAGED_PI_RUN_TERMINATION_FILENAME = "mirrorx-run-termination.mjs";
|
|
20009
|
+
function managedPiRunTerminationExtensionSource() {
|
|
20010
|
+
return `function asRecord(value) {
|
|
20011
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
20012
|
+
}
|
|
20013
|
+
|
|
20014
|
+
function readString(value) {
|
|
20015
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
20016
|
+
}
|
|
20017
|
+
|
|
20018
|
+
const terminalActionDispositions = new Map([
|
|
20019
|
+
["create_interaction", new Set(["waiting_human", "handoff_existing_live_path"])],
|
|
20020
|
+
["upsert_external_wait", new Set(["waiting_external"])],
|
|
20021
|
+
["schedule_monitor", new Set(["scheduled_monitor"])],
|
|
20022
|
+
]);
|
|
20023
|
+
const terminalToolNames = new Set(["runtime_action.submit", "runtime_action.status"]);
|
|
20024
|
+
|
|
20025
|
+
function shouldStopFromReceipt(rawResult) {
|
|
20026
|
+
const expectedRunId = readString(process.env.AMASTER_RUNTIME_RUN_ID);
|
|
20027
|
+
const expectedCommandId = readString(process.env.AMASTER_RUNTIME_COMMAND_ID);
|
|
20028
|
+
const expectedIssueId = readString(process.env.AMASTER_RUNTIME_ISSUE_ID);
|
|
20029
|
+
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return false;
|
|
20030
|
+
|
|
20031
|
+
const result = asRecord(rawResult);
|
|
20032
|
+
const structured = asRecord(result.structuredContent);
|
|
20033
|
+
const providerContent = asRecord(structured.content);
|
|
20034
|
+
const providerResult = asRecord(providerContent.result);
|
|
20035
|
+
const effectResult = asRecord(providerResult.effectResult);
|
|
20036
|
+
const providerReceipt = asRecord(structured.providerReceipt);
|
|
20037
|
+
const invocationId = readString(structured.invocationId);
|
|
20038
|
+
const callId = readString(providerResult.callId);
|
|
20039
|
+
const receiptInvocationId = readString(providerReceipt.invocationId);
|
|
20040
|
+
const receiptCallId = readString(providerReceipt.callId);
|
|
20041
|
+
const actionType = readString(providerReceipt.actionType);
|
|
20042
|
+
const disposition = readString(effectResult.runDisposition);
|
|
20043
|
+
const existingOwner = asRecord(effectResult.existingOwner);
|
|
20044
|
+
const existingOwnerEpoch = Number(existingOwner.executionEpoch);
|
|
20045
|
+
if (!invocationId || !receiptInvocationId || !callId || !receiptCallId) return false;
|
|
20046
|
+
|
|
20047
|
+
const exactQueuedWakeHandoff = disposition === "handoff_existing_live_path"
|
|
20048
|
+
&& readString(existingOwner.kind) === "queued_wake"
|
|
20049
|
+
&& Boolean(readString(existingOwner.id))
|
|
20050
|
+
&& ["pending_dispatch", "queued", "deferred_issue_execution"].includes(readString(existingOwner.status) ?? "")
|
|
20051
|
+
&& Number.isSafeInteger(existingOwnerEpoch)
|
|
20052
|
+
&& existingOwnerEpoch > 0
|
|
20053
|
+
&& readString(existingOwner.nextAction) === "end_current_run";
|
|
20054
|
+
|
|
20055
|
+
return readString(structured.status) === "succeeded"
|
|
20056
|
+
&& readString(providerContent.status) === "accepted"
|
|
20057
|
+
&& ["succeeded", "completed"].includes(readString(providerResult.status) ?? "")
|
|
20058
|
+
&& terminalToolNames.has(readString(providerContent.toolName) ?? "")
|
|
20059
|
+
&& effectResult.mustEndRun === true
|
|
20060
|
+
&& Boolean(terminalActionDispositions.get(actionType ?? "")?.has(disposition ?? ""))
|
|
20061
|
+
&& readString(providerReceipt.provider) === "amaster_actions"
|
|
20062
|
+
&& readString(providerReceipt.status) === "accepted"
|
|
20063
|
+
&& receiptInvocationId === invocationId
|
|
20064
|
+
&& readString(providerReceipt.runId) === expectedRunId
|
|
20065
|
+
&& readString(providerReceipt.commandId) === expectedCommandId
|
|
20066
|
+
&& readString(providerReceipt.issueId) === expectedIssueId
|
|
20067
|
+
&& receiptCallId === callId
|
|
20068
|
+
&& (disposition !== "waiting_human"
|
|
20069
|
+
|| Boolean(readString(effectResult.interactionId) && readString(effectResult.epochKey)))
|
|
20070
|
+
&& (disposition !== "handoff_existing_live_path"
|
|
20071
|
+
|| Boolean(readString(effectResult.epochKey) && exactQueuedWakeHandoff));
|
|
20072
|
+
}
|
|
20073
|
+
|
|
20074
|
+
export default function mirrorxRunTermination(pi) {
|
|
20075
|
+
pi.on("tool_result", (event) => {
|
|
20076
|
+
if (event.isError === true) return undefined;
|
|
20077
|
+
const rawResult = asRecord(event.details).mcpResult;
|
|
20078
|
+
return shouldStopFromReceipt(rawResult) ? { stopAfterTurn: true } : undefined;
|
|
20079
|
+
});
|
|
20080
|
+
}
|
|
20081
|
+
`;
|
|
20082
|
+
}
|
|
20002
20083
|
var MANAGED_PI_CONFIG_MODE_SHARED = "shared_agent_dir_workspace_mcp_file";
|
|
20003
20084
|
var MANAGED_PI_TELEMETRY_PACKAGE = "@amaster.ai/pi-telemetry";
|
|
20004
20085
|
var MANAGED_PI_TELEMETRY_PACKAGE_SOURCE = "npm:@amaster.ai/pi-telemetry";
|
|
@@ -21764,7 +21845,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
21764
21845
|
const config = {
|
|
21765
21846
|
settings: {
|
|
21766
21847
|
toolPrefix: "none",
|
|
21767
|
-
scriptMode: false
|
|
21848
|
+
scriptMode: false,
|
|
21849
|
+
...directCatalog ? { directToolResultDetails: "bounded" } : {}
|
|
21768
21850
|
},
|
|
21769
21851
|
mcpServers: {
|
|
21770
21852
|
[SUPPORTED_SERVER_NAME2]: serverConfig
|
|
@@ -21797,6 +21879,10 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
21797
21879
|
throw new Error("pi_managed_mcp_adapter_extension_unsafe");
|
|
21798
21880
|
}
|
|
21799
21881
|
extensionArgs.push("--extension", adapterExtensionPath);
|
|
21882
|
+
writeProfileExtension(
|
|
21883
|
+
MANAGED_PI_RUN_TERMINATION_FILENAME,
|
|
21884
|
+
managedPiRunTerminationExtensionSource()
|
|
21885
|
+
);
|
|
21800
21886
|
}
|
|
21801
21887
|
const adapterVersion = piMcpAdapterVersion(sharedRuntime.home);
|
|
21802
21888
|
const {
|
|
@@ -21841,6 +21927,9 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
21841
21927
|
// The profile owns the final child environment. Never rely on a caller
|
|
21842
21928
|
// supplied correlation value when governed telemetry is active.
|
|
21843
21929
|
...telemetryExtension ? { PI_TELEMETRY_TASK_RUN_ID: runId } : {},
|
|
21930
|
+
AMASTER_RUNTIME_RUN_ID: authority.runId,
|
|
21931
|
+
AMASTER_RUNTIME_COMMAND_ID: authority.commandId,
|
|
21932
|
+
...authority.issueId ? { AMASTER_RUNTIME_ISSUE_ID: authority.issueId } : {},
|
|
21844
21933
|
HOME: home,
|
|
21845
21934
|
PI_AGENT_HOME: piAgentHome,
|
|
21846
21935
|
PI_CODING_AGENT_SESSION_DIR: sessionsRoot,
|
|
@@ -22185,7 +22274,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
22185
22274
|
// exact identities attested by the Server. A desktop user's adapter
|
|
22186
22275
|
// prefix is local presentation state and must not rename this run's
|
|
22187
22276
|
// governed tools.
|
|
22188
|
-
...directCatalog ? { toolPrefix: "none" } : {}
|
|
22277
|
+
...directCatalog ? { toolPrefix: "none" } : {},
|
|
22278
|
+
...directCatalog ? { directToolResultDetails: "bounded" } : {}
|
|
22189
22279
|
},
|
|
22190
22280
|
mcpServers: {
|
|
22191
22281
|
...record6(sourceMcp.mcpServers),
|
|
@@ -22210,6 +22300,12 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
22210
22300
|
if (desktopAttestationReadiness?.ready) {
|
|
22211
22301
|
extensionArgs.push("--extension", desktopAttestationReadiness.extensionPath);
|
|
22212
22302
|
}
|
|
22303
|
+
if (directCatalog) {
|
|
22304
|
+
writeProfileExtension(
|
|
22305
|
+
MANAGED_PI_RUN_TERMINATION_FILENAME,
|
|
22306
|
+
managedPiRunTerminationExtensionSource()
|
|
22307
|
+
);
|
|
22308
|
+
}
|
|
22213
22309
|
const skillProfiles = roleSkillProfilesForRun(input);
|
|
22214
22310
|
let enabledRoleSkills = null;
|
|
22215
22311
|
let enabledRoleSkillMetadataBytes = 0;
|
|
@@ -22250,6 +22346,9 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
22250
22346
|
const env = {
|
|
22251
22347
|
...input.baseEnv,
|
|
22252
22348
|
...record6(input.commandEnv),
|
|
22349
|
+
AMASTER_RUNTIME_RUN_ID: authority.runId,
|
|
22350
|
+
AMASTER_RUNTIME_COMMAND_ID: authority.commandId,
|
|
22351
|
+
...authority.issueId ? { AMASTER_RUNTIME_ISSUE_ID: authority.issueId } : {},
|
|
22253
22352
|
PI_AGENT_HOME: sourcePiHome,
|
|
22254
22353
|
PI_CODING_AGENT_DIR: piCodingAgentDir,
|
|
22255
22354
|
"AMASTER-CLI_CODING_AGENT_DIR": piCodingAgentDir,
|
|
@@ -25981,6 +26080,27 @@ function compactExecutorJsonlForTranscript(event) {
|
|
|
25981
26080
|
_truncated: true
|
|
25982
26081
|
});
|
|
25983
26082
|
}
|
|
26083
|
+
function compactPiToolLifecycleForTranscript(event, readableSummary) {
|
|
26084
|
+
const record6 = tcAsRecord(event);
|
|
26085
|
+
const type = tcReadString(record6.type);
|
|
26086
|
+
if (type !== "tool_execution_start" && type !== "tool_execution_end") return null;
|
|
26087
|
+
const toolCallId = tcReadString(record6.toolCallId);
|
|
26088
|
+
if (!toolCallId) return null;
|
|
26089
|
+
const toolName = tcReadString(record6.toolName) ?? "tool";
|
|
26090
|
+
const summary = tcTruncateText(readableSummary || `${type === "tool_execution_start" ? "\u5DE5\u5177\u5F00\u59CB" : "\u5DE5\u5177\u5B8C\u6210"}\uFF1A${toolName}`, 500);
|
|
26091
|
+
return JSON.stringify(type === "tool_execution_start" ? {
|
|
26092
|
+
type,
|
|
26093
|
+
toolCallId,
|
|
26094
|
+
toolName,
|
|
26095
|
+
args: { summary }
|
|
26096
|
+
} : {
|
|
26097
|
+
type,
|
|
26098
|
+
toolCallId,
|
|
26099
|
+
toolName,
|
|
26100
|
+
result: summary,
|
|
26101
|
+
isError: record6.isError === true
|
|
26102
|
+
});
|
|
26103
|
+
}
|
|
25984
26104
|
function summarizeTokenUsage(usage) {
|
|
25985
26105
|
const record6 = tcAsRecord(usage);
|
|
25986
26106
|
const inputTokens = tcReadNumber(record6.input_tokens ?? record6.inputTokens, 0);
|
|
@@ -26502,6 +26622,15 @@ var PI_TERMINAL_RUNTIME_ACTION_STATUSES = /* @__PURE__ */ new Set([
|
|
|
26502
26622
|
"completed",
|
|
26503
26623
|
"succeeded"
|
|
26504
26624
|
]);
|
|
26625
|
+
var PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION = /* @__PURE__ */ new Map([
|
|
26626
|
+
["create_interaction", /* @__PURE__ */ new Set(["waiting_human", "handoff_existing_live_path"])],
|
|
26627
|
+
["upsert_external_wait", /* @__PURE__ */ new Set(["waiting_external"])],
|
|
26628
|
+
["schedule_monitor", /* @__PURE__ */ new Set(["scheduled_monitor"])]
|
|
26629
|
+
]);
|
|
26630
|
+
var PI_TERMINATING_RUNTIME_ACTION_TOOLS = /* @__PURE__ */ new Set([
|
|
26631
|
+
"runtime_action.submit",
|
|
26632
|
+
"runtime_action.status"
|
|
26633
|
+
]);
|
|
26505
26634
|
function approvedMcpInvocationSucceeded(results, invocationId) {
|
|
26506
26635
|
const approvedInvocationId = readString(invocationId);
|
|
26507
26636
|
return Boolean(approvedInvocationId && (Array.isArray(results) ? results : []).some((rawResult) => {
|
|
@@ -26539,20 +26668,58 @@ function governedMcpToolResult(structuredContent) {
|
|
|
26539
26668
|
} : null;
|
|
26540
26669
|
const runtimeActionToolName = readString(providerContent.toolName);
|
|
26541
26670
|
const runtimeActionError = asRecord(providerResult.error);
|
|
26671
|
+
const runtimeActionCallId = readString(providerResult.callId);
|
|
26672
|
+
const runtimeActionResultStatus = readString(providerResult.status);
|
|
26542
26673
|
const runtimeAction = runtimeActionToolName?.startsWith("runtime_action.") ? {
|
|
26543
26674
|
toolName: runtimeActionToolName,
|
|
26544
|
-
...
|
|
26675
|
+
...runtimeActionCallId ? { callId: runtimeActionCallId } : {},
|
|
26545
26676
|
...readString(providerResult.planId) ? { planId: readString(providerResult.planId) } : {},
|
|
26546
|
-
...
|
|
26677
|
+
...runtimeActionResultStatus ? { resultStatus: runtimeActionResultStatus } : {},
|
|
26547
26678
|
...readString(providerResult.errorCode) ?? readString(runtimeActionError.code) ? { errorCode: readString(providerResult.errorCode) ?? readString(runtimeActionError.code) } : {}
|
|
26548
26679
|
} : null;
|
|
26680
|
+
const receiptActionType = readString(providerReceipt.actionType);
|
|
26681
|
+
const runDisposition = readString(effectResult.runDisposition);
|
|
26682
|
+
const expectedDispositions = PI_TERMINATING_RUNTIME_ACTION_TO_DISPOSITION.get(receiptActionType ?? "");
|
|
26683
|
+
const receiptRunId = readString(providerReceipt.runId);
|
|
26684
|
+
const receiptCommandId = readString(providerReceipt.commandId);
|
|
26685
|
+
const receiptIssueId = readString(providerReceipt.issueId);
|
|
26686
|
+
const receiptCallId = readString(providerReceipt.callId);
|
|
26687
|
+
const interactionId = readString(effectResult.interactionId);
|
|
26688
|
+
const epochKey = readString(effectResult.epochKey);
|
|
26689
|
+
const existingOwner = asRecord(effectResult.existingOwner);
|
|
26690
|
+
const existingOwnerEpoch = readNumber(existingOwner.executionEpoch, 0);
|
|
26691
|
+
const exactQueuedWakeHandoff = runDisposition === "handoff_existing_live_path" && readString(existingOwner.kind) === "queued_wake" && Boolean(readString(existingOwner.id)) && ["pending_dispatch", "queued", "deferred_issue_execution"].includes(
|
|
26692
|
+
readString(existingOwner.status) ?? ""
|
|
26693
|
+
) && Number.isSafeInteger(existingOwnerEpoch) && existingOwnerEpoch > 0 && readString(existingOwner.nextAction) === "end_current_run";
|
|
26694
|
+
const terminalRunDisposition = status === "succeeded" && providerStatus === "accepted" && PI_TERMINAL_RUNTIME_ACTION_STATUSES.has(runtimeActionResultStatus ?? "") && PI_TERMINATING_RUNTIME_ACTION_TOOLS.has(runtimeActionToolName ?? "") && effectResult.mustEndRun === true && Boolean(expectedDispositions?.has(runDisposition ?? "")) && invocationId && readString(providerReceipt.provider) === "amaster_actions" && readString(providerReceipt.invocationId) === invocationId && readString(providerReceipt.status) === "accepted" && receiptRunId && receiptCommandId && receiptIssueId && runtimeActionCallId && receiptCallId === runtimeActionCallId && (runDisposition !== "waiting_human" || Boolean(interactionId && epochKey)) && (runDisposition !== "handoff_existing_live_path" || Boolean(epochKey && exactQueuedWakeHandoff)) ? {
|
|
26695
|
+
disposition: runDisposition,
|
|
26696
|
+
actionType: receiptActionType,
|
|
26697
|
+
toolName: runtimeActionToolName,
|
|
26698
|
+
invocationId,
|
|
26699
|
+
callId: runtimeActionCallId,
|
|
26700
|
+
runId: receiptRunId,
|
|
26701
|
+
commandId: receiptCommandId,
|
|
26702
|
+
issueId: receiptIssueId,
|
|
26703
|
+
...interactionId ? { interactionId } : {},
|
|
26704
|
+
...epochKey ? { epochKey } : {},
|
|
26705
|
+
...exactQueuedWakeHandoff ? {
|
|
26706
|
+
existingOwner: {
|
|
26707
|
+
kind: "queued_wake",
|
|
26708
|
+
id: readString(existingOwner.id),
|
|
26709
|
+
status: readString(existingOwner.status),
|
|
26710
|
+
executionEpoch: existingOwnerEpoch,
|
|
26711
|
+
nextAction: "end_current_run"
|
|
26712
|
+
}
|
|
26713
|
+
} : {}
|
|
26714
|
+
} : null;
|
|
26549
26715
|
return {
|
|
26550
26716
|
...invocationId ? { invocationId } : {},
|
|
26551
26717
|
status,
|
|
26552
26718
|
...providerStatus ? { providerStatus } : {},
|
|
26553
26719
|
...artifactIntent ? { artifactIntent } : {},
|
|
26554
26720
|
...workspaceDocumentIntent ? { workspaceDocumentIntent } : {},
|
|
26555
|
-
...runtimeAction ? { runtimeAction } : {}
|
|
26721
|
+
...runtimeAction ? { runtimeAction } : {},
|
|
26722
|
+
...terminalRunDisposition ? { terminalRunDisposition } : {}
|
|
26556
26723
|
};
|
|
26557
26724
|
}
|
|
26558
26725
|
function dedupeGovernedMcpToolResults(results) {
|
|
@@ -26578,16 +26745,54 @@ function dedupeGovernedMcpToolResults(results) {
|
|
|
26578
26745
|
const artifactIntent = asRecord(result2.artifactIntent);
|
|
26579
26746
|
const existingWorkspaceDocumentIntent = asRecord(existing.workspaceDocumentIntent);
|
|
26580
26747
|
const workspaceDocumentIntent = asRecord(result2.workspaceDocumentIntent);
|
|
26748
|
+
const existingTerminalRunDisposition = asRecord(existing.terminalRunDisposition);
|
|
26749
|
+
const terminalRunDisposition = asRecord(result2.terminalRunDisposition);
|
|
26581
26750
|
unique[existingIndex] = {
|
|
26582
26751
|
...existing,
|
|
26583
26752
|
...result2,
|
|
26584
26753
|
...Object.keys(existingRuntimeAction).length > 0 || Object.keys(runtimeAction).length > 0 ? { runtimeAction: { ...existingRuntimeAction, ...runtimeAction } } : {},
|
|
26585
26754
|
...Object.keys(existingArtifactIntent).length > 0 || Object.keys(artifactIntent).length > 0 ? { artifactIntent: { ...existingArtifactIntent, ...artifactIntent } } : {},
|
|
26586
|
-
...Object.keys(existingWorkspaceDocumentIntent).length > 0 || Object.keys(workspaceDocumentIntent).length > 0 ? { workspaceDocumentIntent: { ...existingWorkspaceDocumentIntent, ...workspaceDocumentIntent } } : {}
|
|
26755
|
+
...Object.keys(existingWorkspaceDocumentIntent).length > 0 || Object.keys(workspaceDocumentIntent).length > 0 ? { workspaceDocumentIntent: { ...existingWorkspaceDocumentIntent, ...workspaceDocumentIntent } } : {},
|
|
26756
|
+
...Object.keys(existingTerminalRunDisposition).length > 0 || Object.keys(terminalRunDisposition).length > 0 ? { terminalRunDisposition: { ...existingTerminalRunDisposition, ...terminalRunDisposition } } : {}
|
|
26587
26757
|
};
|
|
26588
26758
|
}
|
|
26589
26759
|
return unique;
|
|
26590
26760
|
}
|
|
26761
|
+
function piTerminatingRunDispositionEvidence(results, expected = {}) {
|
|
26762
|
+
const expectedRunId = readString(expected.runId);
|
|
26763
|
+
const expectedCommandId = readString(expected.commandId);
|
|
26764
|
+
const expectedIssueId = readString(expected.issueId);
|
|
26765
|
+
if (!expectedRunId || !expectedCommandId || !expectedIssueId) return null;
|
|
26766
|
+
const result2 = (Array.isArray(results) ? results : []).map(asRecord).find((entry) => {
|
|
26767
|
+
const disposition2 = asRecord(entry.terminalRunDisposition);
|
|
26768
|
+
return readString(entry.status) === "succeeded" && readString(disposition2.runId) === expectedRunId && readString(disposition2.commandId) === expectedCommandId && readString(disposition2.issueId) === expectedIssueId;
|
|
26769
|
+
});
|
|
26770
|
+
if (!result2) return null;
|
|
26771
|
+
const disposition = asRecord(result2.terminalRunDisposition);
|
|
26772
|
+
const existingOwner = asRecord(disposition.existingOwner);
|
|
26773
|
+
return {
|
|
26774
|
+
kind: "runtime_action_run_disposition",
|
|
26775
|
+
disposition: readString(disposition.disposition),
|
|
26776
|
+
actionType: readString(disposition.actionType),
|
|
26777
|
+
toolName: readString(disposition.toolName),
|
|
26778
|
+
invocationId: readString(disposition.invocationId),
|
|
26779
|
+
callId: readString(disposition.callId),
|
|
26780
|
+
runId: expectedRunId,
|
|
26781
|
+
commandId: expectedCommandId,
|
|
26782
|
+
issueId: expectedIssueId,
|
|
26783
|
+
...readString(disposition.interactionId) ? { interactionId: readString(disposition.interactionId) } : {},
|
|
26784
|
+
...readString(disposition.epochKey) ? { epochKey: readString(disposition.epochKey) } : {},
|
|
26785
|
+
...readString(existingOwner.kind) === "queued_wake" && readString(existingOwner.id) ? {
|
|
26786
|
+
existingOwner: {
|
|
26787
|
+
kind: "queued_wake",
|
|
26788
|
+
id: readString(existingOwner.id),
|
|
26789
|
+
status: readString(existingOwner.status),
|
|
26790
|
+
executionEpoch: readNumber(existingOwner.executionEpoch, 0),
|
|
26791
|
+
nextAction: readString(existingOwner.nextAction)
|
|
26792
|
+
}
|
|
26793
|
+
} : {}
|
|
26794
|
+
};
|
|
26795
|
+
}
|
|
26591
26796
|
function durablePiRuntimeActionEvidence(results) {
|
|
26592
26797
|
const normalizedResults = (Array.isArray(results) ? results : []).map(asRecord);
|
|
26593
26798
|
const writeCallIds = /* @__PURE__ */ new Set();
|
|
@@ -29354,7 +29559,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
29354
29559
|
}
|
|
29355
29560
|
|
|
29356
29561
|
// src/amaster-runtime-daemon.mjs
|
|
29357
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
29562
|
+
var CONNECTOR_VERSION = "0.1.1-beta.222";
|
|
29358
29563
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
29359
29564
|
var daemonRequire = createRequire(import.meta.url);
|
|
29360
29565
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
@@ -31567,7 +31772,20 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
31567
31772
|
}
|
|
31568
31773
|
}
|
|
31569
31774
|
let entry = null;
|
|
31570
|
-
|
|
31775
|
+
const summarizedEntry = summarizeExecutorOutputLine(executorKind, stream, text2);
|
|
31776
|
+
const piToolLifecycle = executorKind === "pi" && event ? compactPiToolLifecycleForTranscript(event, summarizedEntry?.message) : null;
|
|
31777
|
+
if (piToolLifecycle) {
|
|
31778
|
+
entry = {
|
|
31779
|
+
stream: "stdout",
|
|
31780
|
+
level: summarizedEntry?.level ?? "info",
|
|
31781
|
+
message: piToolLifecycle,
|
|
31782
|
+
payload: summarizedEntry?.payload ?? {
|
|
31783
|
+
presentationKind: "tool",
|
|
31784
|
+
executorKind,
|
|
31785
|
+
executorEventType: readString(event.type)
|
|
31786
|
+
}
|
|
31787
|
+
};
|
|
31788
|
+
} else if (event && shouldPreserveExecutorJsonlForTranscript(executorKind, event)) {
|
|
31571
31789
|
entry = {
|
|
31572
31790
|
stream: "stdout",
|
|
31573
31791
|
level: "info",
|
|
@@ -31579,7 +31797,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
31579
31797
|
}
|
|
31580
31798
|
};
|
|
31581
31799
|
} else {
|
|
31582
|
-
entry =
|
|
31800
|
+
entry = summarizedEntry;
|
|
31583
31801
|
}
|
|
31584
31802
|
if (entry && shouldSuppressDuplicatePiAgentMessage(entry)) {
|
|
31585
31803
|
if (stream === "stdout") {
|
|
@@ -34251,7 +34469,7 @@ function piCompletionOutputStopped(execution) {
|
|
|
34251
34469
|
}
|
|
34252
34470
|
function piOutputValidationError(parsed, options = {}) {
|
|
34253
34471
|
if (parsed?.errorMessage) return parsed.errorMessage;
|
|
34254
|
-
if (options.completionOutputType === "agent_settled" && options.completionOutputHasFinalAssistantText !== true) {
|
|
34472
|
+
if (options.completionOutputType === "agent_settled" && options.completionOutputHasFinalAssistantText !== true && options.allowMissingFinalAssistantText !== true) {
|
|
34255
34473
|
return "Pi Agent agent_settled without final assistant text";
|
|
34256
34474
|
}
|
|
34257
34475
|
if (!parsed?.hasAssistantOutput && options.allowMissingAssistantOutput !== true) {
|
|
@@ -34814,8 +35032,29 @@ async function executeRunCommand(config, command) {
|
|
|
34814
35032
|
const primaryUsage = { ...asRecord(parsed.usage) };
|
|
34815
35033
|
let terminalTextRepair = null;
|
|
34816
35034
|
let terminalTextRepairUsageBreakdown = null;
|
|
35035
|
+
const terminalRunDisposition = executor.kind === "pi" ? piTerminatingRunDispositionEvidence(mcpToolResults, {
|
|
35036
|
+
runId: commandRunId(command),
|
|
35037
|
+
commandId: command.commandId,
|
|
35038
|
+
issueId: commandIssueId(command)
|
|
35039
|
+
}) : null;
|
|
35040
|
+
if (terminalRunDisposition) {
|
|
35041
|
+
const disposition = readString(terminalRunDisposition.disposition);
|
|
35042
|
+
parsed.summary = disposition === "handoff_existing_live_path" ? "This run handed control to the existing queued live path and ended normally without creating a duplicate interaction." : disposition === "waiting_human" ? "The requested human interaction was persisted; this run ended normally and will resume only under its continuation policy." : disposition === "waiting_external" ? "The external wait was persisted; this run ended normally and will resume only after the recorded condition is satisfied." : "The monitor schedule was persisted; this run ended normally and will resume only at the scheduled check.";
|
|
35043
|
+
parsed.hasAssistantOutput = true;
|
|
35044
|
+
await ingestLog(
|
|
35045
|
+
config,
|
|
35046
|
+
command,
|
|
35047
|
+
"system",
|
|
35048
|
+
"info",
|
|
35049
|
+
`Accepted ${disposition} as the authoritative terminal disposition for the current run`,
|
|
35050
|
+
{
|
|
35051
|
+
presentationKind: "runtime_action_terminal_disposition",
|
|
35052
|
+
terminalRunDisposition
|
|
35053
|
+
}
|
|
35054
|
+
);
|
|
35055
|
+
}
|
|
34817
35056
|
const terminalTextRepairEvidence = executor.kind === "pi" ? piDurableCompletionEvidence(mcpToolResults, runtimeArtifacts, runtimeDocuments) : null;
|
|
34818
|
-
if (terminalTextRepairEvidence && managedMcpProfile && Array.isArray(command.requiredCapabilities) && command.requiredCapabilities.includes("runtime_actions_v2") && piTerminalTextRepairPrimaryEligible(execution, parsed)) {
|
|
35057
|
+
if (terminalTextRepairEvidence && !terminalRunDisposition && managedMcpProfile && Array.isArray(command.requiredCapabilities) && command.requiredCapabilities.includes("runtime_actions_v2") && piTerminalTextRepairPrimaryEligible(execution, parsed)) {
|
|
34819
35058
|
patchActiveRunCommand(command, { phase: "terminal_text_repair" });
|
|
34820
35059
|
const primaryRecordedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
34821
35060
|
try {
|
|
@@ -34982,6 +35221,7 @@ async function executeRunCommand(config, command) {
|
|
|
34982
35221
|
const piInvalidOutputError = executor.kind === "pi" ? piOutputValidationError(parsedForValidation, {
|
|
34983
35222
|
allowMissingTurnEnd: completionOutputStopped,
|
|
34984
35223
|
allowMissingAssistantOutput: execution.completionOutputType === "approval_required",
|
|
35224
|
+
allowMissingFinalAssistantText: Boolean(terminalRunDisposition),
|
|
34985
35225
|
completionOutputType: execution.completionOutputType,
|
|
34986
35226
|
completionOutputHasFinalAssistantText: terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText
|
|
34987
35227
|
}) : null;
|
|
@@ -34994,13 +35234,14 @@ async function executeRunCommand(config, command) {
|
|
|
34994
35234
|
errorMessage: parsedErrorMessage
|
|
34995
35235
|
}) : null;
|
|
34996
35236
|
const repairedPiTerminalOutputStop = terminalTextRepair?.succeeded === true && execution.completionOutputType === "agent_settled" && execution.completionOutputHasFinalAssistantText === false && piCompletionCleanupStopped(execution);
|
|
34997
|
-
const
|
|
35237
|
+
const dispositionPiTerminalOutputStop = Boolean(terminalRunDisposition) && execution.completionOutputType === "agent_settled" && execution.completionOutputHasFinalAssistantText === false && piCompletionCleanupStopped(execution);
|
|
35238
|
+
const succeeded = !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && (execution.exitCode === 0 || completionOutputStopped || repairedPiTerminalOutputStop || dispositionPiTerminalOutputStop) && !execution.timedOut && !execution.spawnError && !parsedErrorMessage;
|
|
34998
35239
|
const resultStderr = filterExecutionStderrForResult(executor.kind, execution.stderr);
|
|
34999
35240
|
const unsafeError = 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"}`);
|
|
35000
35241
|
const error = unsafeError;
|
|
35001
35242
|
const costUsage = parsedCostUsage(parsed.usage);
|
|
35002
|
-
const cleanPiTerminalOutputStop = succeeded && (completionOutputStopped || repairedPiTerminalOutputStop) && execution.completionOutputType === "agent_settled" && parsed.sawAgentSettled === true && Number.isInteger(parsed.settledEventIndex);
|
|
35003
35243
|
const settledTerminalOutput = execution.completionOutputType === "agent_settled" && parsed.sawAgentSettled === true && Number.isInteger(parsed.settledEventIndex);
|
|
35244
|
+
const cleanPiTerminalOutputStop = succeeded && (completionOutputStopped || repairedPiTerminalOutputStop || dispositionPiTerminalOutputStop) && settledTerminalOutput;
|
|
35004
35245
|
const executorOutcome = {
|
|
35005
35246
|
status: cancelled ? "cancelled" : execution.timedOut ? "timed_out" : cleanPiTerminalOutputStop || execution.exitCode === 0 && execution.signal === null ? "completed" : "failed",
|
|
35006
35247
|
exitCode: cleanPiTerminalOutputStop ? 0 : execution.exitCode,
|
|
@@ -35039,6 +35280,7 @@ async function executeRunCommand(config, command) {
|
|
|
35039
35280
|
...terminalTextRepairUsageBreakdown ? { usageBreakdown: terminalTextRepairUsageBreakdown } : {},
|
|
35040
35281
|
...costUsage ? { costUsage } : {},
|
|
35041
35282
|
...terminalTextRepair ? { terminalTextRepair: terminalTextRepair.audit } : {},
|
|
35283
|
+
...terminalRunDisposition ? { terminalRunDisposition } : {},
|
|
35042
35284
|
...runtimeArtifacts.length > 0 ? { runtimeArtifacts } : {},
|
|
35043
35285
|
...runtimeDocuments.length > 0 ? { runtimeDocuments } : {},
|
|
35044
35286
|
outputTelemetry,
|
|
@@ -35342,10 +35584,9 @@ async function runOnce(config) {
|
|
|
35342
35584
|
await flushResultOutbox(config);
|
|
35343
35585
|
await flushRunCompletionStates(config);
|
|
35344
35586
|
const availableSlots = availableCommandSlots(config);
|
|
35345
|
-
if (availableSlots <= 0) return 0;
|
|
35346
35587
|
const leaseId = `amaster-${Date.now()}`;
|
|
35347
35588
|
const polled = await postJson(config, `/api/amaster/runtime-connectors/${config.connectorId}/commands/poll`, {
|
|
35348
|
-
limit: availableSlots,
|
|
35589
|
+
limit: Math.max(1, availableSlots),
|
|
35349
35590
|
maxConcurrentCommands: maxConcurrentCommands(config),
|
|
35350
35591
|
leaseId,
|
|
35351
35592
|
leaseSeconds: config.leaseSeconds
|
|
@@ -35376,10 +35617,9 @@ async function dispatchAvailableCommands(config, options = {}) {
|
|
|
35376
35617
|
await flushResultOutbox(config);
|
|
35377
35618
|
await flushRunCompletionStates(config);
|
|
35378
35619
|
const availableSlots = availableCommandSlots(config);
|
|
35379
|
-
if (availableSlots <= 0) return 0;
|
|
35380
35620
|
const leaseId = `amaster-${Date.now()}`;
|
|
35381
35621
|
const polled = await postJson(config, `/api/amaster/runtime-connectors/${config.connectorId}/commands/poll`, {
|
|
35382
|
-
limit: availableSlots,
|
|
35622
|
+
limit: Math.max(1, availableSlots),
|
|
35383
35623
|
maxConcurrentCommands: maxConcurrentCommands(config),
|
|
35384
35624
|
leaseId,
|
|
35385
35625
|
leaseSeconds: config.leaseSeconds
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { homedir, hostname } from "node:os";
|
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { BUILD_SUPPORTED_CAPABILITIES } from "./amaster-runtime-daemon/capability-registry.mjs";
|
|
9
9
|
|
|
10
|
-
const CONNECTOR_VERSION = "0.1.1-beta.
|
|
10
|
+
const CONNECTOR_VERSION = "0.1.1-beta.222";
|
|
11
11
|
|
|
12
12
|
const CONFIG_KEY_MAP = new Map([
|
|
13
13
|
["server_url", "AMASTER_EMPLOYEE_SERVER_URL"],
|