@amaster.ai/employee-runtime-connector 0.1.1-beta.124 → 0.1.1-beta.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/amaster-runtime-daemon.mjs +276 -235
- package/dist/amaster-runtime.mjs +1 -1
- package/package.json +1 -1
|
@@ -12372,6 +12372,13 @@ var updateCompanySandboxControlSchema = external_exports.object({
|
|
|
12372
12372
|
var restartCompanySandboxSchema = external_exports.object({
|
|
12373
12373
|
reason: external_exports.string().trim().min(1).max(500).optional()
|
|
12374
12374
|
}).strict();
|
|
12375
|
+
var adminSandboxControlSchema = external_exports.object({
|
|
12376
|
+
desiredState: external_exports.enum(COMPANY_SANDBOX_DESIRED_STATES),
|
|
12377
|
+
reason: external_exports.string().trim().min(1).max(500)
|
|
12378
|
+
}).strict();
|
|
12379
|
+
var adminSandboxRestartSchema = external_exports.object({
|
|
12380
|
+
reason: external_exports.string().trim().min(1).max(500)
|
|
12381
|
+
}).strict();
|
|
12375
12382
|
var updateCompanyBrandingSchema = external_exports.object({
|
|
12376
12383
|
name: external_exports.string().min(1).optional(),
|
|
12377
12384
|
description: external_exports.string().nullable().optional(),
|
|
@@ -15332,9 +15339,9 @@ var completeCompanyCreationReviewSchema = external_exports.object({
|
|
|
15332
15339
|
}).strict();
|
|
15333
15340
|
|
|
15334
15341
|
// src/amaster-runtime-daemon.mjs
|
|
15335
|
-
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as
|
|
15342
|
+
import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as realpathSync7, renameSync as renameSync9, rmSync as rmSync9, statSync as statSync9, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync11 } from "node:fs";
|
|
15336
15343
|
import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3, tmpdir } from "node:os";
|
|
15337
|
-
import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as
|
|
15344
|
+
import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as join16, relative as relative8, resolve as resolve13 } from "node:path";
|
|
15338
15345
|
import { spawn, spawnSync as spawnSync5 } from "node:child_process";
|
|
15339
15346
|
|
|
15340
15347
|
// src/amaster-runtime-daemon/common.mjs
|
|
@@ -23628,8 +23635,105 @@ ${resolvedDependencies.details.content}` : ""
|
|
|
23628
23635
|
|
|
23629
23636
|
// src/amaster-runtime-daemon/agent-instruction-delivery.mjs
|
|
23630
23637
|
import { createHash as createHash8, randomBytes as randomBytes2 } from "node:crypto";
|
|
23631
|
-
import { existsSync as
|
|
23632
|
-
import { dirname as
|
|
23638
|
+
import { existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync9, readdirSync as readdirSync6, realpathSync as realpathSync4, renameSync as renameSync6, rmSync as rmSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
23639
|
+
import { dirname as dirname6, isAbsolute as isAbsolute4, join as join8, relative as relative3, resolve as resolve4 } from "node:path";
|
|
23640
|
+
|
|
23641
|
+
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
23642
|
+
import { chownSync as chownSync3, existsSync as existsSync6, readFileSync as readFileSync8, renameSync as renameSync5, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
23643
|
+
import { basename as basename3, dirname as dirname5, join as join7 } from "node:path";
|
|
23644
|
+
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
23645
|
+
function syncManifestDirOwnership(manifestPath, deps = {}) {
|
|
23646
|
+
const stat = deps.statSync ?? statSync3;
|
|
23647
|
+
const chown = deps.chownSync ?? chownSync3;
|
|
23648
|
+
const geteuid = deps.geteuid ?? (typeof process.geteuid === "function" ? process.geteuid.bind(process) : () => null);
|
|
23649
|
+
try {
|
|
23650
|
+
if (geteuid() !== 0) return false;
|
|
23651
|
+
const dirStat = stat(dirname5(manifestPath));
|
|
23652
|
+
if (dirStat.uid === 0 && dirStat.gid === 0) return false;
|
|
23653
|
+
chown(manifestPath, dirStat.uid, dirStat.gid);
|
|
23654
|
+
return true;
|
|
23655
|
+
} catch {
|
|
23656
|
+
return false;
|
|
23657
|
+
}
|
|
23658
|
+
}
|
|
23659
|
+
function nowIso() {
|
|
23660
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
23661
|
+
}
|
|
23662
|
+
function workspaceManifestPath(workspaceOrCwd) {
|
|
23663
|
+
if (!workspaceOrCwd) return null;
|
|
23664
|
+
if (typeof workspaceOrCwd === "string") return join7(workspaceOrCwd, WORKSPACE_MANIFEST_FILENAME);
|
|
23665
|
+
if (typeof workspaceOrCwd.cwd === "string") return join7(workspaceOrCwd.cwd, WORKSPACE_MANIFEST_FILENAME);
|
|
23666
|
+
return null;
|
|
23667
|
+
}
|
|
23668
|
+
function readWorkspaceManifest(manifestPath) {
|
|
23669
|
+
if (!manifestPath || !existsSync6(manifestPath)) return null;
|
|
23670
|
+
try {
|
|
23671
|
+
const parsed = JSON.parse(readFileSync8(manifestPath, "utf8"));
|
|
23672
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
23673
|
+
} catch {
|
|
23674
|
+
return null;
|
|
23675
|
+
}
|
|
23676
|
+
}
|
|
23677
|
+
function writeWorkspaceManifest(manifestPath, manifest, deps) {
|
|
23678
|
+
const tempPath = join7(
|
|
23679
|
+
dirname5(manifestPath),
|
|
23680
|
+
`.${basename3(manifestPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
23681
|
+
);
|
|
23682
|
+
try {
|
|
23683
|
+
writeFileSync6(tempPath, `${JSON.stringify(manifest, null, 2)}
|
|
23684
|
+
`, { mode: 384 });
|
|
23685
|
+
renameSync5(tempPath, manifestPath);
|
|
23686
|
+
syncManifestDirOwnership(manifestPath, deps);
|
|
23687
|
+
} catch (err) {
|
|
23688
|
+
rmSync4(tempPath, { force: true });
|
|
23689
|
+
throw err;
|
|
23690
|
+
}
|
|
23691
|
+
return manifest;
|
|
23692
|
+
}
|
|
23693
|
+
function createWorkspaceManifest(workspace, input = {}) {
|
|
23694
|
+
const manifestPath = workspaceManifestPath(workspace);
|
|
23695
|
+
const createdAt = nowIso();
|
|
23696
|
+
const manifest = {
|
|
23697
|
+
version: 2,
|
|
23698
|
+
managed: true,
|
|
23699
|
+
sourceWorkspacePath: workspace.sourceWorkspacePath,
|
|
23700
|
+
managedCwd: workspace.cwd,
|
|
23701
|
+
executionWorkdir: workspace.cwd,
|
|
23702
|
+
executorKind: input.executorKind ?? null,
|
|
23703
|
+
executorHome: workspace.executorHome ?? null,
|
|
23704
|
+
commandId: input.commandId ?? null,
|
|
23705
|
+
generation: input.generation ?? null,
|
|
23706
|
+
runId: input.runId ?? null,
|
|
23707
|
+
issueId: input.issueId ?? null,
|
|
23708
|
+
workspaceKey: workspace.workspaceKey ?? null,
|
|
23709
|
+
issueKey: workspace.issueKey ?? null,
|
|
23710
|
+
runKey: workspace.runKey ?? null,
|
|
23711
|
+
createdAt,
|
|
23712
|
+
lastTouchedAt: createdAt,
|
|
23713
|
+
lastWorkspaceScanAt: null,
|
|
23714
|
+
artifactCandidateCount: 0,
|
|
23715
|
+
artifactCandidates: [],
|
|
23716
|
+
outboxPending: 0
|
|
23717
|
+
};
|
|
23718
|
+
return writeWorkspaceManifest(manifestPath, manifest);
|
|
23719
|
+
}
|
|
23720
|
+
function updateWorkspaceManifest(workspaceOrManifestPath, patch = {}) {
|
|
23721
|
+
const manifestPath = typeof workspaceOrManifestPath === "string" ? workspaceOrManifestPath : workspaceManifestPath(workspaceOrManifestPath);
|
|
23722
|
+
if (!manifestPath) return null;
|
|
23723
|
+
const current = readWorkspaceManifest(manifestPath) ?? {
|
|
23724
|
+
version: 2,
|
|
23725
|
+
managed: true,
|
|
23726
|
+
createdAt: nowIso()
|
|
23727
|
+
};
|
|
23728
|
+
const next = {
|
|
23729
|
+
...current,
|
|
23730
|
+
...patch,
|
|
23731
|
+
lastTouchedAt: nowIso()
|
|
23732
|
+
};
|
|
23733
|
+
return writeWorkspaceManifest(manifestPath, next);
|
|
23734
|
+
}
|
|
23735
|
+
|
|
23736
|
+
// src/amaster-runtime-daemon/agent-instruction-delivery.mjs
|
|
23633
23737
|
var PROJECT_INSTRUCTION_NAMES = /* @__PURE__ */ new Set(["AGENTS.md", "AGENTS.override.md"]);
|
|
23634
23738
|
var PROJECT_INSTRUCTION_SCAN_IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
23635
23739
|
".git",
|
|
@@ -23645,13 +23749,55 @@ var PROJECT_INSTRUCTION_SCAN_MAX_DIRECTORIES = 5e4;
|
|
|
23645
23749
|
function instructionTopologyError(code, message, details = {}) {
|
|
23646
23750
|
return Object.assign(new Error(`${code}: ${message}`), { code, details });
|
|
23647
23751
|
}
|
|
23648
|
-
function
|
|
23752
|
+
function pathWithin(candidate, root) {
|
|
23753
|
+
const rel = relative3(root, candidate);
|
|
23754
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
23755
|
+
}
|
|
23756
|
+
function lstatIfPresent(path) {
|
|
23757
|
+
try {
|
|
23758
|
+
return lstatSync4(path);
|
|
23759
|
+
} catch (error) {
|
|
23760
|
+
if (error?.code === "ENOENT") return null;
|
|
23761
|
+
throw error;
|
|
23762
|
+
}
|
|
23763
|
+
}
|
|
23764
|
+
function canonicalExistingPath(path) {
|
|
23765
|
+
try {
|
|
23766
|
+
return realpathSync4(resolve4(path));
|
|
23767
|
+
} catch {
|
|
23768
|
+
return resolve4(path);
|
|
23769
|
+
}
|
|
23770
|
+
}
|
|
23771
|
+
function isManagedExecutionDirectory(directory, managedWorkspacesRoot) {
|
|
23772
|
+
if (typeof managedWorkspacesRoot !== "string" || !managedWorkspacesRoot.trim()) return false;
|
|
23773
|
+
const managedRoot = canonicalExistingPath(managedWorkspacesRoot);
|
|
23774
|
+
const candidate = canonicalExistingPath(directory);
|
|
23775
|
+
if (!pathWithin(candidate, managedRoot)) return false;
|
|
23776
|
+
const manifestPath = join8(candidate, WORKSPACE_MANIFEST_FILENAME);
|
|
23777
|
+
const manifestStat = lstatIfPresent(manifestPath);
|
|
23778
|
+
if (!manifestStat?.isFile() || manifestStat.isSymbolicLink()) return false;
|
|
23779
|
+
try {
|
|
23780
|
+
const manifest = JSON.parse(readFileSync9(manifestPath, "utf8"));
|
|
23781
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || manifest.managed !== true) {
|
|
23782
|
+
return false;
|
|
23783
|
+
}
|
|
23784
|
+
return [manifest.managedCwd, manifest.executionWorkdir].some((value) => typeof value === "string" && isAbsolute4(value) && canonicalExistingPath(value) === candidate);
|
|
23785
|
+
} catch {
|
|
23786
|
+
return false;
|
|
23787
|
+
}
|
|
23788
|
+
}
|
|
23789
|
+
function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath, options = {}) {
|
|
23649
23790
|
const root = resolve4(sourceWorkspacePath);
|
|
23650
23791
|
const pending = [root];
|
|
23651
23792
|
const sources = [];
|
|
23793
|
+
const ignoredManagedExecutionDirectories = [];
|
|
23652
23794
|
let visitedDirectories = 0;
|
|
23653
23795
|
while (pending.length > 0) {
|
|
23654
23796
|
const directory = pending.pop();
|
|
23797
|
+
if (isManagedExecutionDirectory(directory, options.managedWorkspacesRoot)) {
|
|
23798
|
+
ignoredManagedExecutionDirectories.push(relative3(root, directory).replaceAll("\\", "/") || ".");
|
|
23799
|
+
continue;
|
|
23800
|
+
}
|
|
23655
23801
|
visitedDirectories += 1;
|
|
23656
23802
|
if (visitedDirectories > PROJECT_INSTRUCTION_SCAN_MAX_DIRECTORIES) {
|
|
23657
23803
|
throw instructionTopologyError(
|
|
@@ -23695,7 +23841,7 @@ function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath) {
|
|
|
23695
23841
|
`project instruction source is not a regular file: ${relativePath}`
|
|
23696
23842
|
);
|
|
23697
23843
|
}
|
|
23698
|
-
const content =
|
|
23844
|
+
const content = readFileSync9(absolutePath);
|
|
23699
23845
|
sources.push({
|
|
23700
23846
|
path: relativePath,
|
|
23701
23847
|
scope: relativePath.includes("/") ? relativePath.slice(0, relativePath.lastIndexOf("/")) : ".",
|
|
@@ -23705,26 +23851,17 @@ function inspectExternalWorkspaceProjectInstructions(sourceWorkspacePath) {
|
|
|
23705
23851
|
}
|
|
23706
23852
|
}
|
|
23707
23853
|
sources.sort((left, right) => left.path.localeCompare(right.path));
|
|
23854
|
+
ignoredManagedExecutionDirectories.sort((left, right) => left.localeCompare(right));
|
|
23708
23855
|
return {
|
|
23709
23856
|
schemaVersion: "mirrorx.workspace-project-instruction-scan.v1",
|
|
23710
23857
|
status: sources.length === 0 ? "absent_verified" : "present_verified",
|
|
23711
23858
|
visitedDirectories,
|
|
23712
23859
|
sources,
|
|
23713
|
-
topologySha256: createHash8("sha256").update(JSON.stringify(sources)).digest("hex")
|
|
23860
|
+
topologySha256: createHash8("sha256").update(JSON.stringify(sources)).digest("hex"),
|
|
23861
|
+
ignoredManagedExecutionDirectoryCount: ignoredManagedExecutionDirectories.length,
|
|
23862
|
+
ignoredManagedExecutionDirectoriesSha256: createHash8("sha256").update(JSON.stringify(ignoredManagedExecutionDirectories)).digest("hex")
|
|
23714
23863
|
};
|
|
23715
23864
|
}
|
|
23716
|
-
function pathWithin(candidate, root) {
|
|
23717
|
-
const rel = relative3(root, candidate);
|
|
23718
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
23719
|
-
}
|
|
23720
|
-
function lstatIfPresent(path) {
|
|
23721
|
-
try {
|
|
23722
|
-
return lstatSync4(path);
|
|
23723
|
-
} catch (error) {
|
|
23724
|
-
if (error?.code === "ENOENT") return null;
|
|
23725
|
-
throw error;
|
|
23726
|
-
}
|
|
23727
|
-
}
|
|
23728
23865
|
function composeProjectedInstruction(sources, platformInstructions) {
|
|
23729
23866
|
const platformBlock = [
|
|
23730
23867
|
'<mirrorx-platform-instructions priority="platform">',
|
|
@@ -23752,7 +23889,7 @@ ${repositoryBlock}
|
|
|
23752
23889
|
}
|
|
23753
23890
|
function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
23754
23891
|
const pending = [];
|
|
23755
|
-
let current =
|
|
23892
|
+
let current = dirname6(targetPath);
|
|
23756
23893
|
while (current !== targetRoot) {
|
|
23757
23894
|
if (!pathWithin(current, targetRoot)) {
|
|
23758
23895
|
throw instructionTopologyError(
|
|
@@ -23761,11 +23898,11 @@ function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
|
23761
23898
|
);
|
|
23762
23899
|
}
|
|
23763
23900
|
pending.push(current);
|
|
23764
|
-
current =
|
|
23901
|
+
current = dirname6(current);
|
|
23765
23902
|
}
|
|
23766
23903
|
pending.push(targetRoot);
|
|
23767
23904
|
for (const directory of pending.reverse()) {
|
|
23768
|
-
if (!
|
|
23905
|
+
if (!existsSync7(directory)) {
|
|
23769
23906
|
mkdirSync5(directory, { mode: 448 });
|
|
23770
23907
|
continue;
|
|
23771
23908
|
}
|
|
@@ -23778,7 +23915,7 @@ function assertProjectionTargetAncestors(targetPath, targetRoot) {
|
|
|
23778
23915
|
}
|
|
23779
23916
|
}
|
|
23780
23917
|
}
|
|
23781
|
-
function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, executionWorkspacePath, platformInstructions) {
|
|
23918
|
+
function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, executionWorkspacePath, platformInstructions, options = {}) {
|
|
23782
23919
|
const sourceRoot = resolve4(sourceWorkspacePath);
|
|
23783
23920
|
const targetRoot = resolve4(executionWorkspacePath);
|
|
23784
23921
|
if (sourceRoot === targetRoot || !platformInstructions?.trim()) {
|
|
@@ -23787,7 +23924,7 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23787
23924
|
sourceRoot === targetRoot ? "source and isolated execution workspaces must differ" : "MirrorX platform instructions are missing"
|
|
23788
23925
|
);
|
|
23789
23926
|
}
|
|
23790
|
-
const inspection = inspectExternalWorkspaceProjectInstructions(sourceRoot);
|
|
23927
|
+
const inspection = inspectExternalWorkspaceProjectInstructions(sourceRoot, options);
|
|
23791
23928
|
const sourcesByScope = /* @__PURE__ */ new Map();
|
|
23792
23929
|
for (const source of inspection.sources) {
|
|
23793
23930
|
const entries = sourcesByScope.get(source.scope) ?? [];
|
|
@@ -23810,7 +23947,7 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23810
23947
|
`project instruction source changed during projection: ${source.path}`
|
|
23811
23948
|
);
|
|
23812
23949
|
}
|
|
23813
|
-
const sourceContent =
|
|
23950
|
+
const sourceContent = readFileSync9(sourcePath, "utf8");
|
|
23814
23951
|
const sourceSha256 = createHash8("sha256").update(sourceContent, "utf8").digest("hex");
|
|
23815
23952
|
if (sourceSha256 !== source.sha256) {
|
|
23816
23953
|
throw instructionTopologyError(
|
|
@@ -23849,10 +23986,10 @@ function projectExternalWorkspaceProjectInstructions(sourceWorkspacePath, execut
|
|
|
23849
23986
|
assertProjectionTargetAncestors(targetPath, targetRoot);
|
|
23850
23987
|
const temporaryPath = `${targetPath}.mirrorx-${randomBytes2(12).toString("hex")}.tmp`;
|
|
23851
23988
|
try {
|
|
23852
|
-
|
|
23853
|
-
|
|
23989
|
+
writeFileSync7(temporaryPath, projectedContent, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
23990
|
+
renameSync6(temporaryPath, targetPath);
|
|
23854
23991
|
} finally {
|
|
23855
|
-
|
|
23992
|
+
rmSync5(temporaryPath, { force: true });
|
|
23856
23993
|
}
|
|
23857
23994
|
modelFacingFile = "AGENTS.md";
|
|
23858
23995
|
modelFacingBytes = Buffer.byteLength(projectedContent, "utf8");
|
|
@@ -23923,9 +24060,9 @@ function agentInstructionDeliveryAudit(bundle, delivery) {
|
|
|
23923
24060
|
}
|
|
23924
24061
|
|
|
23925
24062
|
// src/amaster-runtime-daemon/config-state.mjs
|
|
23926
|
-
import { existsSync as
|
|
24063
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync7, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
23927
24064
|
import { homedir as homedir2, hostname } from "node:os";
|
|
23928
|
-
import { dirname as
|
|
24065
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
23929
24066
|
var CAPABILITIES = [
|
|
23930
24067
|
"remote_registration",
|
|
23931
24068
|
"heartbeat",
|
|
@@ -23988,26 +24125,26 @@ function defaultMachineId() {
|
|
|
23988
24125
|
}
|
|
23989
24126
|
function runtimeHome(env) {
|
|
23990
24127
|
return expandHomePath(String(
|
|
23991
|
-
env.AMASTER_RUNTIME_STATE_HOME || env.AMASTER_RUNTIME_HOME ||
|
|
24128
|
+
env.AMASTER_RUNTIME_STATE_HOME || env.AMASTER_RUNTIME_HOME || join9(homedir2(), ".amaster-employee")
|
|
23992
24129
|
));
|
|
23993
24130
|
}
|
|
23994
24131
|
function stateFilePath(env) {
|
|
23995
|
-
return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) :
|
|
24132
|
+
return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) : join9(runtimeHome(env), "runtime-connector-state.json");
|
|
23996
24133
|
}
|
|
23997
24134
|
function corruptStatePath(path) {
|
|
23998
24135
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14);
|
|
23999
24136
|
const base = `${path}.corrupt-${timestamp}Z`;
|
|
24000
24137
|
let candidate = base;
|
|
24001
|
-
for (let suffix = 1;
|
|
24138
|
+
for (let suffix = 1; existsSync8(candidate); suffix += 1) {
|
|
24002
24139
|
candidate = `${base}.${suffix}`;
|
|
24003
24140
|
}
|
|
24004
24141
|
return candidate;
|
|
24005
24142
|
}
|
|
24006
24143
|
function readState(env) {
|
|
24007
24144
|
const path = stateFilePath(env);
|
|
24008
|
-
if (!
|
|
24145
|
+
if (!existsSync8(path)) return {};
|
|
24009
24146
|
try {
|
|
24010
|
-
const state = JSON.parse(
|
|
24147
|
+
const state = JSON.parse(readFileSync10(path, "utf8"));
|
|
24011
24148
|
if (!state || typeof state !== "object" || Array.isArray(state)) {
|
|
24012
24149
|
throw new TypeError("runtime connector state must be a JSON object");
|
|
24013
24150
|
}
|
|
@@ -24015,7 +24152,7 @@ function readState(env) {
|
|
|
24015
24152
|
} catch {
|
|
24016
24153
|
const quarantinePath = corruptStatePath(path);
|
|
24017
24154
|
try {
|
|
24018
|
-
|
|
24155
|
+
renameSync7(path, quarantinePath);
|
|
24019
24156
|
process.stderr.write(`AMaster runtime state was invalid and quarantined at ${quarantinePath}
|
|
24020
24157
|
`);
|
|
24021
24158
|
} catch (error) {
|
|
@@ -24029,17 +24166,17 @@ function readState(env) {
|
|
|
24029
24166
|
}
|
|
24030
24167
|
function writeState(env, state) {
|
|
24031
24168
|
const path = stateFilePath(env);
|
|
24032
|
-
mkdirSync6(
|
|
24169
|
+
mkdirSync6(dirname7(path), { recursive: true });
|
|
24033
24170
|
const temporaryPath = `${path}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
24034
24171
|
try {
|
|
24035
|
-
|
|
24172
|
+
writeFileSync8(temporaryPath, `${JSON.stringify(state, null, 2)}
|
|
24036
24173
|
`, {
|
|
24037
24174
|
flag: "wx",
|
|
24038
24175
|
mode: 384
|
|
24039
24176
|
});
|
|
24040
|
-
|
|
24177
|
+
renameSync7(temporaryPath, path);
|
|
24041
24178
|
} finally {
|
|
24042
|
-
|
|
24179
|
+
rmSync6(temporaryPath, { force: true });
|
|
24043
24180
|
}
|
|
24044
24181
|
}
|
|
24045
24182
|
function buildConfig(env = process.env, flags = {}) {
|
|
@@ -24051,10 +24188,10 @@ function buildConfig(env = process.env, flags = {}) {
|
|
|
24051
24188
|
const authHeader = String(flags.authHeader ?? env.AMASTER_CONNECTOR_AUTH_HEADER ?? "");
|
|
24052
24189
|
const home = runtimeHome(env);
|
|
24053
24190
|
const runtimeWorkspacesRoot = expandHomePath(
|
|
24054
|
-
String(flags.runtimeWorkspacesRoot ?? env.AMASTER_RUNTIME_WORKSPACES_ROOT ??
|
|
24191
|
+
String(flags.runtimeWorkspacesRoot ?? env.AMASTER_RUNTIME_WORKSPACES_ROOT ?? join9(home, "workspaces"))
|
|
24055
24192
|
);
|
|
24056
24193
|
const browserSessionStateRoot = expandHomePath(String(
|
|
24057
|
-
flags.browserSessionStateRoot ?? env.AMASTER_BROWSER_SESSION_STATE_ROOT ??
|
|
24194
|
+
flags.browserSessionStateRoot ?? env.AMASTER_BROWSER_SESSION_STATE_ROOT ?? join9(home, "browser-auth")
|
|
24058
24195
|
));
|
|
24059
24196
|
const piToolArgumentGuardModeValue = String(
|
|
24060
24197
|
flags.piToolArgumentGuardMode ?? env.AMASTER_PI_TOOL_ARGUMENT_GUARD_MODE ?? "shadow"
|
|
@@ -25906,7 +26043,7 @@ var bestEffortPostJson = bestEffortPostRuntimeConnectorJson;
|
|
|
25906
26043
|
|
|
25907
26044
|
// src/amaster-runtime-daemon/runtime-artifact-upload.mjs
|
|
25908
26045
|
import { createHash as createHash9 } from "node:crypto";
|
|
25909
|
-
import { closeSync as closeSync2, constants, fstatSync, lstatSync as lstatSync5, openSync as openSync2, readFileSync as
|
|
26046
|
+
import { closeSync as closeSync2, constants, fstatSync, lstatSync as lstatSync5, openSync as openSync2, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
25910
26047
|
import { isAbsolute as isAbsolute5, relative as relative4, resolve as resolve5 } from "node:path";
|
|
25911
26048
|
var SHA256_PATTERN3 = /^[a-f0-9]{64}$/;
|
|
25912
26049
|
function requiredString(value, name) {
|
|
@@ -25926,11 +26063,11 @@ function sameFileSnapshot(left, right) {
|
|
|
25926
26063
|
return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
25927
26064
|
}
|
|
25928
26065
|
function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime workspace file", options = {}) {
|
|
25929
|
-
const root =
|
|
26066
|
+
const root = realpathSync5(resolve5(rootPath));
|
|
25930
26067
|
const relativePath = ownedRelativePath(sourceRelativePath);
|
|
25931
26068
|
const sourcePath = resolve5(root, relativePath);
|
|
25932
26069
|
const pathStat = lstatSync5(sourcePath);
|
|
25933
|
-
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(
|
|
26070
|
+
if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(realpathSync5(sourcePath), root)) {
|
|
25934
26071
|
throw new Error(`${label} source is not an owned regular file`);
|
|
25935
26072
|
}
|
|
25936
26073
|
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
@@ -25958,11 +26095,11 @@ function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime w
|
|
|
25958
26095
|
);
|
|
25959
26096
|
}
|
|
25960
26097
|
}
|
|
25961
|
-
const body =
|
|
26098
|
+
const body = readFileSync11(descriptor);
|
|
25962
26099
|
options.afterRead?.({ sourcePath, descriptor });
|
|
25963
26100
|
const after = fstatSync(descriptor);
|
|
25964
26101
|
const pathAfter = lstatSync5(sourcePath);
|
|
25965
|
-
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(
|
|
26102
|
+
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(pathAfter, after) || !pathAfter.isFile() || pathAfter.isSymbolicLink() || !pathWithin2(realpathSync5(sourcePath), root) || body.length !== after.size) {
|
|
25966
26103
|
throw new Error(`${label} source changed during the governed read`);
|
|
25967
26104
|
}
|
|
25968
26105
|
return { body, relativePath, stat: after };
|
|
@@ -26243,105 +26380,8 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
|
|
|
26243
26380
|
|
|
26244
26381
|
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
26245
26382
|
import { createHash as createHash11 } from "node:crypto";
|
|
26246
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync7, realpathSync as
|
|
26247
|
-
import { basename as basename4, join as
|
|
26248
|
-
|
|
26249
|
-
// src/amaster-runtime-daemon/workspace-manifest.mjs
|
|
26250
|
-
import { chownSync as chownSync3, existsSync as existsSync8, readFileSync as readFileSync11, renameSync as renameSync7, rmSync as rmSync6, statSync as statSync3, writeFileSync as writeFileSync8 } from "node:fs";
|
|
26251
|
-
import { basename as basename3, dirname as dirname7, join as join8 } from "node:path";
|
|
26252
|
-
var WORKSPACE_MANIFEST_FILENAME = ".amaster-runtime.json";
|
|
26253
|
-
function syncManifestDirOwnership(manifestPath, deps = {}) {
|
|
26254
|
-
const stat = deps.statSync ?? statSync3;
|
|
26255
|
-
const chown = deps.chownSync ?? chownSync3;
|
|
26256
|
-
const geteuid = deps.geteuid ?? (typeof process.geteuid === "function" ? process.geteuid.bind(process) : () => null);
|
|
26257
|
-
try {
|
|
26258
|
-
if (geteuid() !== 0) return false;
|
|
26259
|
-
const dirStat = stat(dirname7(manifestPath));
|
|
26260
|
-
if (dirStat.uid === 0 && dirStat.gid === 0) return false;
|
|
26261
|
-
chown(manifestPath, dirStat.uid, dirStat.gid);
|
|
26262
|
-
return true;
|
|
26263
|
-
} catch {
|
|
26264
|
-
return false;
|
|
26265
|
-
}
|
|
26266
|
-
}
|
|
26267
|
-
function nowIso() {
|
|
26268
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
26269
|
-
}
|
|
26270
|
-
function workspaceManifestPath(workspaceOrCwd) {
|
|
26271
|
-
if (!workspaceOrCwd) return null;
|
|
26272
|
-
if (typeof workspaceOrCwd === "string") return join8(workspaceOrCwd, WORKSPACE_MANIFEST_FILENAME);
|
|
26273
|
-
if (typeof workspaceOrCwd.cwd === "string") return join8(workspaceOrCwd.cwd, WORKSPACE_MANIFEST_FILENAME);
|
|
26274
|
-
return null;
|
|
26275
|
-
}
|
|
26276
|
-
function readWorkspaceManifest(manifestPath) {
|
|
26277
|
-
if (!manifestPath || !existsSync8(manifestPath)) return null;
|
|
26278
|
-
try {
|
|
26279
|
-
const parsed = JSON.parse(readFileSync11(manifestPath, "utf8"));
|
|
26280
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
26281
|
-
} catch {
|
|
26282
|
-
return null;
|
|
26283
|
-
}
|
|
26284
|
-
}
|
|
26285
|
-
function writeWorkspaceManifest(manifestPath, manifest, deps) {
|
|
26286
|
-
const tempPath = join8(
|
|
26287
|
-
dirname7(manifestPath),
|
|
26288
|
-
`.${basename3(manifestPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
26289
|
-
);
|
|
26290
|
-
try {
|
|
26291
|
-
writeFileSync8(tempPath, `${JSON.stringify(manifest, null, 2)}
|
|
26292
|
-
`, { mode: 384 });
|
|
26293
|
-
renameSync7(tempPath, manifestPath);
|
|
26294
|
-
syncManifestDirOwnership(manifestPath, deps);
|
|
26295
|
-
} catch (err) {
|
|
26296
|
-
rmSync6(tempPath, { force: true });
|
|
26297
|
-
throw err;
|
|
26298
|
-
}
|
|
26299
|
-
return manifest;
|
|
26300
|
-
}
|
|
26301
|
-
function createWorkspaceManifest(workspace, input = {}) {
|
|
26302
|
-
const manifestPath = workspaceManifestPath(workspace);
|
|
26303
|
-
const createdAt = nowIso();
|
|
26304
|
-
const manifest = {
|
|
26305
|
-
version: 2,
|
|
26306
|
-
managed: true,
|
|
26307
|
-
sourceWorkspacePath: workspace.sourceWorkspacePath,
|
|
26308
|
-
managedCwd: workspace.cwd,
|
|
26309
|
-
executionWorkdir: workspace.cwd,
|
|
26310
|
-
executorKind: input.executorKind ?? null,
|
|
26311
|
-
executorHome: workspace.executorHome ?? null,
|
|
26312
|
-
commandId: input.commandId ?? null,
|
|
26313
|
-
generation: input.generation ?? null,
|
|
26314
|
-
runId: input.runId ?? null,
|
|
26315
|
-
issueId: input.issueId ?? null,
|
|
26316
|
-
workspaceKey: workspace.workspaceKey ?? null,
|
|
26317
|
-
issueKey: workspace.issueKey ?? null,
|
|
26318
|
-
runKey: workspace.runKey ?? null,
|
|
26319
|
-
createdAt,
|
|
26320
|
-
lastTouchedAt: createdAt,
|
|
26321
|
-
lastWorkspaceScanAt: null,
|
|
26322
|
-
artifactCandidateCount: 0,
|
|
26323
|
-
artifactCandidates: [],
|
|
26324
|
-
outboxPending: 0
|
|
26325
|
-
};
|
|
26326
|
-
return writeWorkspaceManifest(manifestPath, manifest);
|
|
26327
|
-
}
|
|
26328
|
-
function updateWorkspaceManifest(workspaceOrManifestPath, patch = {}) {
|
|
26329
|
-
const manifestPath = typeof workspaceOrManifestPath === "string" ? workspaceOrManifestPath : workspaceManifestPath(workspaceOrManifestPath);
|
|
26330
|
-
if (!manifestPath) return null;
|
|
26331
|
-
const current = readWorkspaceManifest(manifestPath) ?? {
|
|
26332
|
-
version: 2,
|
|
26333
|
-
managed: true,
|
|
26334
|
-
createdAt: nowIso()
|
|
26335
|
-
};
|
|
26336
|
-
const next = {
|
|
26337
|
-
...current,
|
|
26338
|
-
...patch,
|
|
26339
|
-
lastTouchedAt: nowIso()
|
|
26340
|
-
};
|
|
26341
|
-
return writeWorkspaceManifest(manifestPath, next);
|
|
26342
|
-
}
|
|
26343
|
-
|
|
26344
|
-
// src/amaster-runtime-daemon/workspace-guard.mjs
|
|
26383
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync7, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
|
|
26384
|
+
import { basename as basename4, join as join10, isAbsolute as isAbsolute6, relative as relative5, resolve as resolve6 } from "node:path";
|
|
26345
26385
|
function pathWithin3(candidate, root) {
|
|
26346
26386
|
const rel = relative5(root, candidate);
|
|
26347
26387
|
return rel === "" || !rel.startsWith("..") && !isAbsolute6(rel);
|
|
@@ -26350,10 +26390,10 @@ function resolveWorkspaceCwd(config, command) {
|
|
|
26350
26390
|
const payload = asRecord(command.payload);
|
|
26351
26391
|
const requested = readString(payload.workspacePath);
|
|
26352
26392
|
const fallback = config.workspaceBindings[0] ?? process.cwd();
|
|
26353
|
-
const cwd =
|
|
26393
|
+
const cwd = realpathSync6(resolve6(expandHomePath(requested ?? fallback)));
|
|
26354
26394
|
const allowlist = config.workspaceBindings.flatMap((entry) => {
|
|
26355
26395
|
try {
|
|
26356
|
-
return [
|
|
26396
|
+
return [realpathSync6(resolve6(expandHomePath(entry)))];
|
|
26357
26397
|
} catch {
|
|
26358
26398
|
return [];
|
|
26359
26399
|
}
|
|
@@ -26398,7 +26438,7 @@ function workspaceLabel(sourceWorkspacePath, payload) {
|
|
|
26398
26438
|
function workspacesRoot(config) {
|
|
26399
26439
|
const root = resolve6(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
|
|
26400
26440
|
mkdirSync7(root, { recursive: true });
|
|
26401
|
-
return
|
|
26441
|
+
return realpathSync6(root);
|
|
26402
26442
|
}
|
|
26403
26443
|
function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
26404
26444
|
const sourceWorkspacePath = resolveWorkspaceCwd(config, command);
|
|
@@ -26410,9 +26450,9 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
26410
26450
|
const workspaceKey = `${safeSegment(workspaceLabel(sourceWorkspacePath, payload), "workspace")}-${shortHash(sourceWorkspacePath)}`;
|
|
26411
26451
|
const issueKey = `${safeSegment(issueLabel(command, payload), "issue")}-${shortHash(issueId, 8)}`;
|
|
26412
26452
|
const runKey = `${safeSegment(runId, "run")}-${shortHash(runId, 8)}`;
|
|
26413
|
-
const runDir =
|
|
26414
|
-
const cwd =
|
|
26415
|
-
const executorHome =
|
|
26453
|
+
const runDir = join10(root, workspaceKey, issueKey, runKey);
|
|
26454
|
+
const cwd = join10(runDir, "workdir");
|
|
26455
|
+
const executorHome = join10(runDir, "executors", safeSegment(executorKind, "executor"));
|
|
26416
26456
|
mkdirSync7(cwd, { recursive: true });
|
|
26417
26457
|
mkdirSync7(executorHome, { recursive: true });
|
|
26418
26458
|
const workspace = {
|
|
@@ -26437,7 +26477,7 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
|
|
|
26437
26477
|
|
|
26438
26478
|
// src/amaster-runtime-daemon/workspace-gc.mjs
|
|
26439
26479
|
import { existsSync as existsSync10, readdirSync as readdirSync7, statSync as statSync5 } from "node:fs";
|
|
26440
|
-
import { join as
|
|
26480
|
+
import { join as join11, resolve as resolve7 } from "node:path";
|
|
26441
26481
|
function readIsoTime(value) {
|
|
26442
26482
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
26443
26483
|
const time = new Date(value).getTime();
|
|
@@ -26460,7 +26500,7 @@ function walkWorkdirs(root) {
|
|
|
26460
26500
|
}
|
|
26461
26501
|
for (const entry of entries) {
|
|
26462
26502
|
if (!entry.isDirectory()) continue;
|
|
26463
|
-
const fullPath =
|
|
26503
|
+
const fullPath = join11(current, entry.name);
|
|
26464
26504
|
if (entry.name === "workdir" && existsSync10(workspaceManifestPath(fullPath))) {
|
|
26465
26505
|
workdirs.push(fullPath);
|
|
26466
26506
|
continue;
|
|
@@ -26492,7 +26532,7 @@ function directorySizeBytes(path) {
|
|
|
26492
26532
|
continue;
|
|
26493
26533
|
}
|
|
26494
26534
|
for (const entry of entries) {
|
|
26495
|
-
stack.push(
|
|
26535
|
+
stack.push(join11(current, entry.name));
|
|
26496
26536
|
}
|
|
26497
26537
|
continue;
|
|
26498
26538
|
}
|
|
@@ -26578,7 +26618,7 @@ import {
|
|
|
26578
26618
|
unlinkSync as unlinkSync2,
|
|
26579
26619
|
writeFileSync as writeFileSync9
|
|
26580
26620
|
} from "node:fs";
|
|
26581
|
-
import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as
|
|
26621
|
+
import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as join12, parse as parse2, resolve as resolve8, sep as sep3 } from "node:path";
|
|
26582
26622
|
import { fileURLToPath } from "node:url";
|
|
26583
26623
|
var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
|
|
26584
26624
|
var MAX_PRESET_TEMPLATE_FILES = 256;
|
|
@@ -26628,7 +26668,7 @@ function readManifest(manifestPath, { strict }) {
|
|
|
26628
26668
|
}
|
|
26629
26669
|
function verifiedBundleFiles(sourceDir, manifest) {
|
|
26630
26670
|
return manifest.files.map((entry) => {
|
|
26631
|
-
const sourcePath =
|
|
26671
|
+
const sourcePath = join12(sourceDir, entry.name);
|
|
26632
26672
|
const stat = lstatSync6(sourcePath);
|
|
26633
26673
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
26634
26674
|
throw new Error(`preset_template_bundle_file_unsafe: ${entry.name}`);
|
|
@@ -26643,7 +26683,7 @@ function verifiedBundleFiles(sourceDir, manifest) {
|
|
|
26643
26683
|
function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
|
|
26644
26684
|
for (const entry of previousManifest.files) {
|
|
26645
26685
|
if (nextNames.has(entry.name)) continue;
|
|
26646
|
-
const targetPath =
|
|
26686
|
+
const targetPath = join12(targetDir, entry.name);
|
|
26647
26687
|
if (!existsSync11(targetPath)) continue;
|
|
26648
26688
|
const stat = lstatSync6(targetPath);
|
|
26649
26689
|
if (stat.isDirectory()) {
|
|
@@ -26658,7 +26698,7 @@ function materializeBundledPresetTemplates(input) {
|
|
|
26658
26698
|
if (sourceDir === targetDir || sourceDir.startsWith(`${targetDir}${sep3}`) || targetDir.startsWith(`${sourceDir}${sep3}`)) {
|
|
26659
26699
|
throw new Error("preset_template_source_target_overlap");
|
|
26660
26700
|
}
|
|
26661
|
-
const manifest = readManifest(
|
|
26701
|
+
const manifest = readManifest(join12(sourceDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: true });
|
|
26662
26702
|
const verifiedFiles = verifiedBundleFiles(sourceDir, manifest);
|
|
26663
26703
|
mkdirSync8(dirname8(targetDir), { recursive: true, mode: 493 });
|
|
26664
26704
|
const targetStat = lstatIfExists(targetDir);
|
|
@@ -26666,24 +26706,24 @@ function materializeBundledPresetTemplates(input) {
|
|
|
26666
26706
|
throw new Error("preset_template_target_root_unsafe");
|
|
26667
26707
|
}
|
|
26668
26708
|
mkdirSync8(targetDir, { recursive: true, mode: 493 });
|
|
26669
|
-
const previousManifest = readManifest(
|
|
26670
|
-
const stageDir = mkdtempSync(
|
|
26709
|
+
const previousManifest = readManifest(join12(targetDir, PRESET_TEMPLATE_MANIFEST_FILE), { strict: false });
|
|
26710
|
+
const stageDir = mkdtempSync(join12(dirname8(targetDir), ".mirrorx-preset-templates-"));
|
|
26671
26711
|
try {
|
|
26672
26712
|
for (const file of verifiedFiles) {
|
|
26673
|
-
const stagedPath =
|
|
26713
|
+
const stagedPath = join12(stageDir, file.name);
|
|
26674
26714
|
writeFileSync9(stagedPath, file.body, { mode: 292 });
|
|
26675
26715
|
chmodSync5(stagedPath, 292);
|
|
26676
|
-
renameSync8(stagedPath,
|
|
26716
|
+
renameSync8(stagedPath, join12(targetDir, file.name));
|
|
26677
26717
|
}
|
|
26678
26718
|
removeRetiredPresetFiles(targetDir, previousManifest, new Set(manifest.files.map((file) => file.name)));
|
|
26679
|
-
const stagedManifest =
|
|
26719
|
+
const stagedManifest = join12(stageDir, PRESET_TEMPLATE_MANIFEST_FILE);
|
|
26680
26720
|
writeFileSync9(stagedManifest, `${JSON.stringify({
|
|
26681
26721
|
schemaVersion: manifest.schemaVersion,
|
|
26682
26722
|
files: manifest.files
|
|
26683
26723
|
}, null, 2)}
|
|
26684
26724
|
`, { mode: 292 });
|
|
26685
26725
|
chmodSync5(stagedManifest, 292);
|
|
26686
|
-
renameSync8(stagedManifest,
|
|
26726
|
+
renameSync8(stagedManifest, join12(targetDir, PRESET_TEMPLATE_MANIFEST_FILE));
|
|
26687
26727
|
} finally {
|
|
26688
26728
|
rmSync7(stageDir, { recursive: true, force: true });
|
|
26689
26729
|
}
|
|
@@ -26712,7 +26752,7 @@ function materializeRuntimePresetTemplates(env = process.env, options = {}) {
|
|
|
26712
26752
|
|
|
26713
26753
|
// src/amaster-runtime-daemon/runtime-status-summary.mjs
|
|
26714
26754
|
import { existsSync as existsSync12, readdirSync as readdirSync9, statSync as statSync6 } from "node:fs";
|
|
26715
|
-
import { dirname as dirname9, join as
|
|
26755
|
+
import { dirname as dirname9, join as join13, resolve as resolve9 } from "node:path";
|
|
26716
26756
|
function runtimeStatusDirectoryEntries(path) {
|
|
26717
26757
|
try {
|
|
26718
26758
|
return readdirSync9(path, { withFileTypes: true });
|
|
@@ -26735,7 +26775,7 @@ function runtimeStatusDirectorySizeBytes(path) {
|
|
|
26735
26775
|
if (!stat || stat.isSymbolicLink()) continue;
|
|
26736
26776
|
if (stat.isDirectory()) {
|
|
26737
26777
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
26738
|
-
stack.push(
|
|
26778
|
+
stack.push(join13(current, entry.name));
|
|
26739
26779
|
}
|
|
26740
26780
|
continue;
|
|
26741
26781
|
}
|
|
@@ -26752,7 +26792,7 @@ function walkRuntimeStatusManagedWorkdirs(root) {
|
|
|
26752
26792
|
if (!current) continue;
|
|
26753
26793
|
for (const entry of runtimeStatusDirectoryEntries(current)) {
|
|
26754
26794
|
if (!entry.isDirectory()) continue;
|
|
26755
|
-
const fullPath =
|
|
26795
|
+
const fullPath = join13(current, entry.name);
|
|
26756
26796
|
if (entry.name === "workdir" && existsSync12(workspaceManifestPath(fullPath))) {
|
|
26757
26797
|
workdirs.push(fullPath);
|
|
26758
26798
|
continue;
|
|
@@ -26794,7 +26834,7 @@ function summarizeRuntimeStatusRecentRun(workdir, manifest) {
|
|
|
26794
26834
|
}
|
|
26795
26835
|
function runtimeStatusOutboxDir(config) {
|
|
26796
26836
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
26797
|
-
return
|
|
26837
|
+
return join13(dirname9(stateFilePath({
|
|
26798
26838
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
26799
26839
|
})), "result-outbox");
|
|
26800
26840
|
}
|
|
@@ -26802,7 +26842,7 @@ function runtimeStatusRunCompletionDir(config) {
|
|
|
26802
26842
|
const explicit = config.AMASTER_RUN_COMPLETION_STATE_DIR ?? config.runCompletionStateDir;
|
|
26803
26843
|
if (typeof explicit === "string" && explicit.trim()) return resolve9(explicit);
|
|
26804
26844
|
const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
|
|
26805
|
-
return
|
|
26845
|
+
return join13(dirname9(stateFilePath({
|
|
26806
26846
|
AMASTER_DAEMON_STATE_FILE: statePath
|
|
26807
26847
|
})), "run-completion-state");
|
|
26808
26848
|
}
|
|
@@ -26839,9 +26879,9 @@ function summarizeRuntimeLocalState(input) {
|
|
|
26839
26879
|
}
|
|
26840
26880
|
}
|
|
26841
26881
|
const pendingOutboxDir = runtimeStatusOutboxDir(config);
|
|
26842
|
-
const invalidOutboxDir =
|
|
26882
|
+
const invalidOutboxDir = join13(pendingOutboxDir, "invalid");
|
|
26843
26883
|
const pendingRunCompletionDir = runtimeStatusRunCompletionDir(config);
|
|
26844
|
-
const invalidRunCompletionDir =
|
|
26884
|
+
const invalidRunCompletionDir = join13(pendingRunCompletionDir, "invalid");
|
|
26845
26885
|
return {
|
|
26846
26886
|
managedWorkspacesRoot: root,
|
|
26847
26887
|
managedWorkdirCount: workdirs.length,
|
|
@@ -27454,7 +27494,7 @@ function readPiFinalContextAttestation(input) {
|
|
|
27454
27494
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
27455
27495
|
import { createHash as createHash14 } from "node:crypto";
|
|
27456
27496
|
import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
|
|
27457
|
-
import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as
|
|
27497
|
+
import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as join14, relative as relative6, resolve as resolve11 } from "node:path";
|
|
27458
27498
|
var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
|
|
27459
27499
|
var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
27460
27500
|
[".md", "markdown"],
|
|
@@ -27572,7 +27612,7 @@ function scanArtifactCandidates(cwd, opts = {}) {
|
|
|
27572
27612
|
if (entry.name.startsWith(".") && entry.name !== ".amaster-runtime.json") {
|
|
27573
27613
|
if (entry.name === ".git") continue;
|
|
27574
27614
|
}
|
|
27575
|
-
const fullPath =
|
|
27615
|
+
const fullPath = join14(current, entry.name);
|
|
27576
27616
|
const relativePath = normalizeRelativePath(root, fullPath);
|
|
27577
27617
|
if (!isSafeRelativePath(relativePath)) continue;
|
|
27578
27618
|
if (basename5(relativePath) === ".amaster-runtime.json") continue;
|
|
@@ -27650,7 +27690,7 @@ function sanitizeRuntimeService(entry) {
|
|
|
27650
27690
|
};
|
|
27651
27691
|
}
|
|
27652
27692
|
function readRuntimeServicesSnapshot(cwd) {
|
|
27653
|
-
const snapshotPath =
|
|
27693
|
+
const snapshotPath = join14(resolve11(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
|
|
27654
27694
|
if (!existsSync13(snapshotPath)) return [];
|
|
27655
27695
|
try {
|
|
27656
27696
|
const parsed = JSON.parse(readFileSync15(snapshotPath, "utf8"));
|
|
@@ -27897,7 +27937,7 @@ import {
|
|
|
27897
27937
|
} from "node:fs";
|
|
27898
27938
|
import { createServer as createHttpServer } from "node:http";
|
|
27899
27939
|
import { connect as connectTcp, isIP } from "node:net";
|
|
27900
|
-
import { dirname as dirname10, join as
|
|
27940
|
+
import { dirname as dirname10, join as join15, relative as relative7, resolve as resolve12 } from "node:path";
|
|
27901
27941
|
var MARKER_NAME = ".amaster-browser-session.json";
|
|
27902
27942
|
var HUMAN_LEASE_INACTIVITY_MS = 30 * 60 * 1e3;
|
|
27903
27943
|
var HUMAN_LEASE_HARD_CAP_MS = 2 * 60 * 60 * 1e3;
|
|
@@ -28154,7 +28194,7 @@ function exactProfile(stateRoot, payload, { create = false } = {}) {
|
|
|
28154
28194
|
mkdirSync9(profilePath, { mode: 448 });
|
|
28155
28195
|
chmodSync6(profilePath, 448);
|
|
28156
28196
|
writeFileSync10(
|
|
28157
|
-
|
|
28197
|
+
join15(profilePath, MARKER_NAME),
|
|
28158
28198
|
`${JSON.stringify(expectedOwner(payload))}
|
|
28159
28199
|
`,
|
|
28160
28200
|
{ encoding: "utf8", mode: 384, flag: "wx" }
|
|
@@ -28165,7 +28205,7 @@ function exactProfile(stateRoot, payload, { create = false } = {}) {
|
|
|
28165
28205
|
}
|
|
28166
28206
|
let owner;
|
|
28167
28207
|
try {
|
|
28168
|
-
owner = JSON.parse(readFileSync16(
|
|
28208
|
+
owner = JSON.parse(readFileSync16(join15(profilePath, MARKER_NAME), "utf8"));
|
|
28169
28209
|
} catch {
|
|
28170
28210
|
throw brokerError("browser_session_profile_owner_invalid");
|
|
28171
28211
|
}
|
|
@@ -28450,7 +28490,7 @@ function createBrowserSessionBroker({
|
|
|
28450
28490
|
if (resolve12(payload.userDataDir) !== expectedPath) {
|
|
28451
28491
|
throw brokerError("browser_session_profile_path_invalid");
|
|
28452
28492
|
}
|
|
28453
|
-
const marker = JSON.parse(readFileSync16(
|
|
28493
|
+
const marker = JSON.parse(readFileSync16(join15(expectedPath, MARKER_NAME), "utf8"));
|
|
28454
28494
|
if (marker.version !== 1 || typeof marker.provider !== "string" || !marker.provider.trim() || marker.companyId !== payload.companyId || marker.bindingId !== payload.bindingId || marker.localOpaqueRef !== payload.localOpaqueRef || marker.origin !== payload.origin) {
|
|
28455
28495
|
throw brokerError("browser_session_profile_owner_mismatch");
|
|
28456
28496
|
}
|
|
@@ -28613,7 +28653,7 @@ function createSourceCompletionStopPolicy({
|
|
|
28613
28653
|
}
|
|
28614
28654
|
|
|
28615
28655
|
// src/amaster-runtime-daemon.mjs
|
|
28616
|
-
var CONNECTOR_VERSION = "0.1.1-beta.
|
|
28656
|
+
var CONNECTOR_VERSION = "0.1.1-beta.126";
|
|
28617
28657
|
var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
|
|
28618
28658
|
var SOURCE_ACQUISITION_CAPABILITY2 = source_acquisition_compatibility_default.profileVersion;
|
|
28619
28659
|
var daemonRequire = createRequire(import.meta.url);
|
|
@@ -28661,7 +28701,7 @@ function resultOutboxPendingCount(config) {
|
|
|
28661
28701
|
try {
|
|
28662
28702
|
let pending = 0;
|
|
28663
28703
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json"))) {
|
|
28664
|
-
if (readValidResultOutboxEntryOrQuarantine(config, file,
|
|
28704
|
+
if (readValidResultOutboxEntryOrQuarantine(config, file, join16(dir, file))) {
|
|
28665
28705
|
pending += 1;
|
|
28666
28706
|
}
|
|
28667
28707
|
}
|
|
@@ -28673,15 +28713,15 @@ function resultOutboxPendingCount(config) {
|
|
|
28673
28713
|
function runCompletionStateDir(config) {
|
|
28674
28714
|
const explicit = readString(process.env.AMASTER_RUN_COMPLETION_STATE_DIR);
|
|
28675
28715
|
if (explicit) return resolve13(expandHomePath(explicit));
|
|
28676
|
-
return
|
|
28716
|
+
return join16(dirname11(stateFilePath(process.env)), "run-completion-state");
|
|
28677
28717
|
}
|
|
28678
28718
|
function runCompletionStateInvalidDir(config) {
|
|
28679
|
-
return
|
|
28719
|
+
return join16(runCompletionStateDir(config), "invalid");
|
|
28680
28720
|
}
|
|
28681
28721
|
function quarantineInvalidRunCompletionState(config, filePath, reason) {
|
|
28682
28722
|
const invalidDir = runCompletionStateInvalidDir(config);
|
|
28683
28723
|
mkdirSync10(invalidDir, { recursive: true, mode: 448 });
|
|
28684
|
-
const destination =
|
|
28724
|
+
const destination = join16(invalidDir, basename6(filePath));
|
|
28685
28725
|
try {
|
|
28686
28726
|
renameSync9(filePath, destination);
|
|
28687
28727
|
} catch {
|
|
@@ -28738,7 +28778,7 @@ function resultOutboxActiveRunCommands(config) {
|
|
|
28738
28778
|
const outboxPending = resultOutboxPendingCount(config);
|
|
28739
28779
|
const entries = [];
|
|
28740
28780
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json")).sort()) {
|
|
28741
|
-
const entry = readValidResultOutboxEntryOrQuarantine(config, file,
|
|
28781
|
+
const entry = readValidResultOutboxEntryOrQuarantine(config, file, join16(dir, file));
|
|
28742
28782
|
if (!entry) continue;
|
|
28743
28783
|
const activeRun = asRecord(entry.activeRun);
|
|
28744
28784
|
const commandId = readString(activeRun.commandId) ?? readString(entry.commandId);
|
|
@@ -28773,7 +28813,7 @@ function resultOutboxFailedRunCommands(config) {
|
|
|
28773
28813
|
for (const file of readdirSync11(dir).filter((name) => name.endsWith(".json")).sort().slice(-100)) {
|
|
28774
28814
|
let entry;
|
|
28775
28815
|
try {
|
|
28776
|
-
entry = asRecord(JSON.parse(readFileSync17(
|
|
28816
|
+
entry = asRecord(JSON.parse(readFileSync17(join16(dir, file), "utf8")));
|
|
28777
28817
|
} catch {
|
|
28778
28818
|
continue;
|
|
28779
28819
|
}
|
|
@@ -28883,10 +28923,10 @@ function safeSkillRootSummary(kind, source, pathValue) {
|
|
|
28883
28923
|
try {
|
|
28884
28924
|
for (const name of readdirSync11(pathValue)) {
|
|
28885
28925
|
if (name.startsWith(".")) continue;
|
|
28886
|
-
const skillDir =
|
|
28926
|
+
const skillDir = join16(pathValue, name);
|
|
28887
28927
|
try {
|
|
28888
28928
|
if (!statSync9(skillDir).isDirectory()) continue;
|
|
28889
|
-
if (!existsSync15(
|
|
28929
|
+
if (!existsSync15(join16(skillDir, "SKILL.md"))) continue;
|
|
28890
28930
|
skillCount += 1;
|
|
28891
28931
|
if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
|
|
28892
28932
|
truncated = true;
|
|
@@ -28937,7 +28977,7 @@ function objectKeyCount(value) {
|
|
|
28937
28977
|
return value && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).length : 0;
|
|
28938
28978
|
}
|
|
28939
28979
|
function defaultPiCodingAgentDir() {
|
|
28940
|
-
return
|
|
28980
|
+
return join16(homedir3(), ".pi", "agent");
|
|
28941
28981
|
}
|
|
28942
28982
|
function piCapabilitySourcesDiagnostics() {
|
|
28943
28983
|
const configuredPiCodingAgentDir = safeExpandPath(process.env.PI_CODING_AGENT_DIR);
|
|
@@ -28946,14 +28986,14 @@ function piCapabilitySourcesDiagnostics() {
|
|
|
28946
28986
|
const configuredPiAgentHome = safeExpandPath(process.env.PI_AGENT_HOME);
|
|
28947
28987
|
const piAgentHome = configuredPiAgentHome ?? piCodingAgentDir;
|
|
28948
28988
|
const piAgentHomeSource = configuredPiAgentHome ? "PI_AGENT_HOME" : piCodingAgentDirSource;
|
|
28949
|
-
const userSkillsPath = piAgentHome ?
|
|
28989
|
+
const userSkillsPath = piAgentHome ? join16(piAgentHome, "skills") : null;
|
|
28950
28990
|
const configuredMarketplaceSkillsPath = safeExpandPath(
|
|
28951
28991
|
process.env.PI_AGENT_MARKETPLACE_SKILLS_DIR
|
|
28952
28992
|
);
|
|
28953
|
-
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ?
|
|
28993
|
+
const marketplaceSkillsPath = configuredMarketplaceSkillsPath ?? (piAgentHome ? join16(piAgentHome, "marketplace", "skills") : null);
|
|
28954
28994
|
const builtinSkillsPath = safeExpandPath(process.env.PI_AGENT_BUILTIN_SKILLS_DIR) ?? safeExpandPath(process.env.AMASTER_BUILTIN_SKILLS);
|
|
28955
|
-
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ?
|
|
28956
|
-
const settingsConfigPath = piCodingAgentDir ?
|
|
28995
|
+
const mcpConfigPath = safeExpandPath(process.env.PI_AGENT_MCP_SERVERS_FILE) ?? (piAgentHome ? join16(piAgentHome, "mcp.json") : null);
|
|
28996
|
+
const settingsConfigPath = piCodingAgentDir ? join16(piCodingAgentDir, "settings.json") : null;
|
|
28957
28997
|
const skillRoots = [
|
|
28958
28998
|
safeSkillRootSummary("user", `${piAgentHomeSource}/skills`, userSkillsPath),
|
|
28959
28999
|
safeSkillRootSummary(
|
|
@@ -29073,7 +29113,7 @@ function buildExecutorReadiness(config) {
|
|
|
29073
29113
|
function sourceAcquisitionPackageMetadata(packageName, location = "pi-config") {
|
|
29074
29114
|
const packageBase = location === "runtime" ? readString(process.env.PI_RUNTIME_ROOT) : readString(process.env.PI_CODING_AGENT_DIR ?? process.env.PI_AGENT_HOME);
|
|
29075
29115
|
if (!packageBase) return null;
|
|
29076
|
-
const packagePath =
|
|
29116
|
+
const packagePath = join16(
|
|
29077
29117
|
resolve13(expandHomePath(packageBase)),
|
|
29078
29118
|
...location === "runtime" ? [] : ["npm"],
|
|
29079
29119
|
"node_modules",
|
|
@@ -29538,7 +29578,7 @@ AMASTER_WORKSPACE_ALLOWLIST=${quoteShell(config.workspaceBindings.join(","))}
|
|
|
29538
29578
|
AMASTER_EXECUTORS=${quoteShell(executorEnv)}
|
|
29539
29579
|
AMASTER_CAPABILITIES=${quoteShell(config.capabilities.join(","))}
|
|
29540
29580
|
AMASTER_NETWORK_DOMAINS=${quoteShell(config.networkDomains.join(","))}
|
|
29541
|
-
AMASTER_DAEMON_STATE_FILE=${quoteShell(
|
|
29581
|
+
AMASTER_DAEMON_STATE_FILE=${quoteShell(join16(homedir3(), ".amaster-employee", "runtime-connector-state.json"))}
|
|
29542
29582
|
EOF
|
|
29543
29583
|
|
|
29544
29584
|
set -a
|
|
@@ -29966,7 +30006,7 @@ async function sourceAcquisitionRuntimeProfile(config, command) {
|
|
|
29966
30006
|
const stateRoot = resolve13(config.browserSessionStateRoot);
|
|
29967
30007
|
const userDataDir = resolve13(stateRoot, profileName2);
|
|
29968
30008
|
if (!pathWithin3(userDataDir, stateRoot)) throw new Error("source_acquisition_browser_profile_invalid");
|
|
29969
|
-
const markerPath =
|
|
30009
|
+
const markerPath = join16(userDataDir, ".amaster-browser-session.json");
|
|
29970
30010
|
if (!existsSync15(userDataDir) || lstatSync9(userDataDir).isSymbolicLink() || !lstatSync9(userDataDir).isDirectory() || !existsSync15(markerPath) || lstatSync9(markerPath).isSymbolicLink()) throw new Error("source_acquisition_browser_profile_invalid");
|
|
29971
30011
|
const marker = readJsonFile2(markerPath);
|
|
29972
30012
|
if (marker.version !== 1 || marker.companyId !== companyId || marker.bindingId !== bindingId || marker.localOpaqueRef !== localOpaqueRef || !readString(marker.provider) || !inspection.sourceOrigins.includes(marker.origin) || Object.keys(marker).length !== 6) {
|
|
@@ -30172,7 +30212,7 @@ function wikiTreePathForCommand(command, workspaceBindings) {
|
|
|
30172
30212
|
const candidates = [];
|
|
30173
30213
|
if (root.endsWith("paperclipai.plugin-llm-wiki")) candidates.push(root);
|
|
30174
30214
|
if (basename6(root) === "plugin-data" && companyId) {
|
|
30175
|
-
candidates.push(
|
|
30215
|
+
candidates.push(join16(root, companyId, "paperclipai.plugin-llm-wiki"));
|
|
30176
30216
|
}
|
|
30177
30217
|
for (const candidate of candidates) {
|
|
30178
30218
|
try {
|
|
@@ -30324,7 +30364,7 @@ function attachPiOutputReserve(profile, outputReserveTokens) {
|
|
|
30324
30364
|
if (!profile?.profileRoot || !Number.isSafeInteger(outputReserveTokens) || outputReserveTokens < 1) {
|
|
30325
30365
|
throw new Error("context_envelope_output_reserve_invalid");
|
|
30326
30366
|
}
|
|
30327
|
-
const extensionPath =
|
|
30367
|
+
const extensionPath = join16(profile.profileRoot, "context-output-reserve.js");
|
|
30328
30368
|
writeFileSync11(
|
|
30329
30369
|
extensionPath,
|
|
30330
30370
|
modelCallOutputContractExtensionSource(outputReserveTokens),
|
|
@@ -30351,13 +30391,13 @@ function attachPiFinalContextAttestor(profile, input) {
|
|
|
30351
30391
|
if (!projectInstruction || !/^[a-f0-9]{64}$/.test(readString(projectInstruction.sha256) ?? "")) {
|
|
30352
30392
|
throw new Error("model_context_attestation_unavailable: final AGENTS.md receipt is missing");
|
|
30353
30393
|
}
|
|
30354
|
-
const extensionPath =
|
|
30355
|
-
const projectInstructionExtensionPath =
|
|
30394
|
+
const extensionPath = join16(profile.profileRoot, "extensions", MANAGED_PI_FINAL_CONTEXT_ATTESTOR_FILENAME);
|
|
30395
|
+
const projectInstructionExtensionPath = join16(
|
|
30356
30396
|
profile.profileRoot,
|
|
30357
30397
|
"extensions",
|
|
30358
30398
|
MANAGED_PI_PROJECT_INSTRUCTION_FILENAME
|
|
30359
30399
|
);
|
|
30360
|
-
const receiptPath =
|
|
30400
|
+
const receiptPath = join16(profile.profileRoot, "tmp", "final-model-context-receipt.json");
|
|
30361
30401
|
const contract = {
|
|
30362
30402
|
receiptPath,
|
|
30363
30403
|
projectInstructionPath: resolve13(input.cwd, "AGENTS.md"),
|
|
@@ -30417,17 +30457,17 @@ function buildExecutorEnv(config, command, workspace) {
|
|
|
30417
30457
|
};
|
|
30418
30458
|
}
|
|
30419
30459
|
function preparePiModelCallProfile(commandId, baseEnv, options = {}) {
|
|
30420
|
-
const profileRoot = mkdtempSync2(
|
|
30421
|
-
const home =
|
|
30422
|
-
const sessionsDir =
|
|
30423
|
-
const tempDir =
|
|
30460
|
+
const profileRoot = mkdtempSync2(join16(tmpdir(), "amaster-pi-model-call-"));
|
|
30461
|
+
const home = join16(profileRoot, "home");
|
|
30462
|
+
const sessionsDir = join16(profileRoot, "sessions");
|
|
30463
|
+
const tempDir = join16(profileRoot, "tmp");
|
|
30424
30464
|
for (const directory of [home, sessionsDir, tempDir]) {
|
|
30425
30465
|
mkdirSync10(directory, { recursive: true, mode: 448 });
|
|
30426
30466
|
}
|
|
30427
30467
|
try {
|
|
30428
30468
|
const extensionArgs = [];
|
|
30429
30469
|
if (options.responseContract) {
|
|
30430
|
-
const extensionPath =
|
|
30470
|
+
const extensionPath = join16(profileRoot, "model-call-output-contract.js");
|
|
30431
30471
|
writeFileSync11(
|
|
30432
30472
|
extensionPath,
|
|
30433
30473
|
modelCallOutputContractExtensionSource(options.responseContract.maxOutputTokens),
|
|
@@ -30491,7 +30531,7 @@ function resolveNativeSessionRequest(command, workspace) {
|
|
|
30491
30531
|
let cwdMatched = false;
|
|
30492
30532
|
if (requestedCwd && sourceWorkspacePath) {
|
|
30493
30533
|
try {
|
|
30494
|
-
cwdMatched =
|
|
30534
|
+
cwdMatched = realpathSync7(requestedCwd) === realpathSync7(sourceWorkspacePath);
|
|
30495
30535
|
} catch {
|
|
30496
30536
|
cwdMatched = resolve13(requestedCwd) === resolve13(sourceWorkspacePath);
|
|
30497
30537
|
}
|
|
@@ -31097,7 +31137,7 @@ function sampleProcessGroupRssBytes(processGroupId) {
|
|
|
31097
31137
|
}
|
|
31098
31138
|
function realOrResolvedPath(value) {
|
|
31099
31139
|
try {
|
|
31100
|
-
return
|
|
31140
|
+
return realpathSync7(value);
|
|
31101
31141
|
} catch {
|
|
31102
31142
|
return resolve13(value);
|
|
31103
31143
|
}
|
|
@@ -31106,7 +31146,7 @@ var LSOF_COMMAND = process.platform === "darwin" && existsSync15("/usr/sbin/lsof
|
|
|
31106
31146
|
function processCwdForPid(pid) {
|
|
31107
31147
|
if (process.platform === "linux") {
|
|
31108
31148
|
try {
|
|
31109
|
-
return
|
|
31149
|
+
return realpathSync7(`/proc/${pid}/cwd`);
|
|
31110
31150
|
} catch {
|
|
31111
31151
|
return null;
|
|
31112
31152
|
}
|
|
@@ -31237,7 +31277,7 @@ function walkManagedWorkdirs(root) {
|
|
|
31237
31277
|
}
|
|
31238
31278
|
for (const entry of entries) {
|
|
31239
31279
|
if (!entry.isDirectory()) continue;
|
|
31240
|
-
const fullPath =
|
|
31280
|
+
const fullPath = join16(current, entry.name);
|
|
31241
31281
|
if (entry.name === "workdir" && existsSync15(workspaceManifestPath(fullPath))) {
|
|
31242
31282
|
workdirs.push(fullPath);
|
|
31243
31283
|
continue;
|
|
@@ -32970,10 +33010,10 @@ async function completeCommand(config, command, status, result3, error) {
|
|
|
32970
33010
|
function resultOutboxDir(config) {
|
|
32971
33011
|
const explicit = readString(process.env.AMASTER_RESULT_OUTBOX_DIR);
|
|
32972
33012
|
if (explicit) return resolve13(expandHomePath(explicit));
|
|
32973
|
-
return
|
|
33013
|
+
return join16(dirname11(stateFilePath(process.env)), "result-outbox");
|
|
32974
33014
|
}
|
|
32975
33015
|
function resultOutboxInvalidDir(config) {
|
|
32976
|
-
return
|
|
33016
|
+
return join16(resultOutboxDir(config), "invalid");
|
|
32977
33017
|
}
|
|
32978
33018
|
function writeResultOutboxEntry(config, entry) {
|
|
32979
33019
|
const dir = resultOutboxDir(config);
|
|
@@ -32985,13 +33025,13 @@ function writeResultOutboxEntry(config, entry) {
|
|
|
32985
33025
|
lastAttemptAt: null,
|
|
32986
33026
|
...entry
|
|
32987
33027
|
};
|
|
32988
|
-
writeFileSync11(
|
|
33028
|
+
writeFileSync11(join16(dir, resultOutboxFileName(entry.commandId)), `${JSON.stringify(body, null, 2)}
|
|
32989
33029
|
`, { mode: 384 });
|
|
32990
33030
|
}
|
|
32991
33031
|
function moveResultOutboxEntryToInvalid(config, file, fullPath, reason, detail, original) {
|
|
32992
33032
|
const invalidDir = resultOutboxInvalidDir(config);
|
|
32993
33033
|
mkdirSync10(invalidDir, { recursive: true });
|
|
32994
|
-
const invalidPath =
|
|
33034
|
+
const invalidPath = join16(invalidDir, file);
|
|
32995
33035
|
if (original === void 0) {
|
|
32996
33036
|
try {
|
|
32997
33037
|
renameSync9(fullPath, invalidPath);
|
|
@@ -33058,7 +33098,7 @@ function quarantineResultOutboxEntry(config, fullPath, file, entry, reason, err)
|
|
|
33058
33098
|
...typeof err?.httpStatus === "number" ? { httpStatus: err.httpStatus } : {},
|
|
33059
33099
|
lastError: truncateText(err instanceof Error ? err.message : String(err), 1e3)
|
|
33060
33100
|
};
|
|
33061
|
-
const invalidPath =
|
|
33101
|
+
const invalidPath = join16(invalidDir, file);
|
|
33062
33102
|
writeFileSync11(invalidPath, `${JSON.stringify(body, null, 2)}
|
|
33063
33103
|
`, { mode: 384 });
|
|
33064
33104
|
try {
|
|
@@ -33077,7 +33117,7 @@ async function flushResultOutbox(config) {
|
|
|
33077
33117
|
const files = readdirSync11(dir).filter((name) => name.endsWith(".json")).sort();
|
|
33078
33118
|
let completed = 0;
|
|
33079
33119
|
for (const file of files) {
|
|
33080
|
-
const fullPath =
|
|
33120
|
+
const fullPath = join16(dir, file);
|
|
33081
33121
|
const entry = readValidResultOutboxEntryOrQuarantine(config, file, fullPath);
|
|
33082
33122
|
if (!entry) continue;
|
|
33083
33123
|
try {
|
|
@@ -33274,7 +33314,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
33274
33314
|
runtimeAuth,
|
|
33275
33315
|
issueId
|
|
33276
33316
|
);
|
|
33277
|
-
const targetDir =
|
|
33317
|
+
const targetDir = join16(workspace.cwd, "input-attachments");
|
|
33278
33318
|
mkdirSync10(targetDir, { recursive: true });
|
|
33279
33319
|
const usedFilenames = /* @__PURE__ */ new Set();
|
|
33280
33320
|
const materialized = [];
|
|
@@ -33289,7 +33329,7 @@ async function materializeIssueAttachments(config, command, workspace) {
|
|
|
33289
33329
|
filename = `${stem}-${index + 1}${ext}`;
|
|
33290
33330
|
}
|
|
33291
33331
|
usedFilenames.add(filename);
|
|
33292
|
-
const targetPath =
|
|
33332
|
+
const targetPath = join16(targetDir, filename);
|
|
33293
33333
|
const body = await runtimeApiBuffer(runtimeAuth, contentPath);
|
|
33294
33334
|
writeFileSync11(targetPath, body);
|
|
33295
33335
|
const attachmentId = readString(attachment.id);
|
|
@@ -33365,7 +33405,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33365
33405
|
if (manifest.version !== 1 || !Array.isArray(manifest.entries)) {
|
|
33366
33406
|
throw new Error("artifact_input_manifest_invalid: expected version 1 entries array");
|
|
33367
33407
|
}
|
|
33368
|
-
const targetRoot =
|
|
33408
|
+
const targetRoot = join16(workspace.cwd, "input-artifacts");
|
|
33369
33409
|
rmSync9(targetRoot, { recursive: true, force: true });
|
|
33370
33410
|
mkdirSync10(targetRoot, { recursive: true });
|
|
33371
33411
|
const usedPaths = /* @__PURE__ */ new Set();
|
|
@@ -33396,15 +33436,15 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33396
33436
|
id: attachmentId,
|
|
33397
33437
|
originalFilename: readString(entry.originalFilename)
|
|
33398
33438
|
}, index);
|
|
33399
|
-
let relativePath =
|
|
33439
|
+
let relativePath = join16("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
33400
33440
|
if (usedPaths.has(relativePath)) {
|
|
33401
33441
|
const ext = extname3(filename);
|
|
33402
33442
|
const stem = ext ? filename.slice(0, -ext.length) : filename;
|
|
33403
33443
|
filename = `${stem}-${index + 1}${ext}`;
|
|
33404
|
-
relativePath =
|
|
33444
|
+
relativePath = join16("input-artifacts", sourceDir, filename).split(/[\\/]+/).join("/");
|
|
33405
33445
|
}
|
|
33406
33446
|
usedPaths.add(relativePath);
|
|
33407
|
-
const targetPath =
|
|
33447
|
+
const targetPath = join16(workspace.cwd, relativePath);
|
|
33408
33448
|
mkdirSync10(dirname11(targetPath), { recursive: true });
|
|
33409
33449
|
writeFileSync11(targetPath, body);
|
|
33410
33450
|
chmodSync7(targetPath, 292);
|
|
@@ -33426,7 +33466,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33426
33466
|
version: 1,
|
|
33427
33467
|
entries: materialized.map(({ path: _path, relativePath, ...entry }) => ({ ...entry, path: relativePath }))
|
|
33428
33468
|
};
|
|
33429
|
-
const manifestPath =
|
|
33469
|
+
const manifestPath = join16(targetRoot, "artifact-input-manifest.json");
|
|
33430
33470
|
writeFileSync11(manifestPath, JSON.stringify(localManifest, null, 2) + "\n");
|
|
33431
33471
|
chmodSync7(manifestPath, 292);
|
|
33432
33472
|
updateWorkspaceManifest(workspaceManifestPath(workspace), { artifactInputManifest: localManifest });
|
|
@@ -33437,7 +33477,7 @@ async function materializeRequiredArtifactInputs(config, command, workspace) {
|
|
|
33437
33477
|
return materialized;
|
|
33438
33478
|
}
|
|
33439
33479
|
function issueCheckpointDir(workspace) {
|
|
33440
|
-
return
|
|
33480
|
+
return join16(dirname11(workspace.runDir), "checkpoint");
|
|
33441
33481
|
}
|
|
33442
33482
|
async function clearIssueCheckpoint(config, command, workspace, reason) {
|
|
33443
33483
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
@@ -33459,7 +33499,7 @@ function hashFileSha256(filePath) {
|
|
|
33459
33499
|
}
|
|
33460
33500
|
async function materializeIssueCheckpoint(config, command, workspace) {
|
|
33461
33501
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
33462
|
-
const manifestPath =
|
|
33502
|
+
const manifestPath = join16(checkpointDir, "manifest.json");
|
|
33463
33503
|
if (!existsSync15(manifestPath)) return [];
|
|
33464
33504
|
let manifest;
|
|
33465
33505
|
try {
|
|
@@ -33476,8 +33516,8 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33476
33516
|
try {
|
|
33477
33517
|
const files = Array.isArray(manifest.files) ? manifest.files : [];
|
|
33478
33518
|
if (files.length > 20) throw new Error("issue checkpoint manifest exceeds the limit of 20 files");
|
|
33479
|
-
const filesRoot =
|
|
33480
|
-
const workspaceRoot =
|
|
33519
|
+
const filesRoot = realpathSync7(join16(checkpointDir, "files"));
|
|
33520
|
+
const workspaceRoot = realpathSync7(workspace.cwd);
|
|
33481
33521
|
const validated = [];
|
|
33482
33522
|
let totalBytes = 0;
|
|
33483
33523
|
for (const rawFile of files) {
|
|
@@ -33490,7 +33530,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33490
33530
|
throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
|
|
33491
33531
|
}
|
|
33492
33532
|
if (!existsSync15(sourceCandidate)) throw new Error(`issue checkpoint file is missing: ${relativePath}`);
|
|
33493
|
-
const source =
|
|
33533
|
+
const source = realpathSync7(sourceCandidate);
|
|
33494
33534
|
if (!pathWithin3(source, filesRoot) || !statSync9(source).isFile()) {
|
|
33495
33535
|
throw new Error(`issue checkpoint source escapes its storage root: ${relativePath}`);
|
|
33496
33536
|
}
|
|
@@ -33515,7 +33555,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33515
33555
|
if (err?.code !== "ENOENT") throw err;
|
|
33516
33556
|
}
|
|
33517
33557
|
mkdirSync10(dirname11(target), { recursive: true });
|
|
33518
|
-
const targetParent =
|
|
33558
|
+
const targetParent = realpathSync7(dirname11(target));
|
|
33519
33559
|
if (!pathWithin3(targetParent, workspaceRoot)) {
|
|
33520
33560
|
throw new Error(`issue checkpoint target escapes its workspace: ${relativePath}`);
|
|
33521
33561
|
}
|
|
@@ -33543,17 +33583,17 @@ async function materializeIssueCheckpoint(config, command, workspace) {
|
|
|
33543
33583
|
}
|
|
33544
33584
|
async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
33545
33585
|
const checkpointDir = issueCheckpointDir(workspace);
|
|
33546
|
-
const filesDir =
|
|
33586
|
+
const filesDir = join16(checkpointDir, "files");
|
|
33547
33587
|
rmSync9(checkpointDir, { recursive: true, force: true });
|
|
33548
33588
|
mkdirSync10(filesDir, { recursive: true });
|
|
33549
33589
|
const files = [];
|
|
33550
33590
|
let totalBytes = 0;
|
|
33551
|
-
const workspaceRoot =
|
|
33591
|
+
const workspaceRoot = realpathSync7(workspace.cwd);
|
|
33552
33592
|
for (const candidate of candidates.slice(0, 20)) {
|
|
33553
33593
|
const relativePath = safeCheckpointRelativePath(candidate.rawPath);
|
|
33554
33594
|
const source = readString(candidate.filePath);
|
|
33555
33595
|
if (!relativePath || !source || !existsSync15(source) || !statSync9(source).isFile()) continue;
|
|
33556
|
-
const ownedSource =
|
|
33596
|
+
const ownedSource = realpathSync7(source);
|
|
33557
33597
|
if (!pathWithin3(ownedSource, workspaceRoot)) {
|
|
33558
33598
|
throw new Error(`issue checkpoint source escapes its execution workspace: ${relativePath}`);
|
|
33559
33599
|
}
|
|
@@ -33579,7 +33619,7 @@ async function saveIssueCheckpoint(config, command, workspace, candidates) {
|
|
|
33579
33619
|
totalBytes,
|
|
33580
33620
|
files
|
|
33581
33621
|
};
|
|
33582
|
-
writeFileSync11(
|
|
33622
|
+
writeFileSync11(join16(checkpointDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
33583
33623
|
`);
|
|
33584
33624
|
await ingestLog(config, command, "system", "warn", `Saved ${files.length} required deliverable(s) for continuation recovery`, manifest);
|
|
33585
33625
|
return manifest;
|
|
@@ -33637,7 +33677,8 @@ async function executeRunCommand(config, command) {
|
|
|
33637
33677
|
const workspaceProjectInstructionReceipt = projectExternalWorkspaceProjectInstructions(
|
|
33638
33678
|
workspace.sourceWorkspacePath,
|
|
33639
33679
|
workspace.cwd,
|
|
33640
|
-
readString(asRecord(contextContract.instructions.files)["AGENTS.md"])
|
|
33680
|
+
readString(asRecord(contextContract.instructions.files)["AGENTS.md"]),
|
|
33681
|
+
{ managedWorkspacesRoot: config.runtimeWorkspacesRoot }
|
|
33641
33682
|
);
|
|
33642
33683
|
const finalAgentInstructionFiles = new Map(
|
|
33643
33684
|
materializedAgentInstructions.map((entry) => [entry.path, entry])
|
|
@@ -33729,7 +33770,7 @@ async function executeRunCommand(config, command) {
|
|
|
33729
33770
|
executorCommand: invocation.command,
|
|
33730
33771
|
executorHome: workspace.executorHome,
|
|
33731
33772
|
runDir: workspace.runDir,
|
|
33732
|
-
runtimeCacheRoot:
|
|
33773
|
+
runtimeCacheRoot: join16(dirname11(config.daemonStateFile), "cache"),
|
|
33733
33774
|
cwd,
|
|
33734
33775
|
runtimeAuth: commandRuntimeAuth(command),
|
|
33735
33776
|
nativeSession: asRecord(asRecord(command.payload).nativeSession),
|
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.126";
|
|
10
10
|
|
|
11
11
|
const CAPABILITIES = [
|
|
12
12
|
"remote_registration",
|