@amaster.ai/employee-runtime-connector 0.1.1-beta.271 → 0.1.1-beta.273
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/README.md +23 -4
- package/dist/amaster-runtime-daemon.mjs +218 -454
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,12 +89,14 @@ Pi 0.80.10's internal compaction summarizer calls the provider outside `before_p
|
|
|
89
89
|
|
|
90
90
|
## WorkBuddy Host (CodeBuddy engine)
|
|
91
91
|
|
|
92
|
-
The optional `codebuddy` executor
|
|
93
|
-
Codex, while
|
|
92
|
+
The optional `codebuddy` executor participates in the same governed task lifecycle
|
|
93
|
+
as Codex, while its local execution surface remains deliberately narrower than both
|
|
94
|
+
Codex and the WorkBuddy desktop product.
|
|
94
95
|
It does not expose WorkBuddy experts, projects, Office integrations, marketplace
|
|
95
96
|
connectors, or Pi's `final_model_context_attestation_v1`. The connector creates a
|
|
96
97
|
private per-run CodeBuddy home, supplies one strict MirrorX MCP definition, uses an
|
|
97
|
-
exact
|
|
98
|
+
exact tool allowlist, exposes the governed namespace directly with
|
|
99
|
+
`NoDefer(mcp__amaster__*)`, and preserves only an authority-bound native session
|
|
98
100
|
rollout. It never inherits the user's ordinary `.codebuddy` settings, memory,
|
|
99
101
|
projects, MCP servers, workflows, or marketplace state. When no dedicated provider
|
|
100
102
|
credential is configured, it reuses only the current OS user's WorkBuddy desktop
|
|
@@ -106,10 +108,27 @@ than authentication inputs and are not copied; any logout-marker directory entry
|
|
|
106
108
|
including a dangling symlink, makes the desktop session unavailable. CodeBuddy can
|
|
107
109
|
mutate only the private snapshot.
|
|
108
110
|
|
|
111
|
+
Managed CodeBuddy runs expose the native file tools plus `mcp__amaster__*`; they do
|
|
112
|
+
not expose Bash, WebFetch, or WebSearch. CodeBuddy 2.137.1's Bash sandbox cannot
|
|
113
|
+
prevent a command from connecting to an existing loopback service, so allowing Bash
|
|
114
|
+
would leave a path around Governed MCP even with unsandboxed execution disabled.
|
|
115
|
+
Consequently these runs can inspect and edit a workspace and perform governed
|
|
116
|
+
MirrorX actions, but they cannot run tests, builds, package managers, or arbitrary
|
|
117
|
+
shell commands. This is an explicit capability gap rather than claimed Pi/Codex
|
|
118
|
+
parity. Governed result authority remains correlated until a structured receipt is
|
|
119
|
+
actually parsed; an outer transport `status` cannot shadow a nested
|
|
120
|
+
`structuredContent` receipt, and more than 256 unresolved governed calls fails the
|
|
121
|
+
run instead of evicting an unmatched call id. The managed profile also resolves the
|
|
122
|
+
workspace once and uses that same canonical directory for CodeBuddy trust and child
|
|
123
|
+
process execution; an unavailable cwd fails with a stable managed-profile error.
|
|
124
|
+
|
|
109
125
|
This executor is off by default. Enable discovery with
|
|
110
126
|
`AMASTER_ENABLE_CODEBUDDY_EXECUTOR=true`. `AMASTER_CODEBUDDY_COMMAND` can select an
|
|
111
127
|
explicit CLI; on macOS the gated discovery path can also find the CLI bundled in
|
|
112
|
-
`/Applications/WorkBuddy.app`.
|
|
128
|
+
`/Applications/WorkBuddy.app`. CodeBuddy `2.137.1` is the minimum supported version
|
|
129
|
+
because that is the oldest release on which the native `NoDefer(mcp__amaster__*)`
|
|
130
|
+
tool surface has been verified end to end; older versions fail readiness. The
|
|
131
|
+
Server task-session snapshot owns the model for
|
|
113
132
|
current commands; `AMASTER_CODEBUDDY_MODEL` is only a compatibility fallback for
|
|
114
133
|
older commands without that snapshot. Authentication resolves in two fail-closed
|
|
115
134
|
modes: exactly one explicitly configured `CODEBUDDY_API_KEY` or
|
|
@@ -5033,6 +5033,7 @@ var companyColdStartObligationReadSchema = external_exports.object({
|
|
|
5033
5033
|
kind: external_exports.enum(["agent", "board", "external"]),
|
|
5034
5034
|
id: external_exports.string().trim().min(1).max(200)
|
|
5035
5035
|
}).strict().nullable(),
|
|
5036
|
+
ownerDisplayName: external_exports.string().trim().min(1).max(200).nullable(),
|
|
5036
5037
|
reviewAt: external_exports.string().datetime({ offset: true }).nullable(),
|
|
5037
5038
|
noProgressReviewCount: external_exports.number().int().nonnegative(),
|
|
5038
5039
|
dueState: external_exports.enum(["scheduled", "due", "overdue", "attention", "stalled"])
|
|
@@ -5076,13 +5077,25 @@ var companyColdStartReadModelBaseSchema = external_exports.object({
|
|
|
5076
5077
|
workset: companyColdStartWorksetReadModelSchema.nullable(),
|
|
5077
5078
|
tasks: external_exports.array(companyColdStartTaskReadSchema),
|
|
5078
5079
|
factCoverage: companyColdStartFactCoverageReadSchema,
|
|
5080
|
+
factOwnerDisplayNames: external_exports.record(
|
|
5081
|
+
companyColdStartFactSlotSchema,
|
|
5082
|
+
external_exports.string().trim().min(1).max(200)
|
|
5083
|
+
),
|
|
5079
5084
|
missingFactSlots: external_exports.array(companyColdStartFactSlotSchema),
|
|
5080
5085
|
taskLocalAttentionIds: external_exports.array(external_exports.string().uuid()),
|
|
5081
5086
|
wikiProjectionAttentionCount: external_exports.number().int().nonnegative()
|
|
5082
5087
|
}).strict(),
|
|
5083
5088
|
operations: external_exports.object({
|
|
5084
5089
|
currentObligationCount: external_exports.number().int().nonnegative(),
|
|
5090
|
+
currentObligationCountByGoal: external_exports.record(
|
|
5091
|
+
external_exports.string().uuid(),
|
|
5092
|
+
external_exports.number().int().nonnegative()
|
|
5093
|
+
).optional(),
|
|
5085
5094
|
actionRequiredCount: external_exports.number().int().nonnegative(),
|
|
5095
|
+
actionRequiredCountByGoal: external_exports.record(
|
|
5096
|
+
external_exports.string().uuid(),
|
|
5097
|
+
external_exports.number().int().nonnegative()
|
|
5098
|
+
).optional(),
|
|
5086
5099
|
goalGapRefs: external_exports.array(external_exports.string().trim().min(1).max(200)),
|
|
5087
5100
|
obligations: external_exports.array(companyColdStartObligationReadSchema)
|
|
5088
5101
|
}).strict()
|
|
@@ -8973,6 +8986,7 @@ var recordGoalGapReadinessSchema = external_exports.object({
|
|
|
8973
8986
|
}).strict();
|
|
8974
8987
|
var boardScheduleGoalGapFollowUpSchema = external_exports.object({
|
|
8975
8988
|
expectedRevision: external_exports.number().int().positive(),
|
|
8989
|
+
ownerAgentId: external_exports.string().uuid(),
|
|
8976
8990
|
reviewAt: external_exports.string().datetime({ offset: true })
|
|
8977
8991
|
}).strict();
|
|
8978
8992
|
var goalGapReadinessStateSchema = external_exports.object({
|
|
@@ -17744,6 +17758,7 @@ function managedPiProviderToolContract(tools) {
|
|
|
17744
17758
|
}
|
|
17745
17759
|
const entries = definitions.map(({ name, schemaHash }) => ({ name, schemaHash }));
|
|
17746
17760
|
return {
|
|
17761
|
+
definitions,
|
|
17747
17762
|
entries,
|
|
17748
17763
|
effectiveToolSchemaBytes: definitions.reduce((total, entry) => total + entry.schemaBytes, 0),
|
|
17749
17764
|
effectiveToolSetSha256: sha256(stableJson(entries)),
|
|
@@ -18339,8 +18354,8 @@ function observedPiFinalContextToolContract(input) {
|
|
|
18339
18354
|
const expectedNames = Array.isArray(input?.toolNames) ? [...input.toolNames] : [];
|
|
18340
18355
|
if (expectedNames.length === 0 || expectedNames.some((name) => typeof name !== "string" || !name) || new Set(expectedNames).size !== expectedNames.length) fail2("observed_tool_contract_invalid");
|
|
18341
18356
|
expectedNames.sort();
|
|
18342
|
-
const
|
|
18343
|
-
const observed = Array.isArray(
|
|
18357
|
+
const finalRequiredTools = input?.profileAttestation?.finalRequiredTools;
|
|
18358
|
+
const observed = Array.isArray(finalRequiredTools) ? finalRequiredTools.filter((entry) => expectedNames.includes(entry?.name)).map((entry) => ({
|
|
18344
18359
|
name: entry.name,
|
|
18345
18360
|
schemaHash: entry.schemaHash,
|
|
18346
18361
|
schemaBytes: entry.schemaBytes
|
|
@@ -19361,7 +19376,7 @@ var KNOWN_EXECUTORS = [
|
|
|
19361
19376
|
["openclaw", "openclaw"]
|
|
19362
19377
|
];
|
|
19363
19378
|
var MACOS_WORKBUDDY_CODEBUDDY_COMMAND = "/Applications/WorkBuddy.app/Contents/Resources/app.asar.unpacked/cli/bin/codebuddy";
|
|
19364
|
-
var MINIMUM_CODEBUDDY_VERSION = "2.
|
|
19379
|
+
var MINIMUM_CODEBUDDY_VERSION = "2.137.1";
|
|
19365
19380
|
var MINIMUM_CODEBUDDY_VERSION_TUPLE = MINIMUM_CODEBUDDY_VERSION.split(".").map(Number);
|
|
19366
19381
|
var REQUIRED_CODEBUDDY_FLAGS = [
|
|
19367
19382
|
"--output-format",
|
|
@@ -20338,21 +20353,22 @@ var CODEBUDDY_DESKTOP_AUTH_SOURCE = "workbuddy_desktop_session";
|
|
|
20338
20353
|
var CODEBUDDY_WORKBUDDY_AUTH_FILE = "workbuddy-desktop.info";
|
|
20339
20354
|
var MAX_CODEBUDDY_DESKTOP_AUTH_BYTES = 4 * 1024 * 1024;
|
|
20340
20355
|
var CODEBUDDY_NATIVE_TOOLS = [
|
|
20341
|
-
"Bash",
|
|
20342
20356
|
"Edit",
|
|
20343
20357
|
"Read",
|
|
20344
20358
|
"Write",
|
|
20345
20359
|
"Glob",
|
|
20346
20360
|
"Grep",
|
|
20347
|
-
"LS"
|
|
20348
|
-
"WebFetch",
|
|
20349
|
-
"WebSearch"
|
|
20361
|
+
"LS"
|
|
20350
20362
|
];
|
|
20351
|
-
var
|
|
20363
|
+
var CODEBUDDY_MCP_TOOL_GLOB = `mcp__${SUPPORTED_SERVER_NAME2}__*`;
|
|
20364
|
+
var CODEBUDDY_TOOL_SURFACE = [
|
|
20352
20365
|
...CODEBUDDY_NATIVE_TOOLS,
|
|
20353
|
-
|
|
20354
|
-
|
|
20366
|
+
`NoDefer(${CODEBUDDY_MCP_TOOL_GLOB})`
|
|
20367
|
+
];
|
|
20368
|
+
var CODEBUDDY_ALLOWED_TOOLS = [
|
|
20369
|
+
CODEBUDDY_MCP_TOOL_GLOB
|
|
20355
20370
|
];
|
|
20371
|
+
var CODEBUDDY_DENIED_TOOLS = ["WebFetch", "WebSearch"];
|
|
20356
20372
|
var REQUIRED_AUTHORITY_HEADERS2 = [
|
|
20357
20373
|
"x-amaster-company-id",
|
|
20358
20374
|
"x-amaster-agent-id",
|
|
@@ -20811,10 +20827,27 @@ function validateAuthority2(input) {
|
|
|
20811
20827
|
function attestCli(executorCommand, env, cwd) {
|
|
20812
20828
|
return attestCodebuddyCommand(executorCommand, env, cwd).executorVersion;
|
|
20813
20829
|
}
|
|
20830
|
+
function canonicalCodebuddyCwd(value) {
|
|
20831
|
+
const requestedCwd = resolve6(nonEmpty2(value, "cwd"));
|
|
20832
|
+
try {
|
|
20833
|
+
const canonicalCwd = realpathSync3(requestedCwd);
|
|
20834
|
+
if (!statSync5(canonicalCwd).isDirectory()) {
|
|
20835
|
+
throw new Error("cwd is not a directory");
|
|
20836
|
+
}
|
|
20837
|
+
return canonicalCwd;
|
|
20838
|
+
} catch (cause) {
|
|
20839
|
+
throw new Error(
|
|
20840
|
+
"codebuddy_managed_mcp_cwd_invalid: cwd must resolve to an existing directory",
|
|
20841
|
+
{ cause }
|
|
20842
|
+
);
|
|
20843
|
+
}
|
|
20844
|
+
}
|
|
20814
20845
|
function prepareManagedCodebuddyMcpProfile(input) {
|
|
20815
20846
|
const authority = validateAuthority2(input);
|
|
20816
20847
|
const runDir = resolve6(nonEmpty2(input.runDir, "runDir"));
|
|
20817
20848
|
const executorHome = resolve6(nonEmpty2(input.executorHome, "executorHome"));
|
|
20849
|
+
const cwd = canonicalCodebuddyCwd(input.cwd);
|
|
20850
|
+
const bashSandboxEnabled = ["darwin", "linux"].includes(platform2());
|
|
20818
20851
|
if (!within3(executorHome, join6(runDir, "executors"))) {
|
|
20819
20852
|
throw new Error("codebuddy_managed_mcp_owner_mismatch: executorHome is outside the managed run");
|
|
20820
20853
|
}
|
|
@@ -20856,9 +20889,25 @@ function prepareManagedCodebuddyMcpProfile(input) {
|
|
|
20856
20889
|
}, null, 2)}
|
|
20857
20890
|
`);
|
|
20858
20891
|
privateFile(settingsPath, `${JSON.stringify({
|
|
20892
|
+
trustedDirectories: [cwd],
|
|
20893
|
+
sandbox: {
|
|
20894
|
+
enabled: bashSandboxEnabled,
|
|
20895
|
+
autoAllowBashIfSandboxed: false,
|
|
20896
|
+
network: {
|
|
20897
|
+
allowedDomains: [],
|
|
20898
|
+
deniedDomains: [],
|
|
20899
|
+
allowLocalBinding: false,
|
|
20900
|
+
allowUnixSockets: [],
|
|
20901
|
+
allowAllUnixSockets: false
|
|
20902
|
+
},
|
|
20903
|
+
excludedCommands: [],
|
|
20904
|
+
allowUnsandboxedCommands: false
|
|
20905
|
+
},
|
|
20859
20906
|
permissions: {
|
|
20860
20907
|
allow: CODEBUDDY_ALLOWED_TOOLS,
|
|
20861
|
-
deny:
|
|
20908
|
+
deny: CODEBUDDY_DENIED_TOOLS,
|
|
20909
|
+
defaultMode: "acceptEdits",
|
|
20910
|
+
disableBypassPermissionsMode: "disable"
|
|
20862
20911
|
}
|
|
20863
20912
|
}, null, 2)}
|
|
20864
20913
|
`);
|
|
@@ -20883,7 +20932,7 @@ function prepareManagedCodebuddyMcpProfile(input) {
|
|
|
20883
20932
|
restoredNativeSession,
|
|
20884
20933
|
nativeSessionRestoreSkippedReason
|
|
20885
20934
|
} = resolveManagedCodebuddySessionRollout(input, configDir, runDir, executorHome, profileAuthority);
|
|
20886
|
-
const executorVersion = attestCli(nonEmpty2(input.executorCommand, "executorCommand"), env,
|
|
20935
|
+
const executorVersion = attestCli(nonEmpty2(input.executorCommand, "executorCommand"), env, cwd);
|
|
20887
20936
|
const cliArgs = [
|
|
20888
20937
|
"--setting-sources",
|
|
20889
20938
|
"",
|
|
@@ -20893,17 +20942,20 @@ function prepareManagedCodebuddyMcpProfile(input) {
|
|
|
20893
20942
|
"--mcp-config",
|
|
20894
20943
|
mcpConfigPath,
|
|
20895
20944
|
"--tools",
|
|
20896
|
-
|
|
20945
|
+
CODEBUDDY_TOOL_SURFACE.join(","),
|
|
20897
20946
|
"--allowedTools",
|
|
20898
20947
|
CODEBUDDY_ALLOWED_TOOLS.join(","),
|
|
20899
20948
|
"--permission-mode",
|
|
20900
|
-
"
|
|
20949
|
+
"acceptEdits"
|
|
20901
20950
|
];
|
|
20902
20951
|
const attestationFacts = {
|
|
20903
20952
|
connectorVersion: nonEmpty2(input.connectorVersion, "connectorVersion"),
|
|
20904
20953
|
executorKind: "codebuddy",
|
|
20905
20954
|
executorVersion,
|
|
20906
20955
|
configMode: "isolated_config_strict_http_headers",
|
|
20956
|
+
mcpExposureMode: "native_nodefer",
|
|
20957
|
+
bashIsolation: "not_exposed",
|
|
20958
|
+
networkAccessMode: "governed_mcp_only",
|
|
20907
20959
|
namespace: SUPPORTED_SERVER_NAME2,
|
|
20908
20960
|
schemaVersion: SUPPORTED_SCHEMA_VERSION2,
|
|
20909
20961
|
platform: platform2(),
|
|
@@ -20914,6 +20966,7 @@ function prepareManagedCodebuddyMcpProfile(input) {
|
|
|
20914
20966
|
};
|
|
20915
20967
|
return {
|
|
20916
20968
|
profileRoot,
|
|
20969
|
+
cwd,
|
|
20917
20970
|
markerPath,
|
|
20918
20971
|
mcpConfigPath,
|
|
20919
20972
|
settingsPath,
|
|
@@ -21815,7 +21868,7 @@ function piMcpAdapterServerConfigIdentity(definition, adapterVersion) {
|
|
|
21815
21868
|
import { createHash as createHash6 } from "node:crypto";
|
|
21816
21869
|
var MANAGED_PI_EFFECTIVE_TOOLS_ATTESTOR_FILENAME = "amaster-effective-tools-attestor.js";
|
|
21817
21870
|
var MANAGED_PI_EFFECTIVE_TOOLS_SCHEMA_VERSION = "amaster.pi-effective-tools.v1";
|
|
21818
|
-
function
|
|
21871
|
+
function normalizedPiToolSchema(value, adapterNormalized) {
|
|
21819
21872
|
const schema = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21820
21873
|
if (!adapterNormalized) return schema;
|
|
21821
21874
|
const { $schema: _schema, additionalProperties: _additionalProperties, ...normalized } = schema;
|
|
@@ -21831,7 +21884,7 @@ function stablePiJson(value) {
|
|
|
21831
21884
|
return `{${keys.map((key) => `${JSON.stringify(key)}:${stablePiJson(value[key])}`).join(",")}}`;
|
|
21832
21885
|
}
|
|
21833
21886
|
function stablePiToolSchemaHash(schema, options = {}) {
|
|
21834
|
-
return createHash6("sha256").update(stablePiJson(
|
|
21887
|
+
return createHash6("sha256").update(stablePiJson(normalizedPiToolSchema(schema, options.adapterNormalized === true))).digest("hex");
|
|
21835
21888
|
}
|
|
21836
21889
|
function stablePiEffectiveToolSetHash(entries) {
|
|
21837
21890
|
const normalized = entries.map((entry) => ({ name: entry.name, schemaHash: entry.schemaHash ?? entry.effectiveSchemaHash })).sort((left, right) => left.name.localeCompare(right.name));
|
|
@@ -22697,17 +22750,9 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
22697
22750
|
const SESSION_ROLLOUT_MARKER3 = ".amaster-pi-session-rollout.json";
|
|
22698
22751
|
const DEFAULT_SESSION_ROLLOUT_TTL_MS3 = 24 * 60 * 60 * 1e3;
|
|
22699
22752
|
const PI_VERSION_ATTESTATION_TIMEOUT_MS = 3e4;
|
|
22700
|
-
const PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS = 6e4;
|
|
22701
|
-
const PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS = 3e4;
|
|
22702
|
-
const PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS = PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS + PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS;
|
|
22703
|
-
const PI_EFFECTIVE_TOOLS_SOFT_SLOW_MS = 3e4;
|
|
22704
|
-
const PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION = 1;
|
|
22705
|
-
const PI_EFFECTIVE_TOOLS_CIRCUIT_FAILURE_THRESHOLD = Number.isInteger(options.probeCircuitFailureThreshold) && options.probeCircuitFailureThreshold > 0 ? options.probeCircuitFailureThreshold : 3;
|
|
22706
|
-
const PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS = Number.isFinite(options.probeCircuitCooldownMs) && options.probeCircuitCooldownMs > 0 ? Math.floor(options.probeCircuitCooldownMs) : 6e4;
|
|
22707
22753
|
const PI_ATTESTATION_MAX_ATTEMPTS = 2;
|
|
22708
22754
|
const PI_ATTESTATION_RECENT_LIVE_TTL_MS = Number.isFinite(options.recentLiveTtlMs) && options.recentLiveTtlMs > 0 ? options.recentLiveTtlMs : 30 * 60 * 1e3;
|
|
22709
22755
|
const recentLivePiVersionProbes = /* @__PURE__ */ new Map();
|
|
22710
|
-
const effectiveToolsProbeCircuits = /* @__PURE__ */ new Map();
|
|
22711
22756
|
function record8(value) {
|
|
22712
22757
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
22713
22758
|
}
|
|
@@ -22879,165 +22924,7 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
22879
22924
|
}
|
|
22880
22925
|
return hash.digest("hex");
|
|
22881
22926
|
}
|
|
22882
|
-
function
|
|
22883
|
-
const source = resolve8(sourcePath);
|
|
22884
|
-
const sourceStat = lstatSync8(source);
|
|
22885
|
-
if (!sourceStat.isDirectory() || sourceStat.isSymbolicLink()) {
|
|
22886
|
-
throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${source}`);
|
|
22887
|
-
}
|
|
22888
|
-
mkdirSync4(targetPath, { recursive: true, mode: 448 });
|
|
22889
|
-
chmodSync6(targetPath, 448);
|
|
22890
|
-
for (const entry of readdirSync4(source, { withFileTypes: true })) {
|
|
22891
|
-
const from = join9(source, entry.name);
|
|
22892
|
-
const to = join9(targetPath, entry.name);
|
|
22893
|
-
if (entry.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${from}`);
|
|
22894
|
-
if (entry.isDirectory()) {
|
|
22895
|
-
copyTrustedTree(from, to);
|
|
22896
|
-
continue;
|
|
22897
|
-
}
|
|
22898
|
-
if (!entry.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${from}`);
|
|
22899
|
-
copyFileSync(from, to, 0);
|
|
22900
|
-
chmodSync6(to, 384 | lstatSync8(from).mode & 73);
|
|
22901
|
-
}
|
|
22902
|
-
}
|
|
22903
|
-
function makeTrustedTreeReadOnly(rootPath) {
|
|
22904
|
-
const root = resolve8(rootPath);
|
|
22905
|
-
const pending = [root];
|
|
22906
|
-
const directories = [];
|
|
22907
|
-
while (pending.length > 0) {
|
|
22908
|
-
const current = pending.pop();
|
|
22909
|
-
const currentStat = lstatSync8(current);
|
|
22910
|
-
if (currentStat.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22911
|
-
if (currentStat.isDirectory()) {
|
|
22912
|
-
directories.push(current);
|
|
22913
|
-
for (const entry of readdirSync4(current)) pending.push(join9(current, entry));
|
|
22914
|
-
continue;
|
|
22915
|
-
}
|
|
22916
|
-
if (!currentStat.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22917
|
-
chmodSync6(current, 256 | currentStat.mode & 73);
|
|
22918
|
-
}
|
|
22919
|
-
for (const directory of directories.reverse()) chmodSync6(directory, 320);
|
|
22920
|
-
}
|
|
22921
|
-
function makeTrustedTreeWritable(rootPath) {
|
|
22922
|
-
const pending = [resolve8(rootPath)];
|
|
22923
|
-
while (pending.length > 0) {
|
|
22924
|
-
const current = pending.pop();
|
|
22925
|
-
const currentStat = lstatSync8(current);
|
|
22926
|
-
if (currentStat.isSymbolicLink()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22927
|
-
if (currentStat.isDirectory()) {
|
|
22928
|
-
chmodSync6(current, 448);
|
|
22929
|
-
for (const entry of readdirSync4(current)) pending.push(join9(current, entry));
|
|
22930
|
-
continue;
|
|
22931
|
-
}
|
|
22932
|
-
if (!currentStat.isFile()) throw new Error(`pi_managed_mcp_bootstrap_cache_unsafe: ${current}`);
|
|
22933
|
-
chmodSync6(current, 384 | currentStat.mode & 73);
|
|
22934
|
-
}
|
|
22935
|
-
}
|
|
22936
|
-
function piLoaderIdentity(executorPath) {
|
|
22937
|
-
let cursor = dirname6(realpathSync6(executorPath));
|
|
22938
|
-
for (let depth = 0; depth < 4; depth += 1) {
|
|
22939
|
-
const packagePath = join9(cursor, "package.json");
|
|
22940
|
-
const loaderPath = join9(cursor, "dist", "core", "extensions", "loader.js");
|
|
22941
|
-
if (existsSync8(packagePath) && existsSync8(loaderPath)) {
|
|
22942
|
-
const packageJson = JSON.parse(readFileSync9(packagePath, "utf8"));
|
|
22943
|
-
return sha2565(stablePiJson({
|
|
22944
|
-
name: packageJson.name,
|
|
22945
|
-
version: packageJson.version,
|
|
22946
|
-
loaderSha256: sha2565(readFileSync9(loaderPath))
|
|
22947
|
-
}));
|
|
22948
|
-
}
|
|
22949
|
-
cursor = dirname6(cursor);
|
|
22950
|
-
}
|
|
22951
|
-
return sha2565(readFileSync9(realpathSync6(executorPath)));
|
|
22952
|
-
}
|
|
22953
|
-
function effectiveToolsBootstrapKey(input, sharedRuntime, executorCommand) {
|
|
22954
|
-
const adapterRoot = sharedRuntime.adapterRoot ? resolve8(nonEmpty3(sharedRuntime.adapterRoot, "sharedRuntime.adapterRoot")) : join9(sharedRuntime.home, "npm", "node_modules", "pi-mcp-adapter");
|
|
22955
|
-
const resolvedExecutorCommand = resolvePiExecutablePath(executorCommand, input.baseEnv);
|
|
22956
|
-
return sha2565(stablePiJson({
|
|
22957
|
-
schemaVersion: PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION,
|
|
22958
|
-
connectorVersion: nonEmpty3(input.connectorVersion, "connectorVersion"),
|
|
22959
|
-
executorIdentity: piExecutableIdentity(resolvedExecutorCommand),
|
|
22960
|
-
loaderIdentity: piLoaderIdentity(resolvedExecutorCommand),
|
|
22961
|
-
nodeVersion: process.version,
|
|
22962
|
-
nodeModulesAbi: process.versions.modules,
|
|
22963
|
-
platform: platform3(),
|
|
22964
|
-
arch: arch3(),
|
|
22965
|
-
// npm may install dependency symlinks under the adapter's nested
|
|
22966
|
-
// node_modules. They resolve at runtime and are not Jiti-owned compiled
|
|
22967
|
-
// source; hash every package-owned adapter file while excluding that
|
|
22968
|
-
// dependency graph so ordinary npm links do not make the cache unusable.
|
|
22969
|
-
adapterTreeSha256: trustedTreeDigest(adapterRoot, { ignoredRootEntries: ["node_modules"] }),
|
|
22970
|
-
attestorSourceSha256: sha2565(managedPiEffectiveToolsAttestorExtensionSource())
|
|
22971
|
-
}));
|
|
22972
|
-
}
|
|
22973
|
-
function prepareEffectiveToolsBootstrapCache(input, sharedRuntime, executorCommand, tmpPath) {
|
|
22974
|
-
const cacheRoot = resolve8(nonEmpty3(input.runtimeCacheRoot ?? join9(dirname6(input.runDir), ".runtime-cache"), "runtimeCacheRoot"));
|
|
22975
|
-
const bootstrapRoot = join9(cacheRoot, "pi-effective-tools-jiti-v1");
|
|
22976
|
-
mkdirSync4(bootstrapRoot, { recursive: true, mode: 448 });
|
|
22977
|
-
const bootstrapRootStat = lstatSync8(bootstrapRoot);
|
|
22978
|
-
if (!bootstrapRootStat.isDirectory() || bootstrapRootStat.isSymbolicLink()) {
|
|
22979
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: root");
|
|
22980
|
-
}
|
|
22981
|
-
const key = effectiveToolsBootstrapKey(input, sharedRuntime, executorCommand);
|
|
22982
|
-
const entryPath = join9(bootstrapRoot, key);
|
|
22983
|
-
const markerPath = join9(entryPath, "manifest.json");
|
|
22984
|
-
const sourceCachePath = join9(entryPath, "jiti");
|
|
22985
|
-
const runCachePath = join9(tmpPath, "jiti");
|
|
22986
|
-
let status = "miss";
|
|
22987
|
-
if (existsSync8(entryPath)) {
|
|
22988
|
-
try {
|
|
22989
|
-
const entryStat = lstatSync8(entryPath);
|
|
22990
|
-
const markerStat = lstatSync8(markerPath);
|
|
22991
|
-
const marker = JSON.parse(readFileSync9(markerPath, "utf8"));
|
|
22992
|
-
if (!entryStat.isDirectory() || entryStat.isSymbolicLink() || !markerStat.isFile() || markerStat.isSymbolicLink() || marker.schemaVersion !== PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION || marker.key !== key || marker.treeSha256 !== trustedTreeDigest(sourceCachePath)) throw new Error("bootstrap marker mismatch");
|
|
22993
|
-
copyTrustedTree(sourceCachePath, runCachePath);
|
|
22994
|
-
status = "hit";
|
|
22995
|
-
} catch {
|
|
22996
|
-
const resolvedEntry = resolve8(entryPath);
|
|
22997
|
-
if (!within4(resolvedEntry, bootstrapRoot) || resolvedEntry === bootstrapRoot) {
|
|
22998
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: entry");
|
|
22999
|
-
}
|
|
23000
|
-
makeTrustedTreeWritable(resolvedEntry);
|
|
23001
|
-
rmSync5(resolvedEntry, { recursive: true, force: true });
|
|
23002
|
-
status = "invalidated";
|
|
23003
|
-
}
|
|
23004
|
-
}
|
|
23005
|
-
return { bootstrapRoot, entryPath, key, runCachePath, status };
|
|
23006
|
-
}
|
|
23007
|
-
function publishEffectiveToolsBootstrapCache(cache) {
|
|
23008
|
-
if (cache.status === "hit") return "hit";
|
|
23009
|
-
if (!existsSync8(cache.runCachePath)) return `${cache.status}_unavailable`;
|
|
23010
|
-
const runCacheStat = lstatSync8(cache.runCachePath);
|
|
23011
|
-
if (!runCacheStat.isDirectory() || runCacheStat.isSymbolicLink()) {
|
|
23012
|
-
throw new Error("pi_managed_mcp_bootstrap_cache_unsafe: run cache");
|
|
23013
|
-
}
|
|
23014
|
-
if (existsSync8(cache.entryPath)) return "hit_raced";
|
|
23015
|
-
const stagingPath = `${cache.entryPath}.tmp-${process.pid}-${currentTimeMs()}`;
|
|
23016
|
-
try {
|
|
23017
|
-
mkdirSync4(stagingPath, { mode: 448 });
|
|
23018
|
-
const stagingCachePath = join9(stagingPath, "jiti");
|
|
23019
|
-
copyTrustedTree(cache.runCachePath, stagingCachePath);
|
|
23020
|
-
writePrivateFile2(join9(stagingPath, "manifest.json"), `${JSON.stringify({
|
|
23021
|
-
schemaVersion: PI_EFFECTIVE_TOOLS_BOOTSTRAP_SCHEMA_VERSION,
|
|
23022
|
-
key: cache.key,
|
|
23023
|
-
treeSha256: trustedTreeDigest(stagingCachePath)
|
|
23024
|
-
})}
|
|
23025
|
-
`);
|
|
23026
|
-
try {
|
|
23027
|
-
renameSync4(stagingPath, cache.entryPath);
|
|
23028
|
-
makeTrustedTreeReadOnly(cache.entryPath);
|
|
23029
|
-
} catch (error) {
|
|
23030
|
-
if (error?.code !== "EEXIST" && error?.code !== "ENOTEMPTY") throw error;
|
|
23031
|
-
}
|
|
23032
|
-
} finally {
|
|
23033
|
-
if (existsSync8(stagingPath)) {
|
|
23034
|
-
makeTrustedTreeWritable(stagingPath);
|
|
23035
|
-
rmSync5(stagingPath, { recursive: true, force: true });
|
|
23036
|
-
}
|
|
23037
|
-
}
|
|
23038
|
-
return existsSync8(cache.entryPath) ? `${cache.status}_published` : `${cache.status}_unavailable`;
|
|
23039
|
-
}
|
|
23040
|
-
function writeEffectiveToolsProbePhase(phasePath, phase, attempt) {
|
|
22927
|
+
function writeEffectiveToolsPhase(phasePath, phase, attempt) {
|
|
23041
22928
|
let history = [];
|
|
23042
22929
|
if (existsSync8(phasePath)) {
|
|
23043
22930
|
try {
|
|
@@ -23919,189 +23806,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
23919
23806
|
liveProbeAgeMs
|
|
23920
23807
|
};
|
|
23921
23808
|
}
|
|
23922
|
-
function inspectEffectiveToolsProbeReceipt(receiptPath, phasePath) {
|
|
23923
|
-
let phase = "missing";
|
|
23924
|
-
let history = [];
|
|
23925
|
-
if (existsSync8(phasePath)) {
|
|
23926
|
-
try {
|
|
23927
|
-
const phaseState = JSON.parse(readFileSync9(phasePath, "utf8"));
|
|
23928
|
-
phase = typeof phaseState.phase === "string" ? phaseState.phase : "present";
|
|
23929
|
-
history = Array.isArray(phaseState.history) ? phaseState.history : [];
|
|
23930
|
-
} catch {
|
|
23931
|
-
phase = "invalid";
|
|
23932
|
-
}
|
|
23933
|
-
}
|
|
23934
|
-
if (!existsSync8(receiptPath)) return { phase, history, receipt: null };
|
|
23935
|
-
try {
|
|
23936
|
-
const receipt = JSON.parse(readFileSync9(receiptPath, "utf8"));
|
|
23937
|
-
const receiptPhase = receipt?.status === "attested" || receipt?.status === "rejected" ? receipt.status : phase === "missing" ? "present" : phase;
|
|
23938
|
-
return { phase: receiptPhase, history, receipt };
|
|
23939
|
-
} catch {
|
|
23940
|
-
return { phase: "invalid", history, receipt: null };
|
|
23941
|
-
}
|
|
23942
|
-
}
|
|
23943
|
-
function effectiveToolsProbePhaseDurations(history, attempt) {
|
|
23944
|
-
const entries = history.filter((entry) => entry?.attempt === attempt && typeof entry.phase === "string" && Number.isFinite(entry.atMs)).sort((left, right) => left.atMs - right.atMs);
|
|
23945
|
-
const at = (phase) => entries.find((entry) => entry.phase === phase)?.atMs;
|
|
23946
|
-
const terminalAt = at("attested") ?? at("rejected");
|
|
23947
|
-
const spawnedAt = at("spawned");
|
|
23948
|
-
const loaderReadyAt = at("loader_ready");
|
|
23949
|
-
const sessionStartAt = at("session_start");
|
|
23950
|
-
return {
|
|
23951
|
-
...Number.isFinite(spawnedAt) && Number.isFinite(loaderReadyAt) ? { spawnedToLoaderReadyMs: Math.max(0, loaderReadyAt - spawnedAt) } : {},
|
|
23952
|
-
...Number.isFinite(loaderReadyAt) && Number.isFinite(sessionStartAt) ? { loaderReadyToSessionStartMs: Math.max(0, sessionStartAt - loaderReadyAt) } : {},
|
|
23953
|
-
...Number.isFinite(sessionStartAt) && Number.isFinite(terminalAt) ? { sessionStartToTerminalMs: Math.max(0, terminalAt - sessionStartAt) } : {}
|
|
23954
|
-
};
|
|
23955
|
-
}
|
|
23956
|
-
function attestDirectPiTools(executorCommand, env, input, spawnIdentity = null, circuitKey = null) {
|
|
23957
|
-
const circuit = circuitKey ? effectiveToolsProbeCircuits.get(circuitKey) : null;
|
|
23958
|
-
if (circuit?.open === true) {
|
|
23959
|
-
const retryAfterMs = Math.max(0, circuit.retryAtMs - currentTimeMs());
|
|
23960
|
-
if (retryAfterMs > 0) {
|
|
23961
|
-
const error = new Error(
|
|
23962
|
-
`pi_managed_mcp_probe_circuit_open: connector generation probe circuit is open failures=${circuit.failures} lastPhase=${circuit.lastPhase} retryAfterMs=${retryAfterMs}`
|
|
23963
|
-
);
|
|
23964
|
-
error.code = "pi_managed_mcp_probe_circuit_open";
|
|
23965
|
-
error.retryAfterMs = retryAfterMs;
|
|
23966
|
-
throw error;
|
|
23967
|
-
}
|
|
23968
|
-
effectiveToolsProbeCircuits.set(circuitKey, { ...circuit, open: false, halfOpen: true });
|
|
23969
|
-
}
|
|
23970
|
-
const startedAtMs = currentTimeMs();
|
|
23971
|
-
const attempts = [PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS, PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS];
|
|
23972
|
-
let result2;
|
|
23973
|
-
let completedAttempts = 0;
|
|
23974
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
23975
|
-
const attempt = index + 1;
|
|
23976
|
-
const timeout = attempts[index];
|
|
23977
|
-
completedAttempts = attempt;
|
|
23978
|
-
writeEffectiveToolsProbePhase(input.phasePath, "spawned", attempt);
|
|
23979
|
-
const resolvedExecutorCommand = resolveExecutorCommand(executorCommand, env) ?? executorCommand;
|
|
23980
|
-
result2 = spawnSyncImpl(resolvedExecutorCommand, [
|
|
23981
|
-
"--no-session",
|
|
23982
|
-
"--no-approve",
|
|
23983
|
-
"--no-skills",
|
|
23984
|
-
"--no-context-files",
|
|
23985
|
-
// The enforcement extensions live in the run profile, not an agent dir,
|
|
23986
|
-
// so the probe must load them explicitly alongside the user's normal Pi
|
|
23987
|
-
// extensions and tools to measure the real run surface.
|
|
23988
|
-
...Array.isArray(input.extensionArgs) ? input.extensionArgs : [],
|
|
23989
|
-
"--print",
|
|
23990
|
-
"probe effective tools"
|
|
23991
|
-
], {
|
|
23992
|
-
cwd: env.AMASTER_RUNTIME_EXECUTION_WORKDIR,
|
|
23993
|
-
env: {
|
|
23994
|
-
...env,
|
|
23995
|
-
AMASTER_PI_EFFECTIVE_TOOLS_MODE: "probe",
|
|
23996
|
-
AMASTER_PI_EFFECTIVE_TOOLS_ATTEMPT: String(attempt)
|
|
23997
|
-
},
|
|
23998
|
-
encoding: "utf8",
|
|
23999
|
-
timeout,
|
|
24000
|
-
killSignal: "SIGKILL",
|
|
24001
|
-
maxBuffer: 1024 * 1024,
|
|
24002
|
-
...isWindowsCommandShim(resolvedExecutorCommand) ? { shell: true } : {},
|
|
24003
|
-
...spawnIdentity ?? {}
|
|
24004
|
-
});
|
|
24005
|
-
if (result2.error?.code === "ETIMEDOUT" && attempt < attempts.length) continue;
|
|
24006
|
-
break;
|
|
24007
|
-
}
|
|
24008
|
-
const elapsedMs = Math.max(0, currentTimeMs() - startedAtMs);
|
|
24009
|
-
if (result2.error) {
|
|
24010
|
-
const code = typeof result2.error.code === "string" ? result2.error.code : "UNKNOWN";
|
|
24011
|
-
const receiptDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24012
|
-
if (code === "ETIMEDOUT" && circuitKey) {
|
|
24013
|
-
if (receiptDiagnostic.phase === "missing" || receiptDiagnostic.phase === "spawned") {
|
|
24014
|
-
const previous = effectiveToolsProbeCircuits.get(circuitKey);
|
|
24015
|
-
const failures = (previous?.failures ?? 0) + 1;
|
|
24016
|
-
const shouldOpen = previous?.halfOpen === true || failures >= PI_EFFECTIVE_TOOLS_CIRCUIT_FAILURE_THRESHOLD;
|
|
24017
|
-
const observedAtMs = currentTimeMs();
|
|
24018
|
-
effectiveToolsProbeCircuits.set(circuitKey, {
|
|
24019
|
-
failures,
|
|
24020
|
-
lastPhase: receiptDiagnostic.phase,
|
|
24021
|
-
open: shouldOpen,
|
|
24022
|
-
halfOpen: false,
|
|
24023
|
-
retryAtMs: shouldOpen ? observedAtMs + PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS : null
|
|
24024
|
-
});
|
|
24025
|
-
} else {
|
|
24026
|
-
effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24027
|
-
}
|
|
24028
|
-
} else if (circuitKey) {
|
|
24029
|
-
effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24030
|
-
}
|
|
24031
|
-
const error = new Error(
|
|
24032
|
-
`pi_managed_mcp_effective_tools_failed: probe error=${code} elapsedMs=${elapsedMs} timeoutMs=${PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS} retryTimeoutMs=${PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS} totalBudgetMs=${PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS} attempts=${completedAttempts} receiptPhase=${receiptDiagnostic.phase}`
|
|
24033
|
-
);
|
|
24034
|
-
if (code === "ETIMEDOUT") error.code = "pi_managed_mcp_probe_timeout";
|
|
24035
|
-
throw error;
|
|
24036
|
-
}
|
|
24037
|
-
if (result2.status !== 0) {
|
|
24038
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24039
|
-
const receiptDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24040
|
-
let receiptError = "receipt unavailable";
|
|
24041
|
-
if (typeof receiptDiagnostic.receipt?.error === "string" && receiptDiagnostic.receipt.error.length > 0) {
|
|
24042
|
-
receiptError = receiptDiagnostic.receipt.error.slice(0, 512);
|
|
24043
|
-
}
|
|
24044
|
-
throw new Error(
|
|
24045
|
-
`pi_managed_mcp_effective_tools_failed: probe exit=${result2.status ?? "unknown"} elapsedMs=${elapsedMs} timeoutMs=${PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS} retryTimeoutMs=${PI_EFFECTIVE_TOOLS_RETRY_TIMEOUT_MS} totalBudgetMs=${PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS} attempts=${completedAttempts} receiptPhase=${receiptDiagnostic.phase} reason=${receiptError}`
|
|
24046
|
-
);
|
|
24047
|
-
}
|
|
24048
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24049
|
-
let receipt;
|
|
24050
|
-
try {
|
|
24051
|
-
receipt = JSON.parse(readFileSync9(input.receiptPath, "utf8"));
|
|
24052
|
-
} catch {
|
|
24053
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: probe receipt missing");
|
|
24054
|
-
}
|
|
24055
|
-
const proxyPresenceMismatch = input.proxyMode === "required" ? receipt.proxyPresent !== true : input.proxyMode === "forbidden" && receipt.proxyPresent !== false;
|
|
24056
|
-
if (receipt.status !== "attested" || receipt.mode !== "probe" || receipt.proxyMode !== input.proxyMode || proxyPresenceMismatch || receipt.effectiveSetHash !== input.effectiveSetHash || receipt.attestorSourceSha256 !== input.attestorSourceSha256 || receipt.configSha256 !== input.configSha256) {
|
|
24057
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: probe receipt mismatch");
|
|
24058
|
-
}
|
|
24059
|
-
const finalEffectiveTools = Array.isArray(receipt.finalEffectiveTools) ? receipt.finalEffectiveTools : [];
|
|
24060
|
-
const finalEffectiveToolNames = finalEffectiveTools.map((tool) => tool?.name).filter((name) => typeof name === "string").sort();
|
|
24061
|
-
const expectedFinalActiveToolNames = Array.isArray(input.finalActiveToolNames) ? input.finalActiveToolNames.slice().sort() : [];
|
|
24062
|
-
const finalEffectiveSchemaBytes = finalEffectiveTools.reduce((total, tool) => total + (Number.isSafeInteger(tool?.schemaBytes) && tool.schemaBytes >= 0 ? tool.schemaBytes : Number.NaN), 0);
|
|
24063
|
-
const finalEffectiveToolNameSet = new Set(finalEffectiveToolNames);
|
|
24064
|
-
if (finalEffectiveTools.length === 0 || !/^[a-f0-9]{64}$/.test(receipt.finalEffectiveSetHash ?? "") || stablePiEffectiveToolSetHash(finalEffectiveTools) !== receipt.finalEffectiveSetHash || expectedFinalActiveToolNames.some((name) => !finalEffectiveToolNameSet.has(name)) || !Number.isSafeInteger(receipt.finalEffectiveSchemaBytes) || receipt.finalEffectiveSchemaBytes !== finalEffectiveSchemaBytes) {
|
|
24065
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: final tool schema receipt mismatch");
|
|
24066
|
-
}
|
|
24067
|
-
if (sha2565(readFileSync9(input.configPath)) !== input.configSha256) {
|
|
24068
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: config drifted during probe");
|
|
24069
|
-
}
|
|
24070
|
-
const finalCacheBytes = readFileSync9(input.cachePath);
|
|
24071
|
-
if (receipt.cacheSha256 !== sha2565(finalCacheBytes) || stablePiManagedMcpCacheSemanticHash(finalCacheBytes, { ignoredServers: input.userMcpServerNames }) !== input.cacheSemanticHash) {
|
|
24072
|
-
throw new Error("pi_managed_mcp_effective_tools_failed: cache drifted during probe");
|
|
24073
|
-
}
|
|
24074
|
-
if (circuitKey) effectiveToolsProbeCircuits.delete(circuitKey);
|
|
24075
|
-
const phaseDiagnostic = inspectEffectiveToolsProbeReceipt(input.receiptPath, input.phasePath);
|
|
24076
|
-
return {
|
|
24077
|
-
effectiveToolProxyMode: receipt.proxyMode,
|
|
24078
|
-
effectiveToolProxyPresent: receipt.proxyPresent,
|
|
24079
|
-
effectiveToolSetHash: receipt.effectiveSetHash,
|
|
24080
|
-
finalEffectiveToolSetHash: receipt.finalEffectiveSetHash,
|
|
24081
|
-
finalEffectiveToolSchemaBytes: receipt.finalEffectiveSchemaBytes,
|
|
24082
|
-
finalEffectiveToolCount: finalEffectiveTools.length,
|
|
24083
|
-
finalEffectiveTools: finalEffectiveTools.map((tool) => ({
|
|
24084
|
-
name: tool.name,
|
|
24085
|
-
schemaHash: tool.schemaHash,
|
|
24086
|
-
schemaBytes: tool.schemaBytes
|
|
24087
|
-
})),
|
|
24088
|
-
effectiveToolProbeDigest: sha2565(stablePiJson(receipt)),
|
|
24089
|
-
effectiveToolProbeAt: receipt.attestedAt,
|
|
24090
|
-
effectiveToolProbeElapsedMs: elapsedMs,
|
|
24091
|
-
effectiveToolProbeTimeoutMs: PI_EFFECTIVE_TOOLS_ATTESTATION_TIMEOUT_MS,
|
|
24092
|
-
effectiveToolProbeTotalBudgetMs: PI_EFFECTIVE_TOOLS_TOTAL_TIMEOUT_MS,
|
|
24093
|
-
effectiveToolProbeCircuitCooldownMs: PI_EFFECTIVE_TOOLS_CIRCUIT_COOLDOWN_MS,
|
|
24094
|
-
effectiveToolProbeAttempts: completedAttempts,
|
|
24095
|
-
effectiveToolProbeSoftSlow: elapsedMs >= PI_EFFECTIVE_TOOLS_SOFT_SLOW_MS,
|
|
24096
|
-
effectiveToolProbePhase: phaseDiagnostic.phase,
|
|
24097
|
-
effectiveToolProbePhaseHistory: phaseDiagnostic.history,
|
|
24098
|
-
effectiveToolProbePhaseDurationsMs: effectiveToolsProbePhaseDurations(
|
|
24099
|
-
phaseDiagnostic.history,
|
|
24100
|
-
completedAttempts
|
|
24101
|
-
),
|
|
24102
|
-
effectiveToolBindings: receipt.effectiveToolBindings
|
|
24103
|
-
};
|
|
24104
|
-
}
|
|
24105
23809
|
function prepareDirectPiToolAttestation(input) {
|
|
24106
23810
|
const cachePath = join9(input.profileRoot, "mcp-cache.json");
|
|
24107
23811
|
if (!input.directCatalog) {
|
|
@@ -24164,6 +23868,26 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24164
23868
|
};
|
|
24165
23869
|
writePrivateFile2(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
24166
23870
|
`);
|
|
23871
|
+
const providerToolContract = managedPiProviderToolContract(input.directCatalog.tools.map((tool) => ({
|
|
23872
|
+
name: tool.exposedName,
|
|
23873
|
+
description: tool.description,
|
|
23874
|
+
parameters: normalizedPiToolSchema(tool.inputSchema, true)
|
|
23875
|
+
})));
|
|
23876
|
+
const declaredToolContract = {
|
|
23877
|
+
effectiveToolContractSource: "governed_catalog",
|
|
23878
|
+
effectiveToolValidationMode: "same_run_session_start_and_provider_request",
|
|
23879
|
+
effectiveToolProxyMode: manifest.proxyMode,
|
|
23880
|
+
effectiveToolSetHash: manifest.effectiveSetHash,
|
|
23881
|
+
finalRequiredToolSetHash: providerToolContract.effectiveToolSetSha256,
|
|
23882
|
+
finalRequiredToolSchemaBytes: providerToolContract.effectiveToolSchemaBytes,
|
|
23883
|
+
finalRequiredToolCount: providerToolContract.effectiveToolCount,
|
|
23884
|
+
finalRequiredTools: providerToolContract.definitions,
|
|
23885
|
+
effectiveToolBindings: input.directCatalog.tools.map((tool) => ({
|
|
23886
|
+
canonicalName: tool.name,
|
|
23887
|
+
exposedName: tool.exposedName,
|
|
23888
|
+
effectiveSchemaHash: tool.effectiveSchemaHash
|
|
23889
|
+
})).sort((left, right) => left.canonicalName.localeCompare(right.canonicalName))
|
|
23890
|
+
};
|
|
24167
23891
|
const closureTools = input.directCatalog.tools.filter((tool) => RUN_EXIT_CLOSURE_DIRECT_TYPED_TOOL_NAMES.has(tool.name));
|
|
24168
23892
|
const closureProfile = closureTools.length === RUN_EXIT_CLOSURE_DIRECT_TYPED_TOOL_NAMES.size ? (() => {
|
|
24169
23893
|
const closureToolNames = closureTools.map((tool) => tool.exposedName);
|
|
@@ -24220,7 +23944,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24220
23944
|
finalContextToolContract: managedPiProviderToolContract(closureTools.map((tool) => ({
|
|
24221
23945
|
name: tool.exposedName,
|
|
24222
23946
|
description: tool.description,
|
|
24223
|
-
parameters: tool.inputSchema
|
|
23947
|
+
parameters: normalizedPiToolSchema(tool.inputSchema, true)
|
|
24224
23948
|
}))),
|
|
24225
23949
|
cacheContentsBase64: closureCacheBytes.toString("base64"),
|
|
24226
23950
|
cacheSha256: sha2565(closureCacheBytes),
|
|
@@ -24250,6 +23974,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24250
23974
|
finalActiveToolNames: effectiveRunToolAllowlist,
|
|
24251
23975
|
userMcpServerNames: input.userMcpServerNames,
|
|
24252
23976
|
profileToolAllowlist: null,
|
|
23977
|
+
declaredToolContract,
|
|
24253
23978
|
closureProfile
|
|
24254
23979
|
}
|
|
24255
23980
|
};
|
|
@@ -24335,6 +24060,10 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24335
24060
|
if (!existsSync8(adapterExtensionPath)) {
|
|
24336
24061
|
throw new Error("pi_managed_mcp_adapter_extension_missing");
|
|
24337
24062
|
}
|
|
24063
|
+
const adapterRootStat = lstatSync8(dirname6(adapterExtensionPath));
|
|
24064
|
+
if (!adapterRootStat.isDirectory() || adapterRootStat.isSymbolicLink()) {
|
|
24065
|
+
throw new Error("pi_managed_mcp_adapter_extension_unsafe");
|
|
24066
|
+
}
|
|
24338
24067
|
const adapterExtensionStat = lstatSync8(adapterExtensionPath);
|
|
24339
24068
|
if (!adapterExtensionStat.isFile() || adapterExtensionStat.isSymbolicLink()) {
|
|
24340
24069
|
throw new Error("pi_managed_mcp_adapter_extension_unsafe");
|
|
@@ -24417,14 +24146,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24417
24146
|
} : {}
|
|
24418
24147
|
};
|
|
24419
24148
|
if (directAttestationInput) {
|
|
24420
|
-
|
|
24149
|
+
writeEffectiveToolsPhase(directAttestationInput.phasePath, "prepared", 0);
|
|
24421
24150
|
}
|
|
24422
|
-
const effectiveToolsBootstrapCache = directAttestationInput ? prepareEffectiveToolsBootstrapCache(
|
|
24423
|
-
input,
|
|
24424
|
-
sharedRuntime,
|
|
24425
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24426
|
-
tmp
|
|
24427
|
-
) : null;
|
|
24428
24151
|
const spawnIdentity = typeof input.prepareExecutorAccess === "function" ? input.prepareExecutorAccess({ profileRoot, workspaceRoot: cwd }) : null;
|
|
24429
24152
|
const executorAttestation = attestPi(
|
|
24430
24153
|
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
@@ -24433,14 +24156,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24433
24156
|
config,
|
|
24434
24157
|
spawnIdentity
|
|
24435
24158
|
);
|
|
24436
|
-
const effectiveToolsAttestation = directAttestationInput ? attestDirectPiTools(
|
|
24437
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24438
|
-
env,
|
|
24439
|
-
directAttestationInput,
|
|
24440
|
-
spawnIdentity,
|
|
24441
|
-
effectiveToolsBootstrapCache?.key ?? null
|
|
24442
|
-
) : {};
|
|
24443
|
-
const effectiveToolProbeBootstrapCache = effectiveToolsBootstrapCache ? publishEffectiveToolsBootstrapCache(effectiveToolsBootstrapCache) : null;
|
|
24444
24159
|
const runExitClosureOwnership = directAttestationInput ? {
|
|
24445
24160
|
cache: ownershipStatSyncImpl(directAttestationInput.cachePath),
|
|
24446
24161
|
manifest: ownershipStatSyncImpl(directAttestationInput.manifestPath),
|
|
@@ -24455,9 +24170,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24455
24170
|
mcpArgsNormalization: "none",
|
|
24456
24171
|
...directCatalog ? {
|
|
24457
24172
|
catalogSetHash: directCatalog.setHash,
|
|
24458
|
-
...
|
|
24459
|
-
effectiveToolProbeBootstrapKey: effectiveToolsBootstrapCache?.key ?? null,
|
|
24460
|
-
effectiveToolProbeBootstrapCache
|
|
24173
|
+
...directAttestationInput.declaredToolContract
|
|
24461
24174
|
} : {},
|
|
24462
24175
|
configMode: MANAGED_PI_CONFIG_MODE_SHARED,
|
|
24463
24176
|
namespace: SUPPORTED_SERVER_NAME3,
|
|
@@ -24839,18 +24552,8 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24839
24552
|
} : {}
|
|
24840
24553
|
};
|
|
24841
24554
|
if (directAttestationInput) {
|
|
24842
|
-
|
|
24555
|
+
writeEffectiveToolsPhase(directAttestationInput.phasePath, "prepared", 0);
|
|
24843
24556
|
}
|
|
24844
|
-
const sharedRuntime = {
|
|
24845
|
-
home: sourcePiHome,
|
|
24846
|
-
...desktopAttestationReadiness?.ready ? { adapterRoot: desktopAttestationReadiness.adapterRoot } : {}
|
|
24847
|
-
};
|
|
24848
|
-
const effectiveToolsBootstrapCache = directAttestationInput ? prepareEffectiveToolsBootstrapCache(
|
|
24849
|
-
input,
|
|
24850
|
-
sharedRuntime,
|
|
24851
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24852
|
-
tmp
|
|
24853
|
-
) : null;
|
|
24854
24557
|
const spawnIdentity = typeof input.prepareExecutorAccess === "function" ? input.prepareExecutorAccess({ profileRoot, workspaceRoot: cwd }) : null;
|
|
24855
24558
|
const executorAttestation = directAttestationInput ? attestPi(
|
|
24856
24559
|
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
@@ -24859,14 +24562,6 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24859
24562
|
config,
|
|
24860
24563
|
spawnIdentity
|
|
24861
24564
|
) : {};
|
|
24862
|
-
const effectiveToolsAttestation = directAttestationInput ? attestDirectPiTools(
|
|
24863
|
-
nonEmpty3(input.executorCommand, "executorCommand"),
|
|
24864
|
-
env,
|
|
24865
|
-
directAttestationInput,
|
|
24866
|
-
spawnIdentity,
|
|
24867
|
-
effectiveToolsBootstrapCache?.key ?? null
|
|
24868
|
-
) : {};
|
|
24869
|
-
const effectiveToolProbeBootstrapCache = effectiveToolsBootstrapCache ? publishEffectiveToolsBootstrapCache(effectiveToolsBootstrapCache) : null;
|
|
24870
24565
|
const runExitClosureOwnership = directAttestationInput ? {
|
|
24871
24566
|
cache: ownershipStatSyncImpl(directAttestationInput.cachePath),
|
|
24872
24567
|
manifest: ownershipStatSyncImpl(directAttestationInput.manifestPath),
|
|
@@ -24881,9 +24576,7 @@ ${result2.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
24881
24576
|
mcpArgsNormalization: "none",
|
|
24882
24577
|
...directCatalog ? {
|
|
24883
24578
|
catalogSetHash: directCatalog.setHash,
|
|
24884
|
-
...
|
|
24885
|
-
effectiveToolProbeBootstrapKey: effectiveToolsBootstrapCache?.key ?? null,
|
|
24886
|
-
effectiveToolProbeBootstrapCache
|
|
24579
|
+
...directAttestationInput.declaredToolContract
|
|
24887
24580
|
} : {},
|
|
24888
24581
|
configMode: "desktop_delegated_runtime_action_bridge",
|
|
24889
24582
|
namespace: SUPPORTED_SERVER_NAME3,
|
|
@@ -27392,43 +27085,105 @@ function classifyCodexTransientUpstreamError(input, now = /* @__PURE__ */ new Da
|
|
|
27392
27085
|
}
|
|
27393
27086
|
|
|
27394
27087
|
// src/amaster-runtime-daemon/executor-protocol/codebuddy.mjs
|
|
27395
|
-
|
|
27396
|
-
|
|
27397
|
-
|
|
27398
|
-
|
|
27399
|
-
|
|
27400
|
-
if (
|
|
27088
|
+
var AMASTER_MCP_TOOL_PREFIX = "mcp__amaster__";
|
|
27089
|
+
var MAX_STRUCTURED_RESULT_DEPTH = 8;
|
|
27090
|
+
var MAX_TRACKED_TOOL_USES = 256;
|
|
27091
|
+
function structuredToolResults(value, depth = 0) {
|
|
27092
|
+
if (depth > MAX_STRUCTURED_RESULT_DEPTH || value === null || value === void 0) return [];
|
|
27093
|
+
if (Array.isArray(value)) {
|
|
27094
|
+
return value.flatMap((part) => structuredToolResults(part, depth + 1));
|
|
27095
|
+
}
|
|
27096
|
+
if (typeof value === "string") {
|
|
27401
27097
|
try {
|
|
27402
|
-
return
|
|
27098
|
+
return structuredToolResults(JSON.parse(value), depth + 1);
|
|
27403
27099
|
} catch {
|
|
27404
|
-
return
|
|
27100
|
+
return [];
|
|
27405
27101
|
}
|
|
27406
27102
|
}
|
|
27407
|
-
|
|
27408
|
-
|
|
27409
|
-
|
|
27410
|
-
|
|
27411
|
-
return {};
|
|
27412
|
-
}
|
|
27413
|
-
function codebuddyMcpToolResults(event) {
|
|
27414
|
-
const record8 = asRecord(event);
|
|
27103
|
+
const record8 = asRecord(value);
|
|
27104
|
+
const structuredContent = structuredToolResults(record8.structuredContent, depth + 1);
|
|
27105
|
+
if (structuredContent.length > 0) return structuredContent;
|
|
27106
|
+
if (readString(record8.status)) return [record8];
|
|
27415
27107
|
const candidates = [];
|
|
27416
|
-
|
|
27417
|
-
|
|
27108
|
+
for (const nested of [
|
|
27109
|
+
record8.content,
|
|
27110
|
+
record8.text,
|
|
27111
|
+
record8.result,
|
|
27112
|
+
record8.output
|
|
27113
|
+
]) {
|
|
27114
|
+
candidates.push(...structuredToolResults(nested, depth + 1));
|
|
27418
27115
|
}
|
|
27419
|
-
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
27423
|
-
|
|
27424
|
-
|
|
27116
|
+
return candidates;
|
|
27117
|
+
}
|
|
27118
|
+
function governedResults(candidates) {
|
|
27119
|
+
return candidates.flatMap((candidate) => structuredToolResults(candidate).flatMap((structured) => {
|
|
27120
|
+
const parsed = governedMcpToolResult(structured);
|
|
27121
|
+
return parsed ? [parsed] : [];
|
|
27122
|
+
}));
|
|
27123
|
+
}
|
|
27124
|
+
function createCodebuddyMcpToolResultTracker() {
|
|
27125
|
+
const toolNamesById = /* @__PURE__ */ new Map();
|
|
27126
|
+
let trackingFailure = null;
|
|
27127
|
+
const rememberToolUse = (id, name) => {
|
|
27128
|
+
if (trackingFailure) return;
|
|
27129
|
+
const toolUseId = readString(id);
|
|
27130
|
+
if (!toolUseId) return;
|
|
27131
|
+
const toolName = readString(name);
|
|
27132
|
+
if (!toolName?.startsWith(AMASTER_MCP_TOOL_PREFIX)) {
|
|
27133
|
+
toolNamesById.delete(toolUseId);
|
|
27134
|
+
return;
|
|
27135
|
+
}
|
|
27136
|
+
if (!toolNamesById.has(toolUseId) && toolNamesById.size >= MAX_TRACKED_TOOL_USES) {
|
|
27137
|
+
trackingFailure = `codebuddy_mcp_tool_tracking_overflow: more than ${MAX_TRACKED_TOOL_USES} unresolved governed tool calls`;
|
|
27138
|
+
return;
|
|
27139
|
+
}
|
|
27140
|
+
toolNamesById.set(toolUseId, toolName);
|
|
27141
|
+
};
|
|
27142
|
+
return {
|
|
27143
|
+
failure() {
|
|
27144
|
+
return trackingFailure;
|
|
27145
|
+
},
|
|
27146
|
+
record(event) {
|
|
27147
|
+
if (trackingFailure) return [];
|
|
27148
|
+
const record8 = asRecord(event);
|
|
27149
|
+
const eventType = readString(record8.type);
|
|
27150
|
+
if (eventType === "assistant") {
|
|
27151
|
+
const message2 = asRecord(record8.message);
|
|
27152
|
+
for (const rawBlock of Array.isArray(message2.content) ? message2.content : []) {
|
|
27153
|
+
const block = asRecord(rawBlock);
|
|
27154
|
+
if (["tool_use", "toolUse"].includes(readString(block.type) ?? "")) {
|
|
27155
|
+
rememberToolUse(block.id ?? block.tool_use_id ?? block.toolUseId, block.name ?? block.tool_name);
|
|
27156
|
+
}
|
|
27157
|
+
}
|
|
27158
|
+
return [];
|
|
27159
|
+
}
|
|
27160
|
+
if (eventType === "function_call") {
|
|
27161
|
+
rememberToolUse(record8.call_id ?? record8.tool_use_id ?? record8.id, record8.name);
|
|
27162
|
+
return [];
|
|
27163
|
+
}
|
|
27164
|
+
if (eventType === "function_call_result") {
|
|
27165
|
+
const callId = readString(record8.call_id ?? record8.tool_use_id ?? record8.id);
|
|
27166
|
+
if (!callId || !toolNamesById.has(callId)) return [];
|
|
27167
|
+
const results2 = governedResults([record8.output ?? record8.result]);
|
|
27168
|
+
if (results2.length > 0) toolNamesById.delete(callId);
|
|
27169
|
+
return results2;
|
|
27170
|
+
}
|
|
27171
|
+
if (eventType !== "user") return [];
|
|
27172
|
+
const message = asRecord(record8.message);
|
|
27173
|
+
const results = [];
|
|
27174
|
+
for (const rawBlock of Array.isArray(message.content) ? message.content : []) {
|
|
27175
|
+
const block = asRecord(rawBlock);
|
|
27176
|
+
if (!["tool_result", "toolResult"].includes(readString(block.type) ?? "")) continue;
|
|
27177
|
+
const toolUseId = readString(block.tool_use_id ?? block.toolUseId ?? block.id);
|
|
27178
|
+
if (!toolUseId || !toolNamesById.has(toolUseId)) continue;
|
|
27179
|
+
const blockResults = governedResults([block.content ?? block.result]);
|
|
27180
|
+
if (blockResults.length === 0) continue;
|
|
27181
|
+
toolNamesById.delete(toolUseId);
|
|
27182
|
+
results.push(...blockResults);
|
|
27425
27183
|
}
|
|
27184
|
+
return results;
|
|
27426
27185
|
}
|
|
27427
|
-
}
|
|
27428
|
-
return candidates.flatMap((candidate) => {
|
|
27429
|
-
const parsed = governedMcpToolResult(structuredToolResult(candidate));
|
|
27430
|
-
return parsed ? [parsed] : [];
|
|
27431
|
-
});
|
|
27186
|
+
};
|
|
27432
27187
|
}
|
|
27433
27188
|
function parseCodebuddyStreamJson(stdout) {
|
|
27434
27189
|
let sessionId = null;
|
|
@@ -27437,12 +27192,13 @@ function parseCodebuddyStreamJson(stdout) {
|
|
|
27437
27192
|
let sawSuccessfulResult = false;
|
|
27438
27193
|
const assistantTexts = [];
|
|
27439
27194
|
const mcpToolResults = [];
|
|
27195
|
+
const mcpToolResultTracker = createCodebuddyMcpToolResultTracker();
|
|
27440
27196
|
const usage = { inputTokens: 0, cachedInputTokens: 0, outputTokens: 0 };
|
|
27441
27197
|
for (const rawLine of String(stdout ?? "").split(/\r?\n/)) {
|
|
27442
27198
|
const event = parseJsonLine(rawLine.trim());
|
|
27443
27199
|
if (!event) continue;
|
|
27444
27200
|
sessionId = readString(event.session_id) ?? readString(event.sessionId) ?? sessionId;
|
|
27445
|
-
mcpToolResults.push(...
|
|
27201
|
+
mcpToolResults.push(...mcpToolResultTracker.record(event));
|
|
27446
27202
|
if (event.type === "assistant") {
|
|
27447
27203
|
const message = asRecord(event.message);
|
|
27448
27204
|
for (const rawBlock of Array.isArray(message.content) ? message.content : []) {
|
|
@@ -27480,6 +27236,11 @@ function parseCodebuddyStreamJson(stdout) {
|
|
|
27480
27236
|
errorMessage = readString(event.message) ?? errorMessage;
|
|
27481
27237
|
}
|
|
27482
27238
|
}
|
|
27239
|
+
const trackingFailure = mcpToolResultTracker.failure();
|
|
27240
|
+
if (trackingFailure) {
|
|
27241
|
+
sawSuccessfulResult = false;
|
|
27242
|
+
errorMessage = trackingFailure;
|
|
27243
|
+
}
|
|
27483
27244
|
const uniqueMcpToolResults = dedupeGovernedMcpToolResults(mcpToolResults);
|
|
27484
27245
|
return {
|
|
27485
27246
|
sessionId,
|
|
@@ -33583,11 +33344,11 @@ function resolvePiModelContextBudget({
|
|
|
33583
33344
|
}) {
|
|
33584
33345
|
const instructionBytes = [...finalAgentInstructionFiles.values()].reduce((total, entry) => total + Number(entry.byteSize ?? 0), 0);
|
|
33585
33346
|
const profileAttestation = record7(managedMcpProfile?.attestation);
|
|
33586
|
-
const toolSchemaBytes = Number(profileAttestation.
|
|
33347
|
+
const toolSchemaBytes = Number(profileAttestation.finalRequiredToolSchemaBytes);
|
|
33587
33348
|
if (!Number.isSafeInteger(toolSchemaBytes) || toolSchemaBytes < 1) {
|
|
33588
33349
|
throw stableContextError(
|
|
33589
33350
|
"model_context_attestation_unavailable",
|
|
33590
|
-
"
|
|
33351
|
+
"required governed tool schema size is missing"
|
|
33591
33352
|
);
|
|
33592
33353
|
}
|
|
33593
33354
|
const skillMetadataBytes = Number(profileAttestation.enabledSkillMetadataBytes ?? 0);
|
|
@@ -33616,7 +33377,7 @@ function resolvePiModelContextBudget({
|
|
|
33616
33377
|
knownFixedInputTokens,
|
|
33617
33378
|
fixedInputBreakdown: {
|
|
33618
33379
|
projectInstructionBytes: instructionBytes,
|
|
33619
|
-
|
|
33380
|
+
requiredGovernedToolSchemaBytes: toolSchemaBytes,
|
|
33620
33381
|
skillMetadataBytes
|
|
33621
33382
|
},
|
|
33622
33383
|
dynamicInputTokens,
|
|
@@ -33931,7 +33692,7 @@ function assertRequiredTaskAttachmentMaterialized(input, materialized) {
|
|
|
33931
33692
|
}
|
|
33932
33693
|
|
|
33933
33694
|
// src/amaster-runtime-daemon.mjs
|
|
33934
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
33695
|
+
var CONNECTOR_VERSION = "0.1.1-beta.273";
|
|
33935
33696
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
33936
33697
|
var daemonRequire = createRequire(import.meta.url);
|
|
33937
33698
|
var MAX_CHECKPOINT_BYTES = 20 * 1024 * 1024;
|
|
@@ -35584,11 +35345,12 @@ function requireEffectiveToolSchemaAttestation(contextContract, executorKind, go
|
|
|
35584
35345
|
const attestation = asRecord(managedMcpProfile?.attestation);
|
|
35585
35346
|
const catalogSetHash = readString(attestation.catalogSetHash);
|
|
35586
35347
|
const effectiveToolSetHash = readString(attestation.effectiveToolSetHash);
|
|
35587
|
-
const
|
|
35588
|
-
|
|
35348
|
+
const finalRequiredToolSetHash = readString(attestation.finalRequiredToolSetHash);
|
|
35349
|
+
const catalogToolCount = Array.isArray(catalog.tools) ? catalog.tools.length : 0;
|
|
35350
|
+
if (!/^[a-f0-9]{64}$/.test(declaredSetHash ?? "") || catalogSetHash !== declaredSetHash || readString(attestation.effectiveToolContractSource) !== "governed_catalog" || readString(attestation.effectiveToolValidationMode) !== "same_run_session_start_and_provider_request" || !/^[a-f0-9]{64}$/.test(effectiveToolSetHash ?? "") || !/^[a-f0-9]{64}$/.test(finalRequiredToolSetHash ?? "") || !Number.isSafeInteger(attestation.finalRequiredToolSchemaBytes) || attestation.finalRequiredToolSchemaBytes < 1 || !Number.isSafeInteger(attestation.finalRequiredToolCount) || attestation.finalRequiredToolCount !== catalogToolCount) {
|
|
35589
35351
|
throw stableContextError(
|
|
35590
35352
|
"context_effective_tool_schema_attestation_mismatch",
|
|
35591
|
-
"
|
|
35353
|
+
"the governed Pi tool schema contract is missing or does not match the catalog"
|
|
35592
35354
|
);
|
|
35593
35355
|
}
|
|
35594
35356
|
return {
|
|
@@ -35596,10 +35358,10 @@ function requireEffectiveToolSchemaAttestation(contextContract, executorKind, go
|
|
|
35596
35358
|
executorKind,
|
|
35597
35359
|
declaredCatalogSetHash: declaredSetHash,
|
|
35598
35360
|
effectiveToolSetHash,
|
|
35599
|
-
|
|
35600
|
-
|
|
35601
|
-
|
|
35602
|
-
|
|
35361
|
+
finalRequiredToolSetHash,
|
|
35362
|
+
finalRequiredToolSchemaBytes: attestation.finalRequiredToolSchemaBytes,
|
|
35363
|
+
finalRequiredToolCount: attestation.finalRequiredToolCount,
|
|
35364
|
+
validationMode: attestation.effectiveToolValidationMode,
|
|
35603
35365
|
attestationId: readString(attestation.attestationId)
|
|
35604
35366
|
};
|
|
35605
35367
|
}
|
|
@@ -36138,6 +35900,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36138
35900
|
let piTerminalOutput = null;
|
|
36139
35901
|
let executorSessionId = null;
|
|
36140
35902
|
const liveMcpToolResults = [];
|
|
35903
|
+
const codebuddyMcpToolResultTracker = executorKind === "codebuddy" ? createCodebuddyMcpToolResultTracker() : null;
|
|
36141
35904
|
const onWebEvidence = typeof options.onWebEvidence === "function" ? options.onWebEvidence : null;
|
|
36142
35905
|
let queue = Promise.resolve();
|
|
36143
35906
|
let observationQueue = Promise.resolve();
|
|
@@ -36330,7 +36093,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36330
36093
|
}
|
|
36331
36094
|
}
|
|
36332
36095
|
if (MIRRORX_FORMAL_TASK_EXECUTOR_KINDS.includes(executorKind) && event) {
|
|
36333
|
-
const results = executorKind === "codex" ? codexMcpToolResults(event) : executorKind === "codebuddy" ?
|
|
36096
|
+
const results = executorKind === "codex" ? codexMcpToolResults(event) : executorKind === "codebuddy" ? codebuddyMcpToolResultTracker.record(event) : piMcpToolResults(event, { runId: commandRunId(command), commandId: command.commandId, issueId: commandIssueId(command) });
|
|
36334
36097
|
liveMcpToolResults.push(...results);
|
|
36335
36098
|
if (results.length > 0) onMcpToolResults?.(results);
|
|
36336
36099
|
}
|
|
@@ -36419,6 +36182,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36419
36182
|
processLine(stream, buffers[stream]);
|
|
36420
36183
|
buffers[stream] = "";
|
|
36421
36184
|
}
|
|
36185
|
+
const codebuddyTrackingFailure = codebuddyMcpToolResultTracker?.failure();
|
|
36422
36186
|
await observationQueue;
|
|
36423
36187
|
if (observationError) throw observationError;
|
|
36424
36188
|
flushPendingBatch();
|
|
@@ -36441,6 +36205,7 @@ function createLiveOutputLogger(config, command, executorKind, protectedValues =
|
|
|
36441
36205
|
}
|
|
36442
36206
|
}], { terminalSummary: true });
|
|
36443
36207
|
}
|
|
36208
|
+
if (codebuddyTrackingFailure) throw new Error(codebuddyTrackingFailure);
|
|
36444
36209
|
},
|
|
36445
36210
|
hasStream(stream) {
|
|
36446
36211
|
return displayCounts[stream] > 0;
|
|
@@ -38607,7 +38372,7 @@ async function executeRunCommand(config, command) {
|
|
|
38607
38372
|
if (executor.kind === "pi") {
|
|
38608
38373
|
assertManagedPiNonInteractiveInvocation(invocation.args, managedMcpProfile);
|
|
38609
38374
|
}
|
|
38610
|
-
await ingestLog(config, command, "system", "info", desktopDelegatedRunnerEnabled(config) && executor.kind === "pi" ? "Prepared desktop delegated Pi runtime action bridge" : `Attested isolated ${executor.kind} managed MCP profile`, {
|
|
38375
|
+
await ingestLog(config, command, "system", "info", desktopDelegatedRunnerEnabled(config) && executor.kind === "pi" ? "Prepared desktop delegated Pi runtime action bridge" : executor.kind === "pi" ? "Prepared isolated Pi managed MCP profile" : `Attested isolated ${executor.kind} managed MCP profile`, {
|
|
38611
38376
|
presentationKind: "managed_mcp_attestation",
|
|
38612
38377
|
...managedMcpProfile.attestation
|
|
38613
38378
|
});
|
|
@@ -38840,7 +38605,7 @@ async function executeRunCommand(config, command) {
|
|
|
38840
38605
|
} : null;
|
|
38841
38606
|
try {
|
|
38842
38607
|
execution = await runExecutor(invocation.command, invocation.args, {
|
|
38843
|
-
cwd,
|
|
38608
|
+
cwd: executor.kind === "codebuddy" ? managedMcpProfile?.cwd ?? cwd : cwd,
|
|
38844
38609
|
env: executorEnv,
|
|
38845
38610
|
stdin: invocation.stdin === "prompt" ? prompt : "",
|
|
38846
38611
|
timeoutSeconds: config.executorTimeoutSeconds,
|
|
@@ -39170,16 +38935,15 @@ async function executeRunCommand(config, command) {
|
|
|
39170
38935
|
);
|
|
39171
38936
|
}
|
|
39172
38937
|
const parsedForValidation = parsed;
|
|
39173
|
-
const completionOutputHasFinalAssistantText = terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText;
|
|
39174
38938
|
const piTurnLimitFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiTurnLimitResult(parsedForValidation, {
|
|
39175
38939
|
authoritativeTerminalDisposition: Boolean(terminalRunDisposition)
|
|
39176
38940
|
}) : null;
|
|
39177
38941
|
const piInvalidOutputError = executor.kind === "pi" ? piOutputValidationError(parsedForValidation, {
|
|
39178
|
-
allowMissingTurnEnd: completionOutputStopped
|
|
38942
|
+
allowMissingTurnEnd: completionOutputStopped,
|
|
39179
38943
|
allowMissingAssistantOutput: execution.completionOutputType === "approval_required" || Boolean(terminalRunDisposition),
|
|
39180
38944
|
allowMissingFinalAssistantText: Boolean(terminalRunDisposition),
|
|
39181
38945
|
completionOutputType: execution.completionOutputType,
|
|
39182
|
-
completionOutputHasFinalAssistantText
|
|
38946
|
+
completionOutputHasFinalAssistantText: terminalTextRepair?.succeeded === true ? true : execution.completionOutputHasFinalAssistantText
|
|
39183
38947
|
}) : null;
|
|
39184
38948
|
const piOutputFailure = executor.kind === "pi" && !cancelled && !hasOutputFlood && !hasArgumentAmplification && !hasMemoryLimit && execution.timedOut !== true && !execution.spawnError ? classifyPiOutputFailure(parsedForValidation, {
|
|
39185
38949
|
exitCode: execution.exitCode,
|
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.273";
|
|
11
11
|
|
|
12
12
|
const CONFIG_KEY_MAP = new Map([
|
|
13
13
|
["server_url", "AMASTER_EMPLOYEE_SERVER_URL"],
|