@amaster.ai/employee-runtime-connector 0.1.1-beta.21 → 0.1.1-beta.22
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 +1 -1
- package/dist/amaster-runtime-daemon.mjs +325 -55
- package/dist/amaster-runtime.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ For production images, install an exact version and invoke the package bin:
|
|
|
13
13
|
```sh
|
|
14
14
|
npm install --omit=dev --prefix /opt/pi-cli-runtime @amaster.ai/employee-runtime-connector@0.1.0
|
|
15
15
|
/opt/pi-cli-runtime/node_modules/.bin/amaster-runtime setup https://employee.example.com \
|
|
16
|
-
--capabilities remote_registration,heartbeat,executor_discovery,workspace_binding,run_wakeup,model_call,run_cancel,run_terminate,logs_cost_workspace_status
|
|
16
|
+
--capabilities remote_registration,heartbeat,executor_discovery,workspace_binding,run_wakeup,model_call,model_call_output_contract_v1,run_cancel,run_terminate,logs_cost_workspace_status
|
|
17
17
|
/opt/pi-cli-runtime/node_modules/.bin/amaster-runtime daemon start --foreground
|
|
18
18
|
```
|
|
19
19
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// MirrorX runtime connector daemon bundle.
|
|
3
3
|
|
|
4
4
|
// src/amaster-runtime-daemon.mjs
|
|
5
|
-
import { createHash as
|
|
5
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
6
6
|
import { chmodSync as chmodSync6, copyFileSync as copyFileSync3, existsSync as existsSync14, lstatSync as lstatSync7, mkdirSync as mkdirSync9, mkdtempSync, readFileSync as readFileSync11, readdirSync as readdirSync9, realpathSync as realpathSync5, renameSync as renameSync6, rmSync as rmSync7, statSync as statSync8, symlinkSync as symlinkSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync9 } from "node:fs";
|
|
7
7
|
import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3, tmpdir } from "node:os";
|
|
8
8
|
import { basename as basename6, delimiter as delimiter3, dirname as dirname9, extname as extname2, isAbsolute as isAbsolute8, join as join15, relative as relative9, resolve as resolve12 } from "node:path";
|
|
@@ -2005,6 +2005,43 @@ function syncAmasterProviderFiles(agentDir, executorEnv) {
|
|
|
2005
2005
|
settingsSynced: syncAmasterProviderSettings(agentDir, executorEnv)
|
|
2006
2006
|
};
|
|
2007
2007
|
}
|
|
2008
|
+
function normalizePiModelId(modelId) {
|
|
2009
|
+
return readString(modelId)?.replace(/:(?:off|minimal|low|medium|high|xhigh|max)$/i, "") ?? null;
|
|
2010
|
+
}
|
|
2011
|
+
function applyModelCallOutputContract(agentDir, providerId, modelId, maxOutputTokens) {
|
|
2012
|
+
const provider = readString(providerId);
|
|
2013
|
+
const model = normalizePiModelId(modelId);
|
|
2014
|
+
const tokenLimit = Number(maxOutputTokens);
|
|
2015
|
+
if (!provider || !model || !Number.isSafeInteger(tokenLimit) || tokenLimit <= 0) {
|
|
2016
|
+
throw new Error("pi_model_call_output_contract_invalid");
|
|
2017
|
+
}
|
|
2018
|
+
const modelsPath = join3(agentDir, "models.json");
|
|
2019
|
+
const config = readJsonFile(modelsPath);
|
|
2020
|
+
const providers = asRecord(config.providers);
|
|
2021
|
+
const providerConfig = asRecord(providers[provider]);
|
|
2022
|
+
const configuredModels = Array.isArray(providerConfig.models) ? providerConfig.models : [];
|
|
2023
|
+
const configuredModelExists = configuredModels.some((entry) => readString(asRecord(entry).id) === model);
|
|
2024
|
+
const existingOverrides = asRecord(providerConfig.modelOverrides);
|
|
2025
|
+
if (!configuredModelExists && !(model in existingOverrides)) {
|
|
2026
|
+
throw new Error(`pi_model_call_model_missing: ${provider}/${model}`);
|
|
2027
|
+
}
|
|
2028
|
+
writeJsonFileAtomic(modelsPath, {
|
|
2029
|
+
...config,
|
|
2030
|
+
providers: {
|
|
2031
|
+
...providers,
|
|
2032
|
+
[provider]: {
|
|
2033
|
+
...providerConfig,
|
|
2034
|
+
modelOverrides: {
|
|
2035
|
+
...existingOverrides,
|
|
2036
|
+
[model]: {
|
|
2037
|
+
...asRecord(existingOverrides[model]),
|
|
2038
|
+
maxTokens: tokenLimit
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2008
2045
|
|
|
2009
2046
|
// src/amaster-runtime-daemon/pi-mcp-args-normalizer.mjs
|
|
2010
2047
|
function isJsonObject(value) {
|
|
@@ -2734,11 +2771,11 @@ function createManagedPiMcpProfileApi(options = {}) {
|
|
|
2734
2771
|
if (!Number.isFinite(value)) throw new Error("pi_managed_mcp_attestation_failed: invalid attestation clock");
|
|
2735
2772
|
return value;
|
|
2736
2773
|
}
|
|
2737
|
-
function
|
|
2774
|
+
function sha2562(value) {
|
|
2738
2775
|
return createHash3("sha256").update(value).digest("hex");
|
|
2739
2776
|
}
|
|
2740
2777
|
function adapterServerConfigHash(definition) {
|
|
2741
|
-
return
|
|
2778
|
+
return sha2562(stablePiJson({
|
|
2742
2779
|
command: definition.command,
|
|
2743
2780
|
args: definition.args,
|
|
2744
2781
|
env: definition.env,
|
|
@@ -3278,17 +3315,17 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3278
3315
|
if (receipt.status !== "attested" || receipt.mode !== "probe" || receipt.proxyMode !== input.proxyMode || receipt.proxyPresent !== expectedProxyPresent || receipt.effectiveSetHash !== input.effectiveSetHash || receipt.attestorSourceSha256 !== input.attestorSourceSha256 || receipt.configSha256 !== input.configSha256 || receipt.cacheSha256 !== input.cacheSha256) {
|
|
3279
3316
|
throw new Error("pi_managed_mcp_effective_tools_failed: probe receipt mismatch");
|
|
3280
3317
|
}
|
|
3281
|
-
if (
|
|
3318
|
+
if (sha2562(readFileSync3(input.configPath)) !== input.configSha256) {
|
|
3282
3319
|
throw new Error("pi_managed_mcp_effective_tools_failed: config drifted during probe");
|
|
3283
3320
|
}
|
|
3284
|
-
if (
|
|
3321
|
+
if (sha2562(readFileSync3(input.cachePath)) !== input.cacheSha256) {
|
|
3285
3322
|
throw new Error("pi_managed_mcp_effective_tools_failed: cache drifted during probe");
|
|
3286
3323
|
}
|
|
3287
3324
|
return {
|
|
3288
3325
|
effectiveToolProxyMode: receipt.proxyMode,
|
|
3289
3326
|
effectiveToolProxyPresent: receipt.proxyPresent,
|
|
3290
3327
|
effectiveToolSetHash: receipt.effectiveSetHash,
|
|
3291
|
-
effectiveToolProbeDigest:
|
|
3328
|
+
effectiveToolProbeDigest: sha2562(stablePiJson(receipt)),
|
|
3292
3329
|
effectiveToolProbeAt: receipt.attestedAt,
|
|
3293
3330
|
effectiveToolBindings: receipt.effectiveToolBindings
|
|
3294
3331
|
};
|
|
@@ -3370,8 +3407,8 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3370
3407
|
};
|
|
3371
3408
|
writePrivateFile2(cachePath, `${JSON.stringify(cache, null, 2)}
|
|
3372
3409
|
`);
|
|
3373
|
-
const cacheSha256 =
|
|
3374
|
-
const attestorSourceSha256 =
|
|
3410
|
+
const cacheSha256 = sha2562(readFileSync3(cachePath));
|
|
3411
|
+
const attestorSourceSha256 = sha2562(managedPiEffectiveToolsAttestorExtensionSource());
|
|
3375
3412
|
const manifestPath = join4(piCodingAgentDir, "effective-tools-manifest.json");
|
|
3376
3413
|
const receiptPath = join4(tmp, "effective-tools-receipt.json");
|
|
3377
3414
|
const manifest = {
|
|
@@ -3389,7 +3426,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3389
3426
|
}))),
|
|
3390
3427
|
proxyMode: mcpToolMode === MANAGED_PI_HYBRID_MCP_TOOL_MODE ? "required" : "forbidden",
|
|
3391
3428
|
attestorSourceSha256,
|
|
3392
|
-
configSha256:
|
|
3429
|
+
configSha256: sha2562(readFileSync3(configPath)),
|
|
3393
3430
|
cacheSha256
|
|
3394
3431
|
};
|
|
3395
3432
|
writePrivateFile2(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
@@ -3400,7 +3437,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3400
3437
|
receiptPath,
|
|
3401
3438
|
cacheSha256,
|
|
3402
3439
|
configPath,
|
|
3403
|
-
configSha256:
|
|
3440
|
+
configSha256: sha2562(readFileSync3(configPath)),
|
|
3404
3441
|
attestorSourceSha256,
|
|
3405
3442
|
effectiveSetHash: manifest.effectiveSetHash,
|
|
3406
3443
|
proxyMode: manifest.proxyMode
|
|
@@ -3563,7 +3600,7 @@ ${result3.stderr ?? ""}`, "Pi", MINIMUM_PI_VERSION);
|
|
|
3563
3600
|
sessionId: gateway.sessionId,
|
|
3564
3601
|
sourcePiHome,
|
|
3565
3602
|
piCodingAgentDir,
|
|
3566
|
-
configSha256:
|
|
3603
|
+
configSha256: sha2562(readFileSync3(configPath))
|
|
3567
3604
|
};
|
|
3568
3605
|
return {
|
|
3569
3606
|
profileRoot,
|
|
@@ -5512,6 +5549,187 @@ function agentInstructionDeliveryAudit(bundle, delivery) {
|
|
|
5512
5549
|
};
|
|
5513
5550
|
}
|
|
5514
5551
|
|
|
5552
|
+
// src/amaster-runtime-daemon/agent-instruction-system-kernel-shadow.mjs
|
|
5553
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
5554
|
+
var SHADOW_VERSION = 1;
|
|
5555
|
+
var TARGET_CHARS = 16e3;
|
|
5556
|
+
var USER_RESPONSE_START = "<user-facing-response>";
|
|
5557
|
+
var USER_RESPONSE_END = "</user-facing-response>";
|
|
5558
|
+
var RUNTIME_HEADING = "# AMaster Runtime Contract";
|
|
5559
|
+
var RUNTIME_KERNEL_SECTIONS = /* @__PURE__ */ new Set([
|
|
5560
|
+
"Narrow recovery and terminalization",
|
|
5561
|
+
"Secrets and Safety",
|
|
5562
|
+
"Execution continuity"
|
|
5563
|
+
]);
|
|
5564
|
+
var ROLE_KERNEL_SECTIONS = /* @__PURE__ */ new Set([
|
|
5565
|
+
"How you think",
|
|
5566
|
+
"What you do",
|
|
5567
|
+
"What you do not do",
|
|
5568
|
+
"When you finish"
|
|
5569
|
+
]);
|
|
5570
|
+
function sha256(value) {
|
|
5571
|
+
return createHash5("sha256").update(value, "utf8").digest("hex");
|
|
5572
|
+
}
|
|
5573
|
+
function normalizedText(value) {
|
|
5574
|
+
return typeof value === "string" ? value.trim() : "";
|
|
5575
|
+
}
|
|
5576
|
+
function sectionAudit(scope, section, disposition) {
|
|
5577
|
+
return {
|
|
5578
|
+
scope,
|
|
5579
|
+
heading: section.heading,
|
|
5580
|
+
disposition,
|
|
5581
|
+
chars: section.content.length,
|
|
5582
|
+
sha256: sha256(section.content)
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
function splitH2Sections(content, scope) {
|
|
5586
|
+
const matches = [...content.matchAll(/^## (.+)$/gm)];
|
|
5587
|
+
const sections = [];
|
|
5588
|
+
const preambleEnd = matches[0]?.index ?? content.length;
|
|
5589
|
+
const preamble = content.slice(0, preambleEnd).trim();
|
|
5590
|
+
if (preamble) {
|
|
5591
|
+
sections.push({
|
|
5592
|
+
scope,
|
|
5593
|
+
heading: `${scope}_preamble`,
|
|
5594
|
+
content: preamble
|
|
5595
|
+
});
|
|
5596
|
+
}
|
|
5597
|
+
for (let index = 0; index < matches.length; index += 1) {
|
|
5598
|
+
const match = matches[index];
|
|
5599
|
+
const start = match.index;
|
|
5600
|
+
const end = matches[index + 1]?.index ?? content.length;
|
|
5601
|
+
const sectionContent = content.slice(start, end).trim();
|
|
5602
|
+
if (!sectionContent) continue;
|
|
5603
|
+
sections.push({
|
|
5604
|
+
scope,
|
|
5605
|
+
heading: match[1].trim(),
|
|
5606
|
+
content: sectionContent
|
|
5607
|
+
});
|
|
5608
|
+
}
|
|
5609
|
+
return sections;
|
|
5610
|
+
}
|
|
5611
|
+
function extractUserResponseContract(content) {
|
|
5612
|
+
const start = content.indexOf(USER_RESPONSE_START);
|
|
5613
|
+
if (start === -1) return null;
|
|
5614
|
+
const end = content.indexOf(USER_RESPONSE_END, start);
|
|
5615
|
+
if (end === -1) return null;
|
|
5616
|
+
const contentEnd = end + USER_RESPONSE_END.length;
|
|
5617
|
+
return {
|
|
5618
|
+
start,
|
|
5619
|
+
end: contentEnd,
|
|
5620
|
+
content: content.slice(start, contentEnd).trim()
|
|
5621
|
+
};
|
|
5622
|
+
}
|
|
5623
|
+
function splitManagedLayout(content) {
|
|
5624
|
+
const userResponse = extractUserResponseContract(content);
|
|
5625
|
+
const runtimeStart = content.indexOf(RUNTIME_HEADING);
|
|
5626
|
+
if (!userResponse || runtimeStart === -1 || runtimeStart < userResponse.end) return null;
|
|
5627
|
+
const afterRuntime = content.slice(runtimeStart);
|
|
5628
|
+
const parts = afterRuntime.split(/^---$/gm);
|
|
5629
|
+
if (parts.length < 2) return null;
|
|
5630
|
+
const rolePartIndex = parts.findIndex((part, index) => index > 0 && /^## (?:How you think|What you do|What you do not do|When you finish)$/m.test(part));
|
|
5631
|
+
if (rolePartIndex === -1) return null;
|
|
5632
|
+
const runtime = parts[0].trim();
|
|
5633
|
+
const role = parts.slice(rolePartIndex).join("\n---\n").trim();
|
|
5634
|
+
if (!runtime.startsWith(RUNTIME_HEADING) || !role) return null;
|
|
5635
|
+
return { userResponse: userResponse.content, runtime, role };
|
|
5636
|
+
}
|
|
5637
|
+
function kernelProjection(content) {
|
|
5638
|
+
const layout = splitManagedLayout(content);
|
|
5639
|
+
if (!layout) return null;
|
|
5640
|
+
const selected = [{
|
|
5641
|
+
scope: "response",
|
|
5642
|
+
heading: "User-Facing Response Contract",
|
|
5643
|
+
content: layout.userResponse
|
|
5644
|
+
}];
|
|
5645
|
+
const onDemand = [];
|
|
5646
|
+
for (const section of splitH2Sections(layout.runtime, "runtime")) {
|
|
5647
|
+
if (section.heading === "runtime_preamble" || RUNTIME_KERNEL_SECTIONS.has(section.heading)) {
|
|
5648
|
+
selected.push(section);
|
|
5649
|
+
} else {
|
|
5650
|
+
onDemand.push(section);
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
for (const section of splitH2Sections(layout.role, "role")) {
|
|
5654
|
+
if (section.heading === "role_preamble" || ROLE_KERNEL_SECTIONS.has(section.heading)) {
|
|
5655
|
+
selected.push(section);
|
|
5656
|
+
} else {
|
|
5657
|
+
onDemand.push(section);
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
return {
|
|
5661
|
+
candidate: selected.map((section) => section.content).join("\n\n---\n\n"),
|
|
5662
|
+
selected,
|
|
5663
|
+
onDemand
|
|
5664
|
+
};
|
|
5665
|
+
}
|
|
5666
|
+
function buildAgentInstructionSystemKernelShadow(bundle) {
|
|
5667
|
+
const bundleMode = normalizedText(bundle?.mode).toLowerCase();
|
|
5668
|
+
const source = normalizedText(bundle?.files?.["AGENTS.md"]);
|
|
5669
|
+
const base = {
|
|
5670
|
+
version: SHADOW_VERSION,
|
|
5671
|
+
mode: "shadow_only",
|
|
5672
|
+
activation: "disabled",
|
|
5673
|
+
targetChars: TARGET_CHARS,
|
|
5674
|
+
bundleMode: bundleMode || "unknown",
|
|
5675
|
+
sourceFile: source ? "AGENTS.md" : null
|
|
5676
|
+
};
|
|
5677
|
+
if (!source) {
|
|
5678
|
+
return {
|
|
5679
|
+
candidate: "",
|
|
5680
|
+
audit: {
|
|
5681
|
+
...base,
|
|
5682
|
+
status: "not_applicable",
|
|
5683
|
+
reason: "agents_entry_not_supplied"
|
|
5684
|
+
}
|
|
5685
|
+
};
|
|
5686
|
+
}
|
|
5687
|
+
if (bundleMode !== "managed") {
|
|
5688
|
+
return {
|
|
5689
|
+
candidate: "",
|
|
5690
|
+
audit: {
|
|
5691
|
+
...base,
|
|
5692
|
+
status: "not_applicable",
|
|
5693
|
+
reason: bundleMode === "external" ? "external_instructions_are_user_owned" : "managed_bundle_not_attested",
|
|
5694
|
+
sourceChars: source.length,
|
|
5695
|
+
sourceSha256: sha256(source)
|
|
5696
|
+
}
|
|
5697
|
+
};
|
|
5698
|
+
}
|
|
5699
|
+
const projection = kernelProjection(source);
|
|
5700
|
+
if (!projection) {
|
|
5701
|
+
return {
|
|
5702
|
+
candidate: "",
|
|
5703
|
+
audit: {
|
|
5704
|
+
...base,
|
|
5705
|
+
status: "unavailable",
|
|
5706
|
+
reason: "managed_layout_not_recognized",
|
|
5707
|
+
sourceChars: source.length,
|
|
5708
|
+
sourceSha256: sha256(source)
|
|
5709
|
+
}
|
|
5710
|
+
};
|
|
5711
|
+
}
|
|
5712
|
+
const candidateChars = projection.candidate.length;
|
|
5713
|
+
const reductionChars = source.length - candidateChars;
|
|
5714
|
+
return {
|
|
5715
|
+
candidate: projection.candidate,
|
|
5716
|
+
audit: {
|
|
5717
|
+
...base,
|
|
5718
|
+
status: "candidate_ready",
|
|
5719
|
+
reason: "managed_sections_classified",
|
|
5720
|
+
sourceChars: source.length,
|
|
5721
|
+
sourceSha256: sha256(source),
|
|
5722
|
+
candidateChars,
|
|
5723
|
+
candidateSha256: sha256(projection.candidate),
|
|
5724
|
+
reductionChars,
|
|
5725
|
+
reductionRatio: source.length > 0 ? Number((reductionChars / source.length).toFixed(4)) : 0,
|
|
5726
|
+
withinTarget: candidateChars <= TARGET_CHARS,
|
|
5727
|
+
selectedSections: projection.selected.map((section) => sectionAudit(section.scope, section, "kernel_candidate")),
|
|
5728
|
+
onDemandSections: projection.onDemand.map((section) => sectionAudit(section.scope, section, "on_demand_candidate"))
|
|
5729
|
+
}
|
|
5730
|
+
};
|
|
5731
|
+
}
|
|
5732
|
+
|
|
5515
5733
|
// src/amaster-runtime-daemon/config-state.mjs
|
|
5516
5734
|
import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync5, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "node:fs";
|
|
5517
5735
|
import { homedir as homedir2, hostname } from "node:os";
|
|
@@ -5597,6 +5815,7 @@ var CAPABILITIES = [
|
|
|
5597
5815
|
"run_wakeup",
|
|
5598
5816
|
"runtime_actions_v2",
|
|
5599
5817
|
"model_call",
|
|
5818
|
+
"model_call_output_contract_v1",
|
|
5600
5819
|
"run_cancel",
|
|
5601
5820
|
"run_terminate",
|
|
5602
5821
|
"logs_cost_workspace_status"
|
|
@@ -6434,9 +6653,9 @@ function governedMcpToolResult(structuredContent) {
|
|
|
6434
6653
|
const intentId = readString(effectResult.artifactIntentId);
|
|
6435
6654
|
const manifestId = readString(effectResult.manifestId);
|
|
6436
6655
|
const sourceRelativePath = readString(effectResult.sourceRelativePath);
|
|
6437
|
-
const
|
|
6656
|
+
const sha2562 = readString(effectResult.sha256);
|
|
6438
6657
|
const byteSize = readNumber(effectResult.byteSize, 0);
|
|
6439
|
-
const artifactIntent = providerStatus === "pending_reconcile" && intentId && manifestId && sourceRelativePath && /^[a-f0-9]{64}$/.test(
|
|
6658
|
+
const artifactIntent = providerStatus === "pending_reconcile" && intentId && manifestId && sourceRelativePath && /^[a-f0-9]{64}$/.test(sha2562 ?? "") && Number.isSafeInteger(byteSize) && byteSize > 0 ? { intentId, manifestId, sourceRelativePath, sha256: sha2562, byteSize } : null;
|
|
6440
6659
|
const workspaceDocumentEffect = asRecord(effectResult.workspaceDocumentIntent);
|
|
6441
6660
|
const workspaceDocumentCallId = readString(workspaceDocumentEffect.callId);
|
|
6442
6661
|
const workspaceDocumentManifestId = readString(workspaceDocumentEffect.manifestId);
|
|
@@ -7391,7 +7610,7 @@ var postJsonWithRetry = postRuntimeConnectorJsonWithRetry;
|
|
|
7391
7610
|
var bestEffortPostJson = bestEffortPostRuntimeConnectorJson;
|
|
7392
7611
|
|
|
7393
7612
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
7394
|
-
import { createHash as
|
|
7613
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
7395
7614
|
import { closeSync, constants, fstatSync, lstatSync as lstatSync3, openSync, readFileSync as readFileSync6, realpathSync as realpathSync3 } from "node:fs";
|
|
7396
7615
|
import { isAbsolute as isAbsolute3, relative as relative3, resolve as resolve3 } from "node:path";
|
|
7397
7616
|
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
@@ -7481,7 +7700,7 @@ function prepareRuntimeArtifactUploads(cwd, mcpToolResults) {
|
|
|
7481
7700
|
`Runtime Artifact ${intentId}`,
|
|
7482
7701
|
{ expectedByteSize }
|
|
7483
7702
|
);
|
|
7484
|
-
const actualSha256 =
|
|
7703
|
+
const actualSha256 = createHash6("sha256").update(body).digest("hex");
|
|
7485
7704
|
if (body.length !== expectedByteSize || actualSha256 !== expectedSha256) {
|
|
7486
7705
|
throw new Error(`Runtime Artifact ${intentId} bytes do not match the governed ownership manifest`);
|
|
7487
7706
|
}
|
|
@@ -7498,7 +7717,7 @@ function prepareRuntimeArtifactUploads(cwd, mcpToolResults) {
|
|
|
7498
7717
|
}
|
|
7499
7718
|
|
|
7500
7719
|
// src/amaster-runtime-daemon/runtime-document-upload.mjs
|
|
7501
|
-
import { createHash as
|
|
7720
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
7502
7721
|
|
|
7503
7722
|
// src/amaster-runtime-daemon/workspace-sensitive-path.mjs
|
|
7504
7723
|
var SENSITIVE_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -7573,7 +7792,7 @@ function prepareRuntimeDocumentUploads(cwd, mcpToolResults) {
|
|
|
7573
7792
|
maxByteSize: MAX_WORKSPACE_DOCUMENT_BYTES
|
|
7574
7793
|
}
|
|
7575
7794
|
);
|
|
7576
|
-
const actualSha256 =
|
|
7795
|
+
const actualSha256 = createHash7("sha256").update(body).digest("hex");
|
|
7577
7796
|
if (body.length !== expectedByteSize || actualSha256 !== expectedSha256) {
|
|
7578
7797
|
throw new Error(`Runtime Document ${callId} bytes do not match the governed ownership manifest`);
|
|
7579
7798
|
}
|
|
@@ -7647,9 +7866,9 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
7647
7866
|
let queue = Promise.resolve();
|
|
7648
7867
|
const artifactIdentity = (intent) => {
|
|
7649
7868
|
const sourceRelativePath = readString(asRecord(intent).sourceRelativePath);
|
|
7650
|
-
const
|
|
7869
|
+
const sha2562 = readString(asRecord(intent).sha256);
|
|
7651
7870
|
const byteSize = asRecord(intent).byteSize;
|
|
7652
|
-
return sourceRelativePath &&
|
|
7871
|
+
return sourceRelativePath && sha2562 && Number.isSafeInteger(byteSize) && byteSize > 0 ? `${sourceRelativePath}\0${sha2562}\0${byteSize}` : null;
|
|
7653
7872
|
};
|
|
7654
7873
|
const retainReceipts = (receipts) => {
|
|
7655
7874
|
artifacts.push(...receipts);
|
|
@@ -7699,7 +7918,7 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
7699
7918
|
}
|
|
7700
7919
|
|
|
7701
7920
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
7702
|
-
import { createHash as
|
|
7921
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
7703
7922
|
import { existsSync as existsSync7, mkdirSync as mkdirSync6, realpathSync as realpathSync4, statSync as statSync4 } from "node:fs";
|
|
7704
7923
|
import { basename as basename4, join as join8, isAbsolute as isAbsolute4, relative as relative4, resolve as resolve4 } from "node:path";
|
|
7705
7924
|
|
|
@@ -7825,7 +8044,7 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
7825
8044
|
return cwd;
|
|
7826
8045
|
}
|
|
7827
8046
|
function shortHash(value, length = 12) {
|
|
7828
|
-
return
|
|
8047
|
+
return createHash8("sha256").update(String(value)).digest("hex").slice(0, length);
|
|
7829
8048
|
}
|
|
7830
8049
|
function safeSegment(value, fallback) {
|
|
7831
8050
|
const raw = String(value ?? "").trim();
|
|
@@ -8269,7 +8488,7 @@ function summarizeAmasterRuntimeVersionDrift(input = {}) {
|
|
|
8269
8488
|
}
|
|
8270
8489
|
|
|
8271
8490
|
// src/amaster-runtime-daemon/pi-child-isolation.mjs
|
|
8272
|
-
import { createHash as
|
|
8491
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
8273
8492
|
import {
|
|
8274
8493
|
chmodSync as chmodSync3,
|
|
8275
8494
|
chownSync as chownSync2,
|
|
@@ -8280,7 +8499,7 @@ import {
|
|
|
8280
8499
|
import { resolve as resolve7, sep } from "node:path";
|
|
8281
8500
|
var defaultFs = { chmodSync: chmodSync3, chownSync: chownSync2, lchownSync, lstatSync: lstatSync4, readdirSync: readdirSync6 };
|
|
8282
8501
|
function defaultHashRunId(runId) {
|
|
8283
|
-
return Number.parseInt(
|
|
8502
|
+
return Number.parseInt(createHash9("sha256").update(runId).digest("hex").slice(0, 8), 16);
|
|
8284
8503
|
}
|
|
8285
8504
|
function positiveInteger(value, label) {
|
|
8286
8505
|
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
@@ -8404,7 +8623,7 @@ function preparePiChildIsolation(input) {
|
|
|
8404
8623
|
}
|
|
8405
8624
|
|
|
8406
8625
|
// src/amaster-runtime-daemon/pi-company-memory.mjs
|
|
8407
|
-
import { createHash as
|
|
8626
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
8408
8627
|
import {
|
|
8409
8628
|
chmodSync as chmodSync4,
|
|
8410
8629
|
chownSync as chownSync3,
|
|
@@ -8490,7 +8709,7 @@ function safeCompanyPiHomeSegment(companyId) {
|
|
|
8490
8709
|
const raw = requiredString3(companyId, "companyId");
|
|
8491
8710
|
if (/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(raw)) return raw;
|
|
8492
8711
|
const normalized = raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^[._-]+|[._-]+$/g, "").slice(0, 80);
|
|
8493
|
-
const hash =
|
|
8712
|
+
const hash = createHash10("sha256").update(raw).digest("hex").slice(0, 12);
|
|
8494
8713
|
return normalized ? `${normalized}-${hash}` : `company-${hash}`;
|
|
8495
8714
|
}
|
|
8496
8715
|
function ensureMemoryRoot(root, fs) {
|
|
@@ -8529,7 +8748,7 @@ function allocateCompanyGid(root, companyId, input, fs) {
|
|
|
8529
8748
|
if (groups[companyId]) return groups[companyId];
|
|
8530
8749
|
const used = new Set(Object.values(groups));
|
|
8531
8750
|
const initialOffset = Number.parseInt(
|
|
8532
|
-
|
|
8751
|
+
createHash10("sha256").update(companyId).digest("hex").slice(0, 12),
|
|
8533
8752
|
16
|
|
8534
8753
|
) % gidSpan;
|
|
8535
8754
|
let gid = null;
|
|
@@ -8631,7 +8850,7 @@ function prepareCompanyPiMemory(input, fs = defaultFs2) {
|
|
|
8631
8850
|
}
|
|
8632
8851
|
|
|
8633
8852
|
// src/amaster-runtime-daemon/pi-trusted-runtime-profile.mjs
|
|
8634
|
-
import { createHash as
|
|
8853
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
8635
8854
|
import {
|
|
8636
8855
|
chmodSync as chmodSync5,
|
|
8637
8856
|
copyFileSync as copyFileSync2,
|
|
@@ -8671,7 +8890,7 @@ function sha256File(path, label) {
|
|
|
8671
8890
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
8672
8891
|
throw new Error(`pi_trusted_runtime_source_unsafe:${label}`);
|
|
8673
8892
|
}
|
|
8674
|
-
return
|
|
8893
|
+
return createHash11("sha256").update(readFileSync9(path)).digest("hex");
|
|
8675
8894
|
}
|
|
8676
8895
|
function verifyDeclaredFiles(manifest, root, label, ignoredPaths = [], enforceComplete = true) {
|
|
8677
8896
|
if (!Array.isArray(manifest.files) || manifest.files.length === 0) {
|
|
@@ -8939,12 +9158,12 @@ function materializeTrustedPiRuntimeProfile(input) {
|
|
|
8939
9158
|
// bundle skills were enabled. Absent profile => main skills only.
|
|
8940
9159
|
...skillProfile ? {
|
|
8941
9160
|
skillProfile,
|
|
8942
|
-
enabledSkillsDigest:
|
|
9161
|
+
enabledSkillsDigest: createHash11("sha256").update(JSON.stringify(enabledSkills)).digest("hex")
|
|
8943
9162
|
} : {}
|
|
8944
9163
|
};
|
|
8945
9164
|
return {
|
|
8946
9165
|
facts,
|
|
8947
|
-
attestationId:
|
|
9166
|
+
attestationId: createHash11("sha256").update(JSON.stringify(facts)).digest("hex")
|
|
8948
9167
|
};
|
|
8949
9168
|
}
|
|
8950
9169
|
function assertAuditArgsRedacted(value) {
|
|
@@ -9140,7 +9359,7 @@ function verifyTrustedPiRuntimeAssertion(input) {
|
|
|
9140
9359
|
if (hasSourceAssertion) {
|
|
9141
9360
|
const exactTools = Array.isArray(record7(sourceProfile.tools).exactAllowlist) ? record7(sourceProfile.tools).exactAllowlist : [];
|
|
9142
9361
|
const exactActions = Array.isArray(record7(sourceProfile.actions).exactAllowlist) ? record7(sourceProfile.actions).exactAllowlist : [];
|
|
9143
|
-
const profileHash =
|
|
9362
|
+
const profileHash = createHash11("sha256").update(JSON.stringify(sourceProfile)).digest("hex");
|
|
9144
9363
|
if (assertion.unknownToolMode !== "deny" || maxCalls !== 0 || sourceAssertion.profileVersion !== sourceProfile.purpose || sourceAssertion.profileHash !== profileHash || sourceAssertion.retentionVersion !== sourceProfile.retention || JSON.stringify(sourceAssertion.exactTools) !== JSON.stringify(exactTools) || JSON.stringify(sourceAssertion.exactActions) !== JSON.stringify(exactActions) || sourceAssertion.sourceId !== sourceProfile.sourceId || sourceAssertion.sourceRevisionId !== sourceProfile.sourceRevisionId || sourceAssertion.sourceRevision !== sourceProfile.sourceRevision || sourceAssertion.attemptId !== sourceProfile.attemptId || sourceAssertion.epoch !== sourceProfile.epoch) {
|
|
9145
9364
|
throw new Error("pi_trusted_runtime_assertion_binding_mismatch:sourceAcquisition");
|
|
9146
9365
|
}
|
|
@@ -9169,7 +9388,7 @@ function verifyTrustedPiRuntimeAssertion(input) {
|
|
|
9169
9388
|
|
|
9170
9389
|
// src/amaster-runtime-daemon/workspace-status.mjs
|
|
9171
9390
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
9172
|
-
import { createHash as
|
|
9391
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
9173
9392
|
import { existsSync as existsSync12, readdirSync as readdirSync8, readFileSync as readFileSync10, statSync as statSync7 } from "node:fs";
|
|
9174
9393
|
import { basename as basename5, extname, isAbsolute as isAbsolute7, join as join13, relative as relative7, resolve as resolve10 } from "node:path";
|
|
9175
9394
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
@@ -9240,7 +9459,7 @@ function sanitizeTrackedChange(line) {
|
|
|
9240
9459
|
return isSafeRelativePath(path) ? line : null;
|
|
9241
9460
|
}
|
|
9242
9461
|
function sha256File2(filePath) {
|
|
9243
|
-
return
|
|
9462
|
+
return createHash12("sha256").update(readFileSync10(filePath)).digest("hex");
|
|
9244
9463
|
}
|
|
9245
9464
|
function artifactHashCacheKey(relativePath, stat) {
|
|
9246
9465
|
return `${relativePath}\0${stat.size}\0${stat.mtimeMs}`;
|
|
@@ -9441,7 +9660,7 @@ function readWorkspaceStatus(cwd, opts = {}) {
|
|
|
9441
9660
|
}
|
|
9442
9661
|
|
|
9443
9662
|
// src/amaster-runtime-daemon/pi-browser-session-adapter.mjs
|
|
9444
|
-
import { createHash as
|
|
9663
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
9445
9664
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
9446
9665
|
import { existsSync as existsSync13 } from "node:fs";
|
|
9447
9666
|
import {
|
|
@@ -9564,7 +9783,7 @@ function fail(code) {
|
|
|
9564
9783
|
throw Object.assign(new Error(code), { code });
|
|
9565
9784
|
}
|
|
9566
9785
|
function profileName(identity2) {
|
|
9567
|
-
return
|
|
9786
|
+
return createHash13("sha256").update(`${identity2.companyId}\0${identity2.bindingId}\0${identity2.localOpaqueRef}`).digest("hex");
|
|
9568
9787
|
}
|
|
9569
9788
|
function expectedMarker(identity2) {
|
|
9570
9789
|
return {
|
|
@@ -9963,7 +10182,7 @@ async function executeBrowserSessionCommand(command, dependencies = {}) {
|
|
|
9963
10182
|
}
|
|
9964
10183
|
|
|
9965
10184
|
// src/amaster-runtime-daemon/source-acquisition-invocation.mjs
|
|
9966
|
-
import { createHash as
|
|
10185
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
9967
10186
|
var SOURCE_ACQUISITION_PUBLIC_TOOLS = Object.freeze([
|
|
9968
10187
|
"source_open",
|
|
9969
10188
|
"source_snapshot",
|
|
@@ -10000,7 +10219,7 @@ function serializeSourceAcquisitionProfile(profile) {
|
|
|
10000
10219
|
const input = Buffer.from(JSON.stringify(profile), "utf8");
|
|
10001
10220
|
return {
|
|
10002
10221
|
input,
|
|
10003
|
-
sha256:
|
|
10222
|
+
sha256: createHash14("sha256").update(input).digest("hex")
|
|
10004
10223
|
};
|
|
10005
10224
|
}
|
|
10006
10225
|
function sourceAcquisitionManagedInputs(options) {
|
|
@@ -10036,7 +10255,7 @@ function assertSourceAcquisitionRuntimeAuthority({
|
|
|
10036
10255
|
}
|
|
10037
10256
|
|
|
10038
10257
|
// src/amaster-runtime-daemon.mjs
|
|
10039
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
10258
|
+
var CONNECTOR_VERSION = "0.1.1-beta.22";
|
|
10040
10259
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
10041
10260
|
var SOURCE_ACQUISITION_CAPABILITY = "source_acquisition_v1";
|
|
10042
10261
|
var SOURCE_ACQUISITION_PROFILE_VERSION = "source_acquisition_v1";
|
|
@@ -11370,7 +11589,7 @@ function sourceAcquisitionRuntimeProfile(config, command) {
|
|
|
11370
11589
|
if (!companyId || !bindingId || !/^profile_[a-z0-9]{16,64}$/i.test(localOpaqueRef ?? "")) {
|
|
11371
11590
|
throw new Error("source_acquisition_profile_invalid");
|
|
11372
11591
|
}
|
|
11373
|
-
const profileName2 =
|
|
11592
|
+
const profileName2 = createHash15("sha256").update(`${companyId}\0${bindingId}\0${localOpaqueRef}`).digest("hex");
|
|
11374
11593
|
const stateRoot = resolve12(config.browserSessionStateRoot);
|
|
11375
11594
|
const userDataDir = resolve12(stateRoot, profileName2);
|
|
11376
11595
|
if (!pathWithin2(userDataDir, stateRoot)) throw new Error("source_acquisition_browser_profile_invalid");
|
|
@@ -11541,6 +11760,7 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
11541
11760
|
suppliedFiles: agentInstructionFileNames(agentInstructionsBundle)
|
|
11542
11761
|
});
|
|
11543
11762
|
const agentInstructions = renderAgentInstructionsBundle(agentInstructionsBundle, agentInstructionDelivery);
|
|
11763
|
+
const agentInstructionSystemKernelShadow = buildAgentInstructionSystemKernelShadow(agentInstructionsBundle);
|
|
11544
11764
|
const runtimeAuth = commandRuntimeAuth(command);
|
|
11545
11765
|
const hasGovernedMcp = Object.keys(asRecord(runtimeAuth.governedMcp)).length > 0;
|
|
11546
11766
|
const attachmentsText = materializedAttachments.length > 0 ? [
|
|
@@ -11597,7 +11817,8 @@ function buildCommandPrompt(command, workspace, materializedAttachments = [], op
|
|
|
11597
11817
|
agentInstructionDelivery: agentInstructionDeliveryAudit(
|
|
11598
11818
|
agentInstructionsBundle,
|
|
11599
11819
|
agentInstructionDelivery
|
|
11600
|
-
)
|
|
11820
|
+
),
|
|
11821
|
+
agentInstructionSystemKernelShadow: agentInstructionSystemKernelShadow.audit
|
|
11601
11822
|
}
|
|
11602
11823
|
};
|
|
11603
11824
|
}
|
|
@@ -11721,6 +11942,16 @@ function sanitizePiExtraArgs(value) {
|
|
|
11721
11942
|
function nativeSessionResumeEnabled(session) {
|
|
11722
11943
|
return process.env.AMASTER_RUNTIME_ENABLE_NATIVE_SESSION_RESUME === "true" || readString(session.mode) === "governed_action_approval" && session.required === true;
|
|
11723
11944
|
}
|
|
11945
|
+
function modelCallResponseContract(payload) {
|
|
11946
|
+
if (payload.responseContract === void 0) return null;
|
|
11947
|
+
const contract = asRecord(payload.responseContract);
|
|
11948
|
+
const maxOutputTokens = Number(contract.maxOutputTokens);
|
|
11949
|
+
const maxSemanticBytes = Number(contract.maxSemanticBytes);
|
|
11950
|
+
if (readString(contract.format) !== "json" || readString(contract.thinking) !== "off" || !Number.isSafeInteger(maxOutputTokens) || maxOutputTokens < 1 || maxOutputTokens > 131072 || !Number.isSafeInteger(maxSemanticBytes) || maxSemanticBytes < 1024 || maxSemanticBytes > 256 * 1024) {
|
|
11951
|
+
throw new Error("model_call_response_contract_invalid");
|
|
11952
|
+
}
|
|
11953
|
+
return { format: "json", thinking: "off", maxOutputTokens, maxSemanticBytes };
|
|
11954
|
+
}
|
|
11724
11955
|
function resolveNativeSessionRequest(command, workspace) {
|
|
11725
11956
|
const payload = asRecord(command.payload);
|
|
11726
11957
|
const session = asRecord(payload.nativeSession);
|
|
@@ -11754,17 +11985,21 @@ function resolveNativeSessionRequest(command, workspace) {
|
|
|
11754
11985
|
...enabled && requested && sessionId && requestedCwd && !cwdMatched ? { skippedReason: "native_session_cwd_mismatch" } : {}
|
|
11755
11986
|
};
|
|
11756
11987
|
}
|
|
11757
|
-
function buildExecutorInvocation(executor, command = {}, workspace = null) {
|
|
11988
|
+
function buildExecutorInvocation(executor, command = {}, workspace = null, options = {}) {
|
|
11758
11989
|
const payload = asRecord(command.payload);
|
|
11759
11990
|
if (command.commandType === "model_call") {
|
|
11760
11991
|
if (executor.kind === "pi") {
|
|
11761
11992
|
const args = ["--mode", "json"];
|
|
11993
|
+
const responseContract = options.responseContract ?? null;
|
|
11762
11994
|
const provider = readString(payload.provider) ?? readString(process.env.AMASTER_PI_PROVIDER);
|
|
11763
|
-
const
|
|
11995
|
+
const configuredModel = readString(payload.model) ?? readString(process.env.AMASTER_PI_MODEL);
|
|
11996
|
+
const model = responseContract ? normalizePiModelId(configuredModel) : configuredModel;
|
|
11764
11997
|
if (provider) args.push("--provider", provider);
|
|
11765
11998
|
if (model) args.push("--model", model);
|
|
11999
|
+
if (responseContract?.thinking) args.push("--thinking", responseContract.thinking);
|
|
11766
12000
|
args.push(...sanitizePiExtraArgs(process.env.AMASTER_PI_EXTRA_ARGS));
|
|
11767
12001
|
args.push("--no-extensions", "--no-skills", "--no-session", "--no-tools");
|
|
12002
|
+
if (responseContract) args.push("--no-context-files");
|
|
11768
12003
|
args.push("-p");
|
|
11769
12004
|
return { command: executor.command, args, stdin: "prompt" };
|
|
11770
12005
|
}
|
|
@@ -11852,7 +12087,8 @@ async function executeModelCallCommand(config, command, signal) {
|
|
|
11852
12087
|
if (!prompt) {
|
|
11853
12088
|
throw new Error("model_call command requires a prompt");
|
|
11854
12089
|
}
|
|
11855
|
-
const
|
|
12090
|
+
const responseContract = modelCallResponseContract(payload);
|
|
12091
|
+
const invocation = buildExecutorInvocation(executor, command, null, { responseContract });
|
|
11856
12092
|
const timeoutSeconds = Math.max(1, Math.min(
|
|
11857
12093
|
config.executorTimeoutSeconds,
|
|
11858
12094
|
readNumber(payload.timeoutSeconds, Math.min(config.executorTimeoutSeconds, 60))
|
|
@@ -11884,6 +12120,16 @@ async function executeModelCallCommand(config, command, signal) {
|
|
|
11884
12120
|
piModelCallProfile.env.PI_CODING_AGENT_DIR,
|
|
11885
12121
|
resolvePiExecutorProviderConfig(config, command, baseEnv)
|
|
11886
12122
|
);
|
|
12123
|
+
if (responseContract) {
|
|
12124
|
+
const provider = readString(payload.provider) ?? readString(process.env.AMASTER_PI_PROVIDER);
|
|
12125
|
+
const model = readString(payload.model) ?? readString(process.env.AMASTER_PI_MODEL);
|
|
12126
|
+
applyModelCallOutputContract(
|
|
12127
|
+
piModelCallProfile.env.PI_CODING_AGENT_DIR,
|
|
12128
|
+
provider,
|
|
12129
|
+
model,
|
|
12130
|
+
responseContract.maxOutputTokens
|
|
12131
|
+
);
|
|
12132
|
+
}
|
|
11887
12133
|
}
|
|
11888
12134
|
execution = await runExecutor(invocation.command, invocation.args, {
|
|
11889
12135
|
cwd: process.cwd(),
|
|
@@ -11907,9 +12153,13 @@ async function executeModelCallCommand(config, command, signal) {
|
|
|
11907
12153
|
const hasOutputFlood = Boolean(readString(outputFlood.stream) && readNumber(outputFlood.bytes, 0) > 0);
|
|
11908
12154
|
const timedOut = execution.timedOut === true;
|
|
11909
12155
|
const parsed = hasOutputFlood ? { summary: "", usage: null, errorMessage: null, messages: [] } : executor.kind === "pi" ? parsePiJsonl(execution.stdout) : parseGenericOutput(execution.stdout, execution.stderr);
|
|
11910
|
-
const
|
|
11911
|
-
const
|
|
11912
|
-
const
|
|
12156
|
+
const rawSummary = parsed.summary || parsed.finalMessage || parsed.messages?.join("\n\n") || "";
|
|
12157
|
+
const semanticBytes = Buffer.byteLength(rawSummary, "utf8");
|
|
12158
|
+
const semanticOutputExceeded = Boolean(responseContract && semanticBytes > responseContract.maxSemanticBytes);
|
|
12159
|
+
const summary = semanticOutputExceeded ? "" : responseContract ? rawSummary : truncateText(rawSummary, 8e3);
|
|
12160
|
+
const hasTerminalCompletion = !responseContract || executor.kind !== "pi" || Boolean(parsed.terminalEventType);
|
|
12161
|
+
const succeeded = !hasOutputFlood && !timedOut && !semanticOutputExceeded && !execution.spawnError && execution.exitCode === 0 && hasTerminalCompletion && !parsed.errorMessage && Boolean(summary);
|
|
12162
|
+
const error = timedOut ? `Runtime model call timed out after ${timeoutSeconds}s` : execution.spawnError ?? parsed.errorMessage ?? (hasOutputFlood ? `Runtime model call output flood: ${readString(outputFlood.stream)} exceeded ${readNumber(outputFlood.limitBytes, 0)} bytes` : semanticOutputExceeded ? `Runtime model call semantic output exceeded ${responseContract.maxSemanticBytes} bytes` : !hasTerminalCompletion ? "Runtime model call exited without a terminal provider response" : succeeded ? null : `Runtime model call exited with code ${execution.exitCode ?? "unknown"}`);
|
|
11913
12163
|
await completeCommand(config, command, succeeded ? "succeeded" : "failed", {
|
|
11914
12164
|
callType: "model_call",
|
|
11915
12165
|
executorKind: executor.kind,
|
|
@@ -11920,7 +12170,21 @@ async function executeModelCallCommand(config, command, signal) {
|
|
|
11920
12170
|
timedOut,
|
|
11921
12171
|
summary,
|
|
11922
12172
|
usage: parsed.usage,
|
|
11923
|
-
|
|
12173
|
+
...responseContract ? {
|
|
12174
|
+
driver: "pi_cli_json_v1",
|
|
12175
|
+
responseContract,
|
|
12176
|
+
stopReason: parsed.stopReason ?? null,
|
|
12177
|
+
terminalEventType: parsed.terminalEventType ?? null,
|
|
12178
|
+
semanticBytes,
|
|
12179
|
+
outputBytes: Object.values(execution.outputBytes).reduce((total, bytes) => total + bytes, 0),
|
|
12180
|
+
outputBytesByStream: execution.outputBytes,
|
|
12181
|
+
retainedOutputBytes: Object.values(execution.retainedOutputBytes).reduce((total, bytes) => total + bytes, 0),
|
|
12182
|
+
retainedOutputBytesByStream: execution.retainedOutputBytes
|
|
12183
|
+
} : {},
|
|
12184
|
+
// Contracted model calls persist semantic output and metadata only. Pi's
|
|
12185
|
+
// JSONL stdout may contain provider reasoning/event content, so retaining
|
|
12186
|
+
// even a bounded tail would violate the response-contract data boundary.
|
|
12187
|
+
stdout: responseContract ? "" : truncateText(execution.stdout, 8e3),
|
|
11924
12188
|
stderr: truncateText(filterExecutionStderrForResult(executor.kind, execution.stderr), 8e3),
|
|
11925
12189
|
...hasOutputFlood ? {
|
|
11926
12190
|
errorCode: "model_call_output_flood",
|
|
@@ -11930,6 +12194,12 @@ async function executeModelCallCommand(config, command, signal) {
|
|
|
11930
12194
|
bytes: readNumber(outputFlood.bytes, 0),
|
|
11931
12195
|
limitBytes: readNumber(outputFlood.limitBytes, maxOutputBytes)
|
|
11932
12196
|
}
|
|
12197
|
+
} : semanticOutputExceeded ? {
|
|
12198
|
+
errorCode: "model_call_semantic_output_exceeded",
|
|
12199
|
+
errorFamily: "validation"
|
|
12200
|
+
} : responseContract && !hasTerminalCompletion ? {
|
|
12201
|
+
errorCode: "model_call_terminal_event_missing",
|
|
12202
|
+
errorFamily: "provider_protocol"
|
|
11933
12203
|
} : {}
|
|
11934
12204
|
}, error ?? void 0);
|
|
11935
12205
|
}
|
|
@@ -14202,7 +14472,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
14202
14472
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
14203
14473
|
writeFileSync9(targetPath, body);
|
|
14204
14474
|
const attachmentId = readString(attachment.id);
|
|
14205
|
-
const actualSha256 =
|
|
14475
|
+
const actualSha256 = createHash15("sha256").update(body).digest("hex");
|
|
14206
14476
|
const lineageCandidates = lineageCandidatesByAttachmentId.get(attachmentId) ?? [];
|
|
14207
14477
|
const lineage = selectAttachmentLineage(lineageCandidates, actualSha256);
|
|
14208
14478
|
if (lineageCandidates.length > 0 && !lineage) {
|
|
@@ -14283,10 +14553,10 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
14283
14553
|
const entry = asRecord(rawEntry);
|
|
14284
14554
|
const workProductId = readString(entry.workProductId);
|
|
14285
14555
|
const attachmentId = readString(entry.attachmentId);
|
|
14286
|
-
const
|
|
14556
|
+
const sha2562 = readString(entry.sha256);
|
|
14287
14557
|
const contentPath = readString(entry.contentPath);
|
|
14288
14558
|
const byteSize = readNumber(entry.byteSize, null);
|
|
14289
|
-
if (!workProductId || !attachmentId || !/^[a-f0-9]{64}$/i.test(
|
|
14559
|
+
if (!workProductId || !attachmentId || !/^[a-f0-9]{64}$/i.test(sha2562 ?? "") || !contentPath || byteSize === null) {
|
|
14290
14560
|
throw new Error(`artifact_input_manifest_invalid: entry ${index} is incomplete`);
|
|
14291
14561
|
}
|
|
14292
14562
|
const expectedContentPath = `/api/attachments/${attachmentId}/content`;
|
|
@@ -14294,10 +14564,10 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
14294
14564
|
throw new Error(`artifact_input_manifest_invalid: entry ${index} contentPath does not match attachmentId`);
|
|
14295
14565
|
}
|
|
14296
14566
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
14297
|
-
const actualSha256 =
|
|
14298
|
-
if (body.byteLength !== byteSize || actualSha256 !==
|
|
14567
|
+
const actualSha256 = createHash15("sha256").update(body).digest("hex");
|
|
14568
|
+
if (body.byteLength !== byteSize || actualSha256 !== sha2562) {
|
|
14299
14569
|
throw new Error(
|
|
14300
|
-
`artifact_input_integrity_mismatch: workProductId=${workProductId} expectedBytes=${byteSize} actualBytes=${body.byteLength} expectedSha256=${
|
|
14570
|
+
`artifact_input_integrity_mismatch: workProductId=${workProductId} expectedBytes=${byteSize} actualBytes=${body.byteLength} expectedSha256=${sha2562} actualSha256=${actualSha256}`
|
|
14301
14571
|
);
|
|
14302
14572
|
}
|
|
14303
14573
|
const sourceDir = safeArtifactInputSourceDir(entry, index);
|
|
@@ -14327,7 +14597,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
14327
14597
|
relativePath,
|
|
14328
14598
|
contentType: readString(entry.contentType),
|
|
14329
14599
|
byteSize: body.byteLength,
|
|
14330
|
-
sha256,
|
|
14600
|
+
sha256: sha2562,
|
|
14331
14601
|
contentPath
|
|
14332
14602
|
});
|
|
14333
14603
|
}
|
|
@@ -14364,7 +14634,7 @@ function safeCheckpointRelativePath(rawPath) {
|
|
|
14364
14634
|
return normalized;
|
|
14365
14635
|
}
|
|
14366
14636
|
function hashFileSha256(filePath) {
|
|
14367
|
-
return
|
|
14637
|
+
return createHash15("sha256").update(readFileSync11(filePath)).digest("hex");
|
|
14368
14638
|
}
|
|
14369
14639
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
14370
14640
|
const checkpointDir = issueCheckpointDir(workspace);
|
package/dist/amaster-runtime.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
6
6
|
import { homedir, hostname } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
|
-
const CONNECTOR_VERSION = "0.1.1-beta.
|
|
9
|
+
const CONNECTOR_VERSION = "0.1.1-beta.22";
|
|
10
10
|
|
|
11
11
|
const CAPABILITIES = [
|
|
12
12
|
"remote_registration",
|
|
@@ -16,6 +16,7 @@ const CAPABILITIES = [
|
|
|
16
16
|
"run_wakeup",
|
|
17
17
|
"runtime_actions_v2",
|
|
18
18
|
"model_call",
|
|
19
|
+
"model_call_output_contract_v1",
|
|
19
20
|
"run_cancel",
|
|
20
21
|
"run_terminate",
|
|
21
22
|
"logs_cost_workspace_status",
|