@amaster.ai/employee-runtime-connector 0.1.0-beta.23 → 0.1.0-beta.25
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 +108 -45
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -3218,6 +3218,46 @@ function approvedMcpInvocationSucceeded(results, invocationId) {
|
|
|
3218
3218
|
return readString(result2.invocationId) === approvedInvocationId && readString(result2.status) === "succeeded" && !["rejected", "blocked"].includes(readString(result2.providerStatus) ?? "");
|
|
3219
3219
|
}));
|
|
3220
3220
|
}
|
|
3221
|
+
function governedMcpToolResult(structuredContent) {
|
|
3222
|
+
const status = readString(structuredContent.status);
|
|
3223
|
+
if (!status) return null;
|
|
3224
|
+
const invocationId = readString(structuredContent.invocationId);
|
|
3225
|
+
const providerContent = asRecord(structuredContent.content);
|
|
3226
|
+
const providerStatus = readString(providerContent.status);
|
|
3227
|
+
const effectResult = asRecord(asRecord(providerContent.result).effectResult);
|
|
3228
|
+
const intentId = readString(effectResult.artifactIntentId);
|
|
3229
|
+
const manifestId = readString(effectResult.manifestId);
|
|
3230
|
+
const sourceRelativePath = readString(effectResult.sourceRelativePath);
|
|
3231
|
+
const sha256 = readString(effectResult.sha256);
|
|
3232
|
+
const byteSize = readNumber(effectResult.byteSize, 0);
|
|
3233
|
+
const artifactIntent = providerStatus === "pending_reconcile" && intentId && manifestId && sourceRelativePath && /^[a-f0-9]{64}$/.test(sha256 ?? "") && Number.isSafeInteger(byteSize) && byteSize > 0 ? { intentId, manifestId, sourceRelativePath, sha256, byteSize } : null;
|
|
3234
|
+
return {
|
|
3235
|
+
...invocationId ? { invocationId } : {},
|
|
3236
|
+
status,
|
|
3237
|
+
...providerStatus ? { providerStatus } : {},
|
|
3238
|
+
...artifactIntent ? { artifactIntent } : {}
|
|
3239
|
+
};
|
|
3240
|
+
}
|
|
3241
|
+
function codexMcpToolResults(event) {
|
|
3242
|
+
if (event?.type !== "item.completed") return [];
|
|
3243
|
+
const item = asRecord(event.item);
|
|
3244
|
+
if (item.type !== "mcp_tool_call") return [];
|
|
3245
|
+
const result2 = asRecord(item.result);
|
|
3246
|
+
let structuredContent = asRecord(result2.structuredContent);
|
|
3247
|
+
if (Object.keys(structuredContent).length === 0 && Array.isArray(result2.content)) {
|
|
3248
|
+
for (const part of result2.content) {
|
|
3249
|
+
const text = readString(asRecord(part).text);
|
|
3250
|
+
if (!text) continue;
|
|
3251
|
+
try {
|
|
3252
|
+
structuredContent = asRecord(JSON.parse(text));
|
|
3253
|
+
} catch {
|
|
3254
|
+
}
|
|
3255
|
+
if (Object.keys(structuredContent).length > 0) break;
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
const parsed = governedMcpToolResult(structuredContent);
|
|
3259
|
+
return parsed ? [parsed] : [];
|
|
3260
|
+
}
|
|
3221
3261
|
function parseCodexJsonl(stdout) {
|
|
3222
3262
|
let sessionId = null;
|
|
3223
3263
|
let summary = "";
|
|
@@ -3237,26 +3277,7 @@ function parseCodexJsonl(stdout) {
|
|
|
3237
3277
|
if (item.type === "agent_message") {
|
|
3238
3278
|
summary = readString(item.text) ?? summary;
|
|
3239
3279
|
}
|
|
3240
|
-
|
|
3241
|
-
const result2 = asRecord(item.result);
|
|
3242
|
-
let structuredContent = asRecord(result2.structuredContent);
|
|
3243
|
-
if (Object.keys(structuredContent).length === 0 && Array.isArray(result2.content)) {
|
|
3244
|
-
for (const part of result2.content) {
|
|
3245
|
-
const text = readString(asRecord(part).text);
|
|
3246
|
-
if (!text) continue;
|
|
3247
|
-
try {
|
|
3248
|
-
structuredContent = asRecord(JSON.parse(text));
|
|
3249
|
-
} catch {
|
|
3250
|
-
}
|
|
3251
|
-
if (Object.keys(structuredContent).length > 0) break;
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
|
-
const status = readString(structuredContent.status);
|
|
3255
|
-
if (status) {
|
|
3256
|
-
const invocationId = readString(structuredContent.invocationId);
|
|
3257
|
-
mcpToolResults.push({ ...invocationId ? { invocationId } : {}, status });
|
|
3258
|
-
}
|
|
3259
|
-
}
|
|
3280
|
+
mcpToolResults.push(...codexMcpToolResults(event));
|
|
3260
3281
|
continue;
|
|
3261
3282
|
}
|
|
3262
3283
|
if (event.type === "turn.completed") {
|
|
@@ -3612,24 +3633,8 @@ function piMcpToolResults(event) {
|
|
|
3612
3633
|
const message = asRecord(rawMessage);
|
|
3613
3634
|
if (message.role !== "toolResult") continue;
|
|
3614
3635
|
const structuredContent = asRecord(asRecord(asRecord(message.details).mcpResult).structuredContent);
|
|
3615
|
-
const
|
|
3616
|
-
if (
|
|
3617
|
-
const invocationId = readString(structuredContent.invocationId);
|
|
3618
|
-
const providerContent = asRecord(structuredContent.content);
|
|
3619
|
-
const providerStatus = readString(providerContent.status);
|
|
3620
|
-
const effectResult = asRecord(asRecord(providerContent.result).effectResult);
|
|
3621
|
-
const intentId = readString(effectResult.artifactIntentId);
|
|
3622
|
-
const manifestId = readString(effectResult.manifestId);
|
|
3623
|
-
const sourceRelativePath = readString(effectResult.sourceRelativePath);
|
|
3624
|
-
const sha256 = readString(effectResult.sha256);
|
|
3625
|
-
const byteSize = readNumber(effectResult.byteSize, 0);
|
|
3626
|
-
const artifactIntent = providerContent.status === "pending_reconcile" && intentId && manifestId && sourceRelativePath && /^[a-f0-9]{64}$/.test(sha256 ?? "") && Number.isSafeInteger(byteSize) && byteSize > 0 ? { intentId, manifestId, sourceRelativePath, sha256, byteSize } : null;
|
|
3627
|
-
results.push({
|
|
3628
|
-
...invocationId ? { invocationId } : {},
|
|
3629
|
-
status,
|
|
3630
|
-
...providerStatus ? { providerStatus } : {},
|
|
3631
|
-
...artifactIntent ? { artifactIntent } : {}
|
|
3632
|
-
});
|
|
3636
|
+
const parsed = governedMcpToolResult(structuredContent);
|
|
3637
|
+
if (parsed) results.push(parsed);
|
|
3633
3638
|
}
|
|
3634
3639
|
return results;
|
|
3635
3640
|
}
|
|
@@ -3917,6 +3922,38 @@ function prepareRuntimeArtifactUploads(cwd, mcpToolResults) {
|
|
|
3917
3922
|
return [...uploads.values()];
|
|
3918
3923
|
}
|
|
3919
3924
|
|
|
3925
|
+
// src/amaster-runtime-daemon/runtime-artifact-ingest-queue.mjs
|
|
3926
|
+
function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
3927
|
+
const handledIntentIds = /* @__PURE__ */ new Set();
|
|
3928
|
+
const artifacts = [];
|
|
3929
|
+
let error = null;
|
|
3930
|
+
let queue = Promise.resolve();
|
|
3931
|
+
return {
|
|
3932
|
+
enqueue(results) {
|
|
3933
|
+
if (error) return;
|
|
3934
|
+
const pending = results.filter((result2) => {
|
|
3935
|
+
const intentId = readString(asRecord(result2).artifactIntent?.intentId);
|
|
3936
|
+
if (!intentId || handledIntentIds.has(intentId)) return false;
|
|
3937
|
+
handledIntentIds.add(intentId);
|
|
3938
|
+
return true;
|
|
3939
|
+
});
|
|
3940
|
+
if (pending.length === 0) return;
|
|
3941
|
+
queue = queue.then(async () => artifacts.push(...await ingest(pending))).catch((caught) => {
|
|
3942
|
+
error ??= caught;
|
|
3943
|
+
onError?.(caught);
|
|
3944
|
+
});
|
|
3945
|
+
},
|
|
3946
|
+
hasHandled(intentId) {
|
|
3947
|
+
return handledIntentIds.has(intentId);
|
|
3948
|
+
},
|
|
3949
|
+
async flush() {
|
|
3950
|
+
await queue;
|
|
3951
|
+
if (error) throw error;
|
|
3952
|
+
return [...artifacts];
|
|
3953
|
+
}
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3920
3957
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
3921
3958
|
import { createHash as createHash4 } from "node:crypto";
|
|
3922
3959
|
import { existsSync as existsSync5, mkdirSync as mkdirSync4, realpathSync as realpathSync2, statSync as statSync3 } from "node:fs";
|
|
@@ -4663,7 +4700,7 @@ function readWorkspaceStatus(cwd, opts = {}) {
|
|
|
4663
4700
|
}
|
|
4664
4701
|
|
|
4665
4702
|
// src/amaster-runtime-daemon.mjs
|
|
4666
|
-
var CONNECTOR_VERSION = "0.1.0-beta.
|
|
4703
|
+
var CONNECTOR_VERSION = "0.1.0-beta.25";
|
|
4667
4704
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
4668
4705
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
4669
4706
|
var CHECKPOINT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -6160,7 +6197,7 @@ function redactProtectedText(value, protectedValues = []) {
|
|
|
6160
6197
|
}
|
|
6161
6198
|
return text;
|
|
6162
6199
|
}
|
|
6163
|
-
function createLiveOutputLogger(config, command, executorKind, protectedValues = []) {
|
|
6200
|
+
function createLiveOutputLogger(config, command, executorKind, protectedValues = [], onMcpToolResults = null) {
|
|
6164
6201
|
const buffers = { stdout: "", stderr: "" };
|
|
6165
6202
|
const displayCounts = { stdout: 0, stderr: 0, system: 0 };
|
|
6166
6203
|
const sourceCounts = { stdout: 0, stderr: 0 };
|
|
@@ -6258,7 +6295,11 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
6258
6295
|
if (executorKind === "pi" && readString(asRecord(event).type) === "session") {
|
|
6259
6296
|
executorSessionId = readString(asRecord(event).sessionId ?? asRecord(event).id) ?? executorSessionId;
|
|
6260
6297
|
}
|
|
6261
|
-
if (
|
|
6298
|
+
if (["codex", "pi"].includes(executorKind) && event) {
|
|
6299
|
+
const results = executorKind === "codex" ? codexMcpToolResults(event) : piMcpToolResults(event);
|
|
6300
|
+
liveMcpToolResults.push(...results);
|
|
6301
|
+
if (results.length > 0) onMcpToolResults?.(results);
|
|
6302
|
+
}
|
|
6262
6303
|
let entry = null;
|
|
6263
6304
|
if (event && shouldPreserveExecutorJsonlForTranscript(executorKind, event)) {
|
|
6264
6305
|
entry = {
|
|
@@ -6609,8 +6650,8 @@ function runOrphanReaper(config, options = {}) {
|
|
|
6609
6650
|
return finishSummary();
|
|
6610
6651
|
}
|
|
6611
6652
|
const refs = activeRuntimeExecutionRefs();
|
|
6612
|
-
|
|
6613
|
-
|
|
6653
|
+
let processRows = null;
|
|
6654
|
+
let processCwdsByPid = null;
|
|
6614
6655
|
for (const workdir of walkManagedWorkdirs(config.runtimeWorkspacesRoot)) {
|
|
6615
6656
|
const manifest = readWorkspaceManifest(workspaceManifestPath(workdir));
|
|
6616
6657
|
if (!manifest || manifest.managed !== true) continue;
|
|
@@ -6619,6 +6660,8 @@ function runOrphanReaper(config, options = {}) {
|
|
|
6619
6660
|
summary.protectedWorkdirCount += 1;
|
|
6620
6661
|
continue;
|
|
6621
6662
|
}
|
|
6663
|
+
processRows ??= allProcessRows();
|
|
6664
|
+
processCwdsByPid ??= allProcessCwdsByPid();
|
|
6622
6665
|
const residents = listWorkspaceResidentProcesses(workdir, null, { processRows, processCwdsByPid });
|
|
6623
6666
|
if (residents.length === 0) continue;
|
|
6624
6667
|
summary.orphanWorkdirCount += 1;
|
|
@@ -7791,7 +7834,18 @@ async function executeRunCommand(config, command) {
|
|
|
7791
7834
|
const abortController = new AbortController();
|
|
7792
7835
|
const stopActiveRunHeartbeats = startActiveRunHeartbeats(config, command, abortController);
|
|
7793
7836
|
const protectedExecutorValues = managedMcpProfile?.protectedValues ?? (managedMcpProfile ? [governedMcp.sessionToken] : []);
|
|
7794
|
-
const
|
|
7837
|
+
const runtimeArtifacts = [];
|
|
7838
|
+
const runtimeArtifactIngest = createRuntimeArtifactIngestQueue({
|
|
7839
|
+
ingest: (results) => ingestRuntimeArtifacts(config, command, cwd, results),
|
|
7840
|
+
onError: () => abortController.abort()
|
|
7841
|
+
});
|
|
7842
|
+
const liveOutputLogger = createLiveOutputLogger(
|
|
7843
|
+
config,
|
|
7844
|
+
command,
|
|
7845
|
+
executor.kind,
|
|
7846
|
+
protectedExecutorValues,
|
|
7847
|
+
(results) => runtimeArtifactIngest.enqueue(results)
|
|
7848
|
+
);
|
|
7795
7849
|
let execution;
|
|
7796
7850
|
try {
|
|
7797
7851
|
try {
|
|
@@ -7812,6 +7866,7 @@ async function executeRunCommand(config, command) {
|
|
|
7812
7866
|
} finally {
|
|
7813
7867
|
await liveOutputLogger.flush();
|
|
7814
7868
|
}
|
|
7869
|
+
runtimeArtifacts.push(...await runtimeArtifactIngest.flush());
|
|
7815
7870
|
execution.stdout = redactProtectedText(execution.stdout, protectedExecutorValues);
|
|
7816
7871
|
execution.stderr = redactProtectedText(execution.stderr, protectedExecutorValues);
|
|
7817
7872
|
patchActiveRunCommand(command, {
|
|
@@ -7868,7 +7923,15 @@ async function executeRunCommand(config, command) {
|
|
|
7868
7923
|
...Array.isArray(parsed.mcpToolResults) ? parsed.mcpToolResults.map(asRecord) : [],
|
|
7869
7924
|
...liveOutputLogger.mcpToolResults().map(asRecord)
|
|
7870
7925
|
];
|
|
7871
|
-
|
|
7926
|
+
runtimeArtifacts.push(...await ingestRuntimeArtifacts(
|
|
7927
|
+
config,
|
|
7928
|
+
command,
|
|
7929
|
+
cwd,
|
|
7930
|
+
mcpToolResults.filter((result3) => {
|
|
7931
|
+
const intentId = readString(asRecord(result3).artifactIntent?.intentId);
|
|
7932
|
+
return !intentId || !runtimeArtifactIngest.hasHandled(intentId);
|
|
7933
|
+
})
|
|
7934
|
+
));
|
|
7872
7935
|
const shouldPreserveNativeSession = managedMcpProfile && parsed.sessionId && (execution.exitCode === 0 || execution.completionOutputType === "approval_required") && !execution.timedOut && execution.cancelled !== true && !execution.spawnError && ["codex", "pi"].includes(executor.kind) && mcpToolResults.some((result3) => readString(result3.status) === "approval_required");
|
|
7873
7936
|
if (shouldPreserveNativeSession) {
|
|
7874
7937
|
try {
|
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.25";
|
|
9
9
|
|
|
10
10
|
const CAPABILITIES = [
|
|
11
11
|
"remote_registration",
|